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

Commit

Permalink
Add endpoint to fetch BFT params
Browse files Browse the repository at this point in the history
Refactor code
  • Loading branch information
nagdahimanshu committed Jan 3, 2024
1 parent 87ebda1 commit d0ff8c4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
13 changes: 13 additions & 0 deletions services/blockchain-connector/shared/sdk/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,18 @@ const getGenerators = async () => {
}
};

const getBFTParameters = async height => {
try {
const bftParameters = await invokeEndpoint('consensus_getBFTParameters', { height });
return bftParameters;
} catch (err) {
if (err.message.includes(timeoutMessage)) {
throw new TimeoutException("Request timed out when calling 'getBFTParameters'.");
}
throw err;
}
};

module.exports = {
invokeEndpoint,
getSchemas,
Expand All @@ -328,4 +340,5 @@ module.exports = {
postTransaction,
dryRunTransaction,
getGenerators,
getBFTParameters,
};
10 changes: 7 additions & 3 deletions services/blockchain-connector/shared/sdk/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const {
getEventsByHeight,
getNodeInfo,
getBlockByHeight,
getGenerators,
getBFTParameters,
} = require('./endpoints');
const { updateTokenInfo } = require('./token');

Check notice

Code scanning / Semgrep

Semgrep Finding: javascript.lang.correctness.useless-assign.useless-assignment Note

const is assigned twice; the first assignment is useless
const { getPosConstants } = require('./pos');
Expand Down Expand Up @@ -73,8 +73,12 @@ const emitNodeEvents = async () => {
(latestNodeInfo.height - latestNodeInfo.genesisHeight) % posConstants.roundLength ===
1
) {
const { list: validators } = await getGenerators();
Signals.get(EVENT_CHAIN_VALIDATORS_CHANGE).dispatch({ nextValidators: validators });
const bftParameters = await getBFTParameters(latestNodeInfo.height);
Signals.get(EVENT_CHAIN_VALIDATORS_CHANGE).dispatch({
nextValidators: bftParameters.validators,
certificateThreshold: bftParameters.certificateThreshold,
precommitThreshold: bftParameters.precommitThreshold,
});
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions services/blockchain-coordinator/shared/eventsScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ const scheduleDeleteBlock = async payload => {
};

const scheduleUpdatesOnNewRound = async payload => {
const { validators } = payload;
logger.debug('Scheduling updates on new round.');
await eventMessageQueue.add({ validators, isNewRound: true });
await eventMessageQueue.add({ ...payload, isNewRound: true });
logger.debug('Finished scheduling updates on new round}.');
};

Expand Down

0 comments on commit d0ff8c4

Please sign in to comment.