diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9d47f815f5..5fe68a76cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -215,7 +215,7 @@ jobs: if: ${{ !cancelled() }} && github.event_name == 'pull_request' run: | excluded_files="config.yaml" - excluded_extensions="ans|json|md|png|ssz|txt" + excluded_extensions="ans|json|md|png|service|ssz|txt" current_year=$(date +"%Y") outdated_files=() diff --git a/Makefile b/Makefile index e8f07e01a2..94cb0e9a75 100644 --- a/Makefile +++ b/Makefile @@ -321,7 +321,7 @@ consensus_spec_tests_minimal: | build deps MAKE="$(MAKE)" V="$(V)" $(ENV_SCRIPT) scripts/compile_nim_program.sh \ $@ \ "tests/consensus_spec/consensus_spec_tests_preset.nim" \ - $(NIM_PARAMS) -d:const_preset=minimal $(TEST_MODULES_FLAGS) && \ + $(NIM_PARAMS) -d:const_preset=minimal -d:FIELD_ELEMENTS_PER_BLOB=4 $(TEST_MODULES_FLAGS) && \ echo -e $(BUILD_END_MSG) "build/$@" # Tests we only run for the default preset diff --git a/beacon_chain/fork_choice/fork_choice.nim b/beacon_chain/fork_choice/fork_choice.nim index c8677b7b60..94e09a29b8 100644 --- a/beacon_chain/fork_choice/fork_choice.nim +++ b/beacon_chain/fork_choice/fork_choice.nim @@ -73,6 +73,7 @@ proc init*( version: version, justified: BalanceCheckpoint( checkpoint: checkpoint, + total_active_balance: epochRef.total_active_balance, balances: epochRef.effective_balances), finalized: checkpoint, best_justified: checkpoint)) @@ -98,6 +99,7 @@ proc update_justified( store = self.justified.checkpoint, state = justified self.justified = BalanceCheckpoint( checkpoint: Checkpoint(root: blck.root, epoch: epochRef.epoch), + total_active_balance: epochRef.total_active_balance, balances: epochRef.effective_balances) proc update_justified( @@ -321,10 +323,11 @@ proc process_block*(self: var ForkChoice, ok() -func find_head*( +func find_head( self: var ForkChoiceBackend, current_epoch: Epoch, checkpoints: FinalityCheckpoints, + justified_total_active_balance: Gwei, justified_state_balances: seq[Gwei], proposer_boost_root: Eth2Digest ): FcResult[Eth2Digest] = @@ -343,7 +346,7 @@ func find_head*( # Apply score changes ? self.proto_array.applyScoreChanges( deltas, current_epoch, checkpoints, - justified_state_balances, proposer_boost_root) + justified_total_active_balance, proposer_boost_root) self.balances = justified_state_balances @@ -367,6 +370,7 @@ proc get_head*(self: var ForkChoice, FinalityCheckpoints( justified: self.checkpoints.justified.checkpoint, finalized: self.checkpoints.finalized), + self.checkpoints.justified.total_active_balance, self.checkpoints.justified.balances, self.checkpoints.proposer_boost_root) diff --git a/beacon_chain/fork_choice/fork_choice_types.nim b/beacon_chain/fork_choice/fork_choice_types.nim index 27a94980b9..3f26a06735 100644 --- a/beacon_chain/fork_choice/fork_choice_types.nim +++ b/beacon_chain/fork_choice/fork_choice_types.nim @@ -113,6 +113,7 @@ type BalanceCheckpoint* = object checkpoint*: Checkpoint + total_active_balance*: Gwei balances*: seq[Gwei] Checkpoints* = object diff --git a/beacon_chain/fork_choice/proto_array.nim b/beacon_chain/fork_choice/proto_array.nim index b0d125cdca..836537d1be 100644 --- a/beacon_chain/fork_choice/proto_array.nim +++ b/beacon_chain/fork_choice/proto_array.nim @@ -126,18 +126,15 @@ iterator realizePendingCheckpoints*( self.currentEpochTips.clear() # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/phase0/fork-choice.md#get_weight -func calculateProposerBoost(validatorBalances: openArray[Gwei]): uint64 = - var total_balance: uint64 - for balance in validatorBalances: - total_balance += balance - let committee_weight = total_balance div SLOTS_PER_EPOCH +func calculateProposerBoost(justifiedTotalActiveBalance: Gwei): Gwei = + let committee_weight = justifiedTotalActiveBalance div SLOTS_PER_EPOCH (committee_weight * PROPOSER_SCORE_BOOST) div 100 func applyScoreChanges*(self: var ProtoArray, deltas: var openArray[Delta], currentEpoch: Epoch, checkpoints: FinalityCheckpoints, - newBalances: openArray[Gwei], + justifiedTotalActiveBalance: Gwei, proposerBoostRoot: Eth2Digest): FcResult[void] = ## Iterate backwards through the array, touching all nodes and their parents ## and potentially the best-child of each parent. @@ -169,7 +166,7 @@ func applyScoreChanges*(self: var ProtoArray, self.nodes.buf[nodePhysicalIdx] # Default value, if not otherwise set in first node loop - var proposerBoostScore: uint64 + var proposerBoostScore: Gwei # Iterate backwards through all the indices in `self.nodes` for nodePhysicalIdx in countdown(self.nodes.len - 1, 0): @@ -194,7 +191,7 @@ func applyScoreChanges*(self: var ProtoArray, # # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/phase0/fork-choice.md#get_weight if (not proposerBoostRoot.isZero) and proposerBoostRoot == node.bid.root: - proposerBoostScore = calculateProposerBoost(newBalances) + proposerBoostScore = calculateProposerBoost(justifiedTotalActiveBalance) if nodeDelta >= 0 and high(Delta) - nodeDelta < proposerBoostScore.int64: return err ForkChoiceError( diff --git a/beacon_chain/gossip_processing/gossip_validation.nim b/beacon_chain/gossip_processing/gossip_validation.nim index effa14b36c..a267cc2b07 100644 --- a/beacon_chain/gossip_processing/gossip_validation.nim +++ b/beacon_chain/gossip_processing/gossip_validation.nim @@ -99,9 +99,10 @@ func check_propagation_slot_range( # The spec value of ATTESTATION_PROPAGATION_SLOT_RANGE is 32, but it can # retransmit attestations on the cusp of being out of spec, and which by # the time they reach their destination might be out of spec. - const ATTESTATION_PROPAGATION_SLOT_RANGE = 28 - - if msgSlot + ATTESTATION_PROPAGATION_SLOT_RANGE < pastSlot.slot: + const TIME_IN_FLIGHT_BUFFER = 4 + static: doAssert ATTESTATION_PROPAGATION_SLOT_RANGE > TIME_IN_FLIGHT_BUFFER + if msgSlot + (ATTESTATION_PROPAGATION_SLOT_RANGE - TIME_IN_FLIGHT_BUFFER) < + pastSlot.slot: return errIgnore("Attestation slot in the past") else: # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/deneb/p2p-interface.md#beacon_attestation_subnet_id diff --git a/beacon_chain/spec/datatypes/constants.nim b/beacon_chain/spec/datatypes/constants.nim index 3da0397ab5..0587f7bdfb 100644 --- a/beacon_chain/spec/datatypes/constants.nim +++ b/beacon_chain/spec/datatypes/constants.nim @@ -66,6 +66,7 @@ const # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/phase0/p2p-interface.md#configuration MAX_REQUEST_BLOCKS* = 1024'u64 RESP_TIMEOUT* = 10'u64 + ATTESTATION_PROPAGATION_SLOT_RANGE*: uint64 = 32 # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/bellatrix/p2p-interface.md#configuration GOSSIP_MAX_SIZE* = 10'u64 * 1024 * 1024 # bytes diff --git a/beacon_chain/spec/presets.nim b/beacon_chain/spec/presets.nim index e8aca6697d..96637972dc 100644 --- a/beacon_chain/spec/presets.nim +++ b/beacon_chain/spec/presets.nim @@ -604,6 +604,7 @@ proc readRuntimeConfig*( checkCompatibility TTFB_TIMEOUT checkCompatibility MESSAGE_DOMAIN_INVALID_SNAPPY checkCompatibility MAX_REQUEST_BLOCKS_DENEB + checkCompatibility ATTESTATION_PROPAGATION_SLOT_RANGE # Isn't being used as a preset in the usual way: at any time, there's one correct value checkCompatibility PROPOSER_SCORE_BOOST diff --git a/beacon_chain/spec/state_transition_block.nim b/beacon_chain/spec/state_transition_block.nim index 0c79d19d7e..4224ffe8cc 100644 --- a/beacon_chain/spec/state_transition_block.nim +++ b/beacon_chain/spec/state_transition_block.nim @@ -791,7 +791,10 @@ proc validate_blobs*(expected_kzg_commitments: seq[KzgCommitment], if proofs.len != blobs.len: return err("validate_blobs: different proof and blob lengths") - if verifyProofs(blobs, expected_kzg_commitments, proofs).isErr(): + let res = verifyProofs(blobs, expected_kzg_commitments, proofs).valueOr: + return err("validate_blobs: proof verification error") + + if not res: return err("validate_blobs: proof verification failed") ok() diff --git a/docs/the_nimbus_book/src/developers.md b/docs/the_nimbus_book/src/developers.md index 858fae4ea9..6897d81d4e 100644 --- a/docs/the_nimbus_book/src/developers.md +++ b/docs/the_nimbus_book/src/developers.md @@ -217,7 +217,7 @@ USE_MULTITAIL="yes" make local-testnet-minimal You’ll get something like this (click for full size): -[![](https://i.imgur.com/Pc99VDO.png)](https://i.imgur.com/Pc99VDO.png) +[![](./img/developers_01.png)](./img/developers_01.png) You can find out more about the beacon node simulation [here](https://our.status.im/nimbus-development-update-03/#beaconsimulation). diff --git a/docs/the_nimbus_book/src/email-notifications.md b/docs/the_nimbus_book/src/email-notifications.md index 1aba103420..0399fbe6dc 100644 --- a/docs/the_nimbus_book/src/email-notifications.md +++ b/docs/the_nimbus_book/src/email-notifications.md @@ -8,17 +8,17 @@ You can create an account on [beaconcha.in](https://beaconcha.in/) to set up ema ### 1. Sign up at [beaconcha.in/register](https://beaconcha.in/register) -### 2. Type your validator's public key into the searchbar +### 2. Type your validator's public key into the search bar -![](https://i.imgur.com/jHjkySK.png) +![](./img/email_01.png) ### 3. Click on the bookmark icon -![](https://i.imgur.com/O7zgE0k.png) +![](./img/email_02.png) ### 4. Tick the boxes and select *Add To Watchlist* -![](https://i.imgur.com/7ff4Ta7.png) +![](./img/email_03.png) diff --git a/docs/the_nimbus_book/src/health.md b/docs/the_nimbus_book/src/health.md index 2b98d6a09b..6ee0287cff 100644 --- a/docs/the_nimbus_book/src/health.md +++ b/docs/the_nimbus_book/src/health.md @@ -13,7 +13,7 @@ As long as your validator is within the allowed inclusion distance, you will get You can verify your validator's effectiveness on the [beaconcha.in](https://beaconcha.in/) website. -![](https://i.imgur.com/u80Ub2j.png) +![](./img/health.png) Ideally you want to see a value above 95%. diff --git a/docs/the_nimbus_book/src/holesky.md b/docs/the_nimbus_book/src/holesky.md index b540702f64..b582524948 100644 --- a/docs/the_nimbus_book/src/holesky.md +++ b/docs/the_nimbus_book/src/holesky.md @@ -1,10 +1,18 @@ # Holešky testnet -`holesky` will be launched on 15h of September to succeed Prater as the main long-running Ethereum testnet. +`holesky` is the main long-running Ethereum staking, infrastructure and protocol-developer testnet. +For testing decentralized applications, smart contracts, and other EVM functionality, please use Sepolia testnet! +`holesky` replaces the Prater/Görli network which has been deprecated since early 2023. + It provides an opportunity to verify your setup works as expected through the proof-of-stake transition and in a post-merge context as well as to safely practice node operations such as adding and removing validators, migrating between clients, and performing upgrades and backups. If you come across any issues, please [report them here](https://github.com/status-im/nimbus-eth2/issues). + + + + + ## General Preparation 1. Generate the JWT secret with `openssl rand -hex 32 | tr -d "\n" > "/opt/jwtsecret"`. This file needs to be passed to both the execution client and the consensus client. diff --git a/docs/the_nimbus_book/src/img/developers_01.png b/docs/the_nimbus_book/src/img/developers_01.png new file mode 100644 index 0000000000..0771d1c16d Binary files /dev/null and b/docs/the_nimbus_book/src/img/developers_01.png differ diff --git a/docs/the_nimbus_book/src/img/email_01.png b/docs/the_nimbus_book/src/img/email_01.png new file mode 100644 index 0000000000..a2bc8e4fcc Binary files /dev/null and b/docs/the_nimbus_book/src/img/email_01.png differ diff --git a/docs/the_nimbus_book/src/img/email_02.png b/docs/the_nimbus_book/src/img/email_02.png new file mode 100644 index 0000000000..80d7a67bcf Binary files /dev/null and b/docs/the_nimbus_book/src/img/email_02.png differ diff --git a/docs/the_nimbus_book/src/img/email_03.png b/docs/the_nimbus_book/src/img/email_03.png new file mode 100644 index 0000000000..b7f91a257c Binary files /dev/null and b/docs/the_nimbus_book/src/img/email_03.png differ diff --git a/docs/the_nimbus_book/src/img/health.png b/docs/the_nimbus_book/src/img/health.png new file mode 100644 index 0000000000..46e60293c4 Binary files /dev/null and b/docs/the_nimbus_book/src/img/health.png differ diff --git a/docs/the_nimbus_book/src/img/metrics_01.png b/docs/the_nimbus_book/src/img/metrics_01.png new file mode 100644 index 0000000000..602c9c526d Binary files /dev/null and b/docs/the_nimbus_book/src/img/metrics_01.png differ diff --git a/docs/the_nimbus_book/src/img/metrics_02.png b/docs/the_nimbus_book/src/img/metrics_02.png new file mode 100644 index 0000000000..2f11901f06 Binary files /dev/null and b/docs/the_nimbus_book/src/img/metrics_02.png differ diff --git a/docs/the_nimbus_book/src/img/metrics_03.png b/docs/the_nimbus_book/src/img/metrics_03.png new file mode 100644 index 0000000000..399214a690 Binary files /dev/null and b/docs/the_nimbus_book/src/img/metrics_03.png differ diff --git a/docs/the_nimbus_book/src/img/metrics_04.png b/docs/the_nimbus_book/src/img/metrics_04.png new file mode 100644 index 0000000000..e5187871af Binary files /dev/null and b/docs/the_nimbus_book/src/img/metrics_04.png differ diff --git a/docs/the_nimbus_book/src/img/metrics_05.png b/docs/the_nimbus_book/src/img/metrics_05.png new file mode 100644 index 0000000000..e5514d5298 Binary files /dev/null and b/docs/the_nimbus_book/src/img/metrics_05.png differ diff --git a/docs/the_nimbus_book/src/img/metrics_06.png b/docs/the_nimbus_book/src/img/metrics_06.png new file mode 100644 index 0000000000..b66e03d431 Binary files /dev/null and b/docs/the_nimbus_book/src/img/metrics_06.png differ diff --git a/docs/the_nimbus_book/src/img/metrics_07.png b/docs/the_nimbus_book/src/img/metrics_07.png new file mode 100644 index 0000000000..8a2828384d Binary files /dev/null and b/docs/the_nimbus_book/src/img/metrics_07.png differ diff --git a/docs/the_nimbus_book/src/img/metrics_08.png b/docs/the_nimbus_book/src/img/metrics_08.png new file mode 100644 index 0000000000..9e3640032f Binary files /dev/null and b/docs/the_nimbus_book/src/img/metrics_08.png differ diff --git a/docs/the_nimbus_book/src/img/metrics_09.png b/docs/the_nimbus_book/src/img/metrics_09.png new file mode 100644 index 0000000000..d738c22da6 Binary files /dev/null and b/docs/the_nimbus_book/src/img/metrics_09.png differ diff --git a/docs/the_nimbus_book/src/img/metrics_10.png b/docs/the_nimbus_book/src/img/metrics_10.png new file mode 100644 index 0000000000..60b1f59df8 Binary files /dev/null and b/docs/the_nimbus_book/src/img/metrics_10.png differ diff --git a/docs/the_nimbus_book/src/img/metrics_11.png b/docs/the_nimbus_book/src/img/metrics_11.png new file mode 100644 index 0000000000..fc90a96f6c Binary files /dev/null and b/docs/the_nimbus_book/src/img/metrics_11.png differ diff --git a/docs/the_nimbus_book/src/img/metrics_12.png b/docs/the_nimbus_book/src/img/metrics_12.png new file mode 100644 index 0000000000..f3d209fb78 Binary files /dev/null and b/docs/the_nimbus_book/src/img/metrics_12.png differ diff --git a/docs/the_nimbus_book/src/img/metrics_13.png b/docs/the_nimbus_book/src/img/metrics_13.png new file mode 100644 index 0000000000..ab4e7b3ba2 Binary files /dev/null and b/docs/the_nimbus_book/src/img/metrics_13.png differ diff --git a/docs/the_nimbus_book/src/metrics-pretty-pictures.md b/docs/the_nimbus_book/src/metrics-pretty-pictures.md index b72673517e..609586ad33 100644 --- a/docs/the_nimbus_book/src/metrics-pretty-pictures.md +++ b/docs/the_nimbus_book/src/metrics-pretty-pictures.md @@ -124,7 +124,7 @@ Follow [the instructions for your platform](https://grafana.com/docs/grafana/lat Go to [http://localhost:3000/](http://localhost:3000/), you should see a Grafana login screen that looks like this: -![](https://i.imgur.com/jcP1qWl.png) +![](./img/metrics_01.png) Type in `admin` for both the username and password. You'll be asked to change the password (and we recommend you do so). @@ -134,48 +134,48 @@ You'll be asked to change the password (and we recommend you do so). Hover your mouse over the gear icon in the left menu bar, and click on the `Data Sources` option in the sub-menu that pops up. -![](https://i.imgur.com/0Xsgx61.png) +![](./img/metrics_02.png) Now click on the `Add Data Source` button in the center of the screen -![](https://i.imgur.com/YRVJjdD.png) +![](./img/metrics_03.png) Select `Prometheus` -![](https://i.imgur.com/YpwThOr.png) +![](./img/metrics_04.png) Enter `http://localhost:9090` in the URL field -![](https://i.imgur.com/PtVOnur.png) +![](./img/metrics_05.png) Set the "Scrape interval" field to the same value you used in the Prometheus config ("15s" in our example below). Scroll to the bottom and click on `Save and Test` -![](https://i.imgur.com/GJVdwaK.png) +![](./img/metrics_06.png) If everything is working correctly you should see a green `Data source is working` box pop up -![](https://i.imgur.com/vf5ahNA.png) +![](./img/metrics_07.png) #### 8. Import a dashboard Now, let's import a dashboard; hover your mouse over the `+` icon in the left menu bar and select `import` from the pop-up menu -![](https://i.imgur.com/WnnAcUR.png) +![](./img/metrics_08.png) Click on `Upload JSON file` -![](https://i.imgur.com/l65ICZ2.png) +![](./img/metrics_09.png) Select the `beacon_nodes_Grafana_dashboard.json` from the `nimbus-eth2/grafana/` folder and click on `Import` -![](https://i.imgur.com/SoU5Isz.png) +![](./img/metrics_10.png) You'll be directed to the dashboard where you'll be able to gain insights into the performance of `nimbus-eth2` and your validators -![](https://i.imgur.com/aIfJ1iT.png) +![](./img/metrics_11.png) !!! note The dashboard is very much a work in progress. @@ -190,7 +190,7 @@ And voilà! That's all there is to it :) ### Joe Clapis -![](https://i.imgur.com/05eJeBr.png) +![](./img/metrics_12.png) Joe — who’s done some brilliant work [integrating Nimbus with Rocket Pool](https://our.status.im/rocket-pool-integration/) — has created a [wonderful guide](https://github.com/jclapis/rp-pi-guide/blob/main/Grafana.md) where he takes you through how to set up a Grafana server on your Pi, using his dashboard as an example. @@ -203,7 +203,7 @@ Whether or not you're running a Pi, we recommend you check out [his guide]( http ### Metanull -![](https://i.imgur.com/OlvNGlq.jpg) +![](./img/metrics_13.png) A dashboard aimed primarily at users rather than developers. diff --git a/grafana/README.md b/grafana/README.md index 1f97782f39..884abde88d 100644 --- a/grafana/README.md +++ b/grafana/README.md @@ -19,10 +19,10 @@ In order to use it locally, you would have to make some changes: Click the small "share" icon on the top-left of the Grafana dashboard: -![share icon](https://i.imgur.com/ds3BJoj.png) +![share icon](./img/grafana_01.png) Go to the "Export" tab and enable "Export for sharing externally": -![export tab](https://i.imgur.com/sxgrThb.png) +![export tab](./img/grafana_02.png) Now you can either "Save to file" or "View JSON" and copy/paste into the destination file, whichever is faster for you. diff --git a/grafana/img/grafana_01.png b/grafana/img/grafana_01.png new file mode 100644 index 0000000000..b81997f4cf Binary files /dev/null and b/grafana/img/grafana_01.png differ diff --git a/grafana/img/grafana_02.png b/grafana/img/grafana_02.png new file mode 100644 index 0000000000..ee1deed6fe Binary files /dev/null and b/grafana/img/grafana_02.png differ diff --git a/tests/consensus_spec/test_fixture_fork_choice.nim b/tests/consensus_spec/test_fixture_fork_choice.nim index a3bd37879e..e0fc77d7ab 100644 --- a/tests/consensus_spec/test_fixture_fork_choice.nim +++ b/tests/consensus_spec/test_fixture_fork_choice.nim @@ -9,7 +9,7 @@ import # Status libraries - stew/results, chronicles, + stew/[byteutils, results], chronicles, taskpools, # Internals ../../beacon_chain/spec/[helpers, forks, state_transition_block], @@ -28,7 +28,7 @@ import from std/json import JsonNode, getBool, getInt, getStr, hasKey, items, len, pairs, `$`, `[]` -from std/sequtils import toSeq +from std/sequtils import mapIt, toSeq from std/strutils import contains # Test format described at https://github.com/ethereum/consensus-specs/tree/v1.3.0/tests/formats/fork_choice @@ -45,6 +45,10 @@ type opInvalidateRoot opChecks + BlobData = object + blobs: seq[KzgBlob] + proofs: seq[KzgProof] + Operation = object valid: bool # variant specific fields @@ -55,6 +59,7 @@ type att: Attestation of opOnBlock: blck: ForkedSignedBeaconBlock + blobData: Opt[BlobData] of opOnMergeBlock: powBlock: PowBlock of opOnAttesterSlashing: @@ -69,7 +74,7 @@ from ../../beacon_chain/spec/datatypes/capella import BeaconBlock, BeaconState, SignedBeaconBlock from ../../beacon_chain/spec/datatypes/deneb import - BeaconBlock, BeaconState, SignedBeaconBlock + KzgBlob, KzgProof, BeaconBlock, BeaconState, SignedBeaconBlock proc initialLoad( path: string, db: BeaconChainDB, @@ -134,6 +139,8 @@ proc loadOps(path: string, fork: ConsensusFork): seq[Operation] = result = @[] for step in steps[0]: + var numExtraFields = 0 + if step.hasKey"tick": result.add Operation(kind: opOnTick, tick: step["tick"].getInt()) @@ -147,12 +154,14 @@ proc loadOps(path: string, fork: ConsensusFork): seq[Operation] = att: att) elif step.hasKey"block": let filename = step["block"].getStr() + doAssert step.hasKey"blobs" == step.hasKey"proofs" case fork of ConsensusFork.Phase0: let blck = parseTest( path/filename & ".ssz_snappy", SSZ, phase0.SignedBeaconBlock ) + doAssert not step.hasKey"blobs" result.add Operation(kind: opOnBlock, blck: ForkedSignedBeaconBlock.init(blck)) of ConsensusFork.Altair: @@ -160,6 +169,7 @@ proc loadOps(path: string, fork: ConsensusFork): seq[Operation] = path/filename & ".ssz_snappy", SSZ, altair.SignedBeaconBlock ) + doAssert not step.hasKey"blobs" result.add Operation(kind: opOnBlock, blck: ForkedSignedBeaconBlock.init(blck)) of ConsensusFork.Bellatrix: @@ -167,6 +177,7 @@ proc loadOps(path: string, fork: ConsensusFork): seq[Operation] = path/filename & ".ssz_snappy", SSZ, bellatrix.SignedBeaconBlock ) + doAssert not step.hasKey"blobs" result.add Operation(kind: opOnBlock, blck: ForkedSignedBeaconBlock.init(blck)) of ConsensusFork.Capella: @@ -174,15 +185,27 @@ proc loadOps(path: string, fork: ConsensusFork): seq[Operation] = path/filename & ".ssz_snappy", SSZ, capella.SignedBeaconBlock ) + doAssert not step.hasKey"blobs" result.add Operation(kind: opOnBlock, blck: ForkedSignedBeaconBlock.init(blck)) of ConsensusFork.Deneb: - let blck = parseTest( - path/filename & ".ssz_snappy", - SSZ, deneb.SignedBeaconBlock - ) + let + blck = parseTest( + path/filename & ".ssz_snappy", + SSZ, deneb.SignedBeaconBlock) + blobData = + if step.hasKey"blobs": + numExtraFields += 2 + Opt.some BlobData( + blobs: distinctBase(parseTest( + path/(step["blobs"].getStr()) & ".ssz_snappy", + SSZ, List[KzgBlob, Limit MAX_BLOBS_PER_BLOCK])), + proofs: step["proofs"].mapIt(KzgProof.fromHex(it.getStr()))) + else: + Opt.none(BlobData) result.add Operation(kind: opOnBlock, - blck: ForkedSignedBeaconBlock.init(blck)) + blck: ForkedSignedBeaconBlock.init(blck), + blobData: blobData) elif step.hasKey"attester_slashing": let filename = step["attester_slashing"].getStr() let attesterSlashing = parseTest( @@ -205,10 +228,10 @@ proc loadOps(path: string, fork: ConsensusFork): seq[Operation] = doAssert false, "Unknown test step: " & $step if step.hasKey"valid": - doAssert step.len == 2 + doAssert step.len == 2 + numExtraFields result[^1].valid = step["valid"].getBool() elif not step.hasKey"checks" and not step.hasKey"payload_status": - doAssert step.len == 1 + doAssert step.len == 1 + numExtraFields result[^1].valid = true proc stepOnBlock( @@ -218,10 +241,21 @@ proc stepOnBlock( state: var ForkedHashedBeaconState, stateCache: var StateCache, signedBlock: ForkySignedBeaconBlock, + blobData: Opt[BlobData], time: BeaconTime, invalidatedRoots: Table[Eth2Digest, Eth2Digest]): Result[BlockRef, VerifierError] = - # 1. Move state to proper slot. + # 1. Validate blobs + when typeof(signedBlock).toFork() >= ConsensusFork.Deneb: + let kzgCommits = signedBlock.message.body.blob_kzg_commitments.asSeq + if kzgCommits.len > 0 or blobData.isSome: + if blobData.isNone or kzgCommits.validate_blobs( + blobData.get.blobs, blobData.get.proofs).isErr: + return err(VerifierError.Invalid) + else: + doAssert blobData.isNone, "Pre-Deneb test with specified blob data" + + # 2. Move state to proper slot doAssert dag.updateState( state, dag.getBlockIdAtSlot(time.slotOrZero).expect("block exists"), @@ -229,7 +263,7 @@ proc stepOnBlock( stateCache ) - # 2. Add block to DAG + # 3. Add block to DAG when signedBlock is phase0.SignedBeaconBlock: type TrustedBlock = phase0.TrustedSignedBeaconBlock elif signedBlock is altair.SignedBeaconBlock: @@ -272,12 +306,12 @@ proc stepOnBlock( blckRef: BlockRef, signedBlock: TrustedBlock, epochRef: EpochRef, unrealized: FinalityCheckpoints): - # 3. Update fork choice if valid + # 4. Update fork choice if valid let status = fkChoice[].process_block( dag, epochRef, blckRef, unrealized, signedBlock.message, time) doAssert status.isOk() - # 4. Update DAG with new head + # 5. Update DAG with new head var quarantine = Quarantine.init() let newHead = fkChoice[].get_head(dag, time).get() dag.updateHead(dag.getBlockRef(newHead).get(), quarantine, []) @@ -377,7 +411,7 @@ proc doRunTest(path: string, fork: ConsensusFork) = let status = stepOnBlock( stores.dag, stores.fkChoice, verifier, state[], stateCache, - blck, time, invalidatedRoots) + blck, step.blobData, time, invalidatedRoots) doAssert status.isOk == step.valid of opOnAttesterSlashing: let indices = @@ -436,5 +470,8 @@ template fcSuite(suiteName: static[string], testPathElem: static[string]) = for kind, path in walkDir(basePath, relative = true, checkDir = true): runTest(suiteName, basePath/path, fork) +from ../../beacon_chain/conf import loadKzgTrustedSetup +discard loadKzgTrustedSetup() # Required for Deneb tests + fcSuite("ForkChoice", "fork_choice") fcSuite("Sync", "sync") diff --git a/vendor/nim-chronos b/vendor/nim-chronos index 00614476c6..2e8551b0d9 160000 --- a/vendor/nim-chronos +++ b/vendor/nim-chronos @@ -1 +1 @@ -Subproject commit 00614476c68f0553432b4bb505e24d6ad5586ae4 +Subproject commit 2e8551b0d973cfbebfab3be7f3329e11b9049007 diff --git a/vendor/nim-kzg4844 b/vendor/nim-kzg4844 index f8b78edcc8..6c406c70ad 160000 --- a/vendor/nim-kzg4844 +++ b/vendor/nim-kzg4844 @@ -1 +1 @@ -Subproject commit f8b78edcc8296f412c2593e6d60f47c77aa421c5 +Subproject commit 6c406c70ad8cde6ab56320158dd969beb45322ef diff --git a/vendor/nim-presto b/vendor/nim-presto index cb9353acd5..2ae448ff5b 160000 --- a/vendor/nim-presto +++ b/vendor/nim-presto @@ -1 +1 @@ -Subproject commit cb9353acd5877f7ba197bfe1f365b89a0a4473f8 +Subproject commit 2ae448ff5b0808c8f562c6f0a70bbd7a05407a37