add electra gossip transition

This commit is contained in:
tersec 2024-05-15 13:30:49 +00:00
parent 0b8cb4efc4
commit 69f13eaa51
No known key found for this signature in database
GPG Key ID: 3D7A11A0156519DC
5 changed files with 23 additions and 8 deletions

View File

@ -382,7 +382,8 @@ proc updateGossipStatus*(
currentEpochTargetGossipState = getTargetGossipState(
epoch, cfg.ALTAIR_FORK_EPOCH, cfg.BELLATRIX_FORK_EPOCH,
cfg.CAPELLA_FORK_EPOCH, cfg.DENEB_FORK_EPOCH, isBehind)
cfg.CAPELLA_FORK_EPOCH, cfg.DENEB_FORK_EPOCH, cfg.ELECTRA_FORK_EPOCH,
isBehind)
targetGossipState =
if lcBehind or epoch < 1:
currentEpochTargetGossipState
@ -392,7 +393,8 @@ proc updateGossipStatus*(
# Therefore, LC topic subscriptions are kept for 1 extra epoch.
let previousEpochTargetGossipState = getTargetGossipState(
epoch - 1, cfg.ALTAIR_FORK_EPOCH, cfg.BELLATRIX_FORK_EPOCH,
cfg.CAPELLA_FORK_EPOCH, cfg.DENEB_FORK_EPOCH, isBehind)
cfg.CAPELLA_FORK_EPOCH, cfg.DENEB_FORK_EPOCH, cfg.ELECTRA_FORK_EPOCH,
isBehind)
currentEpochTargetGossipState + previousEpochTargetGossipState
template currentGossipState(): auto = lightClient.gossipState

View File

@ -810,6 +810,9 @@ proc init*(T: type BeaconNode,
func getDenebForkEpoch(): Opt[Epoch] =
Opt.some(cfg.DENEB_FORK_EPOCH)
func getElectraForkEpoch(): Opt[Epoch] =
Opt.some(cfg.ELECTRA_FORK_EPOCH)
proc getForkForEpoch(epoch: Epoch): Opt[Fork] =
Opt.some(dag.forkAtEpoch(epoch))
@ -979,7 +982,8 @@ proc updateBlocksGossipStatus*(
targetGossipState = getTargetGossipState(
slot.epoch, cfg.ALTAIR_FORK_EPOCH, cfg.BELLATRIX_FORK_EPOCH,
cfg.CAPELLA_FORK_EPOCH, cfg.DENEB_FORK_EPOCH, isBehind)
cfg.CAPELLA_FORK_EPOCH, cfg.DENEB_FORK_EPOCH, cfg.ELECTRA_FORK_EPOCH,
isBehind)
template currentGossipState(): auto = node.blocksGossipState
if currentGossipState == targetGossipState:
@ -1285,6 +1289,8 @@ proc updateGossipStatus(node: BeaconNode, slot: Slot) {.async.} =
TOPIC_SUBSCRIBE_THRESHOLD_SLOTS = 64
HYSTERESIS_BUFFER = 16
static: doAssert high(ConsensusFork) == ConsensusFork.Electra
let
head = node.dag.head
headDistance =
@ -1299,6 +1305,7 @@ proc updateGossipStatus(node: BeaconNode, slot: Slot) {.async.} =
node.dag.cfg.BELLATRIX_FORK_EPOCH,
node.dag.cfg.CAPELLA_FORK_EPOCH,
node.dag.cfg.DENEB_FORK_EPOCH,
node.dag.cfg.ELECTRA_FORK_EPOCH,
isBehind)
doAssert targetGossipState.card <= 2

View File

@ -222,7 +222,8 @@ programMain:
targetGossipState = getTargetGossipState(
slot.epoch, cfg.ALTAIR_FORK_EPOCH, cfg.BELLATRIX_FORK_EPOCH,
cfg.CAPELLA_FORK_EPOCH, cfg.DENEB_FORK_EPOCH, isBehind)
cfg.CAPELLA_FORK_EPOCH, cfg.DENEB_FORK_EPOCH, cfg.ELECTRA_FORK_EPOCH,
isBehind)
template currentGossipState(): auto = blocksGossipState
if currentGossipState == targetGossipState:

View File

@ -155,13 +155,15 @@ func getDiscoveryForkID*(cfg: RuntimeConfig,
type GossipState* = set[ConsensusFork]
func getTargetGossipState*(
epoch, ALTAIR_FORK_EPOCH, BELLATRIX_FORK_EPOCH, CAPELLA_FORK_EPOCH,
DENEB_FORK_EPOCH: Epoch, isBehind: bool): GossipState =
DENEB_FORK_EPOCH: Epoch, ELECTRA_FORK_EPOCH: Epoch, isBehind: bool):
GossipState =
if isBehind:
return {}
doAssert BELLATRIX_FORK_EPOCH >= ALTAIR_FORK_EPOCH
doAssert CAPELLA_FORK_EPOCH >= BELLATRIX_FORK_EPOCH
doAssert DENEB_FORK_EPOCH >= CAPELLA_FORK_EPOCH
doAssert ELECTRA_FORK_EPOCH >= DENEB_FORK_EPOCH
# https://github.com/ethereum/consensus-specs/issues/2902
# Don't care whether ALTAIR_FORK_EPOCH == BELLATRIX_FORK_EPOCH or
@ -187,7 +189,9 @@ func getTargetGossipState*(
maybeIncludeFork(
ConsensusFork.Capella, CAPELLA_FORK_EPOCH, DENEB_FORK_EPOCH)
maybeIncludeFork(
ConsensusFork.Deneb, DENEB_FORK_EPOCH, FAR_FUTURE_EPOCH)
ConsensusFork.Deneb, DENEB_FORK_EPOCH, ELECTRA_FORK_EPOCH)
maybeIncludeFork(
ConsensusFork.Electra, ELECTRA_FORK_EPOCH, FAR_FUTURE_EPOCH)
doAssert len(targetForks) <= 2
targetForks

View File

@ -14,7 +14,8 @@ import
../beacon_chain/spec/[forks, network]
template getTargetGossipState(a, b, c, d, e: int, isBehind: bool): auto =
getTargetGossipState(a.Epoch, b.Epoch, c.Epoch, d.Epoch, e.Epoch, isBehind)
getTargetGossipState(
a.Epoch, b.Epoch, c.Epoch, d.Epoch, e.Epoch, FAR_FUTURE_EPOCH, isBehind)
suite "Gossip fork transition":
test "Gossip fork transition":
@ -505,4 +506,4 @@ suite "Gossip fork transition":
getTargetGossipState( 7, 1, 6, 10, 11, false) == {ConsensusFork.Bellatrix}
getTargetGossipState( 0, 6, 9, 10, 11, false) == {ConsensusFork.Phase0}
getTargetGossipState( 4, 1, 2, 3, 5, false) == {ConsensusFork.Capella, ConsensusFork.Deneb}
getTargetGossipState( 9, 1, 2, 7, 8, false) == {ConsensusFork.Deneb}
getTargetGossipState( 9, 1, 2, 7, 8, false) == {ConsensusFork.Deneb}