2021-06-04 10:38:00 +00:00
|
|
|
# beacon_chain
|
2022-01-05 08:42:56 +00:00
|
|
|
# Copyright (c) 2021-2022 Status Research & Development GmbH
|
2021-06-04 10:38:00 +00:00
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
2021-06-17 17:13:14 +00:00
|
|
|
yaml,
|
2021-06-04 10:38:00 +00:00
|
|
|
# Standard library
|
|
|
|
os, sequtils,
|
|
|
|
# Status internal
|
2021-10-13 14:24:36 +00:00
|
|
|
chronicles,
|
2021-06-04 10:38:00 +00:00
|
|
|
faststreams, streams,
|
|
|
|
# Beacon chain internals
|
2021-08-12 13:08:20 +00:00
|
|
|
../../../beacon_chain/spec/[state_transition, forks, helpers],
|
2021-06-04 10:38:00 +00:00
|
|
|
../../../beacon_chain/spec/datatypes/[phase0, altair],
|
|
|
|
# Test utilities
|
|
|
|
../../testutil,
|
|
|
|
../fixtures_utils
|
|
|
|
|
|
|
|
const
|
|
|
|
TransitionDir = SszTestsDir/const_preset/"altair"/"transition"/"core"/"pyspec_tests"
|
|
|
|
|
|
|
|
type
|
2021-10-16 07:17:07 +00:00
|
|
|
TransitionInfo = object
|
2021-06-04 10:38:00 +00:00
|
|
|
post_fork: string
|
|
|
|
fork_epoch: int
|
|
|
|
blocks_count: int
|
2021-10-16 07:17:07 +00:00
|
|
|
fork_block {.defaultVal: -1.}: int
|
|
|
|
bls_setting {.defaultVal: 1.}: int
|
2021-06-04 10:38:00 +00:00
|
|
|
|
|
|
|
proc runTest(testName, testDir, unitTestName: string) =
|
|
|
|
let testPath = testDir / unitTestName
|
|
|
|
|
2021-10-16 07:17:07 +00:00
|
|
|
var transitionInfo: TransitionInfo
|
2022-02-20 20:13:06 +00:00
|
|
|
let s = openFileStream(testPath/"meta.yaml")
|
2021-06-04 10:38:00 +00:00
|
|
|
defer: close(s)
|
2021-10-16 07:17:07 +00:00
|
|
|
yaml.load(s, transitionInfo)
|
2021-06-04 10:38:00 +00:00
|
|
|
|
|
|
|
proc `testImpl _ blck _ testName`() =
|
|
|
|
test testName & " - " & unitTestName & preset():
|
|
|
|
var
|
|
|
|
preState = newClone(parseTest(testPath/"pre.ssz_snappy", SSZ, phase0.BeaconState))
|
2021-10-18 16:37:27 +00:00
|
|
|
fhPreState = (ref ForkedHashedBeaconState)(phase0Data: phase0.HashedBeaconState(
|
|
|
|
data: preState[], root: hash_tree_root(preState[])), kind: BeaconStateFork.Phase0)
|
2021-06-04 10:38:00 +00:00
|
|
|
cache = StateCache()
|
2021-10-13 14:24:36 +00:00
|
|
|
info = ForkedEpochInfo()
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
cfg = defaultRuntimeConfig
|
2021-10-16 07:17:07 +00:00
|
|
|
cfg.ALTAIR_FORK_EPOCH = transitionInfo.fork_epoch.Epoch
|
2021-06-04 10:38:00 +00:00
|
|
|
|
|
|
|
# In test cases with more than 10 blocks the first 10 aren't 0-prefixed,
|
|
|
|
# so purely lexicographic sorting wouldn't sort properly.
|
|
|
|
let numBlocks = toSeq(walkPattern(testPath/"blocks_*.ssz_snappy")).len
|
|
|
|
for i in 0 ..< numBlocks:
|
2021-10-16 07:17:07 +00:00
|
|
|
if i <= transitionInfo.fork_block:
|
2021-06-04 10:38:00 +00:00
|
|
|
let blck = parseTest(testPath/"blocks_" & $i & ".ssz_snappy", SSZ, phase0.SignedBeaconBlock)
|
|
|
|
|
2022-01-17 11:19:58 +00:00
|
|
|
let res = state_transition(
|
2021-10-13 14:24:36 +00:00
|
|
|
cfg, fhPreState[], blck, cache, info,
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
flags = {skipStateRootValidation}, noRollback)
|
2022-01-17 11:19:58 +00:00
|
|
|
res.expect("no failure when applying block " & $i)
|
2021-06-04 10:38:00 +00:00
|
|
|
else:
|
|
|
|
let blck = parseTest(testPath/"blocks_" & $i & ".ssz_snappy", SSZ, altair.SignedBeaconBlock)
|
|
|
|
|
2022-01-17 11:19:58 +00:00
|
|
|
let res = state_transition(
|
2021-10-13 14:24:36 +00:00
|
|
|
cfg, fhPreState[], blck, cache, info,
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
flags = {skipStateRootValidation}, noRollback)
|
2022-01-17 11:19:58 +00:00
|
|
|
res.expect("no failure when applying block " & $i)
|
2021-06-04 10:38:00 +00:00
|
|
|
|
|
|
|
let postState = newClone(parseTest(testPath/"post.ssz_snappy", SSZ, altair.BeaconState))
|
|
|
|
when false:
|
2021-06-11 17:51:46 +00:00
|
|
|
reportDiff(fhPreState.data, postState)
|
|
|
|
doAssert getStateRoot(fhPreState[]) == postState[].hash_tree_root()
|
2021-06-04 10:38:00 +00:00
|
|
|
|
|
|
|
`testImpl _ blck _ testName`()
|
|
|
|
|
2022-01-05 08:42:56 +00:00
|
|
|
suite "EF - Altair - Transition " & preset():
|
2021-10-16 07:17:07 +00:00
|
|
|
for kind, path in walkDir(TransitionDir, relative = true, checkDir = true):
|
2022-01-05 08:42:56 +00:00
|
|
|
runTest("EF - Altair - Transition", TransitionDir, path)
|