diff --git a/beacon_chain/light_client.nim b/beacon_chain/light_client.nim index e757be813..5490b05dd 100644 --- a/beacon_chain/light_client.nim +++ b/beacon_chain/light_client.nim @@ -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 diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index a2e0b5e5b..6a7385105 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -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 diff --git a/beacon_chain/nimbus_light_client.nim b/beacon_chain/nimbus_light_client.nim index 4f2a2b190..8725fd0df 100644 --- a/beacon_chain/nimbus_light_client.nim +++ b/beacon_chain/nimbus_light_client.nim @@ -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: diff --git a/beacon_chain/spec/network.nim b/beacon_chain/spec/network.nim index 6966b46ba..221253d6e 100644 --- a/beacon_chain/spec/network.nim +++ b/beacon_chain/spec/network.nim @@ -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 diff --git a/tests/test_gossip_transition.nim b/tests/test_gossip_transition.nim index 76751234b..00637e958 100644 --- a/tests/test_gossip_transition.nim +++ b/tests/test_gossip_transition.nim @@ -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} \ No newline at end of file