Skip to content

Commit

Permalink
Merge a3029f7 into 9f0c7a6
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech authored Apr 16, 2022
2 parents 9f0c7a6 + a3029f7 commit 9890053
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions packages/lodestar/src/eth1/eth1DepositDataTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ export class Eth1DepositDataTracker {
*/
private async update(): Promise<boolean> {
const remoteHighestBlock = await this.eth1Provider.getBlockNumber();
const remoteFollowBlock = Math.max(0, remoteHighestBlock - this.config.ETH1_FOLLOW_DISTANCE);
const remoteFollowBlock = remoteHighestBlock - this.config.ETH1_FOLLOW_DISTANCE;

// If remoteFollowBlock is not at or beyond deployBlock, there is no need to
// fetch and track any deposit data yet
if (remoteFollowBlock < this.eth1Provider.deployBlock ?? 0) return true;

const hasCaughtUpDeposits = await this.updateDepositCache(remoteFollowBlock);
const hasCaughtUpBlocks = await this.updateBlockCache(remoteFollowBlock);
return hasCaughtUpDeposits && hasCaughtUpBlocks;
Expand Down Expand Up @@ -194,10 +199,17 @@ export class Eth1DepositDataTracker {
// lowestEventBlockNumber set a lower bound of possible block range to fetch in this update
const lowestEventBlockNumber = await this.depositsCache.getLowestDepositEventBlockNumber();

// If lowestEventBlockNumber is null = no deposits have been fetch or found yet.
// So there's not useful blocks to fetch until at least 1 deposit is found. So updateBlockCache() returns true
// because is has caught up to all possible data to fetch which is none.
if (lowestEventBlockNumber === null || lastProcessedDepositBlockNumber === null) {
// We are all caught up if:
// 1. If lowestEventBlockNumber is null = no deposits have been fetch or found yet.
// So there's not useful blocks to fetch until at least 1 deposit is found.
// 2. If the remoteFollowBlock is behind the lowestEventBlockNumber. This can happen
// if the EL's data was wiped and restarted. Not exiting here would other wise
// cause a NO_DEPOSITS_FOR_BLOCK_RANGE error
if (
lowestEventBlockNumber === null ||
lastProcessedDepositBlockNumber === null ||
remoteFollowBlock < lowestEventBlockNumber
) {
return true;
}

Expand Down

0 comments on commit 9890053

Please sign in to comment.