diff --git a/beacon_chain/beacon_chain_db.nim b/beacon_chain/beacon_chain_db.nim index 8e6941f3d..c13c04c0e 100644 --- a/beacon_chain/beacon_chain_db.nim +++ b/beacon_chain/beacon_chain_db.nim @@ -13,12 +13,12 @@ import serialization, chronicles, snappy, eth/db/[kvstore, kvstore_sqlite3], ./networking/network_metadata, ./beacon_chain_db_immutable, - ./spec/[crypto, digest, state_transition], + ./spec/state_transition, ./spec/datatypes/[phase0, altair], ./ssz/[ssz_serialization, merkleization], ./filepath -export crypto +export phase0, altair logScope: topics = "bc_db" diff --git a/beacon_chain/beacon_chain_db_immutable.nim b/beacon_chain/beacon_chain_db_immutable.nim index a07bf7a14..2e1d507b6 100644 --- a/beacon_chain/beacon_chain_db_immutable.nim +++ b/beacon_chain/beacon_chain_db_immutable.nim @@ -11,7 +11,6 @@ import stew/[assign2, objects, results], serialization, eth/db/kvstore, - ./spec/[crypto, digest], ./spec/datatypes/[base, altair], ./ssz/[ssz_serialization, merkleization] diff --git a/beacon_chain/beacon_clock.nim b/beacon_chain/beacon_clock.nim index 3c94d0f47..be61fc3cb 100644 --- a/beacon_chain/beacon_clock.nim +++ b/beacon_chain/beacon_clock.nim @@ -9,7 +9,7 @@ import chronos, chronicles, - ./spec/[datatypes, helpers] + ./spec/helpers from times import Time, getTime, fromUnix, `<`, `-`, inNanoseconds diff --git a/beacon_chain/beacon_node_types.nim b/beacon_chain/beacon_node_types.nim index 16f48c319..c88cef818 100644 --- a/beacon_chain/beacon_node_types.nim +++ b/beacon_chain/beacon_node_types.nim @@ -10,8 +10,7 @@ import std/[deques, intsets, streams, tables], stew/endians2, - ./spec/[digest, crypto], - ./spec/datatypes/base, + ./spec/datatypes/[phase0, altair], ./consensus_object_pools/block_pools_types, ./fork_choice/fork_choice_types, ./validators/slashing_protection diff --git a/beacon_chain/conf.nim b/beacon_chain/conf.nim index f87ff2024..a40c5914d 100644 --- a/beacon_chain/conf.nim +++ b/beacon_chain/conf.nim @@ -17,7 +17,7 @@ import eth/p2p/discoveryv5/enr, json_serialization, web3/[ethtypes, confutils_defs], - ./spec/[crypto, keystore, digest, network], + ./spec/[keystore, network], ./spec/datatypes/base, ./networking/network_metadata, ./validators/slashing_protection_common, diff --git a/beacon_chain/consensus_object_pools/attestation_pool.nim b/beacon_chain/consensus_object_pools/attestation_pool.nim index 9ae080917..ec69f3c63 100644 --- a/beacon_chain/consensus_object_pools/attestation_pool.nim +++ b/beacon_chain/consensus_object_pools/attestation_pool.nim @@ -14,13 +14,11 @@ import metrics, chronicles, stew/byteutils, json_serialization/std/sets as jsonSets, # Internal - ../spec/[ - beaconstate, crypto, digest, forks, - validator], + ../spec/[beaconstate, forks, helpers, validator], ../spec/datatypes/[phase0, altair], ../ssz/[merkleization, types], "."/[spec_cache, blockchain_dag, block_quarantine], - ".."/[beacon_clock, beacon_node_types, extras], + ".."/[beacon_clock, beacon_node_types], ../fork_choice/fork_choice export beacon_node_types diff --git a/beacon_chain/consensus_object_pools/block_clearance.nim b/beacon_chain/consensus_object_pools/block_clearance.nim index ee9d5f7f6..81c868dfe 100644 --- a/beacon_chain/consensus_object_pools/block_clearance.nim +++ b/beacon_chain/consensus_object_pools/block_clearance.nim @@ -12,12 +12,10 @@ import chronicles, stew/[assign2, results], eth/keys, - ../extras, ../beacon_clock, - ../spec/[ - crypto, digest, forks, helpers, signatures, - signatures_batch, state_transition], + ".."/[beacon_clock], + ../spec/[forks, helpers, signatures, signatures_batch, state_transition], ../spec/datatypes/[phase0, altair], - ./block_pools_types, ./blockchain_dag, ./block_quarantine + "."/[block_pools_types, blockchain_dag, block_quarantine] from libp2p/protocols/pubsub/pubsub import ValidationResult diff --git a/beacon_chain/consensus_object_pools/block_pools_types.nim b/beacon_chain/consensus_object_pools/block_pools_types.nim index 6890479a2..ee243e636 100644 --- a/beacon_chain/consensus_object_pools/block_pools_types.nim +++ b/beacon_chain/consensus_object_pools/block_pools_types.nim @@ -14,9 +14,9 @@ import stew/endians2, chronicles, eth/keys, # Internals - ../spec/[crypto, digest, signatures_batch, forks], + ../spec/[signatures_batch, forks], ../spec/datatypes/[phase0, altair], - ".."/[beacon_chain_db, beacon_clock, extras] + ".."/[beacon_chain_db, beacon_clock] export sets, tables diff --git a/beacon_chain/consensus_object_pools/block_quarantine.nim b/beacon_chain/consensus_object_pools/block_quarantine.nim index c6b64ae2d..2628c1e0f 100644 --- a/beacon_chain/consensus_object_pools/block_quarantine.nim +++ b/beacon_chain/consensus_object_pools/block_quarantine.nim @@ -12,7 +12,6 @@ import chronicles, stew/bitops2, eth/keys, - ../spec/[crypto, digest], ../spec/datatypes/[phase0, altair], ./block_pools_types diff --git a/beacon_chain/consensus_object_pools/blockchain_dag.nim b/beacon_chain/consensus_object_pools/blockchain_dag.nim index cff0029f3..bf8385a12 100644 --- a/beacon_chain/consensus_object_pools/blockchain_dag.nim +++ b/beacon_chain/consensus_object_pools/blockchain_dag.nim @@ -11,15 +11,13 @@ import std/[options, sequtils, tables, sets], stew/[assign2, byteutils], metrics, snappy, chronicles, - ../ssz/[ssz_serialization, merkleization], ../beacon_chain_db, ../extras, - ../spec/[ - crypto, digest, helpers, validator, state_transition, - beaconstate, forks], + ../ssz/[ssz_serialization, merkleization], + ../spec/[helpers, validator, state_transition, beaconstate, forks], ../spec/datatypes/[phase0, altair], - ../beacon_clock, + ".."/[beacon_clock, beacon_chain_db], "."/[block_pools_types, block_quarantine, forkedbeaconstate_dbhelpers] -export block_pools_types, helpers, phase0 +export block_pools_types # https://github.com/ethereum/eth2.0-metrics/blob/master/metrics.md#interop-metrics declareGauge beacon_head_root, "Root of the head block of the beacon chain" diff --git a/beacon_chain/consensus_object_pools/exit_pool.nim b/beacon_chain/consensus_object_pools/exit_pool.nim index 3d33ed82f..0d5d054f1 100644 --- a/beacon_chain/consensus_object_pools/exit_pool.nim +++ b/beacon_chain/consensus_object_pools/exit_pool.nim @@ -13,7 +13,7 @@ import # Status libraries chronicles, # Internal - ../spec/[crypto, forks, helpers], + ../spec/[forks, helpers], ../spec/datatypes/base, "."/[blockchain_dag, block_quarantine], ../beacon_node_types diff --git a/beacon_chain/consensus_object_pools/spec_cache.nim b/beacon_chain/consensus_object_pools/spec_cache.nim index 4b5cdbc57..540716b75 100644 --- a/beacon_chain/consensus_object_pools/spec_cache.nim +++ b/beacon_chain/consensus_object_pools/spec_cache.nim @@ -10,10 +10,13 @@ import std/[intsets], chronicles, - ../spec/[crypto, digest, helpers, network, presets, signatures, validator], - ../spec/datatypes/base, ../extras, - ./block_pools_types, ./blockchain_dag + ../spec/[helpers, network, signatures, validator], + ../spec/datatypes/base, + ./block_pools_types, blockchain_dag + +export + base, extras # Spec functions implemented based on cached values instead of the full state func count_active_validators*(epochInfo: EpochRef): uint64 = diff --git a/beacon_chain/eth1/deposit_contract.nim b/beacon_chain/eth1/deposit_contract.nim index 8a862e23b..edc375671 100644 --- a/beacon_chain/eth1/deposit_contract.nim +++ b/beacon_chain/eth1/deposit_contract.nim @@ -14,7 +14,7 @@ import ../networking/network_metadata, web3, web3/confutils_defs, eth/keys, eth/p2p/discoveryv5/random2, stew/io2, - ../spec/[crypto, presets], ../spec/datatypes/base, ../ssz/merkleization, + ../spec/datatypes/base, ../ssz/merkleization, ../validators/keystore_management # Compiled version of /scripts/depositContract.v.py in this repo diff --git a/beacon_chain/eth1/eth1_monitor.nim b/beacon_chain/eth1/eth1_monitor.nim index aa3581a71..9c79082fb 100644 --- a/beacon_chain/eth1/eth1_monitor.nim +++ b/beacon_chain/eth1/eth1_monitor.nim @@ -15,8 +15,8 @@ import web3, web3/ethtypes as web3Types, web3/ethhexstrings, eth/common/eth_types, eth/async_utils, stew/byteutils, # Local modules: - ../spec/[digest, crypto, forks, helpers], - ../spec/datatypes/base, + ../spec/[forks, helpers], + ../spec/datatypes/[base, merge], ../networking/network_metadata, ../consensus_object_pools/block_pools_types, ../ssz, diff --git a/beacon_chain/fork_choice/fork_choice.nim b/beacon_chain/fork_choice/fork_choice.nim index cde88502b..416e2d795 100644 --- a/beacon_chain/fork_choice/fork_choice.nim +++ b/beacon_chain/fork_choice/fork_choice.nim @@ -13,7 +13,7 @@ import # Status libraries stew/results, chronicles, # Internal - ../spec/[beaconstate, digest, helpers], + ../spec/[beaconstate, helpers], ../spec/datatypes/[phase0, altair], # Fork choice ./fork_choice_types, ./proto_array, diff --git a/beacon_chain/fork_choice/fork_choice_types.nim b/beacon_chain/fork_choice/fork_choice_types.nim index 21bd81623..17c370561 100644 --- a/beacon_chain/fork_choice/fork_choice_types.nim +++ b/beacon_chain/fork_choice/fork_choice_types.nim @@ -16,7 +16,6 @@ import chronicles, # Internal ../spec/datatypes/base, - ../spec/digest, ../consensus_object_pools/block_pools_types # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/fork-choice.md diff --git a/beacon_chain/fork_choice/proto_array.nim b/beacon_chain/fork_choice/proto_array.nim index 5e768232c..3179846eb 100644 --- a/beacon_chain/fork_choice/proto_array.nim +++ b/beacon_chain/fork_choice/proto_array.nim @@ -15,7 +15,6 @@ import stew/results, # Internal ../spec/datatypes/base, - ../spec/digest, # Fork choice ./fork_choice_types diff --git a/beacon_chain/gossip_processing/batch_validation.nim b/beacon_chain/gossip_processing/batch_validation.nim index e8b945c9a..67ec24f46 100644 --- a/beacon_chain/gossip_processing/batch_validation.nim +++ b/beacon_chain/gossip_processing/batch_validation.nim @@ -13,7 +13,7 @@ import stew/results, eth/keys, # Internals - ../spec/[crypto, digest, helpers, signatures_batch], + ../spec/[helpers, signatures_batch], ../spec/datatypes/base, ../consensus_object_pools/[ blockchain_dag, block_quarantine, diff --git a/beacon_chain/gossip_processing/block_processor.nim b/beacon_chain/gossip_processing/block_processor.nim index 96acba7b4..eae644e09 100644 --- a/beacon_chain/gossip_processing/block_processor.nim +++ b/beacon_chain/gossip_processing/block_processor.nim @@ -12,7 +12,7 @@ import stew/results, chronicles, chronos, metrics, ../spec/datatypes/[phase0, altair], - ../spec/[crypto, digest, forks], + ../spec/[forks], ../consensus_object_pools/[block_clearance, blockchain_dag, attestation_pool], ./consensus_manager, ".."/[beacon_clock, beacon_node_types], diff --git a/beacon_chain/gossip_processing/consensus_manager.nim b/beacon_chain/gossip_processing/consensus_manager.nim index 54ca363b9..3bdc1d1c9 100644 --- a/beacon_chain/gossip_processing/consensus_manager.nim +++ b/beacon_chain/gossip_processing/consensus_manager.nim @@ -8,8 +8,8 @@ {.push raises: [Defect].} import - chronicles, chronos, - ../spec/[crypto, datatypes], + chronicles, + ../spec/datatypes/base, ../consensus_object_pools/[blockchain_dag, attestation_pool] # TODO: Move to "consensus_object_pools" folder diff --git a/beacon_chain/gossip_processing/eth2_processor.nim b/beacon_chain/gossip_processing/eth2_processor.nim index 6b46010a4..d7adca1d1 100644 --- a/beacon_chain/gossip_processing/eth2_processor.nim +++ b/beacon_chain/gossip_processing/eth2_processor.nim @@ -11,7 +11,7 @@ import std/tables, stew/results, chronicles, chronos, metrics, - ../spec/[crypto, digest, forks], + ../spec/[helpers, forks], ../spec/datatypes/[altair, phase0], ../consensus_object_pools/[block_clearance, blockchain_dag, exit_pool, attestation_pool], ./gossip_validation, ./block_processor, diff --git a/beacon_chain/gossip_processing/gossip_validation.nim b/beacon_chain/gossip_processing/gossip_validation.nim index dfd8cf04c..487ad5ecc 100644 --- a/beacon_chain/gossip_processing/gossip_validation.nim +++ b/beacon_chain/gossip_processing/gossip_validation.nim @@ -16,16 +16,13 @@ import # Internals ../spec/datatypes/[phase0, altair], ../spec/[ - beaconstate, state_transition_block, - crypto, digest, forks, helpers, network, - signatures], + beaconstate, state_transition_block, forks, helpers, network, signatures], ../consensus_object_pools/[ spec_cache, blockchain_dag, block_quarantine, spec_cache, attestation_pool, exit_pool ], ".."/[beacon_node_types, ssz, beacon_clock], ../validators/attestation_aggregation, - ../extras, ./batch_validation from libp2p/protocols/pubsub/pubsub import ValidationResult diff --git a/beacon_chain/interop.nim b/beacon_chain/interop.nim index f150b3d72..2b6a730cd 100644 --- a/beacon_chain/interop.nim +++ b/beacon_chain/interop.nim @@ -9,8 +9,9 @@ import stew/endians2, stint, - ./extras, ./ssz/merkleization, - spec/[crypto, digest, keystore, signatures], + ./ssz/merkleization, + ./extras, + spec/[keystore, signatures], spec/datatypes/base func get_eth1data_stub*(deposit_count: uint64, current_epoch: Epoch): Eth1Data = diff --git a/beacon_chain/networking/eth2_network.nim b/beacon_chain/networking/eth2_network.nim index 11ec3f404..6566a213c 100644 --- a/beacon_chain/networking/eth2_network.nim +++ b/beacon_chain/networking/eth2_network.nim @@ -36,7 +36,7 @@ import version, conf, ssz/ssz_serialization, beacon_clock], ../spec/datatypes/[phase0, altair], - ../spec/[digest, network, helpers, forks], + ../spec/[network, helpers, forks], ../validators/keystore_management, ./eth2_discovery, ./peer_pool, ./libp2p_json_serialization diff --git a/beacon_chain/networking/network_metadata.nim b/beacon_chain/networking/network_metadata.nim index b64bed2ee..be5b62bcf 100644 --- a/beacon_chain/networking/network_metadata.nim +++ b/beacon_chain/networking/network_metadata.nim @@ -15,9 +15,9 @@ import chronicles, json_serialization, json_serialization/std/[options, sets, net], serialization/errors, - ../ssz/navigator, + ../ssz/[navigator, spec_types], eth/common/eth_types_json_serialization, - ../spec/[presets, datatypes, digest] + ../spec/datatypes/phase0 # ATTENTION! This file will produce a large C file, because we are inlining # genesis states as C literals in the generated code (and blobs in the final @@ -200,4 +200,4 @@ proc getRuntimeConfig*( proc extractGenesisValidatorRootFromSnapshop*( snapshot: string): Eth2Digest {.raises: [Defect, IOError, SszError].} = - sszMount(snapshot, BeaconState).genesis_validators_root[] + sszMount(snapshot, phase0.BeaconState).genesis_validators_root[] diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 390315bbf..26703724b 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -23,11 +23,9 @@ import # Local modules "."/[ - beacon_chain_db, - beacon_node_common, beacon_node_status, beacon_node_types, conf, - extras, filepath, interop, - nimbus_binary_common, ssz/merkleization, statusbar, - beacon_clock, version], + beacon_clock, beacon_chain_db, beacon_node_common, beacon_node_status, + beacon_node_types, conf, filepath, interop, nimbus_binary_common, statusbar, + version], ./networking/[eth2_discovery, eth2_network, network_metadata], ./gossip_processing/[eth2_processor, block_processor, consensus_manager], ./validators/[ @@ -36,10 +34,9 @@ import ./sync/[sync_manager, sync_protocol, request_manager], ./rpc/[rest_api, rpc_api], ./spec/datatypes/[altair, phase0], - ./spec/[ - digest, crypto, forks, beaconstate, - eth2_apis/rpc_beacon_client, helpers, network, presets, - weak_subjectivity, signatures], + ./spec/eth2_apis/rpc_beacon_client, + ./spec/[beaconstate, forks, helpers, network, weak_subjectivity, signatures], + ./ssz/merkleization, ./consensus_object_pools/[ blockchain_dag, block_quarantine, block_clearance, block_pools_types, attestation_pool, exit_pool, spec_cache], diff --git a/beacon_chain/nimbus_binary_common.nim b/beacon_chain/nimbus_binary_common.nim index f6759f583..4a5f7ad82 100644 --- a/beacon_chain/nimbus_binary_common.nim +++ b/beacon_chain/nimbus_binary_common.nim @@ -19,8 +19,10 @@ import stew/io2, # Local modules - ./spec/[crypto, helpers], ./spec/datatypes/base, beacon_clock, filepath, - ./beacon_node_status, ./networking/eth2_network + ./spec/[helpers], + ./spec/datatypes/base, + "."/[beacon_clock, filepath, beacon_node_status], + ./networking/eth2_network when defined(posix): import termios diff --git a/beacon_chain/nimbus_signing_process.nim b/beacon_chain/nimbus_signing_process.nim index 57b03db2b..46bb4e41d 100644 --- a/beacon_chain/nimbus_signing_process.nim +++ b/beacon_chain/nimbus_signing_process.nim @@ -9,7 +9,7 @@ import # Standard library - os, strutils, tables, + std/[os, strutils, tables], # Local modules ./spec/[digest, crypto], diff --git a/beacon_chain/rpc/eth_merge_web3.nim b/beacon_chain/rpc/eth_merge_web3.nim index 517ac6da5..c211447c1 100644 --- a/beacon_chain/rpc/eth_merge_web3.nim +++ b/beacon_chain/rpc/eth_merge_web3.nim @@ -1,8 +1,8 @@ import strutils, json_serialization/std/[sets, net], serialization/errors, - ../spec/datatypes/base, - ../spec/[crypto, digest, eth2_apis/rpc_beacon_client], + ../spec/datatypes/[base, merge], + ../spec/eth2_apis/rpc_beacon_client, json_rpc/[client, jsonmarshal] from os import DirSep, AltSep diff --git a/beacon_chain/rpc/rest_beacon_api.nim b/beacon_chain/rpc/rest_beacon_api.nim index bc1a8edcd..d26faff52 100644 --- a/beacon_chain/rpc/rest_beacon_api.nim +++ b/beacon_chain/rpc/rest_beacon_api.nim @@ -12,7 +12,7 @@ import ../consensus_object_pools/[blockchain_dag, exit_pool], ../gossip_processing/gossip_validation, ../validators/validator_duties, - ../spec/[crypto, digest, forks, network], + ../spec/[forks, network], ../spec/datatypes/[phase0, altair], ../ssz/merkleization, ./rest_utils diff --git a/beacon_chain/rpc/rest_config_api.nim b/beacon_chain/rpc/rest_config_api.nim index b1f78c8bc..f0470973c 100644 --- a/beacon_chain/rpc/rest_config_api.nim +++ b/beacon_chain/rpc/rest_config_api.nim @@ -10,8 +10,7 @@ import chronicles, nimcrypto/utils as ncrutils, ../beacon_node_common, ../eth1/eth1_monitor, - ../spec/datatypes/base, - ../spec/[digest, forks, presets], + ../spec/forks, ./rest_utils logScope: topics = "rest_config" diff --git a/beacon_chain/rpc/rest_debug_api.nim b/beacon_chain/rpc/rest_debug_api.nim index 5bf75cd85..ce185c230 100644 --- a/beacon_chain/rpc/rest_debug_api.nim +++ b/beacon_chain/rpc/rest_debug_api.nim @@ -3,7 +3,6 @@ import presto, chronicles, ../version, ../beacon_node_common, - ../spec/[datatypes, digest, presets], ./rest_utils logScope: topics = "rest_debug" diff --git a/beacon_chain/rpc/rest_node_api.nim b/beacon_chain/rpc/rest_node_api.nim index 1787ff648..3f89985c8 100644 --- a/beacon_chain/rpc/rest_node_api.nim +++ b/beacon_chain/rpc/rest_node_api.nim @@ -8,7 +8,6 @@ import ../version, ../beacon_node_common, ../sync/sync_manager, ../networking/[eth2_network, peer_pool], ../spec/datatypes/base, - ../spec/[digest, presets], ../spec/eth2_apis/rpc_types, ./rest_utils diff --git a/beacon_chain/rpc/rest_utils.nim b/beacon_chain/rpc/rest_utils.nim index 3e1ed9fb9..ba01fd2c9 100644 --- a/beacon_chain/rpc/rest_utils.nim +++ b/beacon_chain/rpc/rest_utils.nim @@ -1,6 +1,6 @@ import presto, presto/client as presto_client, nimcrypto/utils as ncrutils, - ../spec/[crypto, datatypes, digest, forks], + ../spec/[forks], ../spec/eth2_apis/[rest_types, eth2_rest_serialization], ../beacon_node_common, ../consensus_object_pools/[block_pools_types, blockchain_dag] diff --git a/beacon_chain/rpc/rest_validator_api.nim b/beacon_chain/rpc/rest_validator_api.nim index c6b41bdbe..d4e938fbb 100644 --- a/beacon_chain/rpc/rest_validator_api.nim +++ b/beacon_chain/rpc/rest_validator_api.nim @@ -12,8 +12,8 @@ import ../consensus_object_pools/[blockchain_dag, spec_cache, attestation_pool], ../gossip_processing/gossip_validation, ../validators/validator_duties, - ../spec/[crypto, digest, forks, network], - ../spec/datatypes/[base, phase0], + ../spec/[forks, network], + ../spec/datatypes/[phase0], ../ssz/merkleization, ./rest_utils diff --git a/beacon_chain/rpc/rpc_beacon_api.nim b/beacon_chain/rpc/rpc_beacon_api.nim index cf4868803..90f72d5ce 100644 --- a/beacon_chain/rpc/rpc_beacon_api.nim +++ b/beacon_chain/rpc/rpc_beacon_api.nim @@ -18,7 +18,8 @@ import ../validators/validator_duties, ../gossip_processing/gossip_validation, ../consensus_object_pools/blockchain_dag, - ../spec/[crypto, datatypes/phase0, digest, forks, network], + ../spec/[forks, network], + ../spec/datatypes/[phase0], ../ssz/merkleization, ./rpc_utils diff --git a/beacon_chain/rpc/rpc_config_api.nim b/beacon_chain/rpc/rpc_config_api.nim index 97b3f63e8..f31d7649d 100644 --- a/beacon_chain/rpc/rpc_config_api.nim +++ b/beacon_chain/rpc/rpc_config_api.nim @@ -14,7 +14,7 @@ import nimcrypto/utils as ncrutils, ../beacon_node_common, ../eth1/eth1_monitor, - ../spec/[datatypes, digest, forks, presets] + ../spec/forks logScope: topics = "configapi" diff --git a/beacon_chain/rpc/rpc_debug_api.nim b/beacon_chain/rpc/rpc_debug_api.nim index 1c10b883e..d9e011282 100644 --- a/beacon_chain/rpc/rpc_debug_api.nim +++ b/beacon_chain/rpc/rpc_debug_api.nim @@ -14,7 +14,6 @@ import ../version, ../beacon_node_common, ../networking/[eth2_network, peer_pool], ../spec/datatypes/phase0, - ../spec/[digest, presets], ./rpc_utils logScope: topics = "debugapi" diff --git a/beacon_chain/rpc/rpc_nimbus_api.nim b/beacon_chain/rpc/rpc_nimbus_api.nim index 54de82221..d725f4325 100644 --- a/beacon_chain/rpc/rpc_nimbus_api.nim +++ b/beacon_chain/rpc/rpc_nimbus_api.nim @@ -18,10 +18,9 @@ import beacon_node_common, nimbus_binary_common, networking/eth2_network, eth1/eth1_monitor, validators/validator_duties], ../spec/datatypes/base, - ../spec/[digest, forks, presets], + ../spec/[forks], ./rpc_utils - logScope: topics = "nimbusapi" type diff --git a/beacon_chain/rpc/rpc_node_api.nim b/beacon_chain/rpc/rpc_node_api.nim index d2bcb9410..4e74f6abe 100644 --- a/beacon_chain/rpc/rpc_node_api.nim +++ b/beacon_chain/rpc/rpc_node_api.nim @@ -17,7 +17,6 @@ import std/options, ../networking/[eth2_network, peer_pool], ../sync/sync_manager, ../spec/datatypes/base, - ../spec/[digest, presets], ./rpc_utils logScope: topics = "nodeapi" diff --git a/beacon_chain/rpc/rpc_utils.nim b/beacon_chain/rpc/rpc_utils.nim index 40aeb6f19..7151030a7 100644 --- a/beacon_chain/rpc/rpc_utils.nim +++ b/beacon_chain/rpc/rpc_utils.nim @@ -13,7 +13,7 @@ import ../beacon_node_common, ../validators/validator_duties, ../consensus_object_pools/[block_pools_types, blockchain_dag], ../spec/datatypes/base, - ../spec/[digest, forks, helpers], + ../spec/[forks, helpers], ../spec/eth2_apis/[rpc_types, eth2_json_rpc_serialization] export rpc_types, eth2_json_rpc_serialization, blockchain_dag diff --git a/beacon_chain/rpc/rpc_validator_api.nim b/beacon_chain/rpc/rpc_validator_api.nim index dc6ccf2bd..927d2c4d1 100644 --- a/beacon_chain/rpc/rpc_validator_api.nim +++ b/beacon_chain/rpc/rpc_validator_api.nim @@ -17,7 +17,7 @@ import chronicles, # Local modules - ../spec/[crypto, digest, forks, helpers, network, signatures], + ../spec/[forks, helpers, network, signatures], ../spec/datatypes/phase0, ../spec/eth2_apis/rpc_types, ../consensus_object_pools/[blockchain_dag, spec_cache, attestation_pool], ../ssz/merkleization, diff --git a/beacon_chain/spec/beaconstate.nim b/beacon_chain/spec/beaconstate.nim index 8dac7cc82..18dfabf8a 100644 --- a/beacon_chain/spec/beaconstate.nim +++ b/beacon_chain/spec/beaconstate.nim @@ -13,10 +13,11 @@ import json_serialization/std/sets, chronicles, ../extras, ../ssz/merkleization, - ./crypto, ./datatypes/[phase0, altair], ./digest, ./helpers, ./signatures, ./validator, + ./datatypes/[phase0, altair, merge], + "."/[helpers, signatures, validator], ../../nbench/bench_lab -import blscurve # TODO bad +export extras, phase0, altair, merge # https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/beacon-chain.md#is_valid_merkle_branch func is_valid_merkle_branch*(leaf: Eth2Digest, branch: openArray[Eth2Digest], diff --git a/beacon_chain/spec/crypto.nim b/beacon_chain/spec/crypto.nim index d0c1dbca9..a6af7a21e 100644 --- a/beacon_chain/spec/crypto.nim +++ b/beacon_chain/spec/crypto.nim @@ -26,8 +26,6 @@ import # Standard library std/[options, hashes, sequtils, tables], - # Internal - ./digest, # Status stew/[endians2, objects, results, byteutils], blscurve, @@ -35,7 +33,7 @@ import json_serialization, nimcrypto/utils as ncrutils -export results, json_serialization, blscurve +export options, results, json_serialization, blscurve # Type definitions # ---------------------------------------------------------------------- @@ -298,12 +296,6 @@ proc blsFastAggregateVerify*( let parsedSig = signature.load() parsedSig.isSome and blsFastAggregateVerify(publicKeys, message, parsedSig.get()) -proc toGaugeValue*(hash: Eth2Digest): int64 = - # Only the last 8 bytes are taken into consideration in accordance - # to the ETH2 metrics spec: - # https://github.com/ethereum/eth2.0-metrics/blob/6a79914cb31f7d54858c7dd57eee75b6162ec737/metrics.md#interop-metrics - cast[int64](uint64.fromBytesLE(hash.data.toOpenArray(24, 31))) - # Codecs # ---------------------------------------------------------------------- diff --git a/beacon_chain/spec/datatypes.nim b/beacon_chain/spec/datatypes.nim deleted file mode 100644 index fedd88173..000000000 --- a/beacon_chain/spec/datatypes.nim +++ /dev/null @@ -1,3 +0,0 @@ -# compatibility wrapper -import datatypes/phase0 -export phase0 diff --git a/beacon_chain/spec/datatypes/altair.nim b/beacon_chain/spec/datatypes/altair.nim index 5d634a9bf..2a937fb6a 100644 --- a/beacon_chain/spec/datatypes/altair.nim +++ b/beacon_chain/spec/datatypes/altair.nim @@ -31,8 +31,7 @@ import chronicles, std/macros, stew/[assign2, bitops2], - json_serialization/types as jsonTypes, - ../../ssz/types as sszTypes, ../crypto, ../digest, ../presets + json_serialization/types as jsonTypes import ./base, ./phase0 export base diff --git a/beacon_chain/spec/datatypes/base.nim b/beacon_chain/spec/datatypes/base.nim index ee958ee8d..dcf0cc23f 100644 --- a/beacon_chain/spec/datatypes/base.nim +++ b/beacon_chain/spec/datatypes/base.nim @@ -28,11 +28,11 @@ import std/[macros, hashes, intsets, strutils, tables, typetraits], stew/[assign2, byteutils], chronicles, json_serialization, - ../../version, ../../ssz/types as sszTypes, ../crypto, ../digest, ../presets, - ./merge + ../../version, ../../ssz/types as sszTypes, + ".."/[crypto, digest, presets] export - crypto, sszTypes, merge, presets, json_serialization + crypto, digest, sszTypes, presets, json_serialization # Presently, we're reusing the data types from the serialization (uint64) in the # objects we pass around to the beacon chain logic, thus keeping the two diff --git a/beacon_chain/spec/datatypes/phase0.nim b/beacon_chain/spec/datatypes/phase0.nim index 1b44b1600..5f369e320 100644 --- a/beacon_chain/spec/datatypes/phase0.nim +++ b/beacon_chain/spec/datatypes/phase0.nim @@ -27,8 +27,7 @@ import std/[macros, intsets, json, strutils, tables], stew/[assign2, byteutils], chronicles, - json_serialization/types as jsonTypes, - ../../ssz/types as sszTypes, ../crypto, ../digest, ../presets + json_serialization/types as jsonTypes import ./base export base diff --git a/beacon_chain/spec/digest.nim b/beacon_chain/spec/digest.nim index d5db1850f..9348e9cbe 100644 --- a/beacon_chain/spec/digest.nim +++ b/beacon_chain/spec/digest.nim @@ -27,7 +27,7 @@ import # Status libraries chronicles, nimcrypto/[sha2, hash], - stew/byteutils, + stew/[endians2, byteutils], json_serialization, blscurve @@ -119,3 +119,9 @@ proc readValue*(r: var JsonReader, a: var Eth2Digest) {.raises: [Defect, IOError a = fromHex(type(a), r.readValue(string)) except ValueError: raiseUnexpectedValue(r, "Hex string expected") + +proc toGaugeValue*(hash: Eth2Digest): int64 = + # Only the last 8 bytes are taken into consideration in accordance + # to the ETH2 metrics spec: + # https://github.com/ethereum/eth2.0-metrics/blob/6a79914cb31f7d54858c7dd57eee75b6162ec737/metrics.md#interop-metrics + cast[int64](uint64.fromBytesLE(hash.data.toOpenArray(24, 31))) diff --git a/beacon_chain/spec/eth2_apis/eth2_json_rpc_serialization.nim b/beacon_chain/spec/eth2_apis/eth2_json_rpc_serialization.nim index 715ec3331..04844c3fe 100644 --- a/beacon_chain/spec/eth2_apis/eth2_json_rpc_serialization.nim +++ b/beacon_chain/spec/eth2_apis/eth2_json_rpc_serialization.nim @@ -30,9 +30,9 @@ import # Local modules ../../ssz/types, - ".."/[datatypes, crypto, digest] + ../datatypes/base -export jsonmarshal, datatypes, crypto, digest +export jsonmarshal, base proc toJsonHex(data: openArray[byte]): string = # Per the eth2 API spec, hex arrays are printed with leading 0x diff --git a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim index 1ea3ce427..b7a3c293e 100644 --- a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim +++ b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim @@ -11,7 +11,7 @@ import libp2p/peerid, json_serialization, json_serialization/std/[options, net], nimcrypto/utils as ncrutils, - ../datatypes/[phase0, altair], + ../datatypes/[phase0, altair, merge], ./rest_types export results, peerid, presto, json_serialization, options, net, rest_types diff --git a/beacon_chain/spec/eth2_apis/rest_types.nim b/beacon_chain/spec/eth2_apis/rest_types.nim index 958f59ad5..818889e72 100644 --- a/beacon_chain/spec/eth2_apis/rest_types.nim +++ b/beacon_chain/spec/eth2_apis/rest_types.nim @@ -14,11 +14,10 @@ {.push raises: [Defect].} import - std/json, - ".."/datatypes/[phase0, altair], - ".."/[crypto, digest] + std/[json, typetraits], + ".."/datatypes/[phase0, altair] -export phase0, altair, crypto, digest +export phase0, altair const # https://github.com/ethereum/eth2.0-APIs/blob/master/apis/beacon/states/validator_balances.yaml#L17 diff --git a/beacon_chain/spec/eth2_apis/rpc_beacon_calls.nim b/beacon_chain/spec/eth2_apis/rpc_beacon_calls.nim index ba85e68c1..388bb520e 100644 --- a/beacon_chain/spec/eth2_apis/rpc_beacon_calls.nim +++ b/beacon_chain/spec/eth2_apis/rpc_beacon_calls.nim @@ -1,6 +1,7 @@ import options, - rpc_types + rpc_types, + ../datatypes/phase0 proc get_v1_beacon_genesis(): RpcBeaconGenesis @@ -34,7 +35,7 @@ proc get_v1_beacon_headers_blockId(blockId: string): tuple[canonical: bool, header: SignedBeaconBlockHeader] # TODO blockId is part of the REST path -proc get_v1_beacon_blocks_blockId(blockId: string): SignedBeaconBlock +proc get_v1_beacon_blocks_blockId(blockId: string): phase0.SignedBeaconBlock # TODO blockId is part of the REST path proc get_v1_beacon_blocks_blockId_root(blockId: string): Eth2Digest diff --git a/beacon_chain/spec/eth2_apis/rpc_beacon_client.nim b/beacon_chain/spec/eth2_apis/rpc_beacon_client.nim index aaf5b02f0..079738ddc 100644 --- a/beacon_chain/spec/eth2_apis/rpc_beacon_client.nim +++ b/beacon_chain/spec/eth2_apis/rpc_beacon_client.nim @@ -1,7 +1,8 @@ import std/os, json_rpc/rpcclient, - "."/[rpc_types, eth2_json_rpc_serialization] + "."/[rpc_types, eth2_json_rpc_serialization], + ../datatypes/[phase0, altair] export rpcclient, diff --git a/beacon_chain/spec/eth2_apis/rpc_debug_calls.nim b/beacon_chain/spec/eth2_apis/rpc_debug_calls.nim index adf2f5785..24dc9e4cb 100644 --- a/beacon_chain/spec/eth2_apis/rpc_debug_calls.nim +++ b/beacon_chain/spec/eth2_apis/rpc_debug_calls.nim @@ -1,7 +1,8 @@ import - rpc_types + rpc_types, + ../datatypes/phase0 export rpc_types -proc get_v1_debug_beacon_states_stateId(stateId: string): BeaconState +proc get_v1_debug_beacon_states_stateId(stateId: string): phase0.BeaconState proc get_v1_debug_beacon_heads(): seq[tuple[root: Eth2Digest, slot: Slot]] diff --git a/beacon_chain/spec/eth2_apis/rpc_types.nim b/beacon_chain/spec/eth2_apis/rpc_types.nim index 05c203400..b056978a4 100644 --- a/beacon_chain/spec/eth2_apis/rpc_types.nim +++ b/beacon_chain/spec/eth2_apis/rpc_types.nim @@ -11,10 +11,9 @@ {.push raises: [Defect].} import - ".."/datatypes/base, - ".."/[digest, crypto] + ../datatypes/[phase0, altair] -export base, crypto, digest +export phase0, altair type RpcAttesterDuties* = tuple diff --git a/beacon_chain/spec/eth2_apis/rpc_validator_calls.nim b/beacon_chain/spec/eth2_apis/rpc_validator_calls.nim index f60101f3d..dd3bb33ac 100644 --- a/beacon_chain/spec/eth2_apis/rpc_validator_calls.nim +++ b/beacon_chain/spec/eth2_apis/rpc_validator_calls.nim @@ -5,9 +5,9 @@ import # calls that return a bool are actually without a return type in the main REST API # spec but nim-json-rpc requires that all RPC calls have a return type. -proc get_v1_validator_block(slot: Slot, graffiti: GraffitiBytes, randao_reveal: ValidatorSig): BeaconBlock +proc get_v1_validator_block(slot: Slot, graffiti: GraffitiBytes, randao_reveal: ValidatorSig): phase0.BeaconBlock -proc post_v1_validator_block(body: SignedBeaconBlock): bool +proc post_v1_validator_block(body: phase0.SignedBeaconBlock): bool proc get_v1_validator_attestation_data(slot: Slot, committee_index: CommitteeIndex): AttestationData diff --git a/beacon_chain/spec/forks.nim b/beacon_chain/spec/forks.nim index 14c43aed9..3322d23fc 100644 --- a/beacon_chain/spec/forks.nim +++ b/beacon_chain/spec/forks.nim @@ -12,10 +12,11 @@ import chronicles, stew/[assign2, results], ../extras, - ../spec/[ - beaconstate, digest, helpers, presets, state_transition_block, validator], + ../spec/[beaconstate, helpers, state_transition_block, validator], ./datatypes/[phase0, altair] +export extras, phase0, altair + type BeaconStateFork* = enum forkPhase0, diff --git a/beacon_chain/spec/helpers.nim b/beacon_chain/spec/helpers.nim index 3320bea28..c9c3b8495 100644 --- a/beacon_chain/spec/helpers.nim +++ b/beacon_chain/spec/helpers.nim @@ -15,7 +15,10 @@ import # Third-party stew/[byteutils, endians2], # Internal - ./datatypes/[phase0, altair], ./digest, ./crypto, ../ssz/merkleization + ./datatypes/[phase0, altair], + ../ssz/merkleization + +export phase0, altair # https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/beacon-chain.md#integer_squareroot func integer_squareroot*(n: SomeInteger): SomeInteger = diff --git a/beacon_chain/spec/keystore.nim b/beacon_chain/spec/keystore.nim index b93c87247..39927635a 100644 --- a/beacon_chain/spec/keystore.nim +++ b/beacon_chain/spec/keystore.nim @@ -18,7 +18,9 @@ import nimcrypto/[sha2, rijndael, pbkdf2, bcmode, hash, scrypt], # Local modules libp2p/crypto/crypto as lcrypto, - ./datatypes/base, ./crypto, ./digest, ./signatures + ./datatypes/base, ./signatures + +export base # We use `ncrutils` for constant-time hexadecimal encoding/decoding procedures. import nimcrypto/utils as ncrutils diff --git a/beacon_chain/spec/network.nim b/beacon_chain/spec/network.nim index e5f409f83..2d313e37f 100644 --- a/beacon_chain/spec/network.nim +++ b/beacon_chain/spec/network.nim @@ -8,9 +8,11 @@ {.push raises: [Defect].} import - "."/[digest, helpers, forks], + "."/[helpers, forks], "."/datatypes/base +export base + const # https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/p2p-interface.md#topics-and-messages topicBeaconBlocksSuffix* = "beacon_block/ssz" diff --git a/beacon_chain/spec/signatures.nim b/beacon_chain/spec/signatures.nim index 7e19fb901..3e59061a2 100644 --- a/beacon_chain/spec/signatures.nim +++ b/beacon_chain/spec/signatures.nim @@ -9,7 +9,9 @@ import ../ssz/merkleization, - ./crypto, ./digest, ./datatypes/[phase0, altair], ./helpers, ./presets + ./datatypes/[phase0, altair], ./helpers + +export phase0, altair template withTrust(sig: SomeSig, body: untyped): bool = when sig is TrustedSig: diff --git a/beacon_chain/spec/signatures_batch.nim b/beacon_chain/spec/signatures_batch.nim index 15f8272fb..33f662bd9 100644 --- a/beacon_chain/spec/signatures_batch.nim +++ b/beacon_chain/spec/signatures_batch.nim @@ -13,15 +13,13 @@ import stew/[byteutils, results], # Internal ../ssz/merkleization, - "."/[ - crypto, helpers, presets, beaconstate, digest, - forks], + "."/[helpers, beaconstate, forks], "."/datatypes/[altair, phase0] # Otherwise, error. import chronicles -export SignatureSet, BatchedBLSVerifierCache, batchVerify, batchVerifySerial, batchVerifyParallel +export altair, phase0 func `$`*(s: SignatureSet): string = "(pubkey: 0x" & s.pubkey.toHex() & diff --git a/beacon_chain/spec/state_transition.nim b/beacon_chain/spec/state_transition.nim index 734288a1c..8211c7949 100644 --- a/beacon_chain/spec/state_transition.nim +++ b/beacon_chain/spec/state_transition.nim @@ -44,11 +44,17 @@ import std/tables, chronicles, stew/results, - ../extras, ../ssz/merkleization, metrics, - ./datatypes/[phase0, altair], ./crypto, ./digest, ./helpers, ./signatures, ./validator, ./beaconstate, - ./state_transition_block, ./state_transition_epoch, forks, + metrics, + ../extras, + ../ssz/merkleization, + ./datatypes/[phase0, altair], + "."/[ + helpers, signatures, validator, beaconstate, state_transition_block, + state_transition_epoch, forks], ../../nbench/bench_lab +export extras, phase0, altair + # TODO why need anything except the first two? type Foo = phase0.SomeSignedBeaconBlock | altair.SomeSignedBeaconBlock | phase0.SignedBeaconBlock | altair.SignedBeaconBlock | phase0.TrustedSignedBeaconBlock | altair.TrustedSignedBeaconBlock | phase0.SigVerifiedSignedBeaconBlock | altair.SigVerifiedSignedBeaconBlock diff --git a/beacon_chain/spec/state_transition_block.nim b/beacon_chain/spec/state_transition_block.nim index 9cbd9b065..2777402c4 100644 --- a/beacon_chain/spec/state_transition_block.nim +++ b/beacon_chain/spec/state_transition_block.nim @@ -23,10 +23,12 @@ import std/[algorithm, intsets, options, sequtils, sets, tables], chronicles, ../extras, ../ssz/merkleization, metrics, - ./beaconstate, ./crypto, ./datatypes/[phase0, altair], ./digest, ./helpers, - ./validator, ./signatures, ./presets, + ./datatypes/[phase0, altair], + "."/[beaconstate, helpers, validator, signatures], ../../nbench/bench_lab +export extras, phase0, altair + # https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/beacon-chain.md#block-header func process_block_header*( state: var SomeBeaconState, blck: SomeSomeBeaconBlock, flags: UpdateFlags, diff --git a/beacon_chain/spec/state_transition_epoch.nim b/beacon_chain/spec/state_transition_epoch.nim index 7403e9af6..d6aecda1c 100644 --- a/beacon_chain/spec/state_transition_epoch.nim +++ b/beacon_chain/spec/state_transition_epoch.nim @@ -24,9 +24,12 @@ import stew/[bitops2], chronicles, ../extras, ../ssz/merkleization, - ./beaconstate, ./crypto, ./datatypes/[phase0, altair], ./digest, ./helpers, ./validator, + ./datatypes/[phase0, altair], + "."/[beaconstate, helpers, validator], ../../nbench/bench_lab +export extras, phase0, altair + # Logging utilities # -------------------------------------------------------- diff --git a/beacon_chain/spec/validator.nim b/beacon_chain/spec/validator.nim index 40e071100..b19501353 100644 --- a/beacon_chain/spec/validator.nim +++ b/beacon_chain/spec/validator.nim @@ -10,7 +10,10 @@ import std/[options, math, tables], - ./datatypes/[phase0, altair], ./digest, ./helpers + ./datatypes/[phase0, altair], + ./helpers + +export phase0, altair const SEED_SIZE = sizeof(Eth2Digest) diff --git a/beacon_chain/spec/weak_subjectivity.nim b/beacon_chain/spec/weak_subjectivity.nim index 6949c54c7..ba051f9b5 100644 --- a/beacon_chain/spec/weak_subjectivity.nim +++ b/beacon_chain/spec/weak_subjectivity.nim @@ -8,7 +8,7 @@ {.push raises: [Defect].} import - ./datatypes/base, ./digest, ./forks, ./helpers + ./datatypes/base, ./forks, ./helpers const SAFETY_DECAY* = 10'u64 diff --git a/beacon_chain/ssz/merkleization.nim b/beacon_chain/ssz/merkleization.nim index 61fe38ad7..8394013e4 100644 --- a/beacon_chain/ssz/merkleization.nim +++ b/beacon_chain/ssz/merkleization.nim @@ -16,7 +16,7 @@ import stew/ranges/ptr_arith, serialization/testing/tracing, ../spec/digest, - ./bitseqs, ./spec_types, ./types + "."/[bitseqs, spec_types, types] export spec_types, types diff --git a/beacon_chain/ssz/spec_types.nim b/beacon_chain/ssz/spec_types.nim index 8ad312d8b..9a84b42d9 100644 --- a/beacon_chain/ssz/spec_types.nim +++ b/beacon_chain/ssz/spec_types.nim @@ -9,7 +9,9 @@ import std/[typetraits], - ../spec/[crypto, digest] + ../spec/datatypes/[phase0, altair] + +export phase0, altair, typetraits # Eth2-spec-specific type handling that is not generic to SSZ diff --git a/beacon_chain/ssz/ssz_serialization.nim b/beacon_chain/ssz/ssz_serialization.nim index d46d5f3c3..1f6543ccc 100644 --- a/beacon_chain/ssz/ssz_serialization.nim +++ b/beacon_chain/ssz/ssz_serialization.nim @@ -15,11 +15,10 @@ import std/[typetraits, options], stew/[endians2, leb128, objects], serialization, serialization/testing/tracing, - ../spec/[digest, datatypes], ./bytes_reader, ./bitseqs, ./types, ./spec_types export - serialization, types, bitseqs + serialization, types, spec_types, bitseqs type SszReader* = object diff --git a/beacon_chain/ssz/sszdump.nim b/beacon_chain/ssz/sszdump.nim index f7b73fee9..64e33d8c6 100644 --- a/beacon_chain/ssz/sszdump.nim +++ b/beacon_chain/ssz/sszdump.nim @@ -11,7 +11,6 @@ import os, strformat, chronicles, ./ssz_serialization, ../spec/datatypes/[phase0, altair], - ../spec/[crypto, digest], ../consensus_object_pools/block_pools_types # Dump errors are generally not fatal where used currently - the code calling diff --git a/beacon_chain/ssz/types.nim b/beacon_chain/ssz/types.nim index 7abf41893..a79b8bffb 100644 --- a/beacon_chain/ssz/types.nim +++ b/beacon_chain/ssz/types.nim @@ -11,7 +11,7 @@ import std/[tables, options, typetraits, strformat], stew/shims/macros, stew/[byteutils, bitops2, objects], serialization/[object_serialization, errors], - ./spec_types, ./bitseqs, + "."/[bitseqs], ../spec/digest export bitseqs diff --git a/beacon_chain/statediff.nim b/beacon_chain/statediff.nim index 47ca4daa4..81fc229b6 100644 --- a/beacon_chain/statediff.nim +++ b/beacon_chain/statediff.nim @@ -9,8 +9,8 @@ import stew/assign2, - ./ssz/types, - ./spec/[crypto, datatypes, digest, helpers] + ./spec/datatypes/phase0, + ./spec/helpers func diffModIncEpoch[T, U](hl: HashArray[U, T], startSlot: uint64): array[SLOTS_PER_EPOCH, T] = @@ -81,7 +81,7 @@ func replaceOrAddDecodeEth1Votes[T, U]( if not votes0.add item: raiseAssert "same limit" -func getMutableValidatorStatuses(state: BeaconState): +func getMutableValidatorStatuses(state: phase0.BeaconState): List[ValidatorStatus, Limit VALIDATOR_REGISTRY_LIMIT] = if not result.setLen(state.validators.len): raiseAssert "same limt as validators" @@ -96,7 +96,7 @@ func getMutableValidatorStatuses(state: BeaconState): assign(result[i].exit_epoch, validator.exit_epoch) assign(result[i].withdrawable_epoch, validator.withdrawable_epoch) -func diffStates*(state0, state1: BeaconState): BeaconStateDiff = +func diffStates*(state0, state1: phase0.BeaconState): BeaconStateDiff = doAssert state1.slot > state0.slot doAssert state0.slot.isEpoch doAssert state1.slot == state0.slot + SLOTS_PER_EPOCH @@ -149,7 +149,7 @@ func diffStates*(state0, state1: BeaconState): BeaconStateDiff = ) func applyDiff*( - state: var BeaconState, + state: var phase0.BeaconState, immutableValidators: openArray[ImmutableValidatorData2], stateDiff: BeaconStateDiff) = template assign[T, U](tgt: var HashList[T, U], src: List[T, U]) = diff --git a/beacon_chain/sync/request_manager.nim b/beacon_chain/sync/request_manager.nim index ea3b64c13..976918a30 100644 --- a/beacon_chain/sync/request_manager.nim +++ b/beacon_chain/sync/request_manager.nim @@ -9,12 +9,14 @@ import options, sequtils, strutils import chronos, chronicles -import ../spec/[datatypes/phase0, datatypes/altair, digest, forks], - ../networking/eth2_network, - ../beacon_node_types, - ../ssz/merkleization, - ../gossip_processing/block_processor, - ./sync_protocol, ./sync_manager +import + ../spec/datatypes/[phase0, altair], + ../spec/forks, + ../networking/eth2_network, + ../beacon_node_types, + ../ssz/merkleization, + ../gossip_processing/block_processor, + "."/sync_protocol, "."/sync_manager export sync_manager logScope: diff --git a/beacon_chain/sync/sync_manager.nim b/beacon_chain/sync/sync_manager.nim index d16642269..43991e836 100644 --- a/beacon_chain/sync/sync_manager.nim +++ b/beacon_chain/sync/sync_manager.nim @@ -7,15 +7,20 @@ {.push raises: [Defect].} -import chronicles -import options, deques, heapqueue, tables, strutils, sequtils, math, algorithm +import std/[ + options, deques, heapqueue, tables, strutils, sequtils, math, algorithm] import stew/results, chronos, chronicles -import ../spec/[datatypes/phase0, datatypes/altair, digest, helpers, eth2_apis/rpc_types, forks], - ../networking/[peer_pool, eth2_network] + +import + ../spec/datatypes/[phase0, altair], + ../spec/eth2_apis/rpc_types, + ../spec/[helpers, forks], + ../networking/[peer_pool, eth2_network] import ../gossip_processing/block_processor import ../consensus_object_pools/block_pools_types -export phase0, altair, digest, chronos, chronicles, results, block_pools_types, + +export phase0, altair, chronos, chronicles, results, block_pools_types, helpers logScope: diff --git a/beacon_chain/sync/sync_protocol.nim b/beacon_chain/sync/sync_protocol.nim index 8a22de053..6912801ef 100644 --- a/beacon_chain/sync/sync_protocol.nim +++ b/beacon_chain/sync/sync_protocol.nim @@ -11,8 +11,8 @@ import options, tables, sets, macros, chronicles, chronos, stew/ranges/bitranges, libp2p/switch, ../spec/datatypes/[phase0, altair], - ../spec/[crypto, datatypes, digest, forks, network], - ../beacon_node_types, ../beacon_clock, + ../spec/[helpers, forks, network], + ".."/[beacon_node_types, beacon_clock], ../networking/eth2_network, ../consensus_object_pools/blockchain_dag diff --git a/beacon_chain/validator_client/common.nim b/beacon_chain/validator_client/common.nim index 723882f76..b21f2f237 100644 --- a/beacon_chain/validator_client/common.nim +++ b/beacon_chain/validator_client/common.nim @@ -5,20 +5,22 @@ import chronos, presto, presto/client as presto_client, chronicles, confutils, eth/db/[kvstore, kvstore_sqlite3] # Local modules -import ".."/spec/[datatypes, digest, crypto, helpers, signatures], - ".."/spec/eth2_apis/rest_beacon_client, - ".."/validators/[attestation_aggregation, keystore_management, - validator_pool, slashing_protection], - ".."/[conf, beacon_clock, version, beacon_node_types, - nimbus_binary_common], - ".."/ssz/merkleization +import + ../spec/datatypes/[phase0, altair], + ../spec/[helpers, signatures], + ../spec/eth2_apis/rest_beacon_client, + ../validators/[attestation_aggregation, keystore_management, + validator_pool, slashing_protection], + ".."/[conf, beacon_clock, version, beacon_node_types, + nimbus_binary_common], + ".."/ssz/merkleization export os, tables, sequtils, sequtils, chronos, presto, chronicles, confutils, nimbus_binary_common, version, conf, options, tables, results, base10, byteutils, presto_client export rest_beacon_client, - datatypes, crypto, digest, helpers, signatures, merkleization, + phase0, altair, helpers, signatures, merkleization, beacon_clock, kvstore, kvstore_sqlite3, keystore_management, slashing_protection, validator_pool, diff --git a/beacon_chain/validators/attestation_aggregation.nim b/beacon_chain/validators/attestation_aggregation.nim index 0629fbcdb..cb4e51000 100644 --- a/beacon_chain/validators/attestation_aggregation.nim +++ b/beacon_chain/validators/attestation_aggregation.nim @@ -10,7 +10,7 @@ import std/options, ../spec/datatypes/base, - ../spec/[digest, crypto, helpers], + ../spec/[helpers], ../consensus_object_pools/[spec_cache, attestation_pool] # https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/validator.md#aggregation-selection diff --git a/beacon_chain/validators/keystore_management.nim b/beacon_chain/validators/keystore_management.nim index 7f53fdc31..1b046f44c 100644 --- a/beacon_chain/validators/keystore_management.nim +++ b/beacon_chain/validators/keystore_management.nim @@ -11,7 +11,7 @@ import std/[os, strutils, terminal, wordwrap, unicode], chronicles, chronos, web3, stint, json_serialization, zxcvbn, serialization, blscurve, eth/common/eth_types, eth/keys, confutils, bearssl, - ../spec/[digest, crypto, keystore], + ../spec/[keystore], ../spec/datatypes/base, stew/io2, libp2p/crypto/crypto as lcrypto, nimcrypto/utils as ncrutils, diff --git a/beacon_chain/validators/slashing_protection.nim b/beacon_chain/validators/slashing_protection.nim index 0f38aae87..1fb394054 100644 --- a/beacon_chain/validators/slashing_protection.nim +++ b/beacon_chain/validators/slashing_protection.nim @@ -16,7 +16,6 @@ import chronicles, chronicles/timings, # Internal ../spec/datatypes/base, - ../spec/[digest, crypto], ./slashing_protection_common, ./slashing_protection_v1, ./slashing_protection_v2 diff --git a/beacon_chain/validators/slashing_protection_common.nim b/beacon_chain/validators/slashing_protection_common.nim index faefc3260..27fae2e3b 100644 --- a/beacon_chain/validators/slashing_protection_common.nim +++ b/beacon_chain/validators/slashing_protection_common.nim @@ -18,8 +18,7 @@ import json_serialization, chronicles, # Internal - ../spec/datatypes/base, - ../spec/[digest, crypto] + ../spec/datatypes/base export serialization, json_serialization # Generic sandwich https://github.com/nim-lang/Nim/issues/11225 diff --git a/beacon_chain/validators/slashing_protection_v1.nim b/beacon_chain/validators/slashing_protection_v1.nim index 02f03f9a6..666ac8c4e 100644 --- a/beacon_chain/validators/slashing_protection_v1.nim +++ b/beacon_chain/validators/slashing_protection_v1.nim @@ -18,7 +18,6 @@ import json_serialization, # Internal ../spec/datatypes/base, - ../spec/[digest, crypto], ../ssz, ./slashing_protection_common diff --git a/beacon_chain/validators/slashing_protection_v2.nim b/beacon_chain/validators/slashing_protection_v2.nim index 89dad240a..c48e7aeb4 100644 --- a/beacon_chain/validators/slashing_protection_v2.nim +++ b/beacon_chain/validators/slashing_protection_v2.nim @@ -16,7 +16,8 @@ import chronicles, sqlite3_abi, # Internal - ../spec/[datatypes, digest, crypto, helpers], + ../spec/datatypes/base, + ../spec/helpers, ../ssz, ./slashing_protection_common diff --git a/beacon_chain/validators/validator_duties.nim b/beacon_chain/validators/validator_duties.nim index fe12703f2..f5c6b1cde 100644 --- a/beacon_chain/validators/validator_duties.nim +++ b/beacon_chain/validators/validator_duties.nim @@ -20,20 +20,18 @@ import eth/keys, eth/p2p/discoveryv5/[protocol, enr], # Local modules - ../spec/[ - datatypes/phase0, datatypes/altair, digest, crypto, - forks, helpers, network, signatures, state_transition], - ../conf, ../beacon_clock, + ../spec/datatypes/[phase0, altair, merge], + ../spec/[forks, helpers, network, signatures, state_transition], ../consensus_object_pools/[ - spec_cache, blockchain_dag, block_clearance, - attestation_pool, exit_pool], + spec_cache, blockchain_dag, block_clearance, attestation_pool, exit_pool], ../eth1/eth1_monitor, ../networking/eth2_network, - ".."/[beacon_node_common, beacon_node_types, version], ../ssz, ../ssz/sszdump, ../sync/sync_manager, - ./slashing_protection, ./attestation_aggregation, - ./validator_pool, ./keystore_management, - ../gossip_processing/consensus_manager + ../gossip_processing/consensus_manager, + ".."/[conf, beacon_clock, beacon_node_common, beacon_node_types, version], + "."/[ + slashing_protection, attestation_aggregation, validator_pool, + keystore_management] # Metrics for tracking attestation and beacon block loss const delayBuckets = [-Inf, -4.0, -2.0, -1.0, -0.5, -0.1, -0.05, diff --git a/beacon_chain/validators/validator_pool.nim b/beacon_chain/validators/validator_pool.nim index dff1a9ac5..ab3dd8654 100644 --- a/beacon_chain/validators/validator_pool.nim +++ b/beacon_chain/validators/validator_pool.nim @@ -12,7 +12,7 @@ import chronos, chronicles, metrics, json_serialization/std/[sets, net], eth/db/[kvstore, kvstore_sqlite3], - ../spec/[crypto, digest, signatures, helpers], + ../spec/[signatures, helpers], ../spec/datatypes/base, ../beacon_node_types, ./slashing_protection diff --git a/nbench/scenarios.nim b/nbench/scenarios.nim index 64045d5c3..66b202dcb 100644 --- a/nbench/scenarios.nim +++ b/nbench/scenarios.nim @@ -11,10 +11,9 @@ import # Status libraries confutils/defs, serialization, chronicles, # Beacon-chain + ../beacon_chain/spec/datatypes/[phase0], ../beacon_chain/spec/[ - beaconstate, crypto, datatypes, forks, helpers, - presets, state_transition, state_transition_block], - ../beacon_chain/extras, + beaconstate, forks, helpers, state_transition, state_transition_block], ../beacon_chain/ssz/[merkleization, ssz_serialization], ../tests/official/fixtures_utils @@ -150,7 +149,7 @@ proc runFullTransition*(dir, preState, blocksPrefix: string, blocksQty: int, ski echo "Running: ", prePath let state = (ref ForkedHashedBeaconState)( - hbsPhase0: HashedBeaconState(data: parseSSZ(prePath, BeaconState)), + hbsPhase0: phase0.HashedBeaconState(data: parseSSZ(prePath, phase0.BeaconState)), beaconStateFork: forkPhase0 ) setStateRoot(state[], hash_tree_root(state[])) @@ -159,7 +158,7 @@ proc runFullTransition*(dir, preState, blocksPrefix: string, blocksQty: int, ski let blockPath = dir / blocksPrefix & $i & ".ssz" echo "Processing: ", blockPath - let signedBlock = parseSSZ(blockPath, SignedBeaconBlock) + let signedBlock = parseSSZ(blockPath, phase0.SignedBeaconBlock) let flags = if skipBLS: {skipBlsValidation} else: {} let success = state_transition( @@ -175,7 +174,8 @@ proc runProcessSlots*(dir, preState: string, numSlots: uint64) = echo "Running: ", prePath let state = (ref ForkedHashedBeaconState)( - hbsPhase0: HashedBeaconState(data: parseSSZ(prePath, BeaconState)), + hbsPhase0: phase0.HashedBeaconState( + data: parseSSZ(prePath, phase0.BeaconState)), beaconStateFork: forkPhase0) setStateRoot(state[], hash_tree_root(state[])) @@ -190,8 +190,9 @@ template processEpochScenarioImpl( let prePath = dir/preState & ".ssz" echo "Running: ", prePath - let state = (ref HashedBeaconState)( - data: parseSSZ(prePath, BeaconState) + type T = phase0.BeaconState + let state = (ref phase0.HashedBeaconState)( + data: parseSSZ(prePath, T) ) state.root = hash_tree_root(state.data) @@ -211,7 +212,7 @@ template genProcessEpochScenario(name, transitionFn: untyped): untyped = proc `name`*(dir, preState: string) = processEpochScenarioImpl(dir, preState, transitionFn) -proc process_deposit(state: var BeaconState; +proc process_deposit(state: var phase0.BeaconState; deposit: Deposit; flags: UpdateFlags = {}): Result[void, cstring] = process_deposit(defaultRuntimeConfig, state, deposit, flags) @@ -223,8 +224,9 @@ template processBlockScenarioImpl( let prePath = dir/preState & ".ssz" echo "Running: ", prePath - let state = (ref HashedBeaconState)( - data: parseSSZ(prePath, BeaconState) + type T = phase0.BeaconState + let state = (ref phase0.HashedBeaconState)( + data: parseSSZ(prePath, T) ) state.root = hash_tree_root(state.data) @@ -267,7 +269,7 @@ genProcessEpochScenario(runProcessSlashings, genProcessBlockScenario(runProcessBlockHeader, process_block_header, block_header, - BeaconBlock) + phase0.BeaconBlock) genProcessBlockScenario(runProcessProposerSlashing, process_proposer_slashing, diff --git a/ncli/e2store.nim b/ncli/e2store.nim index 8052d55a1..e5dacbdfb 100644 --- a/ncli/e2store.nim +++ b/ncli/e2store.nim @@ -3,7 +3,7 @@ import stew/[endians2, results], snappy, snappy/framing, - ../beacon_chain/spec/datatypes, + ../beacon_chain/spec/datatypes/phase0, ../beacon_chain/ssz/ssz_serialization const @@ -79,7 +79,7 @@ proc toCompressedBytes(item: auto): seq[byte] = except CatchableError as exc: raiseAssert exc.msg # shouldn't happen -proc appendRecord*(store: var E2Store, v: SomeSignedBeaconBlock): Result[void, string] = +proc appendRecord*(store: var E2Store, v: phase0.TrustedSignedBeaconBlock): Result[void, string] = if v.message.slot < store.slot: return err("Blocks must be written in order") let start = store.data.appendRecord(SnappyBeaconBlock, toCompressedBytes(v)).get() @@ -91,6 +91,6 @@ proc appendRecord*(store: var E2Store, v: SomeSignedBeaconBlock): Result[void, s ok() -proc appendRecord*(store: var E2Store, v: BeaconState): Result[void, string] = +proc appendRecord*(store: var E2Store, v: phase0.BeaconState): Result[void, string] = discard ? store.data.appendRecord(SnappyBeaconState, toCompressedBytes(v)) ok() diff --git a/ncli/ncli.nim b/ncli/ncli.nim index 603af2705..51382e29f 100644 --- a/ncli/ncli.nim +++ b/ncli/ncli.nim @@ -3,10 +3,8 @@ import confutils, chronicles, json_serialization, stew/byteutils, ../research/simutils, - ../beacon_chain/spec/[ - crypto, datatypes, digest, forks, helpers, presets, - state_transition], - ../beacon_chain/extras, + ../beacon_chain/spec/datatypes/[phase0], + ../beacon_chain/spec/[forks, helpers, state_transition], ../beacon_chain/networking/network_metadata, ../beacon_chain/ssz/[merkleization, ssz_serialization] @@ -83,11 +81,11 @@ template saveSSZFile(filename: string, value: ForkedHashedBeaconState) = proc doTransition(conf: NcliConf) = let stateY = (ref ForkedHashedBeaconState)( - hbsPhase0: HashedBeaconState( - data: SSZ.loadFile(conf.preState, BeaconState)), + hbsPhase0: phase0.HashedBeaconState( + data: SSZ.loadFile(conf.preState, phase0.BeaconState)), beaconStateFork: forkPhase0 ) - blckX = SSZ.loadFile(conf.blck, SignedBeaconBlock) + blckX = SSZ.loadFile(conf.blck, phase0.SignedBeaconBlock) flags = if not conf.verifyStateRoot: {skipStateRootValidation} else: {} setStateRoot(stateY[], hash_tree_root(stateY[])) @@ -113,8 +111,8 @@ proc doSlots(conf: NcliConf) = var timers: array[Timers, RunningStat] let stateY = withTimerRet(timers[tLoadState]): (ref ForkedHashedBeaconState)( - hbsPhase0: HashedBeaconState( - data: SSZ.loadFile(conf.preState2, BeaconState)), + hbsPhase0: phase0.HashedBeaconState( + data: SSZ.loadFile(conf.preState2, phase0.BeaconState)), beaconStateFork: forkPhase0 ) @@ -156,7 +154,7 @@ proc doSSZ(conf: NcliConf) = case conf.cmd: of hashTreeRoot: - when t is SignedBeaconBlock: + when t is phase0.SignedBeaconBlock: echo hash_tree_root(v.message).data.toHex() else: echo hash_tree_root(v[]).data.toHex() @@ -170,14 +168,14 @@ proc doSSZ(conf: NcliConf) = case kind of "attester_slashing": printit(AttesterSlashing) of "attestation": printit(Attestation) - of "signed_block": printit(SignedBeaconBlock) - of "block": printit(BeaconBlock) - of "block_body": printit(BeaconBlockBody) + of "signed_block": printit(phase0.SignedBeaconBlock) + of "block": printit(phase0.BeaconBlock) + of "block_body": printit(phase0.BeaconBlockBody) of "block_header": printit(BeaconBlockHeader) of "deposit": printit(Deposit) of "deposit_data": printit(DepositData) of "eth1_data": printit(Eth1Data) - of "state": printit(BeaconState) + of "state": printit(phase0.BeaconState) of "proposer_slashing": printit(ProposerSlashing) of "voluntary_exit": printit(VoluntaryExit) diff --git a/ncli/ncli_db.nim b/ncli/ncli_db.nim index d43ec182b..3c194412f 100644 --- a/ncli/ncli_db.nim +++ b/ncli/ncli_db.nim @@ -2,12 +2,12 @@ import os, stats, strformat, tables, chronicles, confutils, stew/byteutils, eth/db/kvstore_sqlite3, ../beacon_chain/networking/network_metadata, - ../beacon_chain/[beacon_chain_db, extras], + ../beacon_chain/[beacon_chain_db], ../beacon_chain/consensus_object_pools/[ blockchain_dag, forkedbeaconstate_dbhelpers], + ../beacon_chain/spec/datatypes/phase0, ../beacon_chain/spec/[ - crypto, datatypes/phase0, digest, forks, helpers, - state_transition, state_transition_epoch, presets], + forks, helpers, state_transition, state_transition_epoch], ../beacon_chain/ssz, ../beacon_chain/ssz/sszdump, ../research/simutils, ./e2store @@ -244,7 +244,7 @@ proc cmdDumpState(conf: DbConf) = for stateRoot in conf.stateRoot: try: let root = Eth2Digest(data: hexToByteArray[32](stateRoot)) - var state = (ref HashedBeaconState)(root: root) + var state = (ref phase0.HashedBeaconState)(root: root) if not db.getState(root, state.data, noRollback): echo "Couldn't load ", root else: @@ -280,11 +280,11 @@ proc copyPrunedDatabase( doAssert db.getBlock(tailBlock.get).isOk var - beaconState: ref BeaconState + beaconState: ref phase0.BeaconState finalizedEpoch: Epoch # default value of 0 is conservative/safe prevBlockSlot = db.getBlock(db.getHeadBlock().get).get.message.slot - beaconState = new BeaconState + beaconState = new phase0.BeaconState let headEpoch = db.getBlock(headBlock.get).get.message.slot.epoch # Tail states are specially addressed; no stateroot intermediary @@ -459,7 +459,7 @@ proc cmdValidatorPerf(conf: DbConf, cfg: RuntimeConfig) = getStateField(dag.headState.data, validators).len()) cache = StateCache() rewards = RewardInfo() - blck: TrustedSignedBeaconBlock + blck: phase0.TrustedSignedBeaconBlock doAssert blockRefs.len() > 0, "Must select at least one block" @@ -683,7 +683,7 @@ proc cmdValidatorDb(conf: DbConf, cfg: RuntimeConfig) = var cache = StateCache() rewards = RewardInfo() - blck: TrustedSignedBeaconBlock + blck: phase0.TrustedSignedBeaconBlock let start = minEpoch.compute_start_slot_at_epoch() diff --git a/nfuzz/libnfuzz.nim b/nfuzz/libnfuzz.nim index 8ecb63d6e..23c53dd4a 100644 --- a/nfuzz/libnfuzz.nim +++ b/nfuzz/libnfuzz.nim @@ -3,38 +3,37 @@ import stew/ptrops, stew/ranges/ptr_arith, chronicles, - ../beacon_chain/extras, + ../beacon_chain/spec/datatypes/phase0, ../beacon_chain/spec/[ - beaconstate, crypto, datatypes, digest, forks, presets, - validator, state_transition, state_transition_block], + beaconstate, forks, validator, state_transition, state_transition_block], ../beacon_chain/ssz/[merkleization, ssz_serialization] type AttestationInput = object - state: BeaconState + state: phase0.BeaconState attestation: Attestation AttesterSlashingInput = object - state: BeaconState + state: phase0.BeaconState attesterSlashing: AttesterSlashing BlockInput = object - state: BeaconState - beaconBlock: SignedBeaconBlock + state: phase0.BeaconState + beaconBlock: phase0.SignedBeaconBlock BlockHeaderInput = BlockInput DepositInput = object - state: BeaconState + state: phase0.BeaconState deposit: Deposit ProposerSlashingInput = object - state: BeaconState + state: phase0.BeaconState proposerSlashing: ProposerSlashing VoluntaryExitInput = object - state: BeaconState + state: phase0.BeaconState exit: SignedVoluntaryExit # This and AssertionError are raised to indicate programming bugs # A wrapper to allow exception tracking to identify unexpected exceptions FuzzCrashError = object of CatchableError # TODO: change ptr uint to ptr csize_t when available in newer Nim version. -proc copyState(state: BeaconState, xoutput: ptr byte, +proc copyState(state: phase0.BeaconState, xoutput: ptr byte, xoutput_size: ptr uint): bool {.raises: [FuzzCrashError, Defect].} = var resultState = try: @@ -115,7 +114,7 @@ proc nfuzz_block(input: openArray[byte], xoutput: ptr byte, rollback: RollbackForkedHashedProc): auto = var fhState = (ref ForkedHashedBeaconState)( - hbsPhase0: HashedBeaconState( + hbsPhase0: phase0.HashedBeaconState( data: data.state, root: hash_tree_root(data.state)), beaconStateFork: forkPhase0) cache = StateCache() diff --git a/research/block_sim.nim b/research/block_sim.nim index b11588fda..e3bb876fd 100644 --- a/research/block_sim.nim +++ b/research/block_sim.nim @@ -20,11 +20,10 @@ import confutils, chronicles, eth/db/kvstore_sqlite3, eth/keys, ../tests/testblockutil, - ../beacon_chain/spec/[beaconstate, crypto, digest, - forks, presets, - helpers, signatures, state_transition], + ../beacon_chain/spec/[ + beaconstate, forks, helpers, signatures, state_transition], ../beacon_chain/spec/datatypes/[phase0, altair], - ../beacon_chain/[beacon_node_types, beacon_chain_db, extras], + ../beacon_chain/[beacon_node_types, beacon_chain_db], ../beacon_chain/eth1/eth1_monitor, ../beacon_chain/validators/validator_pool, ../beacon_chain/consensus_object_pools/[blockchain_dag, block_quarantine, diff --git a/research/simutils.nim b/research/simutils.nim index 4f0d08175..0de73b9e0 100644 --- a/research/simutils.nim +++ b/research/simutils.nim @@ -1,11 +1,10 @@ import stats, os, strformat, times, ../tests/testblockutil, - ../beacon_chain/[extras, beacon_chain_db], + ../beacon_chain/beacon_chain_db, ../beacon_chain/ssz/[merkleization, ssz_serialization], - ../beacon_chain/spec/[ - beaconstate, crypto, datatypes, digest, forks, - helpers, presets], + ../beacon_chain/spec/datatypes/[phase0, altair], + ../beacon_chain/spec/[beaconstate, forks, helpers], ../beacon_chain/consensus_object_pools/[blockchain_dag, block_pools_types], ../beacon_chain/eth1/eth1_monitor @@ -28,7 +27,7 @@ template withTimerRet*(stats: var RunningStat, body: untyped): untyped = tmp -func verifyConsensus*(state: BeaconState, attesterRatio: auto) = +func verifyConsensus*(state: phase0.BeaconState, attesterRatio: auto) = if attesterRatio < 0.63: doAssert state.current_justified_checkpoint.epoch == 0 doAssert state.finalized_checkpoint.epoch == 0 @@ -63,16 +62,16 @@ func verifyConsensus*(state: ForkedHashedBeaconState, attesterRatio: auto) = state, finalized_checkpoint).epoch + 2 >= current_epoch proc loadGenesis*(validators: Natural, validate: bool): - (ref HashedBeaconState, DepositContractSnapshot) = + (ref phase0.HashedBeaconState, DepositContractSnapshot) = let genesisFn = &"genesis_{const_preset}_{validators}_{SPEC_VERSION}.ssz" contractSnapshotFn = &"deposit_contract_snapshot_{const_preset}_{validators}_{SPEC_VERSION}.ssz" - res = (ref HashedBeaconState)() + res = (ref phase0.HashedBeaconState)() if fileExists(genesisFn) and fileExists(contractSnapshotFn): - res.data = SSZ.loadFile(genesisFn, BeaconState) + res.data = SSZ.loadFile(genesisFn, phase0.BeaconState) res.root = hash_tree_root(res.data) if res.data.slot != GENESIS_SLOT: echo "Can only start from genesis state" @@ -138,7 +137,7 @@ proc printTimers*[Timers: enum]( $t proc printTimers*[Timers: enum]( - state: BeaconState, attesters: RunningStat, validate: bool, + state: phase0.BeaconState, attesters: RunningStat, validate: bool, timers: array[Timers, RunningStat]) = echo "Validators: ", state.validators.len, ", epoch length: ", SLOTS_PER_EPOCH echo "Validators per attestation (mean): ", attesters.mean diff --git a/research/stack_sizes.nim b/research/stack_sizes.nim index 6a8268ef7..00e124bac 100644 --- a/research/stack_sizes.nim +++ b/research/stack_sizes.nim @@ -1,4 +1,4 @@ -import ../beacon_chain/spec/datatypes +import ../beacon_chain/spec/datatypes/phase0 import typetraits, strformat, strutils diff --git a/research/state_sim.nim b/research/state_sim.nim index 3c84149d5..dbe58a09d 100644 --- a/research/state_sim.nim +++ b/research/state_sim.nim @@ -13,9 +13,8 @@ import strformat, options, sequtils, random, tables, ../tests/testblockutil, - ../beacon_chain/spec/[ - beaconstate, crypto, datatypes, digest, forks, helpers], - ../beacon_chain/extras, + ../beacon_chain/spec/datatypes/phase0, + ../beacon_chain/spec/[beaconstate, forks, helpers], ../beacon_chain/ssz/[merkleization, ssz_serialization], ./simutils @@ -56,7 +55,7 @@ cli do(slots = SLOTS_PER_EPOCH * 5, timers: array[Timers, RunningStat] attesters: RunningStat r = initRand(1) - signedBlock: SignedBeaconBlock + signedBlock: phase0.SignedBeaconBlock cache = StateCache() proc maybeWrite(last: bool) = diff --git a/tests/fork_choice/interpreter.nim b/tests/fork_choice/interpreter.nim index d60ecc4e4..8f7cfd535 100644 --- a/tests/fork_choice/interpreter.nim +++ b/tests/fork_choice/interpreter.nim @@ -12,10 +12,9 @@ import stew/[results, endians2], # Internals ../../beacon_chain/spec/datatypes/base, - ../../beacon_chain/spec/digest, ../../beacon_chain/fork_choice/[fork_choice, fork_choice_types] -export results, base, digest, fork_choice, fork_choice_types, tables, options +export results, base, fork_choice, fork_choice_types, tables, options func fakeHash*(index: SomeInteger): Eth2Digest = ## Create fake hashes diff --git a/tests/fuzzing/ssz_fuzzing.nim b/tests/fuzzing/ssz_fuzzing.nim index b076becbf..4fe6e8f75 100644 --- a/tests/fuzzing/ssz_fuzzing.nim +++ b/tests/fuzzing/ssz_fuzzing.nim @@ -1,10 +1,10 @@ import testutils/fuzzing, faststreams/inputs, serialization/testing/tracing, ../../beacon_chain/ssz, - ../../beacon_chain/spec/[datatypes, crypto, digest, datatypes] + ../../beacon_chain/spec/datatypes/base export - ssz, datatypes, crypto, digest, fuzzing + ssz, base, fuzzing template sszFuzzingTest*(T: type) = test: diff --git a/tests/helpers/debug_state.nim b/tests/helpers/debug_state.nim index f4c6e05dc..08909928f 100644 --- a/tests/helpers/debug_state.nim +++ b/tests/helpers/debug_state.nim @@ -7,10 +7,11 @@ import macros, - ../../beacon_chain/spec/[datatypes, crypto, digest], ../../beacon_chain/ssz/types + ../../beacon_chain/spec/datatypes/base, + ../../beacon_chain/ssz/types # digest is necessary for them to be printed as hex -export crypto.`==` +export base.`==` # --------------------------------------------------------------------- diff --git a/tests/mocking/mock_attestations.nim b/tests/mocking/mock_attestations.nim index 47906c8f9..c8f03b660 100644 --- a/tests/mocking/mock_attestations.nim +++ b/tests/mocking/mock_attestations.nim @@ -14,8 +14,8 @@ import # Status chronicles, # Specs - ../../beacon_chain/spec/[datatypes, beaconstate, helpers, validator, crypto, - signatures, presets], + ../../beacon_chain/spec/datatypes/phase0, + ../../beacon_chain/spec/[beaconstate, helpers, validator, signatures], # Internals ../../beacon_chain/ssz, # Mocking procs @@ -23,7 +23,7 @@ import ./mock_validator_keys proc mockAttestationData( - state: BeaconState, + state: phase0.BeaconState, slot: Slot, index: uint64): AttestationData = doAssert state.slot >= slot @@ -56,7 +56,7 @@ proc mockAttestationData( epoch: target_epoch, root: epoch_boundary_root ) -proc signMockAttestation*(state: BeaconState, attestation: var Attestation) = +proc signMockAttestation*(state: phase0.BeaconState, attestation: var Attestation) = var cache = StateCache() var agg {.noInit.}: AggregateSignature @@ -82,7 +82,7 @@ proc signMockAttestation*(state: BeaconState, attestation: var Attestation) = # Otherwise no participants so zero sig proc mockAttestationImpl( - state: BeaconState, + state: phase0.BeaconState, slot: Slot): Attestation = var cache = StateCache() @@ -106,10 +106,10 @@ proc mockAttestationImpl( signMockAttestation(state, result) proc mockAttestation*( - state: BeaconState): Attestation = + state: phase0.BeaconState): Attestation = mockAttestationImpl(state, state.slot) proc mockAttestation*( - state: BeaconState, + state: phase0.BeaconState, slot: Slot): Attestation = mockAttestationImpl(state, slot) diff --git a/tests/mocking/mock_blocks.nim b/tests/mocking/mock_blocks.nim index 73b4b87de..91a21f5c0 100644 --- a/tests/mocking/mock_blocks.nim +++ b/tests/mocking/mock_blocks.nim @@ -8,7 +8,8 @@ import options, # Specs - ../../beacon_chain/spec/[crypto, datatypes, helpers, signatures, validator], + ../../beacon_chain/spec/datatypes/phase0, + ../../beacon_chain/spec/[helpers, signatures, validator], # Internals ../../beacon_chain/ssz, # Mock helpers @@ -18,8 +19,8 @@ import # --------------------------------------------------------------- proc signMockBlockImpl( - state: BeaconState, - signedBlock: var SignedBeaconBlock + state: phase0.BeaconState, + signedBlock: var phase0.SignedBeaconBlock ) = let block_slot = signedBlock.message.slot doAssert state.slot <= block_slot @@ -34,12 +35,12 @@ proc signMockBlockImpl( state.fork, state.genesis_validators_root, block_slot, signedBlock.root, privkey).toValidatorSig() -proc signMockBlock*(state: BeaconState, signedBlock: var SignedBeaconBlock) = +proc signMockBlock*(state: phase0.BeaconState, signedBlock: var phase0.SignedBeaconBlock) = signMockBlockImpl(state, signedBlock) proc mockBlock( - state: BeaconState, - slot: Slot): SignedBeaconBlock = + state: phase0.BeaconState, + slot: Slot): phase0.SignedBeaconBlock = ## TODO don't do this gradual construction, for exception safety ## Mock a BeaconBlock for the specific slot @@ -56,5 +57,5 @@ proc mockBlock( signMockBlock(state, result) -proc mockBlockForNextSlot*(state: BeaconState): SignedBeaconBlock = +proc mockBlockForNextSlot*(state: phase0.BeaconState): phase0.SignedBeaconBlock = mockBlock(state, state.slot + 1) diff --git a/tests/mocking/mock_deposits.nim b/tests/mocking/mock_deposits.nim index d58243f5c..a8cfbeb49 100644 --- a/tests/mocking/mock_deposits.nim +++ b/tests/mocking/mock_deposits.nim @@ -13,7 +13,7 @@ import math, # Specs - ../../beacon_chain/spec/[crypto, digest, keystore, signatures, presets], + ../../beacon_chain/spec/[keystore, signatures], ../../beacon_chain/spec/datatypes/base, # Internals diff --git a/tests/mocking/mock_genesis.nim b/tests/mocking/mock_genesis.nim index cd62ff0fc..1df7e0182 100644 --- a/tests/mocking/mock_genesis.nim +++ b/tests/mocking/mock_genesis.nim @@ -10,13 +10,14 @@ import # Specs - ../../beacon_chain/spec/[datatypes, beaconstate, presets], + ../../beacon_chain/spec/datatypes/phase0, + ../../beacon_chain/spec/[beaconstate], # Internals ../../beacon_chain/interop, # Mocking procs ./mock_deposits -proc initGenesisState*(num_validators: uint64, genesis_time: uint64 = 0): HashedBeaconState = +proc initGenesisState*(num_validators: uint64, genesis_time: uint64 = 0): phase0.HashedBeaconState = let deposits = mockGenesisBalancedDeposits( validatorCount = num_validators, amountInEth = 32, # We create canonical validators with 32 Eth diff --git a/tests/mocking/mock_validator_keys.nim b/tests/mocking/mock_validator_keys.nim index 29d8667c8..7a0b7a02d 100644 --- a/tests/mocking/mock_validator_keys.nim +++ b/tests/mocking/mock_validator_keys.nim @@ -11,7 +11,6 @@ import bearssl, eth/keys, blscurve, - ../../beacon_chain/spec/[crypto, presets], ../../beacon_chain/spec/datatypes/base proc newKeyPair(rng: var BrHmacDrbgContext): BlsResult[tuple[pub: ValidatorPubKey, priv: ValidatorPrivKey]] = diff --git a/tests/official/altair/test_fixture_operations_attestations.nim b/tests/official/altair/test_fixture_operations_attestations.nim index 59a089192..de2ef9ad7 100644 --- a/tests/official/altair/test_fixture_operations_attestations.nim +++ b/tests/official/altair/test_fixture_operations_attestations.nim @@ -46,11 +46,11 @@ proc runTest(identifier: string) = let attestation = parseTest(testDir/"attestation.ssz_snappy", SSZ, Attestation) var preState = - newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, altair.BeaconState)) if existsFile(testDir/"post.ssz_snappy"): let postState = - newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"post.ssz_snappy", SSZ, altair.BeaconState)) let done = process_attestation( preState[], attestation, {}, get_base_reward_per_increment(preState[], cache), cache).isOk diff --git a/tests/official/altair/test_fixture_operations_attester_slashings.nim b/tests/official/altair/test_fixture_operations_attester_slashings.nim index 86aef13bd..12d02960b 100644 --- a/tests/official/altair/test_fixture_operations_attester_slashings.nim +++ b/tests/official/altair/test_fixture_operations_attester_slashings.nim @@ -45,12 +45,12 @@ proc runTest(identifier: string) = var cache = StateCache() preState = - newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, altair.BeaconState)) if existsFile(testDir/"post.ssz_snappy"): let postState = - newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"post.ssz_snappy", SSZ, altair.BeaconState)) done = process_attester_slashing( defaultRuntimeConfig, preState[], attesterSlashing, {}, cache).isOk doAssert done, "Valid attestater slashing not processed" diff --git a/tests/official/altair/test_fixture_operations_block_header.nim b/tests/official/altair/test_fixture_operations_block_header.nim index c0ad7ecec..52c63343b 100644 --- a/tests/official/altair/test_fixture_operations_block_header.nim +++ b/tests/official/altair/test_fixture_operations_block_header.nim @@ -13,7 +13,7 @@ import # Utilities stew/results, # Beacon chain internals - ../../../beacon_chain/spec/[state_transition_block, crypto], + ../../../beacon_chain/spec/[state_transition_block], ../../../beacon_chain/spec/datatypes/altair, ../../../beacon_chain/ssz, # Test utilities @@ -40,16 +40,16 @@ proc runTest(identifier: string) = prefix = "[Invalid] " test prefix & identifier: - let blck = parseTest(testDir/"block.ssz_snappy", SSZ, BeaconBlock) + let blck = parseTest(testDir/"block.ssz_snappy", SSZ, altair.BeaconBlock) var cache = StateCache() preState = - newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, altair.BeaconState)) if existsFile(testDir/"post.ssz_snappy"): let postState = - newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"post.ssz_snappy", SSZ, altair.BeaconState)) done = process_block_header(preState[], blck, {}, cache).isOk doAssert done, "Valid block header not processed" check: preState[].hash_tree_root() == postState[].hash_tree_root() diff --git a/tests/official/altair/test_fixture_operations_deposits.nim b/tests/official/altair/test_fixture_operations_deposits.nim index cd5c54492..6c5a12f05 100644 --- a/tests/official/altair/test_fixture_operations_deposits.nim +++ b/tests/official/altair/test_fixture_operations_deposits.nim @@ -42,11 +42,11 @@ proc runTest(identifier: string) = test prefix & " " & identifier: let deposit = parseTest(testDir/"deposit.ssz_snappy", SSZ, Deposit) var preState = - newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, altair.BeaconState)) if existsFile(testDir/"post.ssz_snappy"): let postState = - newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"post.ssz_snappy", SSZ, altair.BeaconState)) discard process_deposit(defaultRuntimeConfig, preState[], deposit, {}) reportDiff(preState, postState) else: diff --git a/tests/official/altair/test_fixture_operations_proposer_slashings.nim b/tests/official/altair/test_fixture_operations_proposer_slashings.nim index 8ea2c2170..ddcbb9e81 100644 --- a/tests/official/altair/test_fixture_operations_proposer_slashings.nim +++ b/tests/official/altair/test_fixture_operations_proposer_slashings.nim @@ -47,13 +47,13 @@ proc runTest(identifier: string) = testDir/"proposer_slashing.ssz_snappy", SSZ, ProposerSlashing) var preState = - newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, altair.BeaconState)) cache = StateCache() if existsFile(testDir/"post.ssz_snappy"): let postState = - newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"post.ssz_snappy", SSZ, altair.BeaconState)) done = process_proposer_slashing( defaultRuntimeConfig, preState[], proposerSlashing, {}, cache).isOk doAssert done, "Valid proposer slashing not processed" diff --git a/tests/official/altair/test_fixture_operations_sync_aggregate.nim b/tests/official/altair/test_fixture_operations_sync_aggregate.nim index 865e49a35..098236308 100644 --- a/tests/official/altair/test_fixture_operations_sync_aggregate.nim +++ b/tests/official/altair/test_fixture_operations_sync_aggregate.nim @@ -47,13 +47,13 @@ proc runTest(dir, identifier: string) = testDir/"sync_aggregate.ssz_snappy", SSZ, SyncAggregate) var preState = - newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, altair.BeaconState)) cache = StateCache() if existsFile(testDir/"post.ssz_snappy"): let postState = - newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"post.ssz_snappy", SSZ, altair.BeaconState)) done = process_sync_aggregate( preState[], syncAggregate, cache).isOk doAssert done, "Valid sync aggregate not processed" diff --git a/tests/official/altair/test_fixture_operations_voluntary_exit.nim b/tests/official/altair/test_fixture_operations_voluntary_exit.nim index c37a9cf7a..7843f3291 100644 --- a/tests/official/altair/test_fixture_operations_voluntary_exit.nim +++ b/tests/official/altair/test_fixture_operations_voluntary_exit.nim @@ -44,13 +44,13 @@ proc runTest(identifier: string) = testDir/"voluntary_exit.ssz_snappy", SSZ, SignedVoluntaryExit) var preState = - newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, altair.BeaconState)) cache = StateCache() if existsFile(testDir/"post.ssz_snappy"): let postState = - newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"post.ssz_snappy", SSZ, altair.BeaconState)) done = process_voluntary_exit(defaultRuntimeConfig, preState[], voluntaryExit, {}, cache).isOk doAssert done, "Valid voluntary exit not processed" diff --git a/tests/official/altair/test_fixture_sanity_blocks.nim b/tests/official/altair/test_fixture_sanity_blocks.nim index d7f0eef66..92ecda5f1 100644 --- a/tests/official/altair/test_fixture_sanity_blocks.nim +++ b/tests/official/altair/test_fixture_sanity_blocks.nim @@ -11,8 +11,7 @@ import # Standard library os, sequtils, chronicles, # Beacon chain internals - ../../../beacon_chain/spec/[ - crypto, forks, presets, state_transition], + ../../../beacon_chain/spec/[forks, state_transition], ../../../beacon_chain/spec/datatypes/altair, ../../../beacon_chain/ssz, # Test utilities @@ -38,7 +37,7 @@ proc runTest(testName, testDir, unitTestName: string) = test prefix & testName & " - " & unitTestName & preset(): var - preState = newClone(parseTest(testPath/"pre.ssz_snappy", SSZ, BeaconState)) + preState = newClone(parseTest(testPath/"pre.ssz_snappy", SSZ, altair.BeaconState)) fhPreState = (ref ForkedHashedBeaconState)(hbsAltair: altair.HashedBeaconState( data: preState[], root: hash_tree_root(preState[])), beaconStateFork: forkAltair) cache = StateCache() @@ -48,7 +47,7 @@ proc runTest(testName, testDir, unitTestName: string) = # so purely lexicographic sorting wouldn't sort properly. let numBlocks = toSeq(walkPattern(testPath/"blocks_*.ssz_snappy")).len for i in 0 ..< numBlocks: - let blck = parseTest(testPath/"blocks_" & $i & ".ssz_snappy", SSZ, SignedBeaconBlock) + let blck = parseTest(testPath/"blocks_" & $i & ".ssz_snappy", SSZ, altair.SignedBeaconBlock) if hasPostState: let success = state_transition( @@ -63,7 +62,7 @@ proc runTest(testName, testDir, unitTestName: string) = "We didn't expect these invalid blocks to be processed" if hasPostState: - let postState = newClone(parseTest(testPath/"post.ssz_snappy", SSZ, BeaconState)) + let postState = newClone(parseTest(testPath/"post.ssz_snappy", SSZ, altair.BeaconState)) when false: reportDiff(fhPreState.hbsAltair.data, postState) doAssert getStateRoot(fhPreState[]) == postState[].hash_tree_root() diff --git a/tests/official/altair/test_fixture_sanity_slots.nim b/tests/official/altair/test_fixture_sanity_slots.nim index 4ed74e2d6..d9215559a 100644 --- a/tests/official/altair/test_fixture_sanity_slots.nim +++ b/tests/official/altair/test_fixture_sanity_slots.nim @@ -29,14 +29,14 @@ proc runTest(identifier: string) = proc `testImpl _ slots _ identifier`() = test "Slots - " & identifier: var - preState = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState)) + preState = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, altair.BeaconState)) fhPreState = (ref ForkedHashedBeaconState)( hbsAltair: altair.HashedBeaconState( data: preState[], root: hash_tree_root(preState[])), beaconStateFork: forkAltair) cache = StateCache() rewards: RewardInfo - let postState = newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState)) + let postState = newClone(parseTest(testDir/"post.ssz_snappy", SSZ, altair.BeaconState)) check: process_slots( diff --git a/tests/official/altair/test_fixture_ssz_consensus_objects.nim b/tests/official/altair/test_fixture_ssz_consensus_objects.nim index d00341084..eaca7adef 100644 --- a/tests/official/altair/test_fixture_ssz_consensus_objects.nim +++ b/tests/official/altair/test_fixture_ssz_consensus_objects.nim @@ -14,7 +14,6 @@ import # Third-party yaml, # Beacon chain internals - ../../beacon_chain/spec/[crypto, digest], ../../beacon_chain/spec/datatypes/altair, ../../beacon_chain/ssz, # Status libraries @@ -48,7 +47,7 @@ type # Note this only tracks HashTreeRoot # Checking the values against the yaml file is TODO (require more flexible Yaml parser) -proc checkSSZ(T: type SignedBeaconBlock, dir: string, expectedHash: SSZHashTreeRoot) = +proc checkSSZ(T: type altair.SignedBeaconBlock, dir: string, expectedHash: SSZHashTreeRoot) = # Deserialize into a ref object to not fill Nim stack let encoded = snappy.decode( readFileBytes(dir/"serialized.ssz_snappy"), MaxObjectSize) @@ -108,10 +107,10 @@ suite "Official - Altair - SSZ consensus objects " & preset(): of "Attestation": checkSSZ(Attestation, path, hash) of "AttestationData": checkSSZ(AttestationData, path, hash) of "AttesterSlashing": checkSSZ(AttesterSlashing, path, hash) - of "BeaconBlock": checkSSZ(BeaconBlock, path, hash) - of "BeaconBlockBody": checkSSZ(BeaconBlockBody, path, hash) + of "BeaconBlock": checkSSZ(altair.BeaconBlock, path, hash) + of "BeaconBlockBody": checkSSZ(altair.BeaconBlockBody, path, hash) of "BeaconBlockHeader": checkSSZ(BeaconBlockHeader, path, hash) - of "BeaconState": checkSSZ(BeaconState, path, hash) + of "BeaconState": checkSSZ(altair.BeaconState, path, hash) of "Checkpoint": checkSSZ(Checkpoint, path, hash) of "ContributionAndProof": checkSSZ(ContributionAndProof, path, hash) of "Deposit": checkSSZ(Deposit, path, hash) @@ -129,7 +128,7 @@ suite "Official - Altair - SSZ consensus objects " & preset(): of "ProposerSlashing": checkSSZ(ProposerSlashing, path, hash) of "SignedAggregateAndProof": checkSSZ(SignedAggregateAndProof, path, hash) - of "SignedBeaconBlock": checkSSZ(SignedBeaconBlock, path, hash) + of "SignedBeaconBlock": checkSSZ(altair.SignedBeaconBlock, path, hash) of "SignedBeaconBlockHeader": checkSSZ(SignedBeaconBlockHeader, path, hash) of "SignedContributionAndProof": diff --git a/tests/official/altair/test_fixture_state_transition_epoch.nim b/tests/official/altair/test_fixture_state_transition_epoch.nim index 497b774d7..e0be700b1 100644 --- a/tests/official/altair/test_fixture_state_transition_epoch.nim +++ b/tests/official/altair/test_fixture_state_transition_epoch.nim @@ -32,8 +32,9 @@ template runSuite( let unitTestName = testDir.rsplit(DirSep, 1)[1] test testName & " - " & unitTestName & preset(): # BeaconState objects are stored on the heap to avoid stack overflow - var preState = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState)) - let postState = newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState)) + type T = altair.BeaconState + var preState = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, T)) + let postState = newClone(parseTest(testDir/"post.ssz_snappy", SSZ, T)) doAssert not (useCache and useTAB) when useCache: diff --git a/tests/official/altair/test_fixture_transition.nim b/tests/official/altair/test_fixture_transition.nim index cc953a30f..c1fa557fc 100644 --- a/tests/official/altair/test_fixture_transition.nim +++ b/tests/official/altair/test_fixture_transition.nim @@ -14,10 +14,9 @@ import # Status internal faststreams, streams, # Beacon chain internals - ../../../beacon_chain/spec/[ - crypto, state_transition, presets, forks, helpers], + ../../../beacon_chain/spec/[state_transition, forks, helpers], ../../../beacon_chain/spec/datatypes/[phase0, altair], - ../../../beacon_chain/[extras, ssz], + ../../../beacon_chain/[ssz], # Test utilities ../../testutil, ../fixtures_utils diff --git a/tests/official/fixtures_utils.nim b/tests/official/fixtures_utils.nim index bbaa06a91..0f5e09b94 100644 --- a/tests/official/fixtures_utils.nim +++ b/tests/official/fixtures_utils.nim @@ -10,7 +10,8 @@ import os, strutils, typetraits, # Internals ../../beacon_chain/ssz, - ../../beacon_chain/spec/[datatypes, crypto, state_transition_epoch], + ../../beacon_chain/spec/datatypes/[phase0, altair], + ../../beacon_chain/spec/[state_transition_epoch], # Status libs, snappy, stew/byteutils, @@ -21,7 +22,7 @@ export # Workaround: # - https://github.com/status-im/nim-serialization/issues/5 # - https://github.com/nim-lang/Nim/issues/11225 serialization.readValue, - Json, ssz, crypto + Json, ssz, phase0, altair # Process current EF test format # --------------------------------------------- @@ -77,7 +78,7 @@ proc parseTest*(path: string, Format: typedesc[SSZ], T: typedesc): T = stderr.write err.formatMsg(path), "\n" quit 1 -proc process_justification_and_finalization*(state: var BeaconState) = +proc process_justification_and_finalization*(state: var phase0.BeaconState) = var cache = StateCache() var rewards: RewardInfo @@ -85,7 +86,7 @@ proc process_justification_and_finalization*(state: var BeaconState) = rewards.process_attestations(state, cache) process_justification_and_finalization(state, rewards.total_balances) -func process_slashings*(state: var BeaconState) = +func process_slashings*(state: var phase0.BeaconState) = var cache = StateCache() var rewards: RewardInfo rewards.init(state) diff --git a/tests/official/phase0/test_fixture_operations_attestations.nim b/tests/official/phase0/test_fixture_operations_attestations.nim index eb884f135..d12df0e4b 100644 --- a/tests/official/phase0/test_fixture_operations_attestations.nim +++ b/tests/official/phase0/test_fixture_operations_attestations.nim @@ -46,11 +46,11 @@ proc runTest(identifier: string) = let attestation = parseTest(testDir/"attestation.ssz_snappy", SSZ, Attestation) var preState = - newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, phase0.BeaconState)) if existsFile(testDir/"post.ssz_snappy"): let postState = - newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"post.ssz_snappy", SSZ, phase0.BeaconState)) let done = process_attestation( preState[], attestation, {}, 0.Gwei, cache).isOk doAssert done, "Valid attestation not processed" diff --git a/tests/official/phase0/test_fixture_operations_attester_slashings.nim b/tests/official/phase0/test_fixture_operations_attester_slashings.nim index ca9d35fcf..d54e6ad74 100644 --- a/tests/official/phase0/test_fixture_operations_attester_slashings.nim +++ b/tests/official/phase0/test_fixture_operations_attester_slashings.nim @@ -45,12 +45,12 @@ proc runTest(identifier: string) = var cache = StateCache() preState = - newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, phase0.BeaconState)) if existsFile(testDir/"post.ssz_snappy"): let postState = - newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"post.ssz_snappy", SSZ, phase0.BeaconState)) done = process_attester_slashing( defaultRuntimeConfig, preState[], attesterSlashing, {}, cache).isOk doAssert done, "Valid attestater slashing not processed" diff --git a/tests/official/phase0/test_fixture_operations_block_header.nim b/tests/official/phase0/test_fixture_operations_block_header.nim index d14b1af6a..04e4789d9 100644 --- a/tests/official/phase0/test_fixture_operations_block_header.nim +++ b/tests/official/phase0/test_fixture_operations_block_header.nim @@ -13,7 +13,7 @@ import # Utilities stew/results, # Beacon chain internals - ../../../beacon_chain/spec/[state_transition_block, crypto], + ../../../beacon_chain/spec/[state_transition_block], ../../../beacon_chain/spec/datatypes/phase0, ../../../beacon_chain/ssz, # Test utilities @@ -40,16 +40,16 @@ proc runTest(identifier: string) = prefix = "[Invalid] " test prefix & identifier: - let blck = parseTest(testDir/"block.ssz_snappy", SSZ, BeaconBlock) + let blck = parseTest(testDir/"block.ssz_snappy", SSZ, phase0.BeaconBlock) var cache = StateCache() preState = - newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, phase0.BeaconState)) if existsFile(testDir/"post.ssz_snappy"): let postState = - newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"post.ssz_snappy", SSZ, phase0.BeaconState)) done = process_block_header(preState[], blck, {}, cache).isOk doAssert done, "Valid block header not processed" check: preState[].hash_tree_root() == postState[].hash_tree_root() diff --git a/tests/official/phase0/test_fixture_operations_deposits.nim b/tests/official/phase0/test_fixture_operations_deposits.nim index b5fe92a9a..1006e6a30 100644 --- a/tests/official/phase0/test_fixture_operations_deposits.nim +++ b/tests/official/phase0/test_fixture_operations_deposits.nim @@ -42,11 +42,11 @@ proc runTest(identifier: string) = test prefix & " " & identifier: let deposit = parseTest(testDir/"deposit.ssz_snappy", SSZ, Deposit) var preState = - newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, phase0.BeaconState)) if existsFile(testDir/"post.ssz_snappy"): let postState = - newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"post.ssz_snappy", SSZ, phase0.BeaconState)) discard process_deposit(defaultRuntimeConfig, preState[], deposit, {}) reportDiff(preState, postState) else: diff --git a/tests/official/phase0/test_fixture_operations_proposer_slashings.nim b/tests/official/phase0/test_fixture_operations_proposer_slashings.nim index 712b2bfe6..22b27ecd4 100644 --- a/tests/official/phase0/test_fixture_operations_proposer_slashings.nim +++ b/tests/official/phase0/test_fixture_operations_proposer_slashings.nim @@ -47,13 +47,13 @@ proc runTest(identifier: string) = testDir/"proposer_slashing.ssz_snappy", SSZ, ProposerSlashing) var preState = - newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, phase0.BeaconState)) cache = StateCache() if existsFile(testDir/"post.ssz_snappy"): let postState = - newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"post.ssz_snappy", SSZ, phase0.BeaconState)) done = process_proposer_slashing( defaultRuntimeConfig, preState[], proposerSlashing, {}, cache).isOk doAssert done, "Valid proposer slashing not processed" diff --git a/tests/official/phase0/test_fixture_operations_voluntary_exit.nim b/tests/official/phase0/test_fixture_operations_voluntary_exit.nim index 61821b128..0a54d92e3 100644 --- a/tests/official/phase0/test_fixture_operations_voluntary_exit.nim +++ b/tests/official/phase0/test_fixture_operations_voluntary_exit.nim @@ -44,13 +44,13 @@ proc runTest(identifier: string) = testDir/"voluntary_exit.ssz_snappy", SSZ, SignedVoluntaryExit) var preState = - newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, phase0.BeaconState)) cache = StateCache() if existsFile(testDir/"post.ssz_snappy"): let postState = - newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState)) + newClone(parseTest(testDir/"post.ssz_snappy", SSZ, phase0.BeaconState)) done = process_voluntary_exit( defaultRuntimeConfig, preState[], voluntaryExit, {}, cache).isOk diff --git a/tests/official/phase0/test_fixture_sanity_blocks.nim b/tests/official/phase0/test_fixture_sanity_blocks.nim index a2d1d7c42..ae7646c5a 100644 --- a/tests/official/phase0/test_fixture_sanity_blocks.nim +++ b/tests/official/phase0/test_fixture_sanity_blocks.nim @@ -11,8 +11,7 @@ import # Standard library os, sequtils, chronicles, # Beacon chain internals - ../../../beacon_chain/spec/[ - crypto, forks, presets, state_transition], + ../../../beacon_chain/spec/[forks, state_transition], ../../../beacon_chain/spec/datatypes/phase0, ../../../beacon_chain/ssz, # Test utilities @@ -38,7 +37,7 @@ proc runTest(testName, testDir, unitTestName: string) = test prefix & testName & " - " & unitTestName & preset(): var - preState = newClone(parseTest(testPath/"pre.ssz_snappy", SSZ, BeaconState)) + preState = newClone(parseTest(testPath/"pre.ssz_snappy", SSZ, phase0.BeaconState)) fhPreState = (ref ForkedHashedBeaconState)(hbsPhase0: phase0.HashedBeaconState( data: preState[], root: hash_tree_root(preState[])), beaconStateFork: forkPhase0) cache = StateCache() @@ -48,7 +47,7 @@ proc runTest(testName, testDir, unitTestName: string) = # so purely lexicographic sorting wouldn't sort properly. let numBlocks = toSeq(walkPattern(testPath/"blocks_*.ssz_snappy")).len for i in 0 ..< numBlocks: - let blck = parseTest(testPath/"blocks_" & $i & ".ssz_snappy", SSZ, SignedBeaconBlock) + let blck = parseTest(testPath/"blocks_" & $i & ".ssz_snappy", SSZ, phase0.SignedBeaconBlock) if hasPostState: let success = state_transition( @@ -63,7 +62,7 @@ proc runTest(testName, testDir, unitTestName: string) = "We didn't expect these invalid blocks to be processed" if hasPostState: - let postState = newClone(parseTest(testPath/"post.ssz_snappy", SSZ, BeaconState)) + let postState = newClone(parseTest(testPath/"post.ssz_snappy", SSZ, phase0.BeaconState)) when false: reportDiff(hashedPreState.hbsPhase0.data, postState) doAssert getStateRoot(fhPreState[]) == postState[].hash_tree_root() diff --git a/tests/official/phase0/test_fixture_sanity_slots.nim b/tests/official/phase0/test_fixture_sanity_slots.nim index b2bb63b6d..34b88310b 100644 --- a/tests/official/phase0/test_fixture_sanity_slots.nim +++ b/tests/official/phase0/test_fixture_sanity_slots.nim @@ -28,12 +28,12 @@ proc runTest(identifier: string) = proc `testImpl _ slots _ identifier`() = test "Slots - " & identifier: var - preState = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState)) + preState = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, phase0.BeaconState)) fhPreState = (ref ForkedHashedBeaconState)(hbsPhase0: phase0.HashedBeaconState( data: preState[], root: hash_tree_root(preState[])), beaconStateFork: forkPhase0) cache = StateCache() rewards: RewardInfo - let postState = newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState)) + let postState = newClone(parseTest(testDir/"post.ssz_snappy", SSZ, phase0.BeaconState)) check: process_slots( diff --git a/tests/official/phase0/test_fixture_ssz_consensus_objects.nim b/tests/official/phase0/test_fixture_ssz_consensus_objects.nim index 4720a846e..b9f00c41d 100644 --- a/tests/official/phase0/test_fixture_ssz_consensus_objects.nim +++ b/tests/official/phase0/test_fixture_ssz_consensus_objects.nim @@ -14,7 +14,6 @@ import # Third-party yaml, # Beacon chain internals - ../../beacon_chain/spec/[crypto, digest], ../../beacon_chain/spec/datatypes/phase0, ../../beacon_chain/ssz, # Status libraries @@ -48,7 +47,7 @@ type # Note this only tracks HashTreeRoot # Checking the values against the yaml file is TODO (require more flexible Yaml parser) -proc checkSSZ(T: type SignedBeaconBlock, dir: string, expectedHash: SSZHashTreeRoot) = +proc checkSSZ(T: type phase0.SignedBeaconBlock, dir: string, expectedHash: SSZHashTreeRoot) = # Deserialize into a ref object to not fill Nim stack let encoded = snappy.decode( readFileBytes(dir/"serialized.ssz_snappy"), MaxObjectSize) @@ -108,10 +107,10 @@ suite "Official - Phase 0 - SSZ consensus objects " & preset(): of "Attestation": checkSSZ(Attestation, path, hash) of "AttestationData": checkSSZ(AttestationData, path, hash) of "AttesterSlashing": checkSSZ(AttesterSlashing, path, hash) - of "BeaconBlock": checkSSZ(BeaconBlock, path, hash) - of "BeaconBlockBody": checkSSZ(BeaconBlockBody, path, hash) + of "BeaconBlock": checkSSZ(phase0.BeaconBlock, path, hash) + of "BeaconBlockBody": checkSSZ(phase0.BeaconBlockBody, path, hash) of "BeaconBlockHeader": checkSSZ(BeaconBlockHeader, path, hash) - of "BeaconState": checkSSZ(BeaconState, path, hash) + of "BeaconState": checkSSZ(phase0.BeaconState, path, hash) of "Checkpoint": checkSSZ(Checkpoint, path, hash) of "Deposit": checkSSZ(Deposit, path, hash) of "DepositData": checkSSZ(DepositData, path, hash) @@ -126,7 +125,7 @@ suite "Official - Phase 0 - SSZ consensus objects " & preset(): of "ProposerSlashing": checkSSZ(ProposerSlashing, path, hash) of "SignedAggregateAndProof": checkSSZ(SignedAggregateAndProof, path, hash) - of "SignedBeaconBlock": checkSSZ(SignedBeaconBlock, path, hash) + of "SignedBeaconBlock": checkSSZ(phase0.SignedBeaconBlock, path, hash) of "SignedBeaconBlockHeader": checkSSZ(SignedBeaconBlockHeader, path, hash) of "SignedVoluntaryExit": checkSSZ(SignedVoluntaryExit, path, hash) diff --git a/tests/official/phase0/test_fixture_state_transition_epoch.nim b/tests/official/phase0/test_fixture_state_transition_epoch.nim index cb4fa40d2..ad0f25555 100644 --- a/tests/official/phase0/test_fixture_state_transition_epoch.nim +++ b/tests/official/phase0/test_fixture_state_transition_epoch.nim @@ -30,8 +30,9 @@ template runSuite(suiteDir, testName: string, transitionProc: untyped{ident}, us let unitTestName = testDir.rsplit(DirSep, 1)[1] test testName & " - " & unitTestName & preset(): # BeaconState objects are stored on the heap to avoid stack overflow - var preState = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState)) - let postState = newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState)) + type T = phase0.BeaconState + var preState = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, T)) + let postState = newClone(parseTest(testDir/"post.ssz_snappy", SSZ, T)) var cache {.used.}: StateCache when compiles(transitionProc(defaultRuntimeConfig, preState[], cache)): transitionProc(defaultRuntimeConfig, preState[], cache) diff --git a/tests/official/test_fixture_rewards.nim b/tests/official/test_fixture_rewards.nim index 7159b7af8..40f95f79b 100644 --- a/tests/official/test_fixture_rewards.nim +++ b/tests/official/test_fixture_rewards.nim @@ -13,7 +13,8 @@ import # Utilities stew/results, # Beacon chain internals - ../../beacon_chain/spec/[validator, datatypes, helpers, state_transition_epoch], + ../../beacon_chain/spec/datatypes/phase0, + ../../beacon_chain/spec/[validator, helpers, state_transition_epoch], ../../beacon_chain/ssz, # Test utilities ../testutil, @@ -50,7 +51,7 @@ proc runTest(rewardsDir, identifier: string) = proc `testImpl _ rewards _ identifier`() = test "Rewards" & " - " & identifier & preset(): var - state = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconState)) + state = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, phase0.BeaconState)) cache = StateCache() let sourceDeltas = diff --git a/tests/slashing_protection/test_migration.nim b/tests/slashing_protection/test_migration.nim index 6de7dccfa..6b8a9be69 100644 --- a/tests/slashing_protection/test_migration.nim +++ b/tests/slashing_protection/test_migration.nim @@ -22,7 +22,6 @@ import slashing_protection_v1 ], ../../beacon_chain/spec/datatypes/base, - ../../beacon_chain/spec/[digest, crypto, presets], # Test utilies ../testutil diff --git a/tests/slashing_protection/test_official_interchange_vectors.nim b/tests/slashing_protection/test_official_interchange_vectors.nim index 6549d0ac6..38e6130a2 100644 --- a/tests/slashing_protection/test_official_interchange_vectors.nim +++ b/tests/slashing_protection/test_official_interchange_vectors.nim @@ -15,7 +15,6 @@ import # Internal ../../beacon_chain/validators/[slashing_protection, slashing_protection_v2], ../../beacon_chain/spec/datatypes/base, - ../../beacon_chain/spec/[digest, crypto, presets], # Test utilies ../testutil, ../testdbutil, ../official/fixtures_utils diff --git a/tests/slashing_protection/test_slashing_interchange.nim b/tests/slashing_protection/test_slashing_interchange.nim index a717a2cd8..94796b388 100644 --- a/tests/slashing_protection/test_slashing_interchange.nim +++ b/tests/slashing_protection/test_slashing_interchange.nim @@ -17,7 +17,6 @@ import # Internal ../../beacon_chain/validators/[slashing_protection, slashing_protection_v2], ../../beacon_chain/spec/datatypes/base, - ../../beacon_chain/spec/[digest, crypto, presets], # Test utilies ../testutil diff --git a/tests/slashing_protection/test_slashing_protection_db.nim b/tests/slashing_protection/test_slashing_protection_db.nim index 4c6956a3a..195c3951e 100644 --- a/tests/slashing_protection/test_slashing_protection_db.nim +++ b/tests/slashing_protection/test_slashing_protection_db.nim @@ -15,7 +15,7 @@ import stew/results, # Internal ../../beacon_chain/validators/slashing_protection, - ../../beacon_chain/spec/[crypto, digest, helpers, presets], + ../../beacon_chain/spec/[helpers], ../../beacon_chain/spec/datatypes/base, # Test utilies ../testutil diff --git a/tests/spec_block_processing/test_process_deposits.nim b/tests/spec_block_processing/test_process_deposits.nim index 73342428f..b30893568 100644 --- a/tests/spec_block_processing/test_process_deposits.nim +++ b/tests/spec_block_processing/test_process_deposits.nim @@ -16,11 +16,10 @@ import # Standard library std/math, # Specs - ../../beacon_chain/spec/[crypto, presets, state_transition_block], + ../../beacon_chain/spec/[state_transition_block], ../../beacon_chain/spec/datatypes/base, # Internals ../../beacon_chain/ssz, - ../../beacon_chain/extras, # Mock helpers ../mocking/[mock_deposits, mock_genesis], ../testutil, ../helpers/math_helpers diff --git a/tests/spec_epoch_processing/justification_finalization_helpers.nim b/tests/spec_epoch_processing/justification_finalization_helpers.nim index 8c8cf39bb..0c0d0a055 100644 --- a/tests/spec_epoch_processing/justification_finalization_helpers.nim +++ b/tests/spec_epoch_processing/justification_finalization_helpers.nim @@ -9,7 +9,8 @@ import # Standard library strformat, tables, # Specs - ../../beacon_chain/spec/[beaconstate, datatypes, validator, helpers], + ../../beacon_chain/spec/datatypes/phase0, + ../../beacon_chain/spec/[beaconstate, validator, helpers], # Test helpers ../helpers/digest_helpers @@ -17,7 +18,7 @@ import # --------------------------------------------------------------- proc addMockAttestations*( - state: var BeaconState, epoch: Epoch, + state: var phase0.BeaconState, epoch: Epoch, source, target: Checkpoint, sufficient_support = false ) = @@ -85,7 +86,7 @@ proc getCheckpoints*(epoch: Epoch): tuple[c1, c2, c3, c4, c5: Checkpoint] = if epoch >= 5: result.c5 = Checkpoint(epoch: epoch - 5, root: [byte 0xEE] * 32) proc putCheckpointsInBlockRoots*( - state: var BeaconState, + state: var phase0.BeaconState, checkpoints: openArray[Checkpoint]) = for c in checkpoints: let idx = c.epoch.compute_start_slot_at_epoch() mod SLOTS_PER_HISTORICAL_ROOT diff --git a/tests/test_attestation_pool.nim b/tests/test_attestation_pool.nim index 8b16f710d..2ea3f9a88 100644 --- a/tests/test_attestation_pool.nim +++ b/tests/test_attestation_pool.nim @@ -15,14 +15,14 @@ import stew/byteutils, eth/keys, # Internal - ../beacon_chain/[beacon_node_types, extras], + ../beacon_chain/[beacon_node_types], ../beacon_chain/gossip_processing/[gossip_validation], ../beacon_chain/fork_choice/[fork_choice_types, fork_choice], ../beacon_chain/consensus_object_pools/[ block_quarantine, blockchain_dag, block_clearance, attestation_pool], ../beacon_chain/ssz/merkleization, - ../beacon_chain/spec/[crypto, datatypes, digest, forks, - state_transition, helpers, presets], + ../beacon_chain/spec/datatypes/phase0, + ../beacon_chain/spec/[forks, state_transition, helpers], # Test utilities ./testutil, ./testdbutil, ./testblockutil @@ -379,7 +379,7 @@ suite "Attestation pool processing" & preset(): let b1 = addTestBlock(state.data, dag.tail.root, cache) b1Add = dag.addRawBlock(quarantine, b1) do ( - blckRef: BlockRef, signedBlock: TrustedSignedBeaconBlock, + blckRef: BlockRef, signedBlock: phase0.TrustedSignedBeaconBlock, epochRef: EpochRef): # Callback add to fork choice if valid pool[].addForkChoice(epochRef, blckRef, signedBlock.message, blckRef.slot) @@ -392,7 +392,7 @@ suite "Attestation pool processing" & preset(): let b2 = addTestBlock(state.data, b1.root, cache) b2Add = dag.addRawBlock(quarantine, b2) do ( - blckRef: BlockRef, signedBlock: TrustedSignedBeaconBlock, + blckRef: BlockRef, signedBlock: phase0.TrustedSignedBeaconBlock, epochRef: EpochRef): # Callback add to fork choice if valid pool[].addForkChoice(epochRef, blckRef, signedBlock.message, blckRef.slot) @@ -407,7 +407,7 @@ suite "Attestation pool processing" & preset(): let b10 = makeTestBlock(state.data, dag.tail.root, cache) b10Add = dag.addRawBlock(quarantine, b10) do ( - blckRef: BlockRef, signedBlock: TrustedSignedBeaconBlock, + blckRef: BlockRef, signedBlock: phase0.TrustedSignedBeaconBlock, epochRef: EpochRef): # Callback add to fork choice if valid pool[].addForkChoice(epochRef, blckRef, signedBlock.message, blckRef.slot) @@ -422,7 +422,7 @@ suite "Attestation pool processing" & preset(): graffiti = GraffitiBytes [1'u8, 0, 0, 0 ,0 ,0 ,0 ,0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ) b11Add = dag.addRawBlock(quarantine, b11) do ( - blckRef: BlockRef, signedBlock: TrustedSignedBeaconBlock, + blckRef: BlockRef, signedBlock: phase0.TrustedSignedBeaconBlock, epochRef: EpochRef): # Callback add to fork choice if valid pool[].addForkChoice(epochRef, blckRef, signedBlock.message, blckRef.slot) @@ -468,7 +468,7 @@ suite "Attestation pool processing" & preset(): let b10 = makeTestBlock(state.data, dag.tail.root, cache) b10Add = dag.addRawBlock(quarantine, b10) do ( - blckRef: BlockRef, signedBlock: TrustedSignedBeaconBlock, + blckRef: BlockRef, signedBlock: phase0.TrustedSignedBeaconBlock, epochRef: EpochRef): # Callback add to fork choice if valid pool[].addForkChoice(epochRef, blckRef, signedBlock.message, blckRef.slot) @@ -482,7 +482,7 @@ suite "Attestation pool processing" & preset(): # Add back the old block to ensure we have a duplicate error let b10_clone = b10 # Assumes deep copy let b10Add_clone = dag.addRawBlock(quarantine, b10_clone) do ( - blckRef: BlockRef, signedBlock: TrustedSignedBeaconBlock, + blckRef: BlockRef, signedBlock: phase0.TrustedSignedBeaconBlock, epochRef: EpochRef): # Callback add to fork choice if valid pool[].addForkChoice(epochRef, blckRef, signedBlock.message, blckRef.slot) @@ -497,7 +497,7 @@ suite "Attestation pool processing" & preset(): let b10 = addTestBlock(state.data, dag.tail.root, cache) b10Add = dag.addRawBlock(quarantine, b10) do ( - blckRef: BlockRef, signedBlock: TrustedSignedBeaconBlock, + blckRef: BlockRef, signedBlock: phase0.TrustedSignedBeaconBlock, epochRef: EpochRef): # Callback add to fork choice if valid pool[].addForkChoice(epochRef, blckRef, signedBlock.message, blckRef.slot) @@ -525,7 +525,7 @@ suite "Attestation pool processing" & preset(): block_root = new_block.root let blockRef = dag.addRawBlock(quarantine, new_block) do ( - blckRef: BlockRef, signedBlock: TrustedSignedBeaconBlock, + blckRef: BlockRef, signedBlock: phase0.TrustedSignedBeaconBlock, epochRef: EpochRef): # Callback add to fork choice if valid pool[].addForkChoice(epochRef, blckRef, signedBlock.message, blckRef.slot) @@ -567,7 +567,7 @@ suite "Attestation pool processing" & preset(): # Add back the old block to ensure we have a duplicate error let b10Add_clone = dag.addRawBlock(quarantine, b10_clone) do ( - blckRef: BlockRef, signedBlock: TrustedSignedBeaconBlock, + blckRef: BlockRef, signedBlock: phase0.TrustedSignedBeaconBlock, epochRef: EpochRef): # Callback add to fork choice if valid pool[].addForkChoice(epochRef, blckRef, signedBlock.message, blckRef.slot) diff --git a/tests/test_beacon_chain_db.nim b/tests/test_beacon_chain_db.nim index 92b02ec3f..15f6fccb8 100644 --- a/tests/test_beacon_chain_db.nim +++ b/tests/test_beacon_chain_db.nim @@ -10,10 +10,8 @@ import std/[algorithm, options, sequtils], unittest2, - ../beacon_chain/[beacon_chain_db, extras, interop, ssz], - ../beacon_chain/spec/[ - beaconstate, crypto, digest, forks, presets, - state_transition], + ../beacon_chain/[beacon_chain_db, interop, ssz], + ../beacon_chain/spec/[beaconstate, forks, state_transition], ../beacon_chain/spec/datatypes/[phase0, altair], ../beacon_chain/consensus_object_pools/blockchain_dag, eth/db/kvstore, diff --git a/tests/test_beaconstate.nim b/tests/test_beaconstate.nim index 375cbaaab..6caacb5bf 100644 --- a/tests/test_beaconstate.nim +++ b/tests/test_beaconstate.nim @@ -9,7 +9,8 @@ import unittest2, - ../beacon_chain/spec/[beaconstate, datatypes, digest, presets], + ../beacon_chain/spec/datatypes/base, + ../beacon_chain/spec/beaconstate, ./testutil, ./testblockutil suite "Beacon state" & preset(): diff --git a/tests/test_block_pool.nim b/tests/test_block_pool.nim index 110ec56d9..4b2d5bf07 100644 --- a/tests/test_block_pool.nim +++ b/tests/test_block_pool.nim @@ -14,11 +14,9 @@ import stew/assign2, eth/keys, ../beacon_chain/spec/datatypes/base, - ../beacon_chain/spec/[ - beaconstate, digest, forks, helpers, state_transition, - presets], + ../beacon_chain/spec/[beaconstate, forks, helpers, state_transition], ../beacon_chain/beacon_node_types, - ../beacon_chain/[beacon_chain_db, ssz, extras], + ../beacon_chain/[beacon_chain_db, ssz], ../beacon_chain/consensus_object_pools/[ blockchain_dag, block_quarantine, block_clearance], ./testutil, ./testdbutil, ./testblockutil diff --git a/tests/test_exit_pool.nim b/tests/test_exit_pool.nim index 1f9f45fa9..939a98edf 100644 --- a/tests/test_exit_pool.nim +++ b/tests/test_exit_pool.nim @@ -7,9 +7,9 @@ {.used.} -import chronicles, chronos +import chronicles import eth/keys -import ../beacon_chain/spec/[datatypes, presets] +import ../beacon_chain/spec/datatypes/base import ../beacon_chain/consensus_object_pools/[block_quarantine, blockchain_dag, exit_pool] import "."/[testutil, testdbutil] diff --git a/tests/test_gossip_validation.nim b/tests/test_gossip_validation.nim index 149da7ca5..d9bd850d3 100644 --- a/tests/test_gossip_validation.nim +++ b/tests/test_gossip_validation.nim @@ -10,17 +10,17 @@ import # Status lib unittest2, - chronicles, chronos, + chronicles, eth/keys, # Internal - ../beacon_chain/[beacon_node_types, extras, beacon_clock], + ../beacon_chain/[beacon_node_types, beacon_clock], ../beacon_chain/gossip_processing/[gossip_validation, batch_validation], ../beacon_chain/fork_choice/[fork_choice_types, fork_choice], ../beacon_chain/consensus_object_pools/[ block_quarantine, blockchain_dag, block_clearance, attestation_pool], ../beacon_chain/ssz/merkleization, - ../beacon_chain/spec/[crypto, datatypes, digest, forks, - state_transition, helpers, presets, network], + ../beacon_chain/spec/datatypes/phase0, + ../beacon_chain/spec/[forks, state_transition, helpers, network], # Test utilities ./testutil, ./testdbutil, ./testblockutil @@ -56,7 +56,7 @@ suite "Gossip validation " & preset(): dag.headState.data, dag.head.root, cache, int(SLOTS_PER_EPOCH * 5), false): let added = dag.addRawBlock(quarantine, blck) do ( - blckRef: BlockRef, signedBlock: TrustedSignedBeaconBlock, + blckRef: BlockRef, signedBlock: phase0.TrustedSignedBeaconBlock, epochRef: EpochRef): # Callback add to fork choice if valid pool[].addForkChoice(epochRef, blckRef, signedBlock.message, blckRef.slot) diff --git a/tests/test_honest_validator.nim b/tests/test_honest_validator.nim index f756d6fa2..767286892 100644 --- a/tests/test_honest_validator.nim +++ b/tests/test_honest_validator.nim @@ -3,7 +3,7 @@ import unittest2, ./testutil, - ../beacon_chain/spec/[crypto, network], + ../beacon_chain/spec/network, ../beacon_chain/spec/datatypes/base, ../beacon_chain/validators/attestation_aggregation diff --git a/tests/test_interop.nim b/tests/test_interop.nim index 544f92b41..4162a179c 100644 --- a/tests/test_interop.nim +++ b/tests/test_interop.nim @@ -4,7 +4,7 @@ import stint, ./testutil, stew/byteutils, ../beacon_chain/interop, ../beacon_chain/ssz, - ../beacon_chain/spec/[beaconstate, crypto, presets], + ../beacon_chain/spec/[beaconstate], ../beacon_chain/spec/datatypes/base # Interop test yaml, found here: diff --git a/tests/test_ssz.nim b/tests/test_ssz.nim index b322ba7b9..226b03f9f 100644 --- a/tests/test_ssz.nim +++ b/tests/test_ssz.nim @@ -12,9 +12,9 @@ import unittest2, nimcrypto/hash, json_serialization, - ../beacon_chain/spec/digest, ../beacon_chain/spec/datatypes/base, - ../beacon_chain/ssz, ../beacon_chain/ssz/[navigator, dynamic_navigator] + ../beacon_chain/ssz, + ../beacon_chain/ssz/[navigator, dynamic_navigator] type SomeEnum = enum diff --git a/tests/test_ssz_merkleization.nim b/tests/test_ssz_merkleization.nim index 6fdd2ffa1..c7292d250 100644 --- a/tests/test_ssz_merkleization.nim +++ b/tests/test_ssz_merkleization.nim @@ -1,7 +1,8 @@ import std/[strutils, sequtils, macros, bitops], stew/[bitops2, endians2], - ../beacon_chain/spec/[beaconstate, datatypes, digest, helpers], + ../beacon_chain/spec/datatypes/phase0, + ../beacon_chain/spec/[beaconstate, helpers], ../beacon_chain/eth1/merkle_minimal, ../beacon_chain/ssz, mocking/mock_deposits diff --git a/tests/test_statediff.nim b/tests/test_statediff.nim index d126c0234..7f1b2398b 100644 --- a/tests/test_statediff.nim +++ b/tests/test_statediff.nim @@ -11,8 +11,8 @@ import options, sequtils, unittest2, ./testutil, ./testdbutil, ./teststateutil, - ../beacon_chain/spec/[ - datatypes, digest, forks, helpers, presets], + ../beacon_chain/spec/datatypes/phase0, + ../beacon_chain/spec/[forks, helpers], ../beacon_chain/[beacon_node_types, statediff], ../beacon_chain/ssz, ../beacon_chain/consensus_object_pools/[blockchain_dag, block_quarantine] diff --git a/tests/testblockutil.nim b/tests/testblockutil.nim index d43e86e9e..68e4d4a1d 100644 --- a/tests/testblockutil.nim +++ b/tests/testblockutil.nim @@ -8,11 +8,11 @@ import chronicles, options, stew/endians2, - ../beacon_chain/[beacon_node_types, extras], + ../beacon_chain/[beacon_node_types], ../beacon_chain/validators/validator_pool, ../beacon_chain/ssz/merkleization, - ../beacon_chain/spec/[crypto, datatypes, digest, presets, helpers, - signatures, state_transition, forks], + ../beacon_chain/spec/datatypes/[phase0, altair, merge], + ../beacon_chain/spec/[helpers, signatures, state_transition, forks], ../beacon_chain/consensus_object_pools/attestation_pool func makeFakeValidatorPrivKey(i: int): ValidatorPrivKey = @@ -61,10 +61,10 @@ func makeInitialDeposits*( result.add makeDeposit(i, flags) func signBlock( - fork: Fork, genesis_validators_root: Eth2Digest, blck: BeaconBlock, - privKey: ValidatorPrivKey, flags: UpdateFlags = {}): SignedBeaconBlock = + fork: Fork, genesis_validators_root: Eth2Digest, blck: phase0.BeaconBlock, + privKey: ValidatorPrivKey, flags: UpdateFlags = {}): phase0.SignedBeaconBlock = let root = hash_tree_root(blck) - SignedBeaconBlock( + phase0.SignedBeaconBlock( message: blck, root: root, signature: @@ -84,7 +84,7 @@ proc addTestBlock*( deposits = newSeq[Deposit](), graffiti = default(GraffitiBytes), flags: set[UpdateFlag] = {}, - nextSlot = true): SignedBeaconBlock = + nextSlot = true): phase0.SignedBeaconBlock = # Create and add a block to state - state will advance by one slot! if nextSlot: var rewards: RewardInfo @@ -144,7 +144,7 @@ proc makeTestBlock*( eth1_data = Eth1Data(), attestations = newSeq[Attestation](), deposits = newSeq[Deposit](), - graffiti = default(GraffitiBytes)): SignedBeaconBlock = + graffiti = default(GraffitiBytes)): phase0.SignedBeaconBlock = # Create a block for `state.slot + 1` - like a block proposer would do! # It's a bit awkward - in order to produce a block for N+1, we need to # calculate what the state will look like after that block has been applied, @@ -286,7 +286,7 @@ func makeFullAttestations*( result.add attestation func makeFullAttestations*( - state: HashedBeaconState, beacon_block_root: Eth2Digest, slot: Slot, + state: phase0.HashedBeaconState, beacon_block_root: Eth2Digest, slot: Slot, cache: var StateCache, flags: UpdateFlags = {}): seq[Attestation] = # TODO this only supports phase 0 currently. Either expand that to @@ -297,11 +297,11 @@ func makeFullAttestations*( beacon_block_root, slot, cache, flags) iterator makeTestBlocks*( - state: HashedBeaconState, + state: phase0.HashedBeaconState, parent_root: Eth2Digest, cache: var StateCache, blocks: int, - attested: bool): SignedBeaconBlock = + attested: bool): phase0.SignedBeaconBlock = var # TODO replace wrapper with more native usage state = (ref ForkedHashedBeaconState)( @@ -319,7 +319,7 @@ iterator makeTestBlocks*( parent_root = blck.root iterator makeTestBlocks*(state: ForkedHashedBeaconState; parent_root: Eth2Digest; - cache: var StateCache; blocks: int; attested: bool): SignedBeaconBlock = + cache: var StateCache; blocks: int; attested: bool): phase0.SignedBeaconBlock = for blck in makeTestBlocks(state.hbsPhase0, parent_root, cache, blocks, attested): yield blck diff --git a/tests/testdbutil.nim b/tests/testdbutil.nim index f49145d33..fb1eac622 100644 --- a/tests/testdbutil.nim +++ b/tests/testdbutil.nim @@ -7,15 +7,16 @@ import chronicles, - ../beacon_chain/[beacon_chain_db, extras], + ../beacon_chain/[beacon_chain_db], ../beacon_chain/consensus_object_pools/blockchain_dag, - ../beacon_chain/spec/[beaconstate, digest], + ../beacon_chain/spec/datatypes/phase0, + ../beacon_chain/spec/[beaconstate], eth/db/[kvstore, kvstore_sqlite3], ./testblockutil export beacon_chain_db, testblockutil, kvstore, kvstore_sqlite3 -proc makeTestDB*(tailState: var BeaconState, tailBlock: TrustedSignedBeaconBlock): BeaconChainDB = +proc makeTestDB*(tailState: var phase0.BeaconState, tailBlock: phase0.TrustedSignedBeaconBlock): BeaconChainDB = result = BeaconChainDB.new("", inMemory = true) ChainDAGRef.preInit(result, tailState, tailState, tailBlock) diff --git a/tests/teststateutil.nim b/tests/teststateutil.nim index 9baf0657d..a2233879d 100644 --- a/tests/teststateutil.nim +++ b/tests/teststateutil.nim @@ -13,8 +13,7 @@ import ./helpers/math_helpers, ../beacon_chain/ssz/merkleization, ../beacon_chain/spec/[ - crypto, datatypes, forks, helpers, - presets, state_transition, state_transition_block] + forks, helpers, state_transition, state_transition_block] proc valid_deposit[T](state: var T) = const deposit_amount = MAX_EFFECTIVE_BALANCE