From d025d7b2ca2e0174e796a0e0d1e189ed3978408a Mon Sep 17 00:00:00 2001 From: Sameer Kumar Subudhi Date: Thu, 2 Nov 2023 23:06:28 +0100 Subject: [PATCH 1/5] :hammer: Cache constants at init in connector --- services/blockchain-connector/shared/sdk/index.js | 3 +++ services/blockchain-connector/shared/sdk/token.js | 10 +++++++--- .../shared/dataService/knownAccounts.js | 4 ++-- .../shared/indexer/genesisBlock.js | 14 ++++++++++++++ .../unit/shared/dataservice/knownAccounts.test.js | 2 +- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/services/blockchain-connector/shared/sdk/index.js b/services/blockchain-connector/shared/sdk/index.js index 0c74194b2b..967acb41d6 100644 --- a/services/blockchain-connector/shared/sdk/index.js +++ b/services/blockchain-connector/shared/sdk/index.js @@ -121,6 +121,9 @@ const init = async () => { await cacheRegisteredRewardModule(); await cacheFeeConstants(); await updateTokenInfo(); + await getTokenInitializationFees(); + await getRewardTokenID(); + await getPosConstants(); // Download the genesis block, if applicable await getGenesisBlock(); diff --git a/services/blockchain-connector/shared/sdk/token.js b/services/blockchain-connector/shared/sdk/token.js index 5284ef44ee..04e64b4493 100644 --- a/services/blockchain-connector/shared/sdk/token.js +++ b/services/blockchain-connector/shared/sdk/token.js @@ -24,6 +24,7 @@ const logger = Logger(); let escrowedAmounts; let supportedTokens; let totalSupply; +let initializationFees;; const getTokenBalances = async address => { try { @@ -98,9 +99,12 @@ const getTotalSupply = async (isForceUpdate = false) => { const getTokenInitializationFees = async () => { try { - const response = await invokeEndpoint('token_getInitializationFees'); - if (response.error) throw new Error(response.error); - return response; + if (!initializationFees) { + const response = await invokeEndpoint('token_getInitializationFees'); + if (response.error) throw new Error(response.error); + initializationFees = response; + } + return initializationFees; } catch (err) { if (err.message.includes(timeoutMessage)) { throw new TimeoutException("Request timed out when calling 'getTokenInitializationFees'."); diff --git a/services/blockchain-indexer/shared/dataService/knownAccounts.js b/services/blockchain-indexer/shared/dataService/knownAccounts.js index 4672dd6036..ab28a4f0c1 100644 --- a/services/blockchain-indexer/shared/dataService/knownAccounts.js +++ b/services/blockchain-indexer/shared/dataService/knownAccounts.js @@ -62,10 +62,10 @@ const reloadAccountKnowledge = async () => { } } else { logger.warn('Lisk static URL did not respond with valid data.'); - logger.debug(`Recieved: ${util.inspect(res)}.`); + logger.debug(`Received: ${util.inspect(res)}.`); } } else { - logger.warn(`Static information anavailable for the current chainID: ${chainID}.`); + logger.warn(`Static information unavailable for the current chainID: ${chainID}.`); } } catch (err) { logger.error(`Could not reload known accounts: ${err.message}.`); diff --git a/services/blockchain-indexer/shared/indexer/genesisBlock.js b/services/blockchain-indexer/shared/indexer/genesisBlock.js index 9b051e9d94..745310f5f4 100644 --- a/services/blockchain-indexer/shared/indexer/genesisBlock.js +++ b/services/blockchain-indexer/shared/indexer/genesisBlock.js @@ -44,6 +44,7 @@ const allAccountsAddresses = []; let isTokensBalanceIndexed = false; const indexTokenModuleAssets = async dbTrx => { + logger.info('Starting to index the genesis assets from the Token module.'); const genesisBlockAssetsLength = await requestConnector('getGenesisAssetsLength', { module: MODULE.TOKEN, subStore: MODULE_SUB_STORE.TOKEN.USER, @@ -76,9 +77,13 @@ const indexTokenModuleAssets = async dbTrx => { } await updateTotalLockedAmounts(tokenIDLockedAmountChangeMap, dbTrx); + logger.info('Finished indexing all the genesis assets from the Token module.'); }; const indexPosValidatorsInfo = async (numValidators, dbTrx) => { + logger.debug( + 'Starting to index the PoS Validators information from the genesis PoS module assets.', + ); if (numValidators > 0) { const commissionsTable = await getCommissionsTable(); @@ -100,9 +105,13 @@ const indexPosValidatorsInfo = async (numValidators, dbTrx) => { await commissionsTable.upsert(commissionEntries, dbTrx); } + logger.debug( + 'Finished indexing the PoS Validators information from the genesis PoS module assets.', + ); }; const indexPosStakesInfo = async (numStakers, dbTrx) => { + logger.debug('Starting to index the PoS stakes information from the genesis PoS module assets.'); let totalStake = BigInt(0); let totalSelfStake = BigInt(0); @@ -145,9 +154,11 @@ const indexPosStakesInfo = async (numStakers, dbTrx) => { await updateTotalSelfStake(totalSelfStake, dbTrx); logger.info(`Updated total self-stakes information at genesis: ${totalSelfStake.toString()}.`); + logger.debug('Finished indexing the PoS stakes information from the genesis PoS module assets.'); }; const indexPosModuleAssets = async dbTrx => { + logger.info('Starting to index the genesis assets from the PoS module.'); const genesisBlockAssetsLength = await requestConnector('getGenesisAssetsLength', { module: MODULE.POS, }); @@ -156,11 +167,14 @@ const indexPosModuleAssets = async dbTrx => { await indexPosValidatorsInfo(numValidators, dbTrx); await indexPosStakesInfo(numStakers, dbTrx); + logger.info('Finished indexing all the genesis assets from the PoS module.'); }; const indexGenesisBlockAssets = async dbTrx => { + logger.info('Starting to index the genesis assets.'); await indexTokenModuleAssets(dbTrx); await indexPosModuleAssets(dbTrx); + logger.info('Finished indexing all the genesis assets.'); }; const indexTokenBalances = async () => { diff --git a/services/blockchain-indexer/tests/unit/shared/dataservice/knownAccounts.test.js b/services/blockchain-indexer/tests/unit/shared/dataservice/knownAccounts.test.js index c9faae8b98..4c71f1063c 100644 --- a/services/blockchain-indexer/tests/unit/shared/dataservice/knownAccounts.test.js +++ b/services/blockchain-indexer/tests/unit/shared/dataservice/knownAccounts.test.js @@ -149,7 +149,7 @@ describe('reloadAccountKnowledge', () => { info: jest.fn(), warn: async data => expect(data).toEqual( - 'Static information anavailable for the current chainID: invalidChainID.', + 'Static information unavailable for the current chainID: invalidChainID.', ), error: jest.fn(), }), From b5bdbe1152b60564d7ab2d3eafd241fc6fef89e8 Mon Sep 17 00:00:00 2001 From: nagdahimanshu Date: Mon, 6 Nov 2023 11:32:15 +0100 Subject: [PATCH 2/5] Add limit when indexing genesis block assets --- services/blockchain-indexer/shared/indexer/genesisBlock.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/services/blockchain-indexer/shared/indexer/genesisBlock.js b/services/blockchain-indexer/shared/indexer/genesisBlock.js index 9b051e9d94..3f7fae9331 100644 --- a/services/blockchain-indexer/shared/indexer/genesisBlock.js +++ b/services/blockchain-indexer/shared/indexer/genesisBlock.js @@ -49,11 +49,10 @@ const indexTokenModuleAssets = async dbTrx => { subStore: MODULE_SUB_STORE.TOKEN.USER, }); const totalUsers = genesisBlockAssetsLength[MODULE.TOKEN][MODULE_SUB_STORE.TOKEN.USER]; - const tokenModuleData = await requestAll( requestConnector, 'getGenesisAssetByModule', - { module: MODULE.TOKEN, subStore: MODULE_SUB_STORE.TOKEN.USER }, + { module: MODULE.TOKEN, subStore: MODULE_SUB_STORE.TOKEN.USER, limit: 1000 }, totalUsers, ); const userSubStoreInfos = tokenModuleData[MODULE_SUB_STORE.TOKEN.USER]; @@ -85,7 +84,7 @@ const indexPosValidatorsInfo = async (numValidators, dbTrx) => { const posModuleData = await requestAll( requestConnector, 'getGenesisAssetByModule', - { module: MODULE.POS, subStore: MODULE_SUB_STORE.POS.VALIDATORS }, + { module: MODULE.POS, subStore: MODULE_SUB_STORE.POS.VALIDATORS, limit: 1000 }, numValidators, ); @@ -112,7 +111,7 @@ const indexPosStakesInfo = async (numStakers, dbTrx) => { const posModuleData = await requestAll( requestConnector, 'getGenesisAssetByModule', - { module: MODULE.POS, subStore: MODULE_SUB_STORE.POS.STAKERS }, + { module: MODULE.POS, subStore: MODULE_SUB_STORE.POS.STAKERS, limit: 1000 }, numStakers, ); const stakers = posModuleData[MODULE_SUB_STORE.POS.STAKERS]; From 73732a9d5277c959257a24743c160d0effc58085 Mon Sep 17 00:00:00 2001 From: nagdahimanshu Date: Tue, 7 Nov 2023 09:40:51 +0100 Subject: [PATCH 3/5] :art: Fix formatting --- services/blockchain-connector/shared/sdk/token.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/blockchain-connector/shared/sdk/token.js b/services/blockchain-connector/shared/sdk/token.js index 04e64b4493..f662c64330 100644 --- a/services/blockchain-connector/shared/sdk/token.js +++ b/services/blockchain-connector/shared/sdk/token.js @@ -24,7 +24,7 @@ const logger = Logger(); let escrowedAmounts; let supportedTokens; let totalSupply; -let initializationFees;; +let initializationFees; const getTokenBalances = async address => { try { From 897fc142475287ea5340cf7b42d49032af19559d Mon Sep 17 00:00:00 2001 From: nagdahimanshu Date: Tue, 7 Nov 2023 18:09:29 +0100 Subject: [PATCH 4/5] Improve logging --- services/blockchain-connector/events/proxy/allEvents.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/blockchain-connector/events/proxy/allEvents.js b/services/blockchain-connector/events/proxy/allEvents.js index c3b9413583..f5534e3f40 100644 --- a/services/blockchain-connector/events/proxy/allEvents.js +++ b/services/blockchain-connector/events/proxy/allEvents.js @@ -42,7 +42,12 @@ const exportAllEvents = async () => { const genericController = regEvent => cb => { const eventListener = async payload => { const signalName = toCamelCase(regEvent.split('_')); - logger.info(`Received ${regEvent} event, dispatching ${signalName} signal.`); + + const logMessage = regEvent.endsWith('Block') + ? `Received ${regEvent} event, dispatching ${signalName} signal (id: ${payload.blockHeader.id}, height: ${payload.blockHeader.height}).` + : `Received ${regEvent} event, dispatching ${signalName} signal.`; + + logger.info(logMessage); logger.debug(`Payload: ${JSON.stringify(payload)}`); Signals.get(signalName).dispatch(payload); From 6e5520fcd2cd7f72952364325ce5a8044d358aaf Mon Sep 17 00:00:00 2001 From: Sameer Kumar Subudhi Date: Wed, 8 Nov 2023 16:59:29 +0100 Subject: [PATCH 5/5] :zap: Add log to keep user informed of the genesis asset indexing --- services/blockchain-indexer/shared/indexer/genesisBlock.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/blockchain-indexer/shared/indexer/genesisBlock.js b/services/blockchain-indexer/shared/indexer/genesisBlock.js index dfae724ecb..f65d455f06 100644 --- a/services/blockchain-indexer/shared/indexer/genesisBlock.js +++ b/services/blockchain-indexer/shared/indexer/genesisBlock.js @@ -171,8 +171,13 @@ const indexPosModuleAssets = async dbTrx => { const indexGenesisBlockAssets = async dbTrx => { logger.info('Starting to index the genesis assets.'); + const IntervalTimeout = setInterval( + () => logger.info('Genesis assets indexing still in progress...'), + 5000, + ); await indexTokenModuleAssets(dbTrx); await indexPosModuleAssets(dbTrx); + clearInterval(IntervalTimeout); logger.info('Finished indexing all the genesis assets.'); };