Skip to content

Commit

Permalink
make getTargetGossipState aware of Fulu + other fixes (#6780)
Browse files Browse the repository at this point in the history
* make getTargetGossipState aware of Fulu, make it aware of electra as well in LC

* fix indent

* minonr fix
  • Loading branch information
agnxsh authored Dec 20, 2024
1 parent c728d87 commit 06cf78a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
8 changes: 4 additions & 4 deletions beacon_chain/light_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ proc updateGossipStatus*(

currentEpochTargetGossipState = getTargetGossipState(
epoch, cfg.ALTAIR_FORK_EPOCH, cfg.BELLATRIX_FORK_EPOCH,
cfg.CAPELLA_FORK_EPOCH, cfg.DENEB_FORK_EPOCH, FAR_FUTURE_EPOCH,
isBehind)
cfg.CAPELLA_FORK_EPOCH, cfg.DENEB_FORK_EPOCH, cfg.ELECTRA_FORK_EPOCH,
cfg.FULU_FORK_EPOCH, isBehind)
targetGossipState =
if lcBehind or epoch < 1:
currentEpochTargetGossipState
Expand All @@ -400,8 +400,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, FAR_FUTURE_EPOCH,
isBehind)
cfg.CAPELLA_FORK_EPOCH, cfg.DENEB_FORK_EPOCH, cfg.ELECTRA_FORK_EPOCH,
cfg.FULU_FORK_EPOCH, isBehind)
currentEpochTargetGossipState + previousEpochTargetGossipState

template currentGossipState(): auto = lightClient.gossipState
Expand Down
3 changes: 2 additions & 1 deletion beacon_chain/nimbus_beacon_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ proc updateBlocksGossipStatus*(
targetGossipState = getTargetGossipState(
slot.epoch, cfg.ALTAIR_FORK_EPOCH, cfg.BELLATRIX_FORK_EPOCH,
cfg.CAPELLA_FORK_EPOCH, cfg.DENEB_FORK_EPOCH, cfg.ELECTRA_FORK_EPOCH,
isBehind)
cfg.FULU_FORK_EPOCH, isBehind)

template currentGossipState(): auto = node.blocksGossipState
if currentGossipState == targetGossipState:
Expand Down Expand Up @@ -1494,6 +1494,7 @@ proc updateGossipStatus(node: BeaconNode, slot: Slot) {.async.} =
node.dag.cfg.CAPELLA_FORK_EPOCH,
node.dag.cfg.DENEB_FORK_EPOCH,
node.dag.cfg.ELECTRA_FORK_EPOCH,
node.dag.cfg.FULU_FORK_EPOCH,
isBehind)

doAssert targetGossipState.card <= 2
Expand Down
4 changes: 2 additions & 2 deletions beacon_chain/nimbus_light_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ programMain:

targetGossipState = getTargetGossipState(
slot.epoch, cfg.ALTAIR_FORK_EPOCH, cfg.BELLATRIX_FORK_EPOCH,
cfg.CAPELLA_FORK_EPOCH, cfg.DENEB_FORK_EPOCH, FAR_FUTURE_EPOCH,
isBehind)
cfg.CAPELLA_FORK_EPOCH, cfg.DENEB_FORK_EPOCH, cfg.ELECTRA_FORK_EPOCH,
cfg.FULU_FORK_EPOCH, isBehind)

template currentGossipState(): auto = blocksGossipState
if currentGossipState == targetGossipState:
Expand Down
8 changes: 6 additions & 2 deletions beacon_chain/spec/network.nim
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ func getDiscoveryForkID*(cfg: RuntimeConfig,
type GossipState* = set[ConsensusFork]
func getTargetGossipState*(
epoch, ALTAIR_FORK_EPOCH, BELLATRIX_FORK_EPOCH, CAPELLA_FORK_EPOCH,
DENEB_FORK_EPOCH: Epoch, ELECTRA_FORK_EPOCH: Epoch, isBehind: bool):
DENEB_FORK_EPOCH, ELECTRA_FORK_EPOCH, FULU_FORK_EPOCH: Epoch,
isBehind: bool):
GossipState =
if isBehind:
return {}
Expand All @@ -173,6 +174,7 @@ func getTargetGossipState*(
doAssert CAPELLA_FORK_EPOCH >= BELLATRIX_FORK_EPOCH
doAssert DENEB_FORK_EPOCH >= CAPELLA_FORK_EPOCH
doAssert ELECTRA_FORK_EPOCH >= DENEB_FORK_EPOCH
doAssert FULU_FORK_EPOCH >= ELECTRA_FORK_EPOCH

# https://github.com/ethereum/consensus-specs/issues/2902
# Don't care whether ALTAIR_FORK_EPOCH == BELLATRIX_FORK_EPOCH or
Expand Down Expand Up @@ -200,7 +202,9 @@ func getTargetGossipState*(
maybeIncludeFork(
ConsensusFork.Deneb, DENEB_FORK_EPOCH, ELECTRA_FORK_EPOCH)
maybeIncludeFork(
ConsensusFork.Electra, ELECTRA_FORK_EPOCH, FAR_FUTURE_EPOCH)
ConsensusFork.Electra, ELECTRA_FORK_EPOCH, FULU_FORK_EPOCH)
maybeIncludeFork(
ConsensusFork.Electra, FULU_FORK_EPOCH, FAR_FUTURE_EPOCH)

doAssert len(targetForks) <= 2
targetForks
Expand Down
3 changes: 2 additions & 1 deletion tests/test_gossip_transition.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import

template getTargetGossipState(a, b, c, d, e: int, isBehind: bool): auto =
getTargetGossipState(
a.Epoch, b.Epoch, c.Epoch, d.Epoch, e.Epoch, FAR_FUTURE_EPOCH, isBehind)
a.Epoch, b.Epoch, c.Epoch, d.Epoch, e.Epoch, FAR_FUTURE_EPOCH,
FAR_FUTURE_EPOCH, isBehind)

suite "Gossip fork transition":
test "Gossip fork transition":
Expand Down

0 comments on commit 06cf78a

Please sign in to comment.