remove option to select Capella fork choice algo (#6478)

* remove option to select Capella fork choice algo

With Deneb having run stable for quite a while now, it's time to remove
the option to select the prior fork choice algo from Capella.

* also remove usage from test
This commit is contained in:
Etan Kissling 2024-08-07 16:48:05 +02:00 committed by GitHub
parent 32fe62f084
commit 3375875e05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 17 additions and 60 deletions

View File

@ -32,8 +32,6 @@ import
from std/os import getHomeDir, parentDir, `/` from std/os import getHomeDir, parentDir, `/`
from std/strutils import parseBiggestUInt, replace from std/strutils import parseBiggestUInt, replace
from fork_choice/fork_choice_types
import ForkChoiceVersion
from consensus_object_pools/block_pools_types_light_client from consensus_object_pools/block_pools_types_light_client
import LightClientDataImportMode import LightClientDataImportMode
@ -676,12 +674,6 @@ type
desc: "Bandwidth estimate for the node (bits per second)" desc: "Bandwidth estimate for the node (bits per second)"
name: "debug-bandwidth-estimate" .}: Option[Natural] name: "debug-bandwidth-estimate" .}: Option[Natural]
forkChoiceVersion* {.
hidden
desc: "Forkchoice version to use. " &
"Must be one of: stable"
name: "debug-forkchoice-version" .}: Option[ForkChoiceVersion]
of BNStartUpCmd.wallets: of BNStartUpCmd.wallets:
case walletsCmd* {.command.}: WalletsCmd case walletsCmd* {.command.}: WalletsCmd
of WalletsCmd.create: of WalletsCmd.create:

View File

@ -104,7 +104,6 @@ declareGauge attestation_pool_block_attestation_packing_time,
proc init*(T: type AttestationPool, dag: ChainDAGRef, proc init*(T: type AttestationPool, dag: ChainDAGRef,
quarantine: ref Quarantine, quarantine: ref Quarantine,
forkChoiceVersion = ForkChoiceVersion.Stable,
onAttestation: OnPhase0AttestationCallback = nil, onAttestation: OnPhase0AttestationCallback = nil,
onElectraAttestation: OnElectraAttestationCallback = nil): T = onElectraAttestation: OnElectraAttestationCallback = nil): T =
## Initialize an AttestationPool from the dag `headState` ## Initialize an AttestationPool from the dag `headState`
@ -113,7 +112,7 @@ proc init*(T: type AttestationPool, dag: ChainDAGRef,
let finalizedEpochRef = dag.getFinalizedEpochRef() let finalizedEpochRef = dag.getFinalizedEpochRef()
var forkChoice = ForkChoice.init( var forkChoice = ForkChoice.init(
finalizedEpochRef, dag.finalizedHead.blck, forkChoiceVersion) finalizedEpochRef, dag.finalizedHead.blck)
# Feed fork choice with unfinalized history - during startup, block pool only # Feed fork choice with unfinalized history - during startup, block pool only
# keeps track of a single history so we just need to follow it # keeps track of a single history so we just need to follow it

View File

@ -49,13 +49,11 @@ func compute_deltas(
logScope: topics = "fork_choice" logScope: topics = "fork_choice"
func init*( func init*(
T: type ForkChoiceBackend, checkpoints: FinalityCheckpoints, T: type ForkChoiceBackend, checkpoints: FinalityCheckpoints): T =
version: ForkChoiceVersion): T = T(proto_array: ProtoArray.init(checkpoints))
T(proto_array: ProtoArray.init(checkpoints, version))
proc init*( proc init*(
T: type ForkChoice, epochRef: EpochRef, blck: BlockRef, T: type ForkChoice, epochRef: EpochRef, blck: BlockRef): T =
version: ForkChoiceVersion): T =
## Initialize a fork choice context for a finalized state - in the finalized ## Initialize a fork choice context for a finalized state - in the finalized
## state, the justified and finalized checkpoints are the same, so only one ## state, the justified and finalized checkpoints are the same, so only one
## is used here ## is used here
@ -67,10 +65,8 @@ proc init*(
backend: ForkChoiceBackend.init( backend: ForkChoiceBackend.init(
FinalityCheckpoints( FinalityCheckpoints(
justified: checkpoint, justified: checkpoint,
finalized: checkpoint), finalized: checkpoint)),
version),
checkpoints: Checkpoints( checkpoints: Checkpoints(
version: version,
justified: BalanceCheckpoint( justified: BalanceCheckpoint(
checkpoint: checkpoint, checkpoint: checkpoint,
total_active_balance: epochRef.total_active_balance, total_active_balance: epochRef.total_active_balance,

View File

@ -29,14 +29,6 @@ import
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
type type
ForkChoiceVersion* {.pure.} = enum
## 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 fcKind* = enum
## Fork Choice Error Kinds ## Fork Choice Error Kinds
fcFinalizedNodeUnknown fcFinalizedNodeUnknown
@ -96,7 +88,6 @@ type
## Subtracted from logical index to get the physical index ## Subtracted from logical index to get the physical index
ProtoArray* = object ProtoArray* = object
version*: ForkChoiceVersion
currentEpoch*: Epoch currentEpoch*: Epoch
checkpoints*: FinalityCheckpoints checkpoints*: FinalityCheckpoints
nodes*: ProtoNodes nodes*: ProtoNodes
@ -121,7 +112,6 @@ type
balances*: seq[Gwei] balances*: seq[Gwei]
Checkpoints* = object Checkpoints* = object
version*: ForkChoiceVersion
time*: BeaconTime time*: BeaconTime
justified*: BalanceCheckpoint justified*: BalanceCheckpoint
finalized*: Checkpoint finalized*: Checkpoint

View File

@ -90,8 +90,7 @@ func nodeLeadsToViableHead(
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
func init*( func init*(
T: type ProtoArray, checkpoints: FinalityCheckpoints, T: type ProtoArray, checkpoints: FinalityCheckpoints): T =
version: ForkChoiceVersion): T =
let node = ProtoNode( let node = ProtoNode(
bid: BlockId( bid: BlockId(
slot: checkpoints.finalized.epoch.start_slot, slot: checkpoints.finalized.epoch.start_slot,
@ -103,8 +102,7 @@ func init*(
bestChild: none(int), bestChild: none(int),
bestDescendant: none(int)) bestDescendant: none(int))
T(version: version, T(checkpoints: checkpoints,
checkpoints: checkpoints,
nodes: ProtoNodes(buf: @[node], offset: 0), nodes: ProtoNodes(buf: @[node], offset: 0),
indices: {node.bid.root: 0}.toTable()) indices: {node.bid.root: 0}.toTable())
@ -536,23 +534,10 @@ func nodeIsViableForHead(
node.checkpoints.justified.epoch == self.checkpoints.justified.epoch node.checkpoints.justified.epoch == self.checkpoints.justified.epoch
if not correctJustified: if not correctJustified:
case self.version # The voting source should be either at the same height as the store's
of ForkChoiceVersion.Stable: # justified checkpoint or not more than two epochs ago
# If the previous epoch is justified, the block should be pulled-up. correctJustified =
# In this case, check that unrealized justification is higher than the node.checkpoints.justified.epoch + 2 >= self.currentEpoch
# 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 return
if not correctJustified: if not correctJustified:
@ -565,7 +550,7 @@ func nodeIsViableForHead(
true true
else: else:
# Check that this node is not going to be pruned # Check that this node is not going to be pruned
let let
finalizedEpoch = self.checkpoints.finalized.epoch finalizedEpoch = self.checkpoints.finalized.epoch
finalizedSlot = finalizedEpoch.start_slot finalizedSlot = finalizedEpoch.start_slot
var ancestor = some node var ancestor = some node

View File

@ -385,7 +385,7 @@ proc initFullNode(
quarantine = newClone( quarantine = newClone(
Quarantine.init()) Quarantine.init())
attestationPool = newClone(AttestationPool.init( attestationPool = newClone(AttestationPool.init(
dag, quarantine, config.forkChoiceVersion.get, onAttestationReceived)) dag, quarantine, onAttestationReceived))
syncCommitteeMsgPool = newClone( syncCommitteeMsgPool = newClone(
SyncCommitteeMsgPool.init(rng, dag.cfg, onSyncContribution)) SyncCommitteeMsgPool.init(rng, dag.cfg, onSyncContribution))
lightClientPool = newClone( lightClientPool = newClone(
@ -2249,8 +2249,6 @@ proc doRunBeaconNode(config: var BeaconNodeConf, rng: ref HmacDrbgContext) {.rai
# works # works
for node in metadata.bootstrapNodes: for node in metadata.bootstrapNodes:
config.bootstrapNodes.add node config.bootstrapNodes.add node
if config.forkChoiceVersion.isNone:
config.forkChoiceVersion = some(ForkChoiceVersion.Pr3431)
## Ctrl+C handling ## Ctrl+C handling
proc controlCHandler() {.noconv.} = proc controlCHandler() {.noconv.} =

View File

@ -90,8 +90,7 @@ proc installDebugApiHandlers*(router: var RestRouter, node: BeaconNode) =
var response = GetForkChoiceResponse( var response = GetForkChoiceResponse(
justified_checkpoint: forkChoice.checkpoints.justified.checkpoint, justified_checkpoint: forkChoice.checkpoints.justified.checkpoint,
finalized_checkpoint: forkChoice.checkpoints.finalized, finalized_checkpoint: forkChoice.checkpoints.finalized,
extra_data: RestExtraData( extra_data: RestExtraData())
version: some($forkChoice.backend.proto_array.version)))
for item in forkChoice.backend.proto_array: for item in forkChoice.backend.proto_array:
let let

View File

@ -601,7 +601,7 @@ type
extra_data*: Option[RestNodeExtraData] extra_data*: Option[RestNodeExtraData]
RestExtraData* = object RestExtraData* = object
version*: Option[string] discard
GetForkChoiceResponse* = object GetForkChoiceResponse* = object
justified_checkpoint*: Checkpoint justified_checkpoint*: Checkpoint

View File

@ -90,8 +90,7 @@ proc initialLoad(
dag = ChainDAGRef.init( dag = ChainDAGRef.init(
forkedState[].kind.genesisTestRuntimeConfig, db, validatorMonitor, {}) forkedState[].kind.genesisTestRuntimeConfig, db, validatorMonitor, {})
fkChoice = newClone(ForkChoice.init( fkChoice = newClone(ForkChoice.init(
dag.getFinalizedEpochRef(), dag.finalizedHead.blck, dag.getFinalizedEpochRef(), dag.finalizedHead.blck))
ForkChoiceVersion.Pr3431))
(dag, fkChoice) (dag, fkChoice)

View File

@ -298,8 +298,7 @@ proc startBeaconNode(basePort: int) {.raises: [CatchableError].} =
"--keymanager-port=" & $(basePort + PortKind.KeymanagerBN.ord), "--keymanager-port=" & $(basePort + PortKind.KeymanagerBN.ord),
"--keymanager-token-file=" & tokenFilePath, "--keymanager-token-file=" & tokenFilePath,
"--suggested-fee-recipient=" & $defaultFeeRecipient, "--suggested-fee-recipient=" & $defaultFeeRecipient,
"--doppelganger-detection=off", "--doppelganger-detection=off"], it))
"--debug-forkchoice-version=stable"], it))
except Exception as exc: # TODO fix confutils exceptions except Exception as exc: # TODO fix confutils exceptions
raiseAssert exc.msg raiseAssert exc.msg