rework spec imports (#2779)

The spec imports are a mess to work with, so this branch cleans them up
a bit to ensure that we avoid generic sandwitches and that importing
stuff generally becomes easier.

* reexport crypto/digest/presets because these are part of the public
symbol set of the rest of the spec types
* don't export `merge` types from `base` - this causes circular deps
* fix circular deps in `ssz/spec_types` - this is the first step in
disentangling ssz from spec
* be explicit about phase0 vs altair - longer term, `altair` will become
the "natural" type set, then merge and so on, so no point in giving
`phase0` special preferential treatment
This commit is contained in:
Jacek Sieka 2021-08-12 15:08:20 +02:00 committed by GitHub
parent 01f78fb93e
commit 7a622e8505
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
147 changed files with 405 additions and 408 deletions

View File

@ -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"

View File

@ -11,7 +11,6 @@ import
stew/[assign2, objects, results],
serialization,
eth/db/kvstore,
./spec/[crypto, digest],
./spec/datatypes/[base, altair],
./ssz/[ssz_serialization, merkleization]

View File

@ -9,7 +9,7 @@
import
chronos, chronicles,
./spec/[datatypes, helpers]
./spec/helpers
from times import Time, getTime, fromUnix, `<`, `-`, inNanoseconds

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -12,7 +12,6 @@ import
chronicles,
stew/bitops2,
eth/keys,
../spec/[crypto, digest],
../spec/datatypes/[phase0, altair],
./block_pools_types

View File

@ -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"

View File

@ -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

View File

@ -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 =

View File

@ -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

View File

@ -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,

View File

@ -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,

View File

@ -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

View File

@ -15,7 +15,6 @@ import
stew/results,
# Internal
../spec/datatypes/base,
../spec/digest,
# Fork choice
./fork_choice_types

View File

@ -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,

View File

@ -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],

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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 =

View File

@ -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

View File

@ -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[]

View File

@ -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],

View File

@ -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

View File

@ -9,7 +9,7 @@
import
# Standard library
os, strutils, tables,
std/[os, strutils, tables],
# Local modules
./spec/[digest, crypto],

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -3,7 +3,6 @@ import
presto,
chronicles,
../version, ../beacon_node_common,
../spec/[datatypes, digest, presets],
./rest_utils
logScope: topics = "rest_debug"

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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,

View File

@ -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],

View File

@ -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
# ----------------------------------------------------------------------

View File

@ -1,3 +0,0 @@
# compatibility wrapper
import datatypes/phase0
export phase0

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)))

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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]]

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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 =

View File

@ -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

View File

@ -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"

View File

@ -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:

View File

@ -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() &

View File

@ -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

View File

@ -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,

View File

@ -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
# --------------------------------------------------------

View File

@ -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)

View File

@ -8,7 +8,7 @@
{.push raises: [Defect].}
import
./datatypes/base, ./digest, ./forks, ./helpers
./datatypes/base, ./forks, ./helpers
const
SAFETY_DECAY* = 10'u64

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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]) =

View File

@ -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:

View File

@ -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:

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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,

View File

@ -16,7 +16,6 @@ import
chronicles, chronicles/timings,
# Internal
../spec/datatypes/base,
../spec/[digest, crypto],
./slashing_protection_common,
./slashing_protection_v1,
./slashing_protection_v2

View File

@ -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

View File

@ -18,7 +18,6 @@ import
json_serialization,
# Internal
../spec/datatypes/base,
../spec/[digest, crypto],
../ssz,
./slashing_protection_common

View File

@ -16,7 +16,8 @@ import
chronicles,
sqlite3_abi,
# Internal
../spec/[datatypes, digest, crypto, helpers],
../spec/datatypes/base,
../spec/helpers,
../ssz,
./slashing_protection_common

View File

@ -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,

View File

@ -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

View File

@ -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,

View File

@ -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()

View File

@ -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)

View File

@ -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()

View File

@ -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()

View File

@ -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,

View File

@ -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

View File

@ -1,4 +1,4 @@
import ../beacon_chain/spec/datatypes
import ../beacon_chain/spec/datatypes/phase0
import typetraits, strformat, strutils

View File

@ -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) =

View File

@ -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

View File

@ -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:

View File

@ -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.`==`
# ---------------------------------------------------------------------

View File

@ -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)

View File

@ -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)

Some files were not shown because too many files have changed in this diff Show More