Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1972 from LiskHQ/1971-update-schema-for-txpool-ge…
Browse files Browse the repository at this point in the history
…t-transactions-from-pool

Update schema for txpool_getTransactionsFromPool
  • Loading branch information
vardan10 authored Dec 6, 2023
2 parents fc1e256 + 33f360f commit 23b2767
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 20 deletions.
1 change: 1 addition & 0 deletions docker/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ LISK_APP_WS=ws://host.docker.internal:7887
# ENABLE_SNAPSHOT_ALLOW_INSECURE_HTTP=false
# ACCOUNT_BALANCE_UPDATE_BATCH_SIZE=1000
# INDEX_BLOCKS_QUEUE_SCHEDULED_JOB_MAX_COUNT=100000
# INVOKE_ALLOWED_METHODS='dynamicReward_getExpectedValidatorRewards,token_hasUserAccount,token_getInitializationFees,interoperability_getMinimumMessageFee,txpool_getTransactionsFromPool'

# Moleculer jobs configuration
# JOB_INTERVAL_DELETE_SERIALIZED_EVENTS=0
Expand Down
9 changes: 9 additions & 0 deletions docs/antora/modules/ROOT/pages/configuration/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,15 @@ By default, it is set to `100000`.
| Mainchain service URL for custom deployments.
| https://service.lisk.com

| `INVOKE_ALLOWED_METHODS`
| string
| List of allowed methods that can be invoked via the `/invoke` API endpoint.
The list can be expressed as a CSV.
To allow invocation of all endpoints, set it to `*`.
To allow invocation of all the registered methods under the specified namespaces, set it similar to `legacy,chain`.
To allow invocation of specific methods, set it similar to `chain_getBlocksByIDs,chain_getBlocksByHeight`.
| `*`, `legacy,chain`, `chain_getBlocksByIDs`

|===

==== Database snapshot configuration
Expand Down
1 change: 1 addition & 0 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ module.exports = {
// JOB_SCHEDULE_DELETE_FINALIZED_CCU_METADATA: '0 2 * * *',
// JOB_INTERVAL_TRIGGER_ACCOUNT_UPDATES: 0,
// JOB_SCHEDULE_TRIGGER_ACCOUNT_UPDATES: '*/15 * * * *',
// INVOKE_ALLOWED_METHODS: 'dynamicReward_getExpectedValidatorRewards,token_hasUserAccount,token_getInitializationFees,interoperability_getMinimumMessageFee,txpool_getTransactionsFromPool',
},
},
{
Expand Down
1 change: 1 addition & 0 deletions ecosystem.jenkins.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ module.exports = {
ENABLE_DATA_RETRIEVAL_MODE: true,
ENABLE_INDEXING_MODE: true,
ENABLE_PERSIST_EVENTS: false,
// INVOKE_ALLOWED_METHODS: 'dynamicReward_getExpectedValidatorRewards,token_hasUserAccount,token_getInitializationFees,interoperability_getMinimumMessageFee,txpool_getTransactionsFromPool',
},
},
{
Expand Down
104 changes: 90 additions & 14 deletions services/blockchain-connector/shared/sdk/constants/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,38 @@ const plainKeysObjectSchema = {
};

const engineEndpoints = [
{
name: 'legacy_getTransactionByID',
request: {
$id: '/lisk/legacy/getTransactionByIDRequest',
type: 'object',
required: ['id'],
properties: {
id: {
type: 'string',
format: 'hex',
minLength: 64,
maxLength: 64,
},
},
},
},
{
name: 'legacy_getTransactionsByBlockID',
request: {
$id: '/lisk/legacy/getTransactionsByBlockIDRequest',
type: 'object',
required: ['id'],
properties: {
id: {
type: 'string',
format: 'hex',
minLength: 64,
maxLength: 64,
},
},
},
},
{
name: 'legacy_getBlockByID',
request: {
Expand All @@ -108,8 +140,8 @@ const engineEndpoints = [
id: {
type: 'string',
format: 'hex',
minLength: 32,
maxLength: 32,
minLength: 64,
maxLength: 64,
},
},
},
Expand All @@ -128,6 +160,10 @@ const engineEndpoints = [
},
},
},
{
name: 'legacy_getLegacyBrackets',
request: null,
},
{
name: 'chain_getBlockByID',
request: {
Expand All @@ -138,8 +174,8 @@ const engineEndpoints = [
id: {
type: 'string',
format: 'hex',
minLength: 32,
maxLength: 32,
minLength: 64,
maxLength: 64,
},
},
},
Expand All @@ -156,8 +192,8 @@ const engineEndpoints = [
items: {
type: 'string',
format: 'hex',
minLength: 32,
maxLength: 32,
minLength: 64,
maxLength: 64,
},
},
},
Expand Down Expand Up @@ -205,8 +241,8 @@ const engineEndpoints = [
id: {
type: 'string',
format: 'hex',
minLength: 32,
maxLength: 32,
minLength: 64,
maxLength: 64,
},
},
},
Expand All @@ -223,8 +259,8 @@ const engineEndpoints = [
items: {
type: 'string',
format: 'hex',
minLength: 32,
maxLength: 32,
minLength: 64,
maxLength: 64,
},
},
},
Expand Down Expand Up @@ -327,6 +363,20 @@ const engineEndpoints = [
},
},
},
{
name: 'consensus_getBFTParametersActiveValidators',
request: {
$id: '/lisk/chain/getBFTParametersActiveValidatorsRequest',
type: 'object',
required: ['height'],
properties: {
height: {
type: 'integer',
minimum: 0,
},
},
},
},
{
name: 'consensus_getBFTHeights',
request: null,
Expand Down Expand Up @@ -356,17 +406,27 @@ const engineEndpoints = [
request: null,
},
{
name: 'system_getrequest',
request: {},
name: 'system_getSchema',
request: null,
},
{
name: 'system_getMetricsReport',
request: null,
request: {
$id: '/lisk/system/getMetricsReportRequest',
type: 'object',
required: [],
properties: {
inString: {
type: 'boolean',
},
},
},
},
{
name: 'txpool_postTransaction',
request: {
$id: '/lisk/postTransaction',
title: 'Transactions',
type: 'object',
required: ['transaction'],
properties: {
Expand All @@ -379,12 +439,22 @@ const engineEndpoints = [
},
{
name: 'txpool_getTransactionsFromPool',
request: null,
request: {
$id: '/generator/getTransactionsFromPool',
type: 'object',
properties: {
address: {
type: 'string',
format: 'lisk32',
},
},
},
},
{
name: 'txpool_dryRunTransaction',
request: {
$id: '/lisk/dryRunTransaction',
title: 'Transactions',
type: 'object',
required: ['transaction'],
properties: {
Expand All @@ -396,6 +466,10 @@ const engineEndpoints = [
type: 'boolean',
default: false,
},
strict: {
type: 'boolean',
default: false,
},
},
},
},
Expand All @@ -407,6 +481,7 @@ const engineEndpoints = [
name: 'generator_setStatus',
request: {
$id: '/lisk/setStatusRequest',
title: 'Set block generation status',
type: 'object',
required: ['address', 'height', 'maxHeightGenerated', 'maxHeightPrevoted'],
properties: {
Expand All @@ -433,6 +508,7 @@ const engineEndpoints = [
name: 'generator_updateStatus',
request: {
$id: '/lisk/updateStatusRequest',
title: 'Update block generation status',
type: 'object',
required: [
'address',
Expand Down
1 change: 1 addition & 0 deletions services/blockchain-indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ A list of the most commonly used environment variables is presented below:
- `JOB_SCHEDULE_TRIGGER_ACCOUNT_UPDATES`: Job run cron schedule to trigger account updates. By default, it is set to run every 15th minute (`*/15 * * * *`).
- `ESTIMATES_BUFFER_BYTES_LENGTH`: Transaction buffer bytes to consider when estimating the transaction fees. By default, it is set to 0.
- `MAINCHAIN_SERVICE_URL`: Mainchain service URL for custom deployments.
- `INVOKE_ALLOWED_METHODS`: List of allowed methods that can be invoked via the `/invoke` API endpoint. The list can be expressed as a CSV. To allow invocation of all endpoints, set it to `*`. To allow invocation of all the registered methods under the specified namespaces, set it similar to `legacy,chain`. To allow invocation of specific methods, set it similar to `chain_getBlocksByIDs,chain_getBlocksByHeight`.

> **Note**: `interval` takes priority over `schedule` and must be greater than 0 to be valid for all the moleculer job configurations.
Expand Down
10 changes: 10 additions & 0 deletions services/blockchain-indexer/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,14 @@ config.estimateFees = {
bufferBytesLength: Number(process.env.ESTIMATES_BUFFER_BYTES_LENGTH) || 0,
};

config.invokeAllowedMethods = process.env.INVOKE_ALLOWED_METHODS
? String(process.env.INVOKE_ALLOWED_METHODS).split(',')
: [
'dynamicReward_getExpectedValidatorRewards',
'token_hasUserAccount',
'token_getInitializationFees',
'interoperability_getMinimumMessageFee',
'txpool_getTransactionsFromPool',
];

module.exports = config;
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const {
getEngineEndpoints,
getAllRegisteredEndpoints,
} = require('../../constants');
const config = require('../../../config');

const INVOKE_ALLOWED_METHODS = config.invokeAllowedMethods;

const checkIfEndpointRegistered = async endpoint => {
const allRegisteredEndpoints = await getAllRegisteredEndpoints();
Expand Down Expand Up @@ -67,12 +70,26 @@ const validateEndpointParams = async invokeEndpointParams => {
}
};

const checkIfEndpointInvocationAllowed = endpoint => {
if (INVOKE_ALLOWED_METHODS.includes('*')) {
return true;
}

return INVOKE_ALLOWED_METHODS.some(allowedMethod => endpoint.startsWith(allowedMethod));
};
const invokeEndpoint = async params => {
const invokeEndpointRes = {
data: {},
meta: {},
};

const isEndpointAllowed = checkIfEndpointInvocationAllowed(params.endpoint);
if (!isEndpointAllowed) {
throw new ValidationException(
`Proxy invocation of endpoint '${params.endpoint}' is not allowed.`,
);
}

const isRegisteredEndpoint = await checkIfEndpointRegistered(params.endpoint);
if (!isRegisteredEndpoint) {
throw new ValidationException(`Endpoint '${params.endpoint}' is not registered.`);
Expand All @@ -90,7 +107,9 @@ const invokeEndpoint = async params => {
invokeEndpointRes.data = await requestConnector('invokeEndpoint', params);
invokeEndpointRes.meta = params;
} catch (err) {
throw new ServiceUnavailableException('Node is not reachable at the moment.');
throw new ServiceUnavailableException(
`Node is not reachable at the moment.\nError: ${err.message}`,
);
}

return invokeEndpointRes;
Expand Down
Loading

0 comments on commit 23b2767

Please sign in to comment.