From 0fb9581b9675c1073098da3c03bf0a952ddd8cac Mon Sep 17 00:00:00 2001 From: Kim De Mey Date: Mon, 23 Sep 2024 18:56:28 +0200 Subject: [PATCH] Refactor and apply renaming to post merge block proofs (#2648) --- fluffy/database/era1_db.nim | 7 +++- fluffy/eth_data/era1.nim | 2 +- fluffy/eth_data/history_data_json_store.nim | 2 +- fluffy/eth_data/history_data_seeding.nim | 3 +- fluffy/eth_data/history_data_ssz_e2s.nim | 2 +- .../history/content/content_deprecated.nim | 2 +- fluffy/network/history/history_network.nim | 8 +++-- .../block_proof_common.nim} | 14 +++++--- .../block_proof_historical_roots.nim} | 34 +++++++++--------- .../block_proof_historical_summaries.nim} | 36 +++++++++---------- .../historical_hashes_accumulator.nim} | 4 +-- fluffy/network_metadata.nim | 2 +- fluffy/scripts/test_portal_testnet.nim | 2 +- fluffy/tests/all_fluffy_tests.nim | 3 +- .../all_history_network_tests.nim | 14 ++++++++ .../test_block_proof_historical_roots.nim} | 8 ++--- ..._block_proof_historical_roots_vectors.nim} | 20 +++++------ ...test_block_proof_historical_summaries.nim} | 8 ++--- ...ck_proof_historical_summaries_vectors.nim} | 20 +++++------ .../mainnet/all_fluffy_portal_spec_tests.nim | 2 -- .../mainnet/test_accumulator_root.nim | 2 +- .../mainnet/test_history_content.nim | 3 +- .../mainnet/test_history_content_keys.nim | 2 +- fluffy/tests/test_accumulator.nim | 2 +- fluffy/tests/test_helpers.nim | 2 +- fluffy/tests/test_history_network.nim | 3 +- fluffy/tests/test_history_util.nim | 6 ++-- fluffy/tools/eth_data_exporter.nim | 6 ++-- .../eth_data_exporter/cl_data_exporter.nim | 15 ++++---- 29 files changed, 131 insertions(+), 103 deletions(-) rename fluffy/network/history/{beacon_chain_block_proof_common.nim => validation/block_proof_common.nim} (82%) rename fluffy/network/history/{beacon_chain_block_proof_bellatrix.nim => validation/block_proof_historical_roots.nim} (87%) rename fluffy/network/history/{experimental/beacon_chain_block_proof_capella.nim => validation/block_proof_historical_summaries.nim} (82%) rename fluffy/network/history/{accumulator.nim => validation/historical_hashes_accumulator.nim} (99%) create mode 100644 fluffy/tests/history_network_tests/all_history_network_tests.nim rename fluffy/tests/{test_beacon_chain_block_proof_bellatrix.nim => history_network_tests/test_block_proof_historical_roots.nim} (94%) rename fluffy/tests/{portal_spec_tests/mainnet/test_history_block_proof_bellatrix.nim => history_network_tests/test_block_proof_historical_roots_vectors.nim} (74%) rename fluffy/tests/{test_beacon_chain_block_proof_capella.nim => history_network_tests/test_block_proof_historical_summaries.nim} (94%) rename fluffy/tests/{portal_spec_tests/mainnet/test_history_block_proof_capella.nim => history_network_tests/test_block_proof_historical_summaries_vectors.nim} (83%) diff --git a/fluffy/database/era1_db.nim b/fluffy/database/era1_db.nim index 5fec3aa5c..48a0dd24c 100644 --- a/fluffy/database/era1_db.nim +++ b/fluffy/database/era1_db.nim @@ -7,7 +7,12 @@ {.push raises: [].} -import std/os, stew/io2, results, ../network/history/accumulator, ../eth_data/era1 +import + std/os, + stew/io2, + results, + ../network/history/validation/historical_hashes_accumulator, + ../eth_data/era1 type Era1DB* = ref object ## The Era1 database manages a collection of era files that together make up diff --git a/fluffy/eth_data/era1.nim b/fluffy/eth_data/era1.nim index f579e18b9..e66f2757c 100644 --- a/fluffy/eth_data/era1.nim +++ b/fluffy/eth_data/era1.nim @@ -17,7 +17,7 @@ import beacon_chain/spec/beacon_time, ssz_serialization, ncli/e2store, - ../network/history/accumulator + ../network/history/validation/historical_hashes_accumulator from nimcrypto/hash import fromHex from ../../nimbus/utils/utils import calcTxRoot, calcReceiptsRoot diff --git a/fluffy/eth_data/history_data_json_store.nim b/fluffy/eth_data/history_data_json_store.nim index c7bd8b562..e04fa835a 100644 --- a/fluffy/eth_data/history_data_json_store.nim +++ b/fluffy/eth_data/history_data_json_store.nim @@ -15,7 +15,7 @@ import chronicles, eth/[rlp, common/eth_types], ../../nimbus/common/[chain_config, genesis], - ../network/history/[history_content, accumulator] + ../network/history/[history_content, validation/historical_hashes_accumulator] export results, tables diff --git a/fluffy/eth_data/history_data_seeding.nim b/fluffy/eth_data/history_data_seeding.nim index dd7e84f68..c71955ebd 100644 --- a/fluffy/eth_data/history_data_seeding.nim +++ b/fluffy/eth_data/history_data_seeding.nim @@ -15,7 +15,8 @@ import eth/common/eth_types, eth/rlp, ../network/wire/portal_protocol, - ../network/history/[history_content, history_network, accumulator], + ../network/history/ + [history_content, history_network, validation/historical_hashes_accumulator], "."/[era1, history_data_json_store, history_data_ssz_e2s] export results diff --git a/fluffy/eth_data/history_data_ssz_e2s.nim b/fluffy/eth_data/history_data_ssz_e2s.nim index 7f7c3b442..8b5265a2e 100644 --- a/fluffy/eth_data/history_data_ssz_e2s.nim +++ b/fluffy/eth_data/history_data_ssz_e2s.nim @@ -13,7 +13,7 @@ import results, eth/[rlp, common/eth_types], ncli/e2store, - ../network/history/[history_content, accumulator] + ../network/history/[history_content, validation/historical_hashes_accumulator] export results diff --git a/fluffy/network/history/content/content_deprecated.nim b/fluffy/network/history/content/content_deprecated.nim index 900aca228..66b3e188a 100644 --- a/fluffy/network/history/content/content_deprecated.nim +++ b/fluffy/network/history/content/content_deprecated.nim @@ -18,7 +18,7 @@ import ssz_serialization, ../../../common/common_types, ../../../database/content_db, - ../accumulator + ../validation/historical_hashes_accumulator type ContentType = enum diff --git a/fluffy/network/history/history_network.nim b/fluffy/network/history/history_network.nim index b5504e4de..a77ca6da2 100644 --- a/fluffy/network/history/history_network.nim +++ b/fluffy/network/history/history_network.nim @@ -17,13 +17,17 @@ import ../../database/content_db, ../../network_metadata, ../wire/[portal_protocol, portal_stream, portal_protocol_config], - "."/[history_content, accumulator, beacon_chain_historical_roots], + "."/[ + history_content, + beacon_chain_historical_roots, + validation/historical_hashes_accumulator, + ], ./content/content_deprecated logScope: topics = "portal_hist" -export accumulator +export historical_hashes_accumulator type HistoryNetwork* = ref object diff --git a/fluffy/network/history/beacon_chain_block_proof_common.nim b/fluffy/network/history/validation/block_proof_common.nim similarity index 82% rename from fluffy/network/history/beacon_chain_block_proof_common.nim rename to fluffy/network/history/validation/block_proof_common.nim index 733167ec8..d81d619bf 100644 --- a/fluffy/network/history/beacon_chain_block_proof_common.nim +++ b/fluffy/network/history/validation/block_proof_common.nim @@ -9,7 +9,7 @@ import results, beacon_chain/spec/presets, beacon_chain/spec/forks -type BeaconBlockProof* = array[11, Digest] +type ExecutionBlockProof* = array[11, Digest] func getBlockRootsIndex*(slot: Slot): uint64 = slot mod SLOTS_PER_HISTORICAL_ROOT @@ -19,7 +19,9 @@ func getBlockRootsIndex*(beaconBlock: SomeForkyBeaconBlock): uint64 = # Builds proof to be able to verify that the EL block hash is part of the # CL BeaconBlock for given root. -func buildProof*(blockBody: SomeForkyBeaconBlock): Result[BeaconBlockProof, string] = +func buildProof*( + beaconBlock: SomeForkyBeaconBlock +): Result[ExecutionBlockProof, string] = let # BeaconBlock level: # - 8 as there are 5 fields @@ -34,12 +36,14 @@ func buildProof*(blockBody: SomeForkyBeaconBlock): Result[BeaconBlockProof, stri # - 12 as pos of field is 12 gIndex = GeneralizedIndex(gIndexMidLevel * 1 * 16 + 12) - var proof: BeaconBlockProof - ?blockBody.build_proof(gIndex, proof) + var proof: ExecutionBlockProof + ?beaconBlock.build_proof(gIndex, proof) ok(proof) -func verifyProof*(blockHash: Digest, proof: BeaconBlockProof, blockRoot: Digest): bool = +func verifyProof*( + blockHash: Digest, proof: ExecutionBlockProof, blockRoot: Digest +): bool = let gIndexTopLevel = (1 * 1 * 8 + 4) gIndexMidLevel = (gIndexTopLevel * 1 * 16 + 9) diff --git a/fluffy/network/history/beacon_chain_block_proof_bellatrix.nim b/fluffy/network/history/validation/block_proof_historical_roots.nim similarity index 87% rename from fluffy/network/history/beacon_chain_block_proof_bellatrix.nim rename to fluffy/network/history/validation/block_proof_historical_roots.nim index e8f9df2ff..a12f9abbd 100644 --- a/fluffy/network/history/beacon_chain_block_proof_bellatrix.nim +++ b/fluffy/network/history/validation/block_proof_historical_roots.nim @@ -79,18 +79,18 @@ import ssz_serialization/[proofs, merkleization], beacon_chain/spec/eth2_ssz_serialization, beacon_chain/spec/datatypes/bellatrix, - ./beacon_chain_block_proof_common + ./block_proof_common -export beacon_chain_block_proof_common +export block_proof_common type - HistoricalRootsProof* = array[14, Digest] + BeaconBlockProofHistoricalRoots* = array[14, Digest] - BeaconChainBlockProof* = object + BlockProofHistoricalRoots* = object # Total size (11 + 1 + 14) * 32 bytes + 4 bytes = 836 bytes - beaconBlockProof*: BeaconBlockProof + beaconBlockProof*: BeaconBlockProofHistoricalRoots beaconBlockRoot*: Digest - historicalRootsProof*: HistoricalRootsProof + executionBlockProof*: ExecutionBlockProof slot*: Slot func getHistoricalRootsIndex*(slot: Slot): uint64 = @@ -111,11 +111,11 @@ template `[]`(x: openArray[Eth2Digest], chunk: Limit): Eth2Digest = # HistoricalBatch for given root. func buildProof*( batch: HistoricalBatch, blockRootIndex: uint64 -): Result[HistoricalRootsProof, string] = +): Result[BeaconBlockProofHistoricalRoots, string] = # max list size * 2 is start point of leaves let gIndex = GeneralizedIndex(2 * SLOTS_PER_HISTORICAL_ROOT + blockRootIndex) - var proof: HistoricalRootsProof + var proof: BeaconBlockProofHistoricalRoots ?batch.build_proof(gIndex, proof) ok(proof) @@ -123,24 +123,24 @@ func buildProof*( func buildProof*( batch: HistoricalBatch, beaconBlock: bellatrix.TrustedBeaconBlock | bellatrix.BeaconBlock, -): Result[BeaconChainBlockProof, string] = +): Result[BlockProofHistoricalRoots, string] = let blockRootIndex = getBlockRootsIndex(beaconBlock) - beaconBlockProof = ?beaconBlock.buildProof() - historicalRootsProof = ?batch.buildProof(blockRootIndex) + executionBlockProof = ?beaconBlock.buildProof() + beaconBlockProof = ?batch.buildProof(blockRootIndex) ok( - BeaconChainBlockProof( + BlockProofHistoricalRoots( beaconBlockProof: beaconBlockProof, beaconBlockRoot: hash_tree_root(beaconBlock), - historicalRootsProof: historicalRootsProof, + executionBlockProof: executionBlockProof, slot: beaconBlock.slot, ) ) func verifyProof*( blockHeaderRoot: Digest, - proof: HistoricalRootsProof, + proof: BeaconBlockProofHistoricalRoots, historicalRoot: Digest, blockRootIndex: uint64, ): bool = @@ -150,14 +150,14 @@ func verifyProof*( func verifyProof*( historical_roots: HashList[Eth2Digest, Limit HISTORICAL_ROOTS_LIMIT], - proof: BeaconChainBlockProof, + proof: BlockProofHistoricalRoots, blockHash: Digest, ): bool = let historicalRootsIndex = getHistoricalRootsIndex(proof.slot) blockRootIndex = getBlockRootsIndex(proof.slot) - blockHash.verifyProof(proof.beaconBlockProof, proof.beaconBlockRoot) and + blockHash.verifyProof(proof.executionBlockProof, proof.beaconBlockRoot) and proof.beaconBlockRoot.verifyProof( - proof.historicalRootsProof, historical_roots[historicalRootsIndex], blockRootIndex + proof.beaconBlockProof, historical_roots[historicalRootsIndex], blockRootIndex ) diff --git a/fluffy/network/history/experimental/beacon_chain_block_proof_capella.nim b/fluffy/network/history/validation/block_proof_historical_summaries.nim similarity index 82% rename from fluffy/network/history/experimental/beacon_chain_block_proof_capella.nim rename to fluffy/network/history/validation/block_proof_historical_summaries.nim index 26d6f876b..a2c1ff4db 100644 --- a/fluffy/network/history/experimental/beacon_chain_block_proof_capella.nim +++ b/fluffy/network/history/validation/block_proof_historical_summaries.nim @@ -30,18 +30,18 @@ import beacon_chain/spec/eth2_ssz_serialization, beacon_chain/spec/presets, beacon_chain/spec/datatypes/capella, - ../beacon_chain_block_proof_common + ./block_proof_common -export beacon_chain_block_proof_common +export block_proof_common type - HistoricalSummariesProof* = array[13, Digest] + BeaconBlockProofHistoricalRoots* = array[13, Digest] - BeaconChainBlockProof* = object + BlockProofHistoricalSummaries* = object # Total size (11 + 1 + 13) * 32 bytes + 4 bytes = 804 bytes - beaconBlockProof*: BeaconBlockProof + beaconBlockProof*: BeaconBlockProofHistoricalRoots beaconBlockRoot*: Digest - historicalSummariesProof*: HistoricalSummariesProof + executionBlockProof*: ExecutionBlockProof slot*: Slot template `[]`(x: openArray[Eth2Digest], chunk: Limit): Eth2Digest = @@ -64,11 +64,11 @@ func getHistoricalSummariesIndex*( # block_roots for given root. func buildProof*( blockRoots: array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest], blockRootIndex: uint64 -): Result[HistoricalSummariesProof, string] = +): Result[BeaconBlockProofHistoricalRoots, string] = # max list size * 1 is start point of leaves let gIndex = GeneralizedIndex(SLOTS_PER_HISTORICAL_ROOT + blockRootIndex) - var proof: HistoricalSummariesProof + var proof: BeaconBlockProofHistoricalRoots ?blockRoots.build_proof(gIndex, proof) ok(proof) @@ -78,24 +78,24 @@ func buildProof*( func buildProof*( blockRoots: array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest], beaconBlock: capella.TrustedBeaconBlock | capella.BeaconBlock, -): Result[BeaconChainBlockProof, string] = +): Result[BlockProofHistoricalSummaries, string] = let blockRootIndex = getBlockRootsIndex(beaconBlock) - beaconBlockProof = ?beaconBlock.buildProof() - historicalSummariesProof = ?blockRoots.buildProof(blockRootIndex) + executionBlockProof = ?beaconBlock.buildProof() + beaconBlockProof = ?blockRoots.buildProof(blockRootIndex) ok( - BeaconChainBlockProof( - beaconBlockProof: beaconBlockProof, + BlockProofHistoricalSummaries( beaconBlockRoot: hash_tree_root(beaconBlock), - historicalSummariesProof: historicalSummariesProof, + beaconBlockProof: beaconBlockProof, + executionBlockProof: executionBlockProof, slot: beaconBlock.slot, ) ) func verifyProof*( blockHeaderRoot: Digest, - proof: HistoricalSummariesProof, + proof: BeaconBlockProofHistoricalRoots, historicalRoot: Digest, blockRootIndex: uint64, ): bool = @@ -105,7 +105,7 @@ func verifyProof*( func verifyProof*( historical_summaries: HashList[HistoricalSummary, Limit HISTORICAL_ROOTS_LIMIT], - proof: BeaconChainBlockProof, + proof: BlockProofHistoricalSummaries, blockHash: Digest, cfg: RuntimeConfig, ): bool = @@ -113,9 +113,9 @@ func verifyProof*( historicalRootsIndex = getHistoricalSummariesIndex(proof.slot, cfg) blockRootIndex = getBlockRootsIndex(proof.slot) - blockHash.verifyProof(proof.beaconBlockProof, proof.beaconBlockRoot) and + blockHash.verifyProof(proof.executionBlockProof, proof.beaconBlockRoot) and proof.beaconBlockRoot.verifyProof( - proof.historicalSummariesProof, + proof.beaconBlockProof, historical_summaries[historicalRootsIndex].block_summary_root, blockRootIndex, ) diff --git a/fluffy/network/history/accumulator.nim b/fluffy/network/history/validation/historical_hashes_accumulator.nim similarity index 99% rename from fluffy/network/history/accumulator.nim rename to fluffy/network/history/validation/historical_hashes_accumulator.nim index c639b3ff9..1dd39cf14 100644 --- a/fluffy/network/history/accumulator.nim +++ b/fluffy/network/history/validation/historical_hashes_accumulator.nim @@ -12,8 +12,8 @@ import eth/common/eth_types_rlp, ssz_serialization, ssz_serialization/[proofs, merkleization], - ../../common/common_types, - ./history_content + ../../../common/common_types, + ../history_content export ssz_serialization, merkleization, proofs, eth_types_rlp diff --git a/fluffy/network_metadata.nim b/fluffy/network_metadata.nim index aecc8d578..08f7b9476 100644 --- a/fluffy/network_metadata.nim +++ b/fluffy/network_metadata.nim @@ -13,7 +13,7 @@ import stew/io2, chronos/timer, beacon_chain/spec/forks, - ./network/history/accumulator + ./network/history/validation/historical_hashes_accumulator proc loadBootstrapNodes(path: string): seq[string] {.raises: [IOError].} = # Read a list of ENR URIs from a file containing a flat list of entries. diff --git a/fluffy/scripts/test_portal_testnet.nim b/fluffy/scripts/test_portal_testnet.nim index 5fc51a4c7..e788d9014 100644 --- a/fluffy/scripts/test_portal_testnet.nim +++ b/fluffy/scripts/test_portal_testnet.nim @@ -19,7 +19,7 @@ import ../rpc/portal_rpc_client, ../rpc/eth_rpc_client, ../eth_data/[history_data_seeding, history_data_json_store, history_data_ssz_e2s], - ../network/history/[history_content, accumulator], + ../network/history/[history_content, validation/historical_hashes_accumulator], ../tests/test_history_util type diff --git a/fluffy/tests/all_fluffy_tests.nim b/fluffy/tests/all_fluffy_tests.nim index cd70f2873..3733240d6 100644 --- a/fluffy/tests/all_fluffy_tests.nim +++ b/fluffy/tests/all_fluffy_tests.nim @@ -13,9 +13,8 @@ import ./test_history_network, ./test_content_db, ./test_discovery_rpc, - ./test_beacon_chain_block_proof_bellatrix, - ./test_beacon_chain_block_proof_capella, ./test_beacon_chain_historical_roots, ./test_beacon_chain_historical_summaries, + ./history_network_tests/all_history_network_tests, ./beacon_network_tests/all_beacon_network_tests, ./state_network_tests/all_state_network_tests diff --git a/fluffy/tests/history_network_tests/all_history_network_tests.nim b/fluffy/tests/history_network_tests/all_history_network_tests.nim new file mode 100644 index 000000000..7f8aa023b --- /dev/null +++ b/fluffy/tests/history_network_tests/all_history_network_tests.nim @@ -0,0 +1,14 @@ +# Nimbus +# Copyright (c) 2024 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + +{.warning[UnusedImport]: off.} + +import + ./test_block_proof_historical_roots, + ./test_block_proof_historical_roots_vectors, + ./test_block_proof_historical_summaries, + ./test_block_proof_historical_summaries_vectors diff --git a/fluffy/tests/test_beacon_chain_block_proof_bellatrix.nim b/fluffy/tests/history_network_tests/test_block_proof_historical_roots.nim similarity index 94% rename from fluffy/tests/test_beacon_chain_block_proof_bellatrix.nim rename to fluffy/tests/history_network_tests/test_block_proof_historical_roots.nim index 982d6d2bd..edf6f34ad 100644 --- a/fluffy/tests/test_beacon_chain_block_proof_bellatrix.nim +++ b/fluffy/tests/history_network_tests/test_block_proof_historical_roots.nim @@ -16,7 +16,7 @@ import beacon_chain /../ tests/testblockutil, # Mock helpers beacon_chain /../ tests/mocking/mock_genesis, - ../network/history/beacon_chain_block_proof_bellatrix + ../../network/history/validation/block_proof_historical_roots # Test suite for the proofs: # - HistoricalRootsProof @@ -67,7 +67,7 @@ suite "Beacon Chain Block Proofs - Bellatrix": SLOTS_PER_HISTORICAL_ROOT - 2, ] - test "HistoricalRootsProof for BeaconBlock": + test "BeaconBlockProofHistoricalRoots for BeaconBlock": let # Historical batch of first historical root batch = HistoricalBatch( @@ -91,7 +91,7 @@ suite "Beacon Chain Block Proofs - Bellatrix": blocks[i].root, proof, historical_roots[historicalRootsIndex], blockRootIndex ) - test "BeaconBlockProof for BeaconBlock": + test "ExecutionBlockProof for Execution BlockHeader": # for i in 0..<(SLOTS_PER_HISTORICAL_ROOT - 1): # Test all blocks for i in blocksToTest: let beaconBlock = blocks[i].message @@ -103,7 +103,7 @@ suite "Beacon Chain Block Proofs - Bellatrix": let leave = beaconBlock.body.execution_payload.block_hash check verifyProof(leave, proof, blocks[i].root) - test "BeaconChainBlockProof for Execution BlockHeader": + test "BlockProofHistoricalRoots for Execution BlockHeader": let # Historical batch of first historical root batch = HistoricalBatch( diff --git a/fluffy/tests/portal_spec_tests/mainnet/test_history_block_proof_bellatrix.nim b/fluffy/tests/history_network_tests/test_block_proof_historical_roots_vectors.nim similarity index 74% rename from fluffy/tests/portal_spec_tests/mainnet/test_history_block_proof_bellatrix.nim rename to fluffy/tests/history_network_tests/test_block_proof_historical_roots_vectors.nim index 767cefb9f..7b249cfa5 100644 --- a/fluffy/tests/portal_spec_tests/mainnet/test_history_block_proof_bellatrix.nim +++ b/fluffy/tests/history_network_tests/test_block_proof_historical_roots_vectors.nim @@ -14,13 +14,13 @@ import unittest2, yaml, beacon_chain/spec/datatypes/bellatrix, - ../../../common/common_types, - ../../../network_metadata, - ../../../network/history/beacon_chain_block_proof_bellatrix, - ../../../eth_data/[yaml_utils, yaml_eth_types] + ../../common/common_types, + ../../network_metadata, + ../../network/history/validation/block_proof_historical_roots, + ../../eth_data/[yaml_utils, yaml_eth_types] -suite "History Block Proofs - Bellatrix": - test "BeaconChainBlockProof for Execution BlockHeader": +suite "History Block Proofs - Historical Roots": + test "BlockProofHistoricalRoots for Execution BlockHeader": let testsPath = "./vendor/portal-spec-tests/tests/mainnet/history/headers_with_proof/block_proofs_bellatrix/" @@ -33,11 +33,11 @@ suite "History Block Proofs - Bellatrix": raiseAssert "Cannot read test vector: " & error blockHash = BlockHash.fromHex(testProof.execution_block_header) - blockProof = BeaconChainBlockProof( - beaconBlockProof: array[11, Digest].fromHex(testProof.beacon_block_proof), - beaconBlockRoot: Digest.fromHex(testProof.beacon_block_root), - historicalRootsProof: + blockProof = BlockProofHistoricalRoots( + beaconBlockProof: array[14, Digest].fromHex(testProof.historical_roots_proof), + beaconBlockRoot: Digest.fromHex(testProof.beacon_block_root), + executionBlockProof: array[11, Digest].fromHex(testProof.beacon_block_proof), slot: Slot(testProof.slot), ) diff --git a/fluffy/tests/test_beacon_chain_block_proof_capella.nim b/fluffy/tests/history_network_tests/test_block_proof_historical_summaries.nim similarity index 94% rename from fluffy/tests/test_beacon_chain_block_proof_capella.nim rename to fluffy/tests/history_network_tests/test_block_proof_historical_summaries.nim index 78605d432..041a5d420 100644 --- a/fluffy/tests/test_beacon_chain_block_proof_capella.nim +++ b/fluffy/tests/history_network_tests/test_block_proof_historical_summaries.nim @@ -16,7 +16,7 @@ import beacon_chain /../ tests/testblockutil, # Mock helpers beacon_chain /../ tests/mocking/mock_genesis, - ../network/history/experimental/beacon_chain_block_proof_capella + ../../network/history/validation/block_proof_historical_summaries # Test suite for the proofs: # - historicalSummariesProof @@ -82,7 +82,7 @@ suite "Beacon Chain Block Proofs - Capella": SLOTS_PER_HISTORICAL_ROOT - 2, ] - test "HistoricalRootsProof for BeaconBlockHeader": + test "BeaconBlockProofHistoricalSummaries for BeaconBlock": let blockRoots = getStateField(state[], block_roots).data withState(state[]): @@ -107,7 +107,7 @@ suite "Beacon Chain Block Proofs - Capella": blockRootIndex, ) - test "BeaconBlockProof for BeaconBlock": + test "ExecutionBlockProof for Execution BlockHeader": # for i in 0..<(SLOTS_PER_HISTORICAL_ROOT - 1): # Test all blocks for i in blocksToTest: let beaconBlock = blocks[i].message @@ -119,7 +119,7 @@ suite "Beacon Chain Block Proofs - Capella": let leave = beaconBlock.body.execution_payload.block_hash check verifyProof(leave, proof, blocks[i].root) - test "BeaconChainBlockProof for Execution BlockHeader": + test "BlockProofHistoricalSummaries for Execution BlockHeader": let blockRoots = getStateField(state[], block_roots).data withState(state[]): diff --git a/fluffy/tests/portal_spec_tests/mainnet/test_history_block_proof_capella.nim b/fluffy/tests/history_network_tests/test_block_proof_historical_summaries_vectors.nim similarity index 83% rename from fluffy/tests/portal_spec_tests/mainnet/test_history_block_proof_capella.nim rename to fluffy/tests/history_network_tests/test_block_proof_historical_summaries_vectors.nim index 365467b06..628f78f9a 100644 --- a/fluffy/tests/portal_spec_tests/mainnet/test_history_block_proof_capella.nim +++ b/fluffy/tests/history_network_tests/test_block_proof_historical_summaries_vectors.nim @@ -16,10 +16,10 @@ import yaml, ssz_serialization, beacon_chain/spec/datatypes/capella, - ../../../common/common_types, - ../../../network/history/experimental/beacon_chain_block_proof_capella, - ../../../network/beacon/beacon_init_loader, - ../../../eth_data/[yaml_utils, yaml_eth_types] + ../../common/common_types, + ../../network/history/validation/block_proof_historical_summaries, + ../../network/beacon/beacon_init_loader, + ../../eth_data/[yaml_utils, yaml_eth_types] proc toString(v: IoErrorCode): string = try: @@ -44,8 +44,8 @@ proc readHistoricalSummaries( except SerializationError as err: err("Failed decoding historical_summaries: " & err.msg) -suite "History Block Proofs - Capella": - test "BeaconChainBlockProof for Execution BlockHeader": +suite "History Block Proofs - Historical Summaries": + test "BlockProofHistoricalSummaries for Execution BlockHeader": let testsPath = "./vendor/portal-spec-tests/tests/mainnet/history/headers_with_proof/block_proofs_capella/" @@ -62,11 +62,11 @@ suite "History Block Proofs - Capella": raiseAssert "Cannot read test vector: " & error blockHash = BlockHash.fromHex(testProof.execution_block_header) - blockProof = BeaconChainBlockProof( - beaconBlockProof: array[11, Digest].fromHex(testProof.beacon_block_proof), - beaconBlockRoot: Digest.fromHex(testProof.beacon_block_root), - historicalSummariesProof: + blockProof = BlockProofHistoricalSummaries( + beaconBlockProof: array[13, Digest].fromHex(testProof.historical_summaries_proof), + beaconBlockRoot: Digest.fromHex(testProof.beacon_block_root), + executionBlockProof: array[11, Digest].fromHex(testProof.beacon_block_proof), slot: Slot(testProof.slot), ) diff --git a/fluffy/tests/portal_spec_tests/mainnet/all_fluffy_portal_spec_tests.nim b/fluffy/tests/portal_spec_tests/mainnet/all_fluffy_portal_spec_tests.nim index a7c31e146..08ecfa805 100644 --- a/fluffy/tests/portal_spec_tests/mainnet/all_fluffy_portal_spec_tests.nim +++ b/fluffy/tests/portal_spec_tests/mainnet/all_fluffy_portal_spec_tests.nim @@ -12,6 +12,4 @@ import ./test_history_content_keys, ./test_history_content, ./test_history_content_validation, - ./test_history_block_proof_bellatrix, - ./test_history_block_proof_capella, ./test_accumulator_root diff --git a/fluffy/tests/portal_spec_tests/mainnet/test_accumulator_root.nim b/fluffy/tests/portal_spec_tests/mainnet/test_accumulator_root.nim index f9eea9a6b..7918744e7 100644 --- a/fluffy/tests/portal_spec_tests/mainnet/test_accumulator_root.nim +++ b/fluffy/tests/portal_spec_tests/mainnet/test_accumulator_root.nim @@ -15,7 +15,7 @@ import stew/byteutils, eth/common/eth_types_rlp, ../../../eth_data/history_data_json_store, - ../../../network/history/[history_content, accumulator] + ../../../network/history/[history_content, validation/historical_hashes_accumulator] suite "Header Accumulator Root": test "Header Accumulator Update": diff --git a/fluffy/tests/portal_spec_tests/mainnet/test_history_content.nim b/fluffy/tests/portal_spec_tests/mainnet/test_history_content.nim index 15b58f17a..6aff72350 100644 --- a/fluffy/tests/portal_spec_tests/mainnet/test_history_content.nim +++ b/fluffy/tests/portal_spec_tests/mainnet/test_history_content.nim @@ -15,7 +15,8 @@ import eth/common/eth_types_rlp, ../../../network_metadata, ../../../eth_data/[history_data_json_store, history_data_ssz_e2s], - ../../../network/history/[history_content, history_network, accumulator], + ../../../network/history/ + [history_content, history_network, validation/historical_hashes_accumulator], ../../test_history_util, ../../../eth_data/yaml_utils diff --git a/fluffy/tests/portal_spec_tests/mainnet/test_history_content_keys.nim b/fluffy/tests/portal_spec_tests/mainnet/test_history_content_keys.nim index 8e143a262..79b6ca2a4 100644 --- a/fluffy/tests/portal_spec_tests/mainnet/test_history_content_keys.nim +++ b/fluffy/tests/portal_spec_tests/mainnet/test_history_content_keys.nim @@ -13,7 +13,7 @@ import stint, ssz_serialization, ssz_serialization/[proofs, merkleization], - ../../../network/history/[history_content, accumulator] + ../../../network/history/history_content # According to test vectors: # https://github.com/ethereum/portal-network-specs/blob/master/content-keys-test-vectors.md#history-network-keys diff --git a/fluffy/tests/test_accumulator.nim b/fluffy/tests/test_accumulator.nim index 743a49e0f..4c294bedf 100644 --- a/fluffy/tests/test_accumulator.nim +++ b/fluffy/tests/test_accumulator.nim @@ -14,7 +14,7 @@ import stint, eth/common/eth_types_rlp, ../eth_data/history_data_json_store, - ../network/history/[history_content, accumulator], + ../network/history/[history_content, validation/historical_hashes_accumulator], ./test_helpers suite "Header Accumulator": diff --git a/fluffy/tests/test_helpers.nim b/fluffy/tests/test_helpers.nim index b07eb11a6..f24c9c67d 100644 --- a/fluffy/tests/test_helpers.nim +++ b/fluffy/tests/test_helpers.nim @@ -12,7 +12,7 @@ import eth/[common, keys, rlp], eth/p2p/discoveryv5/[enr, node, routing_table], eth/p2p/discoveryv5/protocol as discv5_protocol, - ../network/history/[accumulator, history_content], + ../network/history/[history_content, validation/historical_hashes_accumulator], ../database/content_db proc localAddress*(port: int): Address {.raises: [ValueError].} = diff --git a/fluffy/tests/test_history_network.nim b/fluffy/tests/test_history_network.nim index 2b681c03f..7025e278a 100644 --- a/fluffy/tests/test_history_network.nim +++ b/fluffy/tests/test_history_network.nim @@ -13,7 +13,8 @@ import eth/common/eth_types_rlp, eth/rlp, ../network/wire/[portal_protocol, portal_stream, portal_protocol_config], - ../network/history/[history_network, accumulator, history_content], + ../network/history/ + [history_network, history_content, validation/historical_hashes_accumulator], ../database/content_db, ./test_helpers diff --git a/fluffy/tests/test_history_util.nim b/fluffy/tests/test_history_util.nim index 6dd039a25..69e202c47 100644 --- a/fluffy/tests/test_history_util.nim +++ b/fluffy/tests/test_history_util.nim @@ -8,9 +8,11 @@ {.push raises: [].} import - results, eth/common/eth_types_rlp, ../network/history/[history_content, accumulator] + results, + eth/common/eth_types_rlp, + ../network/history/[history_content, validation/historical_hashes_accumulator] -export results, accumulator, history_content +export results, historical_hashes_accumulator, history_content proc buildHeadersWithProof*( blockHeaders: seq[BlockHeader], epochRecord: EpochRecordCached diff --git a/fluffy/tools/eth_data_exporter.nim b/fluffy/tools/eth_data_exporter.nim index e00bafcc4..050d08a1d 100644 --- a/fluffy/tools/eth_data_exporter.nim +++ b/fluffy/tools/eth_data_exporter.nim @@ -50,7 +50,7 @@ import snappy, ncli/e2store, ../../premix/[downloader, parser], - ../network/history/[history_content, accumulator], + ../network/history/[history_content, validation/historical_hashes_accumulator], ../eth_data/[history_data_json_store, history_data_ssz_e2s, era1], eth_data_exporter/[exporter_conf, exporter_common, cl_data_exporter] @@ -200,7 +200,7 @@ proc cmdExportEra1(config: ExporterConf) = var group = Era1Group.init(e2, startNumber).get() # Header records to build the accumulator root - var headerRecords: seq[accumulator.HeaderRecord] + var headerRecords: seq[historical_hashes_accumulator.HeaderRecord] for blockNumber in startNumber .. endNumber: let blck = try: @@ -220,7 +220,7 @@ proc cmdExportEra1(config: ExporterConf) = break writeFileBlock headerRecords.add( - accumulator.HeaderRecord( + historical_hashes_accumulator.HeaderRecord( blockHash: blck.header.blockHash(), totalDifficulty: ttd ) ) diff --git a/fluffy/tools/eth_data_exporter/cl_data_exporter.nim b/fluffy/tools/eth_data_exporter/cl_data_exporter.nim index 0b9af40df..3656eb9b4 100644 --- a/fluffy/tools/eth_data_exporter/cl_data_exporter.nim +++ b/fluffy/tools/eth_data_exporter/cl_data_exporter.nim @@ -20,8 +20,8 @@ import beacon_chain/beacon_clock, ../../network/beacon/beacon_content, ../../network/beacon/beacon_init_loader, - ../../network/history/beacon_chain_block_proof_bellatrix, - ../../network/history/experimental/beacon_chain_block_proof_capella, + ../../network/history/validation/block_proof_historical_roots, + ../../network/history/validation/block_proof_historical_summaries, ../../network_metadata, ../../eth_data/[yaml_utils, yaml_eth_types], ./exporter_common @@ -295,9 +295,9 @@ proc exportBeaconBlockProofBellatrix( let yamlTestProof = YamlTestProofBellatrix( execution_block_header: beaconBlock.message.body.execution_payload.block_hash.data.to0xHex(), - beacon_block_proof: blockProof.beaconBlockProof.toHex(array[11, string]), + beacon_block_proof: blockProof.executionBlockProof.toHex(array[11, string]), beacon_block_root: blockProof.beaconBlockRoot.data.to0xHex(), - historical_roots_proof: blockProof.historicalRootsProof.toHex(array[14, string]), + historical_roots_proof: blockProof.beaconBlockProof.toHex(array[14, string]), slot: blockProof.slot.uint64, ) @@ -405,7 +405,7 @@ proc exportBeaconBlockProofCapella( quit QuitFailure blockRoots = getStateField(state, block_roots).data - blockProof = beacon_chain_block_proof_capella.buildProof( + blockProof = block_proof_historical_summaries.buildProof( blockRoots, beaconBlock.message ).valueOr: error "Failed to build proof for Bellatrix block", slot, error @@ -414,10 +414,9 @@ proc exportBeaconBlockProofCapella( let yamlTestProof = YamlTestProof( execution_block_header: beaconBlock.message.body.execution_payload.block_hash.data.to0xHex(), - beacon_block_proof: blockProof.beaconBlockProof.toHex(array[11, string]), + beacon_block_proof: blockProof.executionBlockProof.toHex(array[11, string]), beacon_block_root: blockProof.beaconBlockRoot.data.to0xHex(), - historical_summaries_proof: - blockProof.historicalSummariesProof.toHex(array[13, string]), + historical_summaries_proof: blockProof.beaconBlockProof.toHex(array[13, string]), slot: blockProof.slot.uint64, )