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 #1983 from LiskHQ/1979-missing-error-handling-in-c…
Browse files Browse the repository at this point in the history
…oordinator

Missing error handling in coordinator
  • Loading branch information
sameersubudhi authored Dec 7, 2023
2 parents a1ef426 + c8e25a3 commit 587106c
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docker/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# CLIENT_INSTANTIATION_RETRY_INTERVAL=1
# CLIENT_ALIVE_ASSUMPTION_TIME=5000
# HEARTBEAT_ACK_MAX_WAIT_TIME=1000
# ENDPOINT_INVOKE_MAX_RETRIES=5
# ENDPOINT_INVOKE_MAX_RETRIES=3
# ENDPOINT_INVOKE_RETRY_DELAY=10
# CONNECTOR_EXIT_DELAY_IN_HOURS=0

Expand Down
2 changes: 1 addition & 1 deletion docs/antora/modules/ROOT/pages/configuration/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ By default, it is set to `1000`.
| `ENDPOINT_INVOKE_MAX_RETRIES`
| number
| Maximum number of endpoint invocation request retries to the node.
By default, it is set to `5`.
By default, it is set to `3`.
| 5

| `ENDPOINT_INVOKE_RETRY_DELAY`
Expand Down
2 changes: 1 addition & 1 deletion ecosystem.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ module.exports = {
// CLIENT_INSTANTIATION_RETRY_INTERVAL: 1,
// CLIENT_ALIVE_ASSUMPTION_TIME: 5 * 1000,
// HEARTBEAT_ACK_MAX_WAIT_TIME: 1000,
// ENDPOINT_INVOKE_MAX_RETRIES: 5,
// ENDPOINT_INVOKE_MAX_RETRIES: 3,
// ENDPOINT_INVOKE_RETRY_DELAY: 10,
// CONNECTOR_EXIT_DELAY_IN_HOURS: 0,
// JOB_INTERVAL_CACHE_CLEANUP: 0,
Expand Down
2 changes: 1 addition & 1 deletion services/blockchain-connector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ A list of the most commonly used environment variables is presented below:
- `CLIENT_INSTANTIATION_RETRY_INTERVAL`: Retry interval (in milliseconds) to invoke instantiate API client when getApiClient is invoked. By default, it is set to 5.
- `CLIENT_ALIVE_ASSUMPTION_TIME`: Interval (in milliseconds) for which the WS API Client is assumed to be alive since the last ping/pong success check. By default, it is set to 5000.
- `HEARTBEAT_ACK_MAX_WAIT_TIME`: Maximum time (in milliseconds) within which the checkIsClientAlive's algorithm expects a corresponding `pong` for the `ping` sent to the WS server. By default, it is set to 1000.
- `ENDPOINT_INVOKE_MAX_RETRIES`: Maximum number of endpoint invocation request retries to the node. By default, it is set to 1.
- `ENDPOINT_INVOKE_MAX_RETRIES`: Maximum number of endpoint invocation request retries to the node. By default, it is set to 3.
- `ENDPOINT_INVOKE_RETRY_DELAY`: Delay (in milliseconds) between each endpoint invocation request retry. By default, it is set to 10.
- `CONNECTOR_EXIT_DELAY_IN_HOURS`: Delay (in hours) after which the blockchain-connector microservice exits. The service should restart automatically if deployed using Docker or PM2. To be removed eventually. To enable it, set it higher than `0`. By default, it is set to `0`.
- `JOB_INTERVAL_CACHE_CLEANUP`: Job run interval to cleanup block cache. By default, it is set to 0.
Expand Down
2 changes: 1 addition & 1 deletion services/blockchain-connector/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ config.apiClient = {
retryInterval: Number(process.env.CLIENT_INSTANTIATION_RETRY_INTERVAL) || 1, // in millisecs
},
request: {
maxRetries: Number(process.env.ENDPOINT_INVOKE_MAX_RETRIES) || 5,
maxRetries: Number(process.env.ENDPOINT_INVOKE_MAX_RETRIES) || 3,
retryDelay: Number(process.env.ENDPOINT_INVOKE_RETRY_DELAY) || 10, // in millisecs
},
};
Expand Down
11 changes: 10 additions & 1 deletion services/blockchain-connector/events/controller/blockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*
*/
const { Logger, Signals } = require('lisk-service-framework');
const { MODULE_NAME_POS } = require('../../shared/sdk/constants/names');

const { getBlockByID } = require('../../shared/sdk/endpoints');
const { formatBlock: formatBlockFromFormatter } = require('../../shared/sdk/formatter');
Expand Down Expand Up @@ -92,12 +93,20 @@ const chainNewBlockController = async cb => {
transactions,
}),
);

// Reload validators cache on pos module transactions
if (transactions.some(t => t.module === MODULE_NAME_POS)) {
Signals.get('reloadAllPosValidators').dispatch();
}
};
Signals.get('chainNewBlock').add(chainNewBlockListener);
};

const chainDeleteBlockController = async cb => {
const chainDeleteBlockListener = async payload => cb(formatBlock(payload));
const chainDeleteBlockListener = async payload => {
cb(formatBlock(payload));
Signals.get('reloadAllPosValidators').dispatch();
};
Signals.get('chainDeleteBlock').add(chainDeleteBlockListener);
};

Expand Down
1 change: 1 addition & 0 deletions services/blockchain-connector/shared/sdk/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const init = async () => {
await getTokenInitializationFees();
await getRewardTokenID();
await getPosConstants();
await getAllPosValidators();

// Download the genesis block, if applicable
await getGenesisBlock().then(() => {
Expand Down
16 changes: 13 additions & 3 deletions services/blockchain-connector/shared/sdk/pos.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
const {
Logger,
Signals,
Exceptions: { TimeoutException },
} = require('lisk-service-framework');

Expand All @@ -27,6 +28,7 @@ const { getGenesisHeight } = require('./genesisBlock');
const logger = Logger();

let posModuleConstants;
let allPosValidators;

const getPosValidator = async address => {
try {
Expand All @@ -43,10 +45,16 @@ const getPosValidator = async address => {
}
};

const getAllPosValidators = async () => {
const getAllPosValidators = async isForceReload => {
try {
const validators = await invokeEndpoint('pos_getAllValidators');
return validators;
if (!allPosValidators || isForceReload) {
const response = await invokeEndpoint('pos_getAllValidators');
if (Array.isArray(response)) {
allPosValidators = response;
logger.info(`Reloaded pos validators list. Validators count: ${allPosValidators.length}.`);
}
}
return allPosValidators;
} catch (err) {
if (err.message.includes(timeoutMessage)) {
throw new TimeoutException("Request timed out when calling 'getAllPosValidators'.");
Expand All @@ -56,6 +64,8 @@ const getAllPosValidators = async () => {
}
};

Signals.get('reloadAllPosValidators').add(() => getAllPosValidators(true));

const getPosValidatorsByStake = async limit => {
try {
const validators = await invokeEndpoint('pos_getValidatorsByStake', { limit });
Expand Down

0 comments on commit 587106c

Please sign in to comment.