Introduce constant presets (#269)

* Initial move constants to mainnet preset

* Bump fixtures to include shuffling with minimal preset

* Add minimal preset with shuffling test

* Add minimal preset to the full test suite

* use preset() everywhere
This commit is contained in:
Mamy Ratsimbazafy 2019-05-27 14:48:13 +02:00 committed by GitHub
parent 46cfce652d
commit 6b1f0e816c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 375 additions and 164 deletions

View File

@ -44,4 +44,7 @@ proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") =
### tasks ### tasks
task test, "Run all tests": task test, "Run all tests":
# Mainnet config
buildBinary "all_tests", "tests/", "-r -d:release -d:chronicles_log_level=ERROR" buildBinary "all_tests", "tests/", "-r -d:release -d:chronicles_log_level=ERROR"
# Minimal config
buildBinary "all_tests", "tests/", "-r -d:release -d:chronicles_log_level=ERROR -d:const_preset=minimal"

View File

@ -38,12 +38,19 @@ import
# Eventually, we could also differentiate between user/tainted data and # Eventually, we could also differentiate between user/tainted data and
# internal state that's gone through sanity checks already. # internal state that's gone through sanity checks already.
# TODO Many of these constants should go into a config object that can be used
# to run.. well.. a chain with different constants!
type # Constant presets
Slot* = distinct uint64 # https://github.com/ethereum/eth2.0-specs/blob/v0.6.1/configs/constant_presets/
Epoch* = distinct uint64 const const_preset*{.strdefine.} = "mainnet"
when const_preset == "mainnet":
import ./presets/mainnet
export mainnet
elif const_preset == "minimal":
import ./presets/minimal
export minimal
else:
{.fatal: "Preset \"" & const_preset ".nim\" is not supported.".}
const const
SPEC_VERSION* = "0.5.1" ## \ SPEC_VERSION* = "0.5.1" ## \
@ -51,142 +58,27 @@ const
## TODO: improve this scheme once we can negotiate versions in protocol ## TODO: improve this scheme once we can negotiate versions in protocol
# Misc # Misc
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#misc # https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#misc
SHARD_COUNT* {.intdefine.} = 1024 ##\
## Number of shards supported by the network - validators will jump around
## between these shards and provide attestations to their state.
## Compile with -d:SHARD_COUNT=4 for fewer shard (= better with low validator counts)
TARGET_COMMITTEE_SIZE* = 2^7 ##\
## Number of validators in the committee attesting to one shard
## Per spec:
## For the safety of crosslinks `TARGET_COMMITTEE_SIZE` exceeds
## [the recommended minimum committee size of 111](https://vitalik.ca/files/Ithaca201807_Sharding.pdf);
## with sufficient active validators (at least
## `SLOTS_PER_EPOCH * TARGET_COMMITTEE_SIZE`), the shuffling algorithm ensures
## committee sizes at least `TARGET_COMMITTEE_SIZE`. (Unbiasable randomness
## with a Verifiable Delay Function (VDF) will improve committee robustness
## and lower the safe minimum committee size.)
# TODO remove, not in post-0.5.1 # TODO remove, not in post-0.5.1
MAX_BALANCE_CHURN_QUOTIENT* = 2^5 ##\ MAX_BALANCE_CHURN_QUOTIENT* = 2^5 ##\
MAX_INDICES_PER_ATTESTATION* = 2^12 ##\
## votes
MIN_PER_EPOCH_CHURN_LIMIT* = 4
CHURN_LIMIT_QUOTIENT* = 2^16
BASE_REWARDS_PER_EPOCH* = 5
SHUFFLE_ROUND_COUNT* = 90
# Deposit contract
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.0/specs/core/0_beacon-chain.md#deposit-contract
DEPOSIT_CONTRACT_TREE_DEPTH* = 32
# Gwei values # Gwei values
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#gwei-values # https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#gwei-values
MIN_DEPOSIT_AMOUNT* = 2'u64^0 * 10'u64^9 ##\
## Minimum amounth of ETH that can be deposited in one call - deposits can
## be used either to top up an existing validator or commit to a new one
MAX_EFFECTIVE_BALANCE* = 2'u64^5 * 10'u64^9 ##\
## Maximum amounth of ETH that can be deposited in one call
# TODO remove erstwhile blob/v0.5.0 # TODO remove erstwhile blob/v0.5.0
FORK_CHOICE_BALANCE_INCREMENT* = 2'u64^0 * 10'u64^9 FORK_CHOICE_BALANCE_INCREMENT* = 2'u64^0 * 10'u64^9
EJECTION_BALANCE* = 2'u64^4 * 10'u64^9 ##\ # Initial values
## Once the balance of a validator drops below this, it will be ejected from # ---------------------------------------------------------------
## the validator pool
EFFECTIVE_BALANCE_INCREMENT* = 2'u64^0 * 10'u64^9
# Time parameter, here so that GENESIS_EPOCH can access it
# TODO re-merge
SLOTS_PER_EPOCH* {.intdefine.} = 64 ##\
## (~6.4 minutes)
## slots that make up an epoch, at the end of which more heavy
## processing is done
## Compile with -d:SLOTS_PER_EPOCH=4 for shorter epochs
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#initial-values # https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#initial-values
# TODO: in 0.5.0, GENESIS_FORK_VERSION defined as int, but used as [byte]
GENESIS_FORK_VERSION* = [0'u8, 0'u8, 0'u8, 0'u8]
GENESIS_SLOT* = (2'u64^32).Slot
GENESIS_EPOCH* = (GENESIS_SLOT.uint64 div SLOTS_PER_EPOCH).Epoch ##\ GENESIS_EPOCH* = (GENESIS_SLOT.uint64 div SLOTS_PER_EPOCH).Epoch ##\
## slot_to_epoch(GENESIS_SLOT) ## slot_to_epoch(GENESIS_SLOT)
GENESIS_START_SHARD* = 0'u64 GENESIS_START_SHARD* = 0'u64
FAR_FUTURE_EPOCH* = (not 0'u64).Epoch # 2^64 - 1 in spec
ZERO_HASH* = Eth2Digest() ZERO_HASH* = Eth2Digest()
EMPTY_SIGNATURE* = ValidatorSig() EMPTY_SIGNATURE* = ValidatorSig()
BLS_WITHDRAWAL_PREFIX_BYTE* = 0'u8
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.1/specs/core/0_fork-choice.md#time-parameters
SECONDS_PER_SLOT*{.intdefine.} = 6'u64 # Compile with -d:SECONDS_PER_SLOT=1 for 6x faster slots
## TODO consistent time unit across projects, similar to C++ chrono?
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.1/specs/core/0_beacon-chain.md#time-parameters
MIN_ATTESTATION_INCLUSION_DELAY* = 2'u64^2 ##\
## (24 seconds)
## Number of slots that attestations stay in the attestation
## pool before being added to a block.
## The attestation delay exists so that there is time for attestations to
## propagate before the block is created.
## When creating an attestation, the validator will look at the best
## information known to at that time, and may not revise it during the same
## slot (see `is_double_vote`) - the delay gives the validator a chance to
## wait towards the end of the slot and still have time to publish the
## attestation.
# SLOTS_PER_EPOCH is defined above.
# TODO it doesn't need to be anymore
MIN_SEED_LOOKAHEAD* = 1 ##\
## epochs (~6.4 minutes)
ACTIVATION_EXIT_DELAY* = 4 ##\
## epochs (~25.6 minutes)
SLOTS_PER_ETH1_VOTING_PERIOD* = 1024 ##\
## slots (~1.7 hours)
SLOTS_PER_HISTORICAL_ROOT* = 8192 ##\
## slots (13 hours)
MIN_VALIDATOR_WITHDRAWABILITY_DELAY* = 2'u64^8 ##\
## epochs (~27 hours)
PERSISTENT_COMMITTEE_PERIOD* = 2'u64^11 ##\
## epochs (9 days)
MAX_CROSSLINK_EPOCHS* = 2'u64^6 ##\
## epochs (~7 hours)
MIN_EPOCHS_TO_INACTIVITY_PENALTY* = 2'u64^2 ##\
## epochs (25.6 minutes)
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.0/specs/core/0_beacon-chain.md#state-list-lengths
LATEST_RANDAO_MIXES_LENGTH* = 8192
LATEST_ACTIVE_INDEX_ROOTS_LENGTH* = 8192 # 2'u64^13, epochs
LATEST_SLASHED_EXIT_LENGTH* = 8192 # epochs
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.0/specs/core/0_beacon-chain.md#reward-and-penalty-quotients
BASE_REWARD_QUOTIENT* = 2'u64^5
WHISTLEBLOWER_REWARD_QUOTIENT* = 2'u64^9
PROPOSER_REWARD_QUOTIENT* = 2'u64^3
INACTIVITY_PENALTY_QUOTIENT* = 2'u64^25
MIN_PENALTY_QUOTIENT* = 32 # 2^5
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.0/specs/core/0_beacon-chain.md#max-operations-per-block
MAX_PROPOSER_SLASHINGS* = 2^4
MAX_ATTESTER_SLASHINGS* = 2^0
MAX_ATTESTATIONS* = 2^7
MAX_DEPOSITS* = 2^4
MAX_VOLUNTARY_EXITS* = 2^4
MAX_TRANSFERS* = 0
type type
ValidatorIndex* = range[0'u32 .. 0xFFFFFF'u32] # TODO: wrap-around ValidatorIndex* = range[0'u32 .. 0xFFFFFF'u32] # TODO: wrap-around
@ -512,15 +404,6 @@ type
Activation = 0 Activation = 0
Exit = 1 Exit = 1
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.0/specs/core/0_beacon-chain.md#signature-domains
SignatureDomain* {.pure.} = enum
DOMAIN_BEACON_PROPOSER = 0
DOMAIN_RANDAO = 1
DOMAIN_ATTESTATION = 2
DOMAIN_DEPOSIT = 3
DOMAIN_VOLUNTARY_EXIT = 4
DOMAIN_TRANSFER = 5
# TODO: not in spec # TODO: not in spec
CrosslinkCommittee* = tuple[committee: seq[ValidatorIndex], shard: uint64] CrosslinkCommittee* = tuple[committee: seq[ValidatorIndex], shard: uint64]
@ -629,4 +512,3 @@ chronicles.formatIt AttestationData: it.shortLog
import nimcrypto, json_serialization import nimcrypto, json_serialization
export json_serialization export json_serialization
export writeValue, readValue, append, read export writeValue, readValue, append, read

View File

@ -0,0 +1,178 @@
# beacon_chain
# Copyright (c) 2018-2019 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
# This file contains constants that are part of the spec and thus subject to
# serialization and spec updates.
import
# Standard library
math,
# Third-party
eth/common,
# Internals
../crypto, ../digest
type
Slot* = distinct uint64
Epoch* = distinct uint64
{.experimental: "codeReordering".} # SLOTS_PER_EPOCH is use before being defined in spec
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.1/configs/constant_presets/mainnet.yaml
const
# Misc
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#misc
SHARD_COUNT* {.intdefine.} = 1024 ##\
## Number of shards supported by the network - validators will jump around
## between these shards and provide attestations to their state.
## Compile with -d:SHARD_COUNT=4 for fewer shard (= better with low validator counts)
TARGET_COMMITTEE_SIZE* = 2^7 ##\
## Number of validators in the committee attesting to one shard
## Per spec:
## For the safety of crosslinks `TARGET_COMMITTEE_SIZE` exceeds
## [the recommended minimum committee size of 111](https://vitalik.ca/files/Ithaca201807_Sharding.pdf);
## with sufficient active validators (at least
## `SLOTS_PER_EPOCH * TARGET_COMMITTEE_SIZE`), the shuffling algorithm ensures
## committee sizes at least `TARGET_COMMITTEE_SIZE`. (Unbiasable randomness
## with a Verifiable Delay Function (VDF) will improve committee robustness
## and lower the safe minimum committee size.)
MAX_INDICES_PER_ATTESTATION* = 2^12 ##\
## votes
MIN_PER_EPOCH_CHURN_LIMIT* = 4
CHURN_LIMIT_QUOTIENT* = 2^16
BASE_REWARDS_PER_EPOCH* = 5
SHUFFLE_ROUND_COUNT* = 90
# Deposit contract
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.0/specs/core/0_beacon-chain.md#deposit-contract
DEPOSIT_CONTRACT_ADDRESS = "0x1234567890123456789012345678901234567890"
# TODO
DEPOSIT_CONTRACT_TREE_DEPTH* = 32
# Gwei values
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#gwei-values
MIN_DEPOSIT_AMOUNT* = 2'u64^0 * 10'u64^9 ##\
## Minimum amounth of ETH that can be deposited in one call - deposits can
## be used either to top up an existing validator or commit to a new one
MAX_EFFECTIVE_BALANCE* = 2'u64^5 * 10'u64^9 ##\
## Maximum amounth of ETH that can be deposited in one call
EJECTION_BALANCE* = 2'u64^4 * 10'u64^9 ##\
## Once the balance of a validator drops below this, it will be ejected from
## the validator pool
EFFECTIVE_BALANCE_INCREMENT* = 2'u64^0 * 10'u64^9
# Initial values
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#initial-values
GENESIS_FORK_VERSION* = [0'u8, 0'u8, 0'u8, 0'u8]
GENESIS_SLOT* = (2'u64^32).Slot
FAR_FUTURE_EPOCH* = (not 0'u64).Epoch # 2^64 - 1 in spec
BLS_WITHDRAWAL_PREFIX_BYTE* = 0'u8
# Time parameters
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.1/specs/core/0_fork-choice.md#time-parameters
SECONDS_PER_SLOT*{.intdefine.} = 6'u64 # Compile with -d:SECONDS_PER_SLOT=1 for 6x faster slots
## TODO consistent time unit across projects, similar to C++ chrono?
MIN_ATTESTATION_INCLUSION_DELAY* = 2'u64^2 ##\
## (24 seconds)
## Number of slots that attestations stay in the attestation
## pool before being added to a block.
## The attestation delay exists so that there is time for attestations to
## propagate before the block is created.
## When creating an attestation, the validator will look at the best
## information known to at that time, and may not revise it during the same
## slot (see `is_double_vote`) - the delay gives the validator a chance to
## wait towards the end of the slot and still have time to publish the
## attestation.
SLOTS_PER_EPOCH* {.intdefine.} = 64 ##\
## (~6.4 minutes)
## slots that make up an epoch, at the end of which more heavy
## processing is done
## Compile with -d:SLOTS_PER_EPOCH=4 for shorter epochs
MIN_SEED_LOOKAHEAD* = 1 ##\
## epochs (~6.4 minutes)
ACTIVATION_EXIT_DELAY* = 4 ##\
## epochs (~25.6 minutes)
SLOTS_PER_ETH1_VOTING_PERIOD* = 1024 ##\
## slots (~1.7 hours)
SLOTS_PER_HISTORICAL_ROOT* = 8192 ##\
## slots (13 hours)
MIN_VALIDATOR_WITHDRAWABILITY_DELAY* = 2'u64^8 ##\
## epochs (~27 hours)
PERSISTENT_COMMITTEE_PERIOD* = 2'u64^11 ##\
## epochs (9 days)
MAX_CROSSLINK_EPOCHS* = 2'u64^6 ##\
## epochs (~7 hours)
MIN_EPOCHS_TO_INACTIVITY_PENALTY* = 2'u64^2 ##\
## epochs (25.6 minutes)
# State list lengths
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.0/specs/core/0_beacon-chain.md#state-list-lengths
LATEST_RANDAO_MIXES_LENGTH* = 8192
LATEST_ACTIVE_INDEX_ROOTS_LENGTH* = 8192 # 2'u64^13, epochs
LATEST_SLASHED_EXIT_LENGTH* = 8192 # epochs
# Reward and penalty quotients
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.0/specs/core/0_beacon-chain.md#reward-and-penalty-quotients
BASE_REWARD_QUOTIENT* = 2'u64^5
WHISTLEBLOWER_REWARD_QUOTIENT* = 2'u64^9
PROPOSER_REWARD_QUOTIENT* = 2'u64^3
INACTIVITY_PENALTY_QUOTIENT* = 2'u64^25
MIN_PENALTY_QUOTIENT* = 32 # 2^5
# Max operations per block
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.0/specs/core/0_beacon-chain.md#max-operations-per-block
MAX_PROPOSER_SLASHINGS* = 2^4
MAX_ATTESTER_SLASHINGS* = 2^0
MAX_ATTESTATIONS* = 2^7
MAX_DEPOSITS* = 2^4
MAX_VOLUNTARY_EXITS* = 2^4
MAX_TRANSFERS* = 0
type
# Signature domains
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.0/specs/core/0_beacon-chain.md#signature-domains
SignatureDomain* {.pure.} = enum
DOMAIN_BEACON_PROPOSER = 0
DOMAIN_RANDAO = 1
DOMAIN_ATTESTATION = 2
DOMAIN_DEPOSIT = 3
DOMAIN_VOLUNTARY_EXIT = 4
DOMAIN_TRANSFER = 5

View File

@ -0,0 +1,139 @@
# beacon_chain
# Copyright (c) 2018-2019 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
# This file contains constants that are part of the spec and thus subject to
# serialization and spec updates.
import
# Standard library
math,
# Third-party
eth/common,
# Internals
../crypto, ../digest
type
Slot* = distinct uint64
Epoch* = distinct uint64
{.experimental: "codeReordering".} # SLOTS_PER_EPOCH is use before being defined in spec
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.1/configs/constant_presets/minimal.yaml
const
# Misc
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#misc
# Changed
SHARD_COUNT* {.intdefine.} = 8
TARGET_COMMITTEE_SIZE* = 4
# Unchanged
MAX_INDICES_PER_ATTESTATION* = 4096
MIN_PER_EPOCH_CHURN_LIMIT* = 4
CHURN_LIMIT_QUOTIENT* = 2^16
BASE_REWARDS_PER_EPOCH* = 5
# Changed
SHUFFLE_ROUND_COUNT* = 10
# Deposit contract
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.0/specs/core/0_beacon-chain.md#deposit-contract
# Unchanged
DEPOSIT_CONTRACT_ADDRESS = "0x1234567890123456789012345678901234567890"
DEPOSIT_CONTRACT_TREE_DEPTH* = 32
# Gwei values
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#gwei-values
# Unchanged
MIN_DEPOSIT_AMOUNT* = 2'u64^0 * 10'u64^9
MAX_EFFECTIVE_BALANCE* = 2'u64^5 * 10'u64^9
EJECTION_BALANCE* = 2'u64^4 * 10'u64^9
EFFECTIVE_BALANCE_INCREMENT* = 2'u64^0 * 10'u64^9
# Initial values
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#initial-values
# Unchanged
GENESIS_FORK_VERSION* = [0'u8, 0'u8, 0'u8, 0'u8]
GENESIS_SLOT* = (2'u64^32).Slot
FAR_FUTURE_EPOCH* = (not 0'u64).Epoch # 2^64 - 1 in spec
BLS_WITHDRAWAL_PREFIX_BYTE* = 0'u8
# Time parameters
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.1/specs/core/0_fork-choice.md#time-parameters
# Unchanged
SECONDS_PER_SLOT*{.intdefine.} = 6'u64
MIN_ATTESTATION_INCLUSION_DELAY* = 2'u64^2
# Changed
SLOTS_PER_EPOCH* {.intdefine.} = 64
# Unchanged
MIN_SEED_LOOKAHEAD* = 1
ACTIVATION_EXIT_DELAY* = 4
# Changed
SLOTS_PER_ETH1_VOTING_PERIOD* = 16
SLOTS_PER_HISTORICAL_ROOT* = 64
# Unchanged
MIN_VALIDATOR_WITHDRAWABILITY_DELAY* = 2'u64^8
PERSISTENT_COMMITTEE_PERIOD* = 2'u64^11
MAX_CROSSLINK_EPOCHS* = 2'u64^6
MIN_EPOCHS_TO_INACTIVITY_PENALTY* = 2'u64^2
# State list lengths
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.0/specs/core/0_beacon-chain.md#state-list-lengths
# Changed
LATEST_RANDAO_MIXES_LENGTH* = 64
LATEST_ACTIVE_INDEX_ROOTS_LENGTH* = 64
LATEST_SLASHED_EXIT_LENGTH* = 64
# Reward and penalty quotients
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.0/specs/core/0_beacon-chain.md#reward-and-penalty-quotients
# Unchanged
BASE_REWARD_QUOTIENT* = 2'u64^5
WHISTLEBLOWER_REWARD_QUOTIENT* = 2'u64^9
PROPOSER_REWARD_QUOTIENT* = 2'u64^3
INACTIVITY_PENALTY_QUOTIENT* = 2'u64^25
MIN_PENALTY_QUOTIENT* = 32 # 2^5
# Max operations per block
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.0/specs/core/0_beacon-chain.md#max-operations-per-block
# Unchanged
MAX_PROPOSER_SLASHINGS* = 2^4
MAX_ATTESTER_SLASHINGS* = 2^0
MAX_ATTESTATIONS* = 2^7
MAX_DEPOSITS* = 2^4
MAX_VOLUNTARY_EXITS* = 2^4
MAX_TRANSFERS* = 0
type
# Signature domains
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.0/specs/core/0_beacon-chain.md#signature-domains
SignatureDomain* {.pure.} = enum
DOMAIN_BEACON_PROPOSER = 0
DOMAIN_RANDAO = 1
DOMAIN_ATTESTATION = 2
DOMAIN_DEPOSIT = 3
DOMAIN_VOLUNTARY_EXIT = 4
DOMAIN_TRANSFER = 5

@ -1 +1 @@
Subproject commit 76fd020646fef404c55837fbc40833b0d0b2ac72 Subproject commit fa7ebca4cbe5a9d5dce3114daa977427adc1892c

Binary file not shown.

View File

@ -6,25 +6,30 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms. # at your option. This file may not be copied, modified, or distributed except according to those terms.
import import
# Standard libs # Standard library
ospaths, strutils, json, unittest, ospaths, strutils, json, unittest,
# Third parties # Third parties
# Beacon chain internals # Beacon chain internals
../../beacon_chain/spec/validator, ../../beacon_chain/spec/[datatypes, validator],
# Test utilities # Test utilities
../testutil,
./fixtures_utils ./fixtures_utils
const TestFolder = currentSourcePath.rsplit(DirSep, 1)[0] const TestFolder = currentSourcePath.rsplit(DirSep, 1)[0]
when const_preset == "mainnet":
const TestsPath = "fixtures" / "json_tests" / "shuffling" / "core" / "shuffling_full.json" const TestsPath = "fixtures" / "json_tests" / "shuffling" / "core" / "shuffling_full.json"
elif const_preset == "minimal":
const TestsPath = "fixtures" / "json_tests" / "shuffling" / "core" / "shuffling_minimal.json"
var shufflingTests: Tests[Shuffling] var shufflingTests: Tests[Shuffling]
suite "Official - Shuffling tests": suite "Official - Shuffling tests [Preset: " & preset():
test "Parsing the official shuffling tests": test "Parsing the official shuffling tests [Preset: " & preset():
shufflingTests = parseTestsShuffling(TestFolder / TestsPath) shufflingTests = parseTestsShuffling(TestFolder / TestsPath)
test "Shuffling a sequence of N validators": test "Shuffling a sequence of N validators" & preset():
for t in shufflingTests.test_cases: for t in shufflingTests.test_cases:
let implResult = get_shuffled_seq(t.seed, t.count) let implResult = get_shuffled_seq(t.seed, t.count)
check: implResult == t.shuffled check: implResult == t.shuffled

View File

@ -11,7 +11,7 @@ import
../beacon_chain/spec/[beaconstate, crypto, datatypes, digest, helpers, validator], ../beacon_chain/spec/[beaconstate, crypto, datatypes, digest, helpers, validator],
../beacon_chain/[beacon_node_types, attestation_pool, block_pool, extras, state_transition, ssz] ../beacon_chain/[beacon_node_types, attestation_pool, block_pool, extras, state_transition, ssz]
suite "Attestation pool processing": suite "Attestation pool processing" & preset():
## For now just test that we can compile and execute block processing with ## For now just test that we can compile and execute block processing with
## mock data. ## mock data.
@ -22,7 +22,7 @@ suite "Attestation pool processing":
{skipValidation}) {skipValidation})
genBlock = get_initial_beacon_block(genState) genBlock = get_initial_beacon_block(genState)
test "Can add and retrieve simple attestation": test "Can add and retrieve simple attestation" & preset():
var var
blockPool = BlockPool.init(makeTestDB(genState, genBlock)) blockPool = BlockPool.init(makeTestDB(genState, genBlock))
pool = AttestationPool.init(blockPool) pool = AttestationPool.init(blockPool)
@ -46,7 +46,7 @@ suite "Attestation pool processing":
# check: # check:
# attestations.len == 1 # attestations.len == 1
test "Attestations may arrive in any order": test "Attestations may arrive in any order" & preset():
var var
blockPool = BlockPool.init(makeTestDB(genState, genBlock)) blockPool = BlockPool.init(makeTestDB(genState, genBlock))
pool = AttestationPool.init(blockPool) pool = AttestationPool.init(blockPool)

View File

@ -7,11 +7,13 @@
import options, unittest, sequtils, strutils, eth/trie/[db], import options, unittest, sequtils, strutils, eth/trie/[db],
../beacon_chain/[beacon_chain_db, ssz], ../beacon_chain/[beacon_chain_db, ssz],
../beacon_chain/spec/[datatypes, digest, crypto] ../beacon_chain/spec/[datatypes, digest, crypto],
# test utilies
./testutil
suite "Beacon chain DB": suite "Beacon chain DB" & preset():
test "empty database": test "empty database" & preset():
var var
db = init(BeaconChainDB, newMemoryDB()) db = init(BeaconChainDB, newMemoryDB())
@ -19,7 +21,7 @@ suite "Beacon chain DB":
db.getState(Eth2Digest()).isNone db.getState(Eth2Digest()).isNone
db.getBlock(Eth2Digest()).isNone db.getBlock(Eth2Digest()).isNone
test "sanity check blocks": test "sanity check blocks" & preset():
var var
db = init(BeaconChainDB, newMemoryDB()) db = init(BeaconChainDB, newMemoryDB())
@ -37,7 +39,7 @@ suite "Beacon chain DB":
check: check:
db.getStateRoot(root, blck.slot).get() == root db.getStateRoot(root, blck.slot).get() == root
test "sanity check states": test "sanity check states" & preset():
var var
db = init(BeaconChainDB, newMemoryDB()) db = init(BeaconChainDB, newMemoryDB())
@ -51,7 +53,7 @@ suite "Beacon chain DB":
db.containsState(root) db.containsState(root)
db.getState(root).get() == state db.getState(root).get() == state
test "find ancestors": test "find ancestors" & preset():
var var
db = init(BeaconChainDB, newMemoryDB()) db = init(BeaconChainDB, newMemoryDB())
x: ValidatorSig x: ValidatorSig

View File

@ -11,8 +11,8 @@ import
../beacon_chain/extras, ../beacon_chain/extras,
../beacon_chain/spec/[beaconstate, datatypes, digest] ../beacon_chain/spec/[beaconstate, datatypes, digest]
suite "Beacon state": suite "Beacon state" & preset():
test "Smoke test get_genesis_beacon_state": test "Smoke test get_genesis_beacon_state" & preset():
let state = get_genesis_beacon_state( let state = get_genesis_beacon_state(
makeInitialDeposits(SLOTS_PER_EPOCH, {}), 0, Eth1Data(), {}) makeInitialDeposits(SLOTS_PER_EPOCH, {}), 0, Eth1Data(), {})
check: state.validator_registry.len == SLOTS_PER_EPOCH check: state.validator_registry.len == SLOTS_PER_EPOCH

View File

@ -11,14 +11,14 @@ import
../beacon_chain/spec/[beaconstate, crypto, datatypes, digest, helpers, validator], ../beacon_chain/spec/[beaconstate, crypto, datatypes, digest, helpers, validator],
../beacon_chain/[beacon_node_types, block_pool, beacon_chain_db, extras, state_transition, ssz] ../beacon_chain/[beacon_node_types, block_pool, beacon_chain_db, extras, state_transition, ssz]
suite "Block pool processing": suite "Block pool processing" & preset():
let let
genState = get_genesis_beacon_state( genState = get_genesis_beacon_state(
makeInitialDeposits(flags = {skipValidation}), 0, Eth1Data(), makeInitialDeposits(flags = {skipValidation}), 0, Eth1Data(),
{skipValidation}) {skipValidation})
genBlock = get_initial_beacon_block(genState) genBlock = get_initial_beacon_block(genState)
test "loadTailState gets genesis block on first load": test "loadTailState gets genesis block on first load" & preset():
var var
pool = BlockPool.init(makeTestDB(genState, genBlock)) pool = BlockPool.init(makeTestDB(genState, genBlock))
state = pool.loadTailState() state = pool.loadTailState()
@ -29,7 +29,7 @@ suite "Block pool processing":
b0.isSome() b0.isSome()
toSeq(pool.blockRootsForSlot(GENESIS_SLOT)) == @[state.blck.root] toSeq(pool.blockRootsForSlot(GENESIS_SLOT)) == @[state.blck.root]
test "Simple block add&get": test "Simple block add&get" & preset():
var var
pool = BlockPool.init(makeTestDB(genState, genBlock)) pool = BlockPool.init(makeTestDB(genState, genBlock))
state = pool.loadTailState() state = pool.loadTailState()
@ -48,7 +48,7 @@ suite "Block pool processing":
b1Ref.get().refs.root == b1Root b1Ref.get().refs.root == b1Root
hash_tree_root(state.data.data) == state.data.root hash_tree_root(state.data.data) == state.data.root
test "Reverse order block add & get": test "Reverse order block add & get" & preset():
var var
db = makeTestDB(genState, genBlock) db = makeTestDB(genState, genBlock)
pool = BlockPool.init(db) pool = BlockPool.init(db)

View File

@ -11,7 +11,7 @@ import
../beacon_chain/spec/[beaconstate, crypto, datatypes, digest, helpers, validator], ../beacon_chain/spec/[beaconstate, crypto, datatypes, digest, helpers, validator],
../beacon_chain/[extras, state_transition, ssz] ../beacon_chain/[extras, state_transition, ssz]
suite "Block processing": suite "Block processing" & preset():
## For now just test that we can compile and execute block processing with ## For now just test that we can compile and execute block processing with
## mock data. ## mock data.
@ -23,7 +23,7 @@ suite "Block processing":
genesisBlock = get_initial_beacon_block(genesisState) genesisBlock = get_initial_beacon_block(genesisState)
genesisRoot = signing_root(genesisBlock) genesisRoot = signing_root(genesisBlock)
test "Passes from genesis state, no block": test "Passes from genesis state, no block" & preset():
var var
state = genesisState state = genesisState
@ -31,7 +31,7 @@ suite "Block processing":
check: check:
state.slot == genesisState.slot + 1 state.slot == genesisState.slot + 1
test "Passes from genesis state, empty block": test "Passes from genesis state, empty block" & preset():
var var
state = genesisState state = genesisState
previous_block_root = signing_root(genesisBlock) previous_block_root = signing_root(genesisBlock)
@ -44,7 +44,7 @@ suite "Block processing":
state.slot == genesisState.slot + 1 state.slot == genesisState.slot + 1
test "Passes through epoch update, no block": test "Passes through epoch update, no block" & preset():
var var
state = genesisState state = genesisState
@ -54,7 +54,7 @@ suite "Block processing":
check: check:
state.slot == genesisState.slot + SLOTS_PER_EPOCH state.slot == genesisState.slot + SLOTS_PER_EPOCH
test "Passes through epoch update, empty block": test "Passes through epoch update, empty block" & preset():
var var
state = genesisState state = genesisState
previous_block_root = genesisRoot previous_block_root = genesisRoot
@ -72,7 +72,7 @@ suite "Block processing":
check: check:
state.slot == genesisState.slot + SLOTS_PER_EPOCH state.slot == genesisState.slot + SLOTS_PER_EPOCH
test "Attestation gets processed at epoch": test "Attestation gets processed at epoch" & preset():
var var
state = genesisState state = genesisState
previous_block_root = genesisRoot previous_block_root = genesisRoot

View File

@ -13,6 +13,9 @@ import
../beacon_chain/spec/[beaconstate, bitfield, crypto, datatypes, digest, ../beacon_chain/spec/[beaconstate, bitfield, crypto, datatypes, digest,
helpers, validator] helpers, validator]
func preset*(): string =
" [Preset: " & const_preset & ']'
func makeFakeValidatorPrivKey*(i: int): ValidatorPrivKey = func makeFakeValidatorPrivKey*(i: int): ValidatorPrivKey =
var i = i + 1 # 0 does not work, as private key... var i = i + 1 # 0 does not work, as private key...
copyMem(result.x[0].addr, i.addr, min(sizeof(result.x), sizeof(i))) copyMem(result.x[0].addr, i.addr, min(sizeof(result.x), sizeof(i)))
@ -189,4 +192,3 @@ proc makeTestDB*(tailState: BeaconState, tailBlock: BeaconBlock): BeaconChainDB
result = init(BeaconChainDB, newMemoryDB()) result = init(BeaconChainDB, newMemoryDB())
BlockPool.preInit(result, tailState, tailBlock) BlockPool.preInit(result, tailState, tailBlock)