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

Commit

Permalink
Moved Index missing blocks max schedule to config
Browse files Browse the repository at this point in the history
  • Loading branch information
vardan10 committed Nov 23, 2023
1 parent b03cd84 commit f8896d4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ services:
- DOCKER_HOST=${DOCKER_HOST}
- JOB_INTERVAL_INDEX_MISSING_BLOCKS=${JOB_INTERVAL_INDEX_MISSING_BLOCKS}
- JOB_SCHEDULE_INDEX_MISSING_BLOCKS=${JOB_SCHEDULE_INDEX_MISSING_BLOCKS}
- INDEX_MISSING_BLOCKS_SKIP_THRESHOLD=${INDEX_MISSING_BLOCKS_SKIP_THRESHOLD}
- INDEX_MISSING_BLOCKS_MAX_SCHEDULE=${INDEX_MISSING_BLOCKS_MAX_SCHEDULE}
restart: always

transaction-statistics:
Expand Down
4 changes: 3 additions & 1 deletion docker/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ ENABLE_PERSIST_EVENTS=false
# JOB_INTERVAL_TRIGGER_ACCOUNT_UPDATES=0
# JOB_SCHEDULE_TRIGGER_ACCOUNT_UPDATES='*/15 * * * *'

## Lisk Service Blockchain Connector
## Lisk Service Blockchain coordinator
# JOB_INTERVAL_INDEX_MISSING_BLOCKS=0
# JOB_SCHEDULE_INDEX_MISSING_BLOCKS='*/15 * * * *'
# INDEX_MISSING_BLOCKS_SKIP_THRESHOLD=1000
# INDEX_MISSING_BLOCKS_MAX_SCHEDULE=25000

## Lisk Service Fee Estimator
ENABLE_FEE_ESTIMATOR_QUICK=true
Expand Down
2 changes: 2 additions & 0 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ module.exports = {
// DOCKER_HOST: 'local',
// JOB_INTERVAL_INDEX_MISSING_BLOCKS: 0,
// JOB_SCHEDULE_INDEX_MISSING_BLOCKS: '*/15 * * * *',
// INDEX_MISSING_BLOCKS_SKIP_THRESHOLD: 1000,
// INDEX_MISSING_BLOCKS_MAX_SCHEDULE: 25000,
},
},
{
Expand Down
1 change: 1 addition & 0 deletions services/blockchain-coordinator/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ config.job = {
interval: process.env.JOB_INTERVAL_INDEX_MISSING_BLOCKS || 0,
schedule: process.env.JOB_SCHEDULE_INDEX_MISSING_BLOCKS || '*/15 * * * *',
skipThreshold: process.env.INDEX_MISSING_BLOCKS_SKIP_THRESHOLD || 1000,
maxBlocksToSchedule: process.env.INDEX_MISSING_BLOCKS_MAX_SCHEDULE || 25000,
},
};

Expand Down
5 changes: 2 additions & 3 deletions services/blockchain-coordinator/shared/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const accountMessageQueue = new MessageQueue(

let intervalID;
const REFRESH_INTERVAL = 30000;
const MAX_BLOCKS_TO_SCHEDULE = 10000;

const getInProgressJobCount = async queue => {
const jobCount = await queue.getJobCounts();
Expand Down Expand Up @@ -245,7 +244,7 @@ const scheduleMissingBlocksIndexing = async () => {
// Lowest and highest block heights expected to be indexed
const blockIndexLowerRange = lastVerifiedHeight;
const blockIndexHigherRange = Math.min(
blockIndexLowerRange + MAX_BLOCKS_TO_SCHEDULE,
blockIndexLowerRange + config.job.indexMissingBlocks.maxBlocksToSchedule,
currentHeight,
);

Expand All @@ -267,7 +266,7 @@ const scheduleMissingBlocksIndexing = async () => {
const lastIndexVerifiedHeight = await getIndexVerifiedHeight();
if (batchEndHeight <= lastIndexVerifiedHeight + MAX_QUERY_RANGE) {
await setIndexVerifiedHeight(batchEndHeight);
logger.info(
logger.debug(
`No missing blocks found in range ${batchStartHeight} - ${batchEndHeight}. Setting index verified height to ${batchEndHeight}.`,
);
}
Expand Down
12 changes: 9 additions & 3 deletions services/blockchain-indexer/shared/indexer/blockchainIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ const indexBlock = async job => {
if (dbTrx) {
await rollbackDBTransaction(dbTrx);
logger.debug(
`Rolled back MySQL transaction to index block ${failedBlockInfo.id} at height ${failedBlockInfo.height}.`,
failedBlockInfo.id
? `Rolled back MySQL transaction to index block ${failedBlockInfo.id} at height ${failedBlockInfo.height}.`
: `Rolled back MySQL transaction to index block at height ${failedBlockInfo.height}.`,
);

// Add safety check to ensure that the DB transaction is rolled back successfully
Expand All @@ -413,15 +415,19 @@ const indexBlock = async job => {
error.message.includes(e),
)
) {
const errMessage = `Deadlock encountered while indexing block ${failedBlockInfo.id} at height ${failedBlockInfo.height}. Will retry.`;
const errMessage = failedBlockInfo.id
? `Deadlock encountered while indexing block ${failedBlockInfo.id} at height ${failedBlockInfo.height}. Will retry.`
: `Deadlock encountered while indexing block at height ${failedBlockInfo.height}. Will retry.`;
logger.warn(errMessage);
logger.debug(`SQL query: ${error.sql}`);

throw new Error(errMessage);
}

logger.warn(
`Error occurred while indexing block ${failedBlockInfo.id} at height ${failedBlockInfo.height}. Will retry.`,
failedBlockInfo.id
? `Error occurred while indexing block ${failedBlockInfo.id} at height ${failedBlockInfo.height}. Will retry.`
: `Error occurred while indexing block at height ${failedBlockInfo.height}. Will retry.`,
);
logger.debug(error.stack);
throw error;
Expand Down

0 comments on commit f8896d4

Please sign in to comment.