Skip to content

Commit

Permalink
support EIP4844 LC data format
Browse files Browse the repository at this point in the history
Implements the proposed light client data format for EIP4844:
- ethereum/consensus-specs#3151
  • Loading branch information
etan-status committed Jan 16, 2023
1 parent f1ffc15 commit e101f70
Show file tree
Hide file tree
Showing 9 changed files with 605 additions and 57 deletions.
10 changes: 9 additions & 1 deletion ConsensusSpecPreset-mainnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,14 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Testing Withdrawal OK
```
OK: 48/48 Fail: 0/48 Skip: 0/48
## EF - EIP4844 - Unittests - Light client - Sync protocol [Preset: mainnet]
```diff
+ process_light_client_update_finality_updated OK
+ process_light_client_update_timeout OK
+ test_process_light_client_update_at_period_boundary OK
+ test_process_light_client_update_not_timeout OK
```
OK: 4/4 Fail: 0/4 Skip: 0/4
## EF - Phase 0 - Epoch Processing - Effective balance updates [Preset: mainnet]
```diff
+ Effective balance updates - effective_balance_hysteresis [Preset: mainnet] OK
Expand Down Expand Up @@ -2588,4 +2596,4 @@ OK: 63/63 Fail: 0/63 Skip: 0/63
OK: 100/100 Fail: 0/100 Skip: 0/100

---TOTAL---
OK: 2289/2298 Fail: 0/2298 Skip: 9/2298
OK: 2293/2302 Fail: 0/2302 Skip: 9/2302
10 changes: 9 additions & 1 deletion ConsensusSpecPreset-minimal.md
Original file line number Diff line number Diff line change
Expand Up @@ -2187,6 +2187,14 @@ OK: 5/5 Fail: 0/5 Skip: 0/5
+ Testing Withdrawal OK
```
OK: 48/48 Fail: 0/48 Skip: 0/48
## EF - EIP4844 - Unittests - Light client - Sync protocol [Preset: minimal]
```diff
+ process_light_client_update_finality_updated OK
+ process_light_client_update_timeout OK
+ test_process_light_client_update_at_period_boundary OK
+ test_process_light_client_update_not_timeout OK
```
OK: 4/4 Fail: 0/4 Skip: 0/4
## EF - Phase 0 - Epoch Processing - Effective balance updates [Preset: minimal]
```diff
+ Effective balance updates - effective_balance_hysteresis [Preset: minimal] OK
Expand Down Expand Up @@ -2755,4 +2763,4 @@ OK: 68/68 Fail: 0/68 Skip: 0/68
OK: 102/102 Fail: 0/102 Skip: 0/102

---TOTAL---
OK: 2440/2449 Fail: 0/2449 Skip: 9/2449
OK: 2444/2453 Fail: 0/2453 Skip: 9/2453
10 changes: 0 additions & 10 deletions beacon_chain/light_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,6 @@ proc installMessageValidators*(

let forkDigests = lightClient.forkDigests
for stateFork in BeaconStateFork:
if stateFork >= BeaconStateFork.EIP4844:
# Format is still in development, do not use Gossip at this time.
continue

withLcDataFork(lcDataForkAtStateFork(stateFork)):
when lcDataFork > LightClientDataFork.None:
let
Expand Down Expand Up @@ -420,9 +416,6 @@ proc updateGossipStatus*(

for gossipFork in oldGossipForks:
if gossipFork >= BeaconStateFork.Altair:
if gossipFork >= BeaconStateFork.EIP4844:
# Format is still in development, do not use Gossip at this time.
continue
let forkDigest = lightClient.forkDigests[].atStateFork(gossipFork)
lightClient.network.unsubscribe(
getLightClientFinalityUpdateTopic(forkDigest))
Expand All @@ -431,9 +424,6 @@ proc updateGossipStatus*(

for gossipFork in newGossipForks:
if gossipFork >= BeaconStateFork.Altair:
if gossipFork >= BeaconStateFork.EIP4844:
# Format is still in development, do not use Gossip at this time.
continue
let forkDigest = lightClient.forkDigests[].atStateFork(gossipFork)
lightClient.network.subscribe(
getLightClientFinalityUpdateTopic(forkDigest),
Expand Down
14 changes: 10 additions & 4 deletions beacon_chain/nimbus_beacon_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ proc installMessageValidators(node: BeaconNode) =
installPhase0Validators(forkDigests.altair)
installPhase0Validators(forkDigests.bellatrix)
installPhase0Validators(forkDigests.capella)
if node.dag.cfg.EIP4844_FORK_EPOCH != FAR_FUTURE_EPOCH:
if node.dag.cfg.EIP4844_FORK_EPOCH != FAR_FUTURE_EPOCH:
installPhase0Validators(forkDigests.eip4844)

node.network.addValidator(
Expand Down Expand Up @@ -1463,11 +1463,17 @@ proc installMessageValidators(node: BeaconNode) =
toValidationResult(node.processor[].processSignedBeaconBlock(
MsgSource.gossip, signedBlock)))

if node.dag.cfg.EIP4844_FORK_EPOCH != FAR_FUTURE_EPOCH:
if node.dag.cfg.EIP4844_FORK_EPOCH != FAR_FUTURE_EPOCH:
node.network.addValidator(
getBeaconBlockAndBlobsSidecarTopic(forkDigests.eip4844),
proc (signedBlock: eip4844.SignedBeaconBlockAndBlobsSidecar): ValidationResult =
# TODO: take into account node.shouldSyncOptimistically(node.currentSlot)
proc (
signedBlock: eip4844.SignedBeaconBlockAndBlobsSidecar
): ValidationResult =
if node.shouldSyncOptimistically(node.currentSlot):
toValidationResult(
node.optimisticProcessor.processSignedBeaconBlock(
signedBlock.beacon_block))
else:
toValidationResult(node.processor[].processSignedBeaconBlock(
MsgSource.gossip, signedBlock)))

Expand Down
16 changes: 9 additions & 7 deletions beacon_chain/nimbus_light_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import
./gossip_processing/optimistic_processor,
./networking/topic_params,
./spec/beaconstate,
./spec/datatypes/[phase0, altair, bellatrix, capella],
./spec/datatypes/[phase0, altair, bellatrix, capella, eip4844],
"."/[filepath, light_client, light_client_db, nimbus_binary_common, version]

from ./consensus_object_pools/consensus_manager import runForkchoiceUpdated
Expand Down Expand Up @@ -159,6 +159,14 @@ programMain:
proc (signedBlock: capella.SignedBeaconBlock): ValidationResult =
toValidationResult(
optimisticProcessor.processSignedBeaconBlock(signedBlock)))
network.addValidator(
getBeaconBlockAndBlobsSidecarTopic(forkDigests.eip4844),
proc (
signedBlock: eip4844.SignedBeaconBlockAndBlobsSidecar
): ValidationResult =
toValidationResult(
optimisticProcessor.processSignedBeaconBlock(
signedBlock.beacon_block)))
lightClient.installMessageValidators()
waitFor network.startListening()
waitFor network.start()
Expand Down Expand Up @@ -255,16 +263,10 @@ programMain:
oldGossipForks = currentGossipState - targetGossipState

for gossipFork in oldGossipForks:
if gossipFork >= BeaconStateFork.EIP4844:
# Format is still in development, do not use Gossip at this time.
continue
let forkDigest = forkDigests[].atStateFork(gossipFork)
network.unsubscribe(getBeaconBlocksTopic(forkDigest))

for gossipFork in newGossipForks:
if gossipFork >= BeaconStateFork.EIP4844:
# Format is still in development, do not use Gossip at this time.
continue
let forkDigest = forkDigests[].atStateFork(gossipFork)
network.subscribe(
getBeaconBlocksTopic(forkDigest), blocksTopicParams,
Expand Down
Loading

0 comments on commit e101f70

Please sign in to comment.