Skip to content

Commit

Permalink
Make block proposing flow resilient to errors (#3737)
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Mar 4, 2022
1 parent 25a8b22 commit 4ebb668
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions packages/lodestar/src/eth1/eth1DepositDataTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,18 @@ export class Eth1DepositDataTracker {
* Requires internal caches to be updated regularly to return good results
*/
private async getEth1Data(state: allForks.BeaconState): Promise<phase0.Eth1Data> {
const eth1VotesToConsider = await getEth1VotesToConsider(
this.config,
state,
this.eth1DataCache.get.bind(this.eth1DataCache)
);
return pickEth1Vote(state, eth1VotesToConsider);
try {
const eth1VotesToConsider = await getEth1VotesToConsider(
this.config,
state,
this.eth1DataCache.get.bind(this.eth1DataCache)
);
return pickEth1Vote(state, eth1VotesToConsider);
} catch (e) {
// Note: In case there's a DB issue, don't stop a block proposal. Just vote for current eth1Data
this.logger.error("CRITICIAL: Error reading valid votes, voting for current eth1Data", {}, e as Error);
return state.eth1Data;
}
}

/**
Expand All @@ -99,6 +105,11 @@ export class Eth1DepositDataTracker {
state: CachedBeaconStateAllForks,
eth1DataVote: phase0.Eth1Data
): Promise<phase0.Deposit[]> {
// No new deposits have to be included, continue
if (eth1DataVote.depositCount === state.eth1DepositIndex) {
return [];
}

// Eth1 data may change due to the vote included in this block
const newEth1Data = allForks.getNewEth1Data(state, eth1DataVote) || state.eth1Data;
return await getDeposits(state, newEth1Data, this.depositsCache.get.bind(this.depositsCache));
Expand Down

0 comments on commit 4ebb668

Please sign in to comment.