remove BeaconStateNew and associated testing scaffolding/infrastructure
This commit is contained in:
parent
96dcb1cf95
commit
7e70d16da9
|
@ -190,64 +190,6 @@ type
|
||||||
deposits*: List[Deposit, MAX_DEPOSITS]
|
deposits*: List[Deposit, MAX_DEPOSITS]
|
||||||
voluntary_exits*: List[VoluntaryExit, MAX_VOLUNTARY_EXITS]
|
voluntary_exits*: List[VoluntaryExit, MAX_VOLUNTARY_EXITS]
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.1/specs/core/0_beacon-chain.md#beaconstate
|
|
||||||
BeaconStateNew* = object
|
|
||||||
# Versioning
|
|
||||||
genesis_time*: uint64
|
|
||||||
slot*: Slot
|
|
||||||
fork*: Fork
|
|
||||||
|
|
||||||
# History
|
|
||||||
latest_block_header*: BeaconBlockHeader ##\
|
|
||||||
## `latest_block_header.state_root == ZERO_HASH` temporarily
|
|
||||||
|
|
||||||
block_roots*: array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest] ##\
|
|
||||||
## Needed to process attestations, older to newer
|
|
||||||
|
|
||||||
state_roots*: array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
|
|
||||||
|
|
||||||
historical_roots*: seq[Eth2Digest] ##\
|
|
||||||
## model List with HISTORICAL_ROOTS_LIMIT limit as seq
|
|
||||||
## TODO bound explicitly somewhere
|
|
||||||
|
|
||||||
# Eth1
|
|
||||||
eth1_data*: Eth1Data
|
|
||||||
|
|
||||||
eth1_data_votes*: seq[Eth1Data] ##\
|
|
||||||
## As with `hitorical_roots`, this is a `List`. TODO bound explicitly.
|
|
||||||
|
|
||||||
eth1_deposit_index*: uint64
|
|
||||||
|
|
||||||
# Registry
|
|
||||||
validators*: seq[Validator]
|
|
||||||
balances*: seq[uint64] ##\
|
|
||||||
## Validator balances in Gwei!
|
|
||||||
## Also more `List`s which need to be bounded explicitly at
|
|
||||||
## VALIDATOR_REGISTRY_LIMIT
|
|
||||||
|
|
||||||
# Randomness
|
|
||||||
randao_mixes*: array[EPOCHS_PER_HISTORICAL_VECTOR, Eth2Digest]
|
|
||||||
|
|
||||||
# Slashings
|
|
||||||
slashings*: array[EPOCHS_PER_SLASHINGS_VECTOR, uint64] ##\
|
|
||||||
## Per-epoch sums of slashed effective balances
|
|
||||||
|
|
||||||
# Attestations
|
|
||||||
previous_epoch_attestations*: seq[PendingAttestation]
|
|
||||||
current_epoch_attestations*: seq[PendingAttestation]
|
|
||||||
|
|
||||||
# Finality
|
|
||||||
justification_bits*: uint8 ##\
|
|
||||||
## Bit set for every recent justified epoch
|
|
||||||
## Model a Bitvector[4] as a one-byte uint, which should remain consistent
|
|
||||||
## with ssz/hashing.
|
|
||||||
|
|
||||||
previous_justified_checkpoint*: Checkpoint ##\
|
|
||||||
## Previous epoch snapshot
|
|
||||||
|
|
||||||
current_justified_checkpoint*: Checkpoint
|
|
||||||
finalized_checkpoint*: Checkpoint
|
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.1/specs/core/0_beacon-chain.md#beaconstate
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.1/specs/core/0_beacon-chain.md#beaconstate
|
||||||
BeaconState* = object
|
BeaconState* = object
|
||||||
# Versioning
|
# Versioning
|
||||||
|
@ -511,54 +453,6 @@ proc `$`*(x: ValidatorIndex): auto = $(x.int64)
|
||||||
ethTimeUnit Slot
|
ethTimeUnit Slot
|
||||||
ethTimeUnit Epoch
|
ethTimeUnit Epoch
|
||||||
|
|
||||||
func GetOldBeaconState*(newState: BeaconStateNew): BeaconState =
|
|
||||||
BeaconState(
|
|
||||||
genesis_time: newState.genesis_time,
|
|
||||||
slot: newState.slot,
|
|
||||||
fork: newState.fork,
|
|
||||||
latest_block_header: newState.latest_block_header,
|
|
||||||
block_roots: newState.block_roots,
|
|
||||||
state_roots: newState.state_roots,
|
|
||||||
historical_roots: newState.historical_roots,
|
|
||||||
eth1_data: newState.eth1_data,
|
|
||||||
eth1_data_votes: newState.eth1_data_votes,
|
|
||||||
eth1_deposit_index: newState.eth1_deposit_index,
|
|
||||||
validators: newState.validators,
|
|
||||||
balances: newState.balances,
|
|
||||||
randao_mixes: newState.randao_mixes,
|
|
||||||
slashings: newState.slashings,
|
|
||||||
previous_epoch_attestations: newState.previous_epoch_attestations,
|
|
||||||
current_epoch_attestations: newState.current_epoch_attestations,
|
|
||||||
justification_bits: newState.justification_bits,
|
|
||||||
previous_justified_checkpoint: newState.previous_justified_checkpoint,
|
|
||||||
current_justified_checkpoint: newState.current_justified_checkpoint,
|
|
||||||
finalized_checkpoint: newState.finalized_checkpoint
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetNewBeaconState*(oldState: BeaconState): BeaconStateNew =
|
|
||||||
BeaconStateNew(
|
|
||||||
genesis_time: oldState.genesis_time,
|
|
||||||
slot: oldState.slot,
|
|
||||||
fork: oldState.fork,
|
|
||||||
latest_block_header: oldState.latest_block_header,
|
|
||||||
block_roots: oldState.block_roots,
|
|
||||||
state_roots: oldState.state_roots,
|
|
||||||
historical_roots: oldState.historical_roots,
|
|
||||||
eth1_data: oldState.eth1_data,
|
|
||||||
eth1_data_votes: oldState.eth1_data_votes,
|
|
||||||
eth1_deposit_index: oldState.eth1_deposit_index,
|
|
||||||
validators: oldState.validators,
|
|
||||||
balances: oldState.balances,
|
|
||||||
randao_mixes: oldState.randao_mixes,
|
|
||||||
slashings: oldState.slashings,
|
|
||||||
previous_epoch_attestations: oldState.previous_epoch_attestations,
|
|
||||||
current_epoch_attestations: oldState.current_epoch_attestations,
|
|
||||||
justification_bits: oldState.justification_bits,
|
|
||||||
previous_justified_checkpoint: oldState.previous_justified_checkpoint,
|
|
||||||
current_justified_checkpoint: oldState.current_justified_checkpoint,
|
|
||||||
finalized_checkpoint: oldState.finalized_checkpoint
|
|
||||||
)
|
|
||||||
|
|
||||||
Json.useCustomSerialization(BeaconState.justification_bits):
|
Json.useCustomSerialization(BeaconState.justification_bits):
|
||||||
read:
|
read:
|
||||||
let s = reader.readValue(string)
|
let s = reader.readValue(string)
|
||||||
|
|
|
@ -40,29 +40,24 @@ template runTest(testName: string, identifier: untyped) =
|
||||||
prefix = "[Invalid] "
|
prefix = "[Invalid] "
|
||||||
|
|
||||||
test prefix & testName & " (" & astToStr(identifier) & ")":
|
test prefix & testName & " (" & astToStr(identifier) & ")":
|
||||||
var stateRef, postRef: ref BeaconStateNew
|
var stateRef, postRef: ref BeaconState
|
||||||
var sr_pre, sr_post: ref BeaconState
|
|
||||||
var depositRef: ref Deposit
|
var depositRef: ref Deposit
|
||||||
new depositRef
|
new depositRef
|
||||||
new stateRef
|
new stateRef
|
||||||
new sr_pre
|
|
||||||
new sr_post
|
|
||||||
|
|
||||||
depositRef[] = parseTest(testDir/"deposit.ssz", SSZ, Deposit)
|
depositRef[] = parseTest(testDir/"deposit.ssz", SSZ, Deposit)
|
||||||
stateRef[] = parseTest(testDir/"pre.ssz", SSZ, BeaconStateNew)
|
stateRef[] = parseTest(testDir/"pre.ssz", SSZ, BeaconState)
|
||||||
sr_pre[] = GetOldBeaconState(stateRef[])
|
|
||||||
|
|
||||||
if existsFile(testDir/"post.ssz"):
|
if existsFile(testDir/"post.ssz"):
|
||||||
new postRef
|
new postRef
|
||||||
postRef[] = parseTest(testDir/"post.ssz", SSZ, BeaconStateNew)
|
postRef[] = parseTest(testDir/"post.ssz", SSZ, BeaconState)
|
||||||
sr_post[] = GetOldBeaconState(postRef[])
|
|
||||||
|
|
||||||
if postRef.isNil:
|
if postRef.isNil:
|
||||||
expect(AssertionError):
|
expect(AssertionError):
|
||||||
let done = process_deposit(sr_pre[], depositRef[], flags)
|
discard process_deposit(stateRef[], depositRef[], flags)
|
||||||
else:
|
else:
|
||||||
let done = process_deposit(sr_pre[], depositRef[], flags)
|
discard process_deposit(stateRef[], depositRef[], flags)
|
||||||
reportDiff(sr_pre, sr_post)
|
reportDiff(stateRef, postRef)
|
||||||
|
|
||||||
`testImpl _ operations_deposits _ identifier`()
|
`testImpl _ operations_deposits _ identifier`()
|
||||||
|
|
||||||
|
|
|
@ -46,12 +46,7 @@ template runValidTest(testName: string, identifier: untyped, num_blocks: int): u
|
||||||
|
|
||||||
# Checks:
|
# Checks:
|
||||||
# check: stateRef.hash_tree_root() == postRef.hash_tree_root()
|
# check: stateRef.hash_tree_root() == postRef.hash_tree_root()
|
||||||
var sr_pre, sr_post: ref BeaconStateNew
|
reportDiff(stateRef, postRef)
|
||||||
new sr_pre
|
|
||||||
new sr_post
|
|
||||||
sr_pre[] = GetNewBeaconState(stateRef[])
|
|
||||||
sr_post[] = GetNewBeaconState(postRef[])
|
|
||||||
reportDiff(sr_pre, sr_post)
|
|
||||||
|
|
||||||
`testImpl _ blck _ identifier`()
|
`testImpl _ blck _ identifier`()
|
||||||
|
|
||||||
|
|
|
@ -39,12 +39,7 @@ template runTest(testName: string, identifier: untyped, num_slots: uint64): unty
|
||||||
process_slots(stateRef[], stateRef.slot + num_slots)
|
process_slots(stateRef[], stateRef.slot + num_slots)
|
||||||
# check: stateRef.hash_tree_root() == postRef.hash_tree_root()
|
# check: stateRef.hash_tree_root() == postRef.hash_tree_root()
|
||||||
|
|
||||||
var sr_pre, sr_post: ref BeaconStateNew
|
reportDiff(stateRef, postRef)
|
||||||
new sr_pre
|
|
||||||
new sr_post
|
|
||||||
sr_pre[] = GetNewBeaconState(stateRef[])
|
|
||||||
sr_post[] = GetNewBeaconState(postRef[])
|
|
||||||
reportDiff(sr_pre, sr_post)
|
|
||||||
|
|
||||||
`testImpl _ slots _ identifier`()
|
`testImpl _ slots _ identifier`()
|
||||||
|
|
||||||
|
|
|
@ -50,12 +50,7 @@ template runSuite(suiteDir, testName: string, transitionProc: untyped{ident}, us
|
||||||
else:
|
else:
|
||||||
transitionProc(stateRef[])
|
transitionProc(stateRef[])
|
||||||
|
|
||||||
var sr_pre, sr_post: ref BeaconStateNew
|
reportDiff(stateRef, postRef)
|
||||||
new sr_pre
|
|
||||||
new sr_post
|
|
||||||
sr_pre[] = GetNewBeaconState(stateRef[])
|
|
||||||
sr_post[] = GetNewBeaconState(postRef[])
|
|
||||||
reportDiff(sr_pre, sr_post)
|
|
||||||
|
|
||||||
`suiteImpl _ transitionProc`()
|
`suiteImpl _ transitionProc`()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue