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 #1913 from LiskHQ/1912-lisk-service-does-work-agai…
Browse files Browse the repository at this point in the history
…nst-the-migrated-mainnet

Lisk Service does not work against the migrated mainnet
  • Loading branch information
sameersubudhi authored Nov 8, 2023
2 parents c120db0 + 6e5520f commit 6cfba0b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
7 changes: 6 additions & 1 deletion services/blockchain-connector/events/proxy/allEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions services/blockchain-connector/shared/sdk/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 7 additions & 3 deletions services/blockchain-connector/shared/sdk/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const logger = Logger();
let escrowedAmounts;
let supportedTokens;
let totalSupply;
let initializationFees;

const getTokenBalances = async address => {
try {
Expand Down Expand Up @@ -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'.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.`);
Expand Down
26 changes: 22 additions & 4 deletions services/blockchain-indexer/shared/indexer/genesisBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ 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,
});
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];
Expand All @@ -76,16 +76,20 @@ 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();

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,
);

Expand All @@ -100,9 +104,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);

Expand All @@ -112,7 +120,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];
Expand Down Expand Up @@ -145,9 +153,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,
});
Expand All @@ -156,11 +166,19 @@ 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.');
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.');
};

const indexTokenBalances = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}),
Expand Down

0 comments on commit 6cfba0b

Please sign in to comment.