Skip to content

Commit

Permalink
implement Confirmation rule prerequisite - fork choice filter change
Browse files Browse the repository at this point in the history
To support confirmation rule via beacon-APIs as described in spec PR,
add `--debug-fork-choice-version=pr3431` option and enable when Deneb
fork is scheduled. To opt-out, `--debug-fork-choice-version=stable`,
or don't schedule Deneb.

- ethereum/consensus-specs#3431
- ethereum/consensus-specs#3466

"will bundle this with deneb release":

- ethereum/pm#844 (comment)
  • Loading branch information
etan-status committed Sep 20, 2023
1 parent 273f1d3 commit b355da5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
3 changes: 3 additions & 0 deletions beacon_chain/fork_choice/fork_choice_types.nim
Expand Up @@ -33,6 +33,9 @@ type
## Controls which version of fork choice to run.
Stable = "stable"
## Use current version from stable Ethereum consensus specifications
Pr3431 = "pr3431"
## https://github.com/ethereum/consensus-specs/pull/3431
## https://github.com/ethereum/consensus-specs/issues/3466

fcKind* = enum
## Fork Choice Error Kinds
Expand Down
28 changes: 18 additions & 10 deletions beacon_chain/fork_choice/proto_array.nim
Expand Up @@ -530,16 +530,24 @@ func nodeIsViableForHead(
self.checkpoints.justified.epoch == GENESIS_EPOCH or
node.checkpoints.justified.epoch == self.checkpoints.justified.epoch

# If the previous epoch is justified, the block should be pulled-up.
# In this case, check that unrealized justification is higher than the store
# and that the voting source is not more than two epochs ago
if not correctJustified and self.isPreviousEpochJustified and
node.bid.slot.epoch == self.currentEpoch:
let unrealized =
self.currentEpochTips.getOrDefault(nodeIdx, node.checkpoints)
correctJustified =
unrealized.justified.epoch >= self.checkpoints.justified.epoch and
node.checkpoints.justified.epoch + 2 >= self.currentEpoch
if not correctJustified:
case self.version
of ForkChoiceVersion.Stable:
# If the previous epoch is justified, the block should be pulled-up.
# In this case, check that unrealized justification is higher than the
# store and that the voting source is not more than two epochs ago
if self.isPreviousEpochJustified and
node.bid.slot.epoch == self.currentEpoch:
let unrealized =
self.currentEpochTips.getOrDefault(nodeIdx, node.checkpoints)
correctJustified =
unrealized.justified.epoch >= self.checkpoints.justified.epoch and
node.checkpoints.justified.epoch + 2 >= self.currentEpoch
of ForkChoiceVersion.Pr3431:
# The voting source should be either at the same height as the store's
# justified checkpoint or not more than two epochs ago
correctJustified =
node.checkpoints.justified.epoch + 2 >= self.currentEpoch

return
if not correctJustified:
Expand Down
7 changes: 6 additions & 1 deletion beacon_chain/nimbus_beacon_node.nim
Expand Up @@ -1903,7 +1903,12 @@ proc doRunBeaconNode(config: var BeaconNodeConf, rng: ref HmacDrbgContext) {.rai
for node in metadata.bootstrapNodes:
config.bootstrapNodes.add node
if config.forkChoiceVersion.isNone:
config.forkChoiceVersion = some(ForkChoiceVersion.Stable)
config.forkChoiceVersion =
if metadata.cfg.DENEB_FORK_EPOCH != FAR_FUTURE_EPOCH:
# https://github.com/ethereum/pm/issues/844#issuecomment-1673359012
some(ForkChoiceVersion.Pr3431)
else:
some(ForkChoiceVersion.Stable)

## Ctrl+C handling
proc controlCHandler() {.noconv.} =
Expand Down

0 comments on commit b355da5

Please sign in to comment.