From b355da5a1bb2f03a6d6ba3ea0b7c78d40b82dc4b Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Wed, 20 Sep 2023 15:36:23 +0200 Subject: [PATCH] implement Confirmation rule prerequisite - fork choice filter change 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. - https://github.com/ethereum/consensus-specs/pull/3431 - https://github.com/ethereum/consensus-specs/issues/3466 "will bundle this with deneb release": - https://github.com/ethereum/pm/issues/844#issuecomment-1673359012 --- .../fork_choice/fork_choice_types.nim | 3 ++ beacon_chain/fork_choice/proto_array.nim | 28 ++++++++++++------- beacon_chain/nimbus_beacon_node.nim | 7 ++++- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/beacon_chain/fork_choice/fork_choice_types.nim b/beacon_chain/fork_choice/fork_choice_types.nim index 3f26a06735..50cc63c5d9 100644 --- a/beacon_chain/fork_choice/fork_choice_types.nim +++ b/beacon_chain/fork_choice/fork_choice_types.nim @@ -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 diff --git a/beacon_chain/fork_choice/proto_array.nim b/beacon_chain/fork_choice/proto_array.nim index 836537d1be..02075ea0be 100644 --- a/beacon_chain/fork_choice/proto_array.nim +++ b/beacon_chain/fork_choice/proto_array.nim @@ -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: diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 5a63af7ecd..93c180e5d2 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -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.} =