Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit clock slot event on updated currentSlot #2417

Merged
merged 2 commits into from
Apr 29, 2021

Conversation

wemeetagain
Copy link
Member

Motivation

Currently, we can run into a situation where the clock.currentSlot is updated but that slot's event has not yet been triggered (and important callbacks have not yet been executed).
This can lead to confusing bugs, like:

Eph 1/3 0.084 [NODE-A CHAIN]    error: Block error slot=11 code=BLOCK_ERROR_BEACON_CHAIN_ERROR, error={"code":"FORKCHOICE_ERROR_INVALID_BLOCK","err":{"code":"FUTURE_SLOT","currentSlot":10,"blockSlot":11}}
Error: FORKCHOICE_ERROR_INVALID_BLOCK
    at LodestarForkChoice.onBlock (/home/runner/work/lodestar/lodestar/packages/fork-choice/src/forkChoice/forkChoice.ts:238:13)
    at Object.runStateTransition (/home/runner/work/lodestar/lodestar/packages/lodestar/src/chain/blocks/stateTransition.ts:151:14)
    at Object.processBlock (/home/runner/work/lodestar/lodestar/packages/lodestar/src/chain/blocks/process.ts:60:11)
    at processBlockJob (/home/runner/work/lodestar/lodestar/packages/lodestar/src/chain/blocks/processor.ts:80:5)
    at Object.job (/home/runner/work/lodestar/lodestar/packages/lodestar/src/chain/blocks/processor.ts:59:42)
    at Object.wrapError (/home/runner/work/lodestar/lodestar/packages/lodestar/src/util/wrapError.ts:18:32)
    at Timeout.JobQueue.runJob [as _onTimeout] (/home/runner/work/lodestar/lodestar/packages/lodestar/src/util/queue/index.ts:93:17)
Error: BLOCK_ERROR_BEACON_CHAIN_ERROR
    at Object.processBlock (/home/runner/work/lodestar/lodestar/packages/lodestar/src/chain/blocks/process.ts:73:11)

Where even though the block passes validation (including that block.slot >= clock.currentSlot), the fork choice store isn't yet updated.

Description

Update the clock.currentSlot getter to trigger clock events if the call results in an updated slot. This will give important slot event handlers a chance to run before the consumer of a currentSlot continues.

Specifically, with regards to the above error, when the block in question is now validated (and checked against clock.currentSlot), the slot event handler will be called, allowing the fork choice to be updated before continuing block processing at that slot.

@codeclimate
Copy link

codeclimate bot commented Apr 24, 2021

Code Climate has analyzed commit 143e4c3 and detected 0 issues on this pull request.

View more on Code Climate.

dapplion
dapplion previously approved these changes Apr 24, 2021
@dapplion
Copy link
Contributor

This may be necessary to potentially fix a bug in #2416 where the fork-choice currentSlot is not in sync with the rest of the beacon node

Eph 1/3 0.084 [NODE-A CHAIN]    error: Block error slot=11 code=BLOCK_ERROR_BEACON_CHAIN_ERROR, error={"code":"FORKCHOICE_ERROR_INVALID_BLOCK","err":{"code":"FUTURE_SLOT","currentSlot":10,"blockSlot":11}}
Error: FORKCHOICE_ERROR_INVALID_BLOCK
    at LodestarForkChoice.onBlock (/home/runner/work/lodestar/lodestar/packages/fork-choice/src/forkChoice/forkChoice.ts:238:13)
    at Object.runStateTransition (/home/runner/work/lodestar/lodestar/packages/lodestar/src/chain/blocks/stateTransition.ts:151:14)
    at Object.processBlock (/home/runner/work/lodestar/lodestar/packages/lodestar/src/chain/blocks/process.ts:60:11)
    at processBlockJob (/home/runner/work/lodestar/lodestar/packages/lodestar/src/chain/blocks/processor.ts:80:5)
    at Object.job (/home/runner/work/lodestar/lodestar/packages/lodestar/src/chain/blocks/processor.ts:59:42)
    at Object.wrapError (/home/runner/work/lodestar/lodestar/packages/lodestar/src/util/wrapError.ts:18:32)
    at Timeout.JobQueue.runJob [as _onTimeout] (/home/runner/work/lodestar/lodestar/packages/lodestar/src/util/queue/index.ts:93:17)
Error: BLOCK_ERROR_BEACON_CHAIN_ERROR
    at Object.processBlock (/home/runner/work/lodestar/lodestar/packages/lodestar/src/chain/blocks/process.ts:73:11)

However, we should look in the future at how to do this cleanly. Potentially triggering expensive events on this getter sounds like an unpredictable bottleneck.

@twoeths
Copy link
Contributor

twoeths commented Apr 27, 2021

there are build errors in CI

@chainsafe/lodestar: [1] src/chain/clock/LocalClock.ts:36:5 - error TS2322: Type 'number' is not assignable to type 'Timeout'.
@chainsafe/lodestar: [1] 
@chainsafe/lodestar: [1] 36     this.timeoutId = setTimeout(this.onNextSlot, this.msUntilNextSlot());

@wemeetagain wemeetagain merged commit daf8797 into master Apr 29, 2021
@wemeetagain wemeetagain deleted the cayman/clock-slot-update branch April 29, 2021 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants