Skip to content

Commit

Permalink
fix: 🐛 Synchronize with a confidence of 6 blocks
Browse files Browse the repository at this point in the history
Closes: #161
  • Loading branch information
siriusyim authored and lovel8 committed Apr 1, 2024
1 parent acddcf3 commit e8d6153
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/backgroundTask/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface Config {
evm: EvmContext
notRunSynctask: boolean
network: string
confidenceInterval: number
}

/**
Expand All @@ -78,6 +79,7 @@ export class Context implements IContext {
* @param config - The network configuration.
*/
constructor(config: Config) {
this.chain.confidenceInterval = config.confidenceInterval
this.chain.network = config.network
this.chain.startHeight = config.startHeight
this.chain.notRunSynctask = config.notRunSynctask
Expand Down
11 changes: 9 additions & 2 deletions src/backgroundTask/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,19 @@ export class BackgroundTask implements IBackgroundTask {
}
//step 3.4 store chainInfo
await this.storager.storeChainInfo(chainInfo)
} else if (this.syncHeight + 6 < chainHeadHeight) {
} else if (
this.syncHeight +
this.context.chain.confidenceInterval <
chainHeadHeight
) {
this.syncHeight++
} else {
await delay(3000)
}
} else if (this.syncHeight + 6 < chainHeadHeight) {
} else if (
this.syncHeight + this.context.chain.confidenceInterval <
chainHeadHeight
) {
this.syncHeight++
} else {
await delay(3000)
Expand Down
1 change: 1 addition & 0 deletions src/backgroundTask/interface/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export interface ChainContext {
startHeight: number
notRunSynctask: boolean
network: string
confidenceInterval: number
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/config/backgroundTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const calibrationConfig: Config = {
(process.env.CALIBRATION_NOT_RUN_SYNCTASK as string).toLowerCase() ===
"yes",
network: "calibration",
confidenceInterval: 6,
}

/**
Expand Down Expand Up @@ -113,6 +114,7 @@ export const mainConfig: Config = {
process.env.MAIN_NOT_RUN_SYNCTASK &&
(process.env.MAIN_NOT_RUN_SYNCTASK as string).toLowerCase() === "yes",
network: "main",
confidenceInterval: 6,
}

/**
Expand Down

0 comments on commit e8d6153

Please sign in to comment.