update 10 modules from using merge to bellatrix (#3257)

This commit is contained in:
tersec 2022-01-07 17:10:40 +00:00 committed by GitHub
parent ba99c8fe4f
commit bac0eaa92e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 61 additions and 52 deletions

View File

@ -1,5 +1,5 @@
# beacon_chain
# Copyright (c) 2018-2021 Status Research & Development GmbH
# Copyright (c) 2018-2022 Status Research & Development GmbH
# 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).
@ -14,7 +14,7 @@ import
eth/db/[kvstore, kvstore_sqlite3],
./networking/network_metadata, ./beacon_chain_db_immutable,
./spec/[eth2_ssz_serialization, eth2_merkleization, forks, state_transition],
./spec/datatypes/[phase0, altair, merge],
./spec/datatypes/[phase0, altair, bellatrix],
./filepath
export
@ -91,7 +91,7 @@ type
keyValues: KvStoreRef # Random stuff using DbKeyKind - suitable for small values mainly!
blocks: KvStoreRef # BlockRoot -> phase0.TrustedBeaconBlock
altairBlocks: KvStoreRef # BlockRoot -> altair.TrustedBeaconBlock
mergeBlocks: KvStoreRef # BlockRoot -> merge.TrustedBeaconBlock
mergeBlocks: KvStoreRef # BlockRoot -> bellatrix.TrustedBeaconBlock
stateRoots: KvStoreRef # (Slot, BlockRoot) -> StateRoot
statesNoVal: KvStoreRef # StateRoot -> Phase0BeaconStateNoImmutableValidators
altairStatesNoVal: KvStoreRef # StateRoot -> AltairBeaconStateNoImmutableValidators
@ -494,7 +494,7 @@ proc putBlock*(db: BeaconChainDB, value: altair.TrustedSignedBeaconBlock) =
db.altairBlocks.putSnappySSZ(value.root.data, value)
db.putBeaconBlockSummary(value.root, value.message.toBeaconBlockSummary())
proc putBlock*(db: BeaconChainDB, value: merge.TrustedSignedBeaconBlock) =
proc putBlock*(db: BeaconChainDB, value: bellatrix.TrustedSignedBeaconBlock) =
db.mergeBlocks.putSnappySSZ(value.root.data, value)
db.putBeaconBlockSummary(value.root, value.message.toBeaconBlockSummary())
@ -519,7 +519,7 @@ template toBeaconStateNoImmutableValidators(state: altair.BeaconState):
AltairBeaconStateNoImmutableValidators =
isomorphicCast[AltairBeaconStateNoImmutableValidators](state)
template toBeaconStateNoImmutableValidators(state: merge.BeaconState):
template toBeaconStateNoImmutableValidators(state: bellatrix.BeaconState):
MergeBeaconStateNoImmutableValidators =
isomorphicCast[MergeBeaconStateNoImmutableValidators](state)
@ -533,7 +533,7 @@ proc putState*(db: BeaconChainDB, key: Eth2Digest, value: altair.BeaconState) =
db.altairStatesNoVal.putSnappySSZ(
key.data, toBeaconStateNoImmutableValidators(value))
proc putState*(db: BeaconChainDB, key: Eth2Digest, value: merge.BeaconState) =
proc putState*(db: BeaconChainDB, key: Eth2Digest, value: bellatrix.BeaconState) =
db.updateImmutableValidators(value.validators.asSeq())
db.mergeStatesNoVal.putSnappySSZ(
key.data, toBeaconStateNoImmutableValidators(value))
@ -624,9 +624,9 @@ proc getAltairBlock*(db: BeaconChainDB, key: Eth2Digest):
result.err()
proc getMergeBlock*(db: BeaconChainDB, key: Eth2Digest):
Opt[merge.TrustedSignedBeaconBlock] =
Opt[bellatrix.TrustedSignedBeaconBlock] =
# We only store blocks that we trust in the database
result.ok(default(merge.TrustedSignedBeaconBlock))
result.ok(default(bellatrix.TrustedSignedBeaconBlock))
if db.mergeBlocks.getSnappySSZ(key.data, result.get) == GetResult.found:
# set root after deserializing (so it doesn't get zeroed)
result.get().root = key
@ -773,7 +773,7 @@ proc getState*(
db.immutableValidators, db.altairStatesNoVal, key.data, output, rollback)
proc getState*(
db: BeaconChainDB, key: Eth2Digest, output: var merge.BeaconState,
db: BeaconChainDB, key: Eth2Digest, output: var bellatrix.BeaconState,
rollback: RollbackProc): bool =
## Load state into `output` - BeaconState is large so we want to avoid
## re-allocating it if possible

View File

@ -1,5 +1,5 @@
# beacon_chain
# Copyright (c) 2021 Status Research & Development GmbH
# Copyright (c) 2021-2022 Status Research & Development GmbH
# 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).
@ -11,7 +11,7 @@ import
stew/[assign2, results],
serialization,
eth/db/kvstore,
./spec/datatypes/[base, altair, merge],
./spec/datatypes/[base, altair, bellatrix],
./spec/[eth2_ssz_serialization, eth2_merkleization]
type

View File

@ -1,5 +1,5 @@
# beacon_chain
# Copyright (c) 2018-2021 Status Research & Development GmbH
# Copyright (c) 2018-2022 Status Research & Development GmbH
# 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).
@ -15,12 +15,12 @@ import
chronicles, stew/byteutils,
# Internal
../spec/[beaconstate, eth2_merkleization, forks, helpers, validator],
../spec/datatypes/[phase0, altair, merge],
../spec/datatypes/[phase0, altair, bellatrix],
"."/[spec_cache, blockchain_dag, block_quarantine],
../fork_choice/fork_choice,
../beacon_clock
export options, tables, phase0, altair, merge, blockchain_dag, fork_choice
export options, tables, phase0, altair, bellatrix, blockchain_dag, fork_choice
const
ATTESTATION_LOOKBACK* =
@ -450,7 +450,7 @@ func init(T: type AttestationCache, state: phase0.HashedBeaconState): T =
func init(
T: type AttestationCache,
state: altair.HashedBeaconState | merge.HashedBeaconState,
state: altair.HashedBeaconState | bellatrix.HashedBeaconState,
cache: var StateCache): T =
# Load attestations that are scheduled for being given rewards for
let
@ -533,7 +533,7 @@ proc getAttestationsForBlock*(pool: var AttestationPool,
attCache =
when state is phase0.HashedBeaconState:
AttestationCache.init(state)
elif state is altair.HashedBeaconState or state is merge.HashedBeaconState:
elif state is altair.HashedBeaconState or state is bellatrix.HashedBeaconState:
AttestationCache.init(state, cache)
else:
static: doAssert false
@ -588,7 +588,7 @@ proc getAttestationsForBlock*(pool: var AttestationPool,
var
prevEpoch = state.data.get_previous_epoch()
prevEpochSpace =
when state is altair.HashedBeaconState or state is merge.HashedBeaconState:
when state is altair.HashedBeaconState or state is bellatrix.HashedBeaconState:
MAX_ATTESTATIONS
elif state is phase0.HashedBeaconState:
state.data.previous_epoch_attestations.maxLen -

View File

@ -1,5 +1,5 @@
# beacon_chain
# Copyright (c) 2018-2021 Status Research & Development GmbH
# Copyright (c) 2018-2022 Status Research & Development GmbH
# 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).
@ -14,7 +14,7 @@ import
stew/endians2, chronicles,
# Internals
../spec/[signatures_batch, forks, helpers],
../spec/datatypes/[phase0, altair, merge],
../spec/datatypes/[phase0, altair, bellatrix],
".."/beacon_chain_db,
../validators/validator_monitor,
./block_dag
@ -226,7 +226,7 @@ type
OnMergeBlockAdded* = proc(
blckRef: BlockRef,
blck: merge.TrustedSignedBeaconBlock,
blck: bellatrix.TrustedSignedBeaconBlock,
epochRef: EpochRef) {.gcsafe, raises: [Defect].}
HeadChangeInfoObject* = object

View File

@ -15,7 +15,7 @@ import
# Internal
../beacon_clock,
../spec/[beaconstate, helpers],
../spec/datatypes/[phase0, altair, merge],
../spec/datatypes/[phase0, altair, bellatrix],
# Fork choice
./fork_choice_types, ./proto_array,
../consensus_object_pools/[spec_cache, blockchain_dag]
@ -337,9 +337,9 @@ func process_block*(self: var ForkChoiceBackend,
# blck: SomeSomeBeaconBlock
# as comes up. Other types can be added as needed.
type ReallyAnyBeaconBlock =
phase0.BeaconBlock | altair.BeaconBlock | merge.BeaconBlock |
phase0.BeaconBlock | altair.BeaconBlock | bellatrix.BeaconBlock |
phase0.TrustedBeaconBlock | altair.TrustedBeaconBlock |
merge.TrustedBeaconBlock
bellatrix.TrustedBeaconBlock
proc process_block*(self: var ForkChoice,
dag: ChainDAGRef,
epochRef: EpochRef,

View File

@ -12,7 +12,7 @@ import
os,
# Beacon chain internals
../../../beacon_chain/spec/[beaconstate, helpers],
../../../beacon_chain/spec/datatypes/[altair, merge],
../../../beacon_chain/spec/datatypes/[altair, bellatrix],
# Test utilities
../../testutil,
../fixtures_utils,
@ -29,7 +29,7 @@ proc runTest(identifier: string) =
preState = newClone(
parseTest(testDir/"pre.ssz_snappy", SSZ, altair.BeaconState))
postState = newClone(
parseTest(testDir/"post.ssz_snappy", SSZ, merge.BeaconState))
parseTest(testDir/"post.ssz_snappy", SSZ, bellatrix.BeaconState))
var cfg = defaultRuntimeConfig

View File

@ -16,7 +16,7 @@ import
stew/results,
# Beacon chain internals
../../../beacon_chain/spec/[beaconstate, state_transition_block],
../../../beacon_chain/spec/datatypes/merge,
../../../beacon_chain/spec/datatypes/bellatrix,
# Test utilities
../../testutil,
../fixtures_utils,
@ -55,13 +55,14 @@ proc runTest[T, U](
test prefix & baseDescription & testSuiteName & " - " & identifier:
var preState = newClone(
parseTest(testDir/"pre.ssz_snappy", SSZ, merge.BeaconState))
parseTest(testDir/"pre.ssz_snappy", SSZ, bellatrix.BeaconState))
let done = applyProc(
preState[], parseTest(testDir/(applyFile & ".ssz_snappy"), SSZ, T))
if existsFile(testDir/"post.ssz_snappy"):
let postState =
newClone(parseTest(testDir/"post.ssz_snappy", SSZ, merge.BeaconState))
newClone(parseTest(
testDir/"post.ssz_snappy", SSZ, bellatrix.BeaconState))
check:
done.isOk()
@ -74,7 +75,7 @@ proc runTest[T, U](
suite baseDescription & "Attestation " & preset():
proc applyAttestation(
preState: var merge.BeaconState, attestation: Attestation):
preState: var bellatrix.BeaconState, attestation: Attestation):
Result[void, cstring] =
var cache = StateCache()
let
@ -91,7 +92,7 @@ suite baseDescription & "Attestation " & preset():
suite baseDescription & "Attester Slashing " & preset():
proc applyAttesterSlashing(
preState: var merge.BeaconState, attesterSlashing: AttesterSlashing):
preState: var bellatrix.BeaconState, attesterSlashing: AttesterSlashing):
Result[void, cstring] =
var cache = StateCache()
process_attester_slashing(
@ -104,18 +105,18 @@ suite baseDescription & "Attester Slashing " & preset():
suite baseDescription & "Block Header " & preset():
func applyBlockHeader(
preState: var merge.BeaconState, blck: merge.BeaconBlock):
preState: var bellatrix.BeaconState, blck: bellatrix.BeaconBlock):
Result[void, cstring] =
var cache = StateCache()
process_block_header(preState, blck, {}, cache)
for path in walkTests(OpBlockHeaderDir):
runTest[merge.BeaconBlock, typeof applyBlockHeader](
runTest[bellatrix.BeaconBlock, typeof applyBlockHeader](
OpBlockHeaderDir, "Block Header", "block", applyBlockHeader, path)
suite baseDescription & "Deposit " & preset():
proc applyDeposit(
preState: var merge.BeaconState, deposit: Deposit):
preState: var bellatrix.BeaconState, deposit: Deposit):
Result[void, cstring] =
process_deposit(defaultRuntimeConfig, preState, deposit, {})
@ -126,7 +127,8 @@ suite baseDescription & "Deposit " & preset():
suite baseDescription & "Execution Payload " & preset():
for path in walkTests(OpExecutionPayloadDir):
proc applyExecutionPayload(
preState: var merge.BeaconState, executionPayload: ExecutionPayload):
preState: var bellatrix.BeaconState,
executionPayload: ExecutionPayload):
Result[void, cstring] =
let payloadValid =
readFile(OpExecutionPayloadDir/"pyspec_tests"/path/"execution.yaml").
@ -141,7 +143,7 @@ suite baseDescription & "Execution Payload " & preset():
suite baseDescription & "Proposer Slashing " & preset():
proc applyProposerSlashing(
preState: var merge.BeaconState, proposerSlashing: ProposerSlashing):
preState: var bellatrix.BeaconState, proposerSlashing: ProposerSlashing):
Result[void, cstring] =
var cache = StateCache()
process_proposer_slashing(
@ -154,7 +156,7 @@ suite baseDescription & "Proposer Slashing " & preset():
suite baseDescription & "Sync Aggregate " & preset():
proc applySyncAggregate(
preState: var merge.BeaconState, syncAggregate: SyncAggregate):
preState: var bellatrix.BeaconState, syncAggregate: SyncAggregate):
Result[void, cstring] =
var cache = StateCache()
process_sync_aggregate(
@ -167,7 +169,7 @@ suite baseDescription & "Sync Aggregate " & preset():
suite baseDescription & "Voluntary Exit " & preset():
proc applyVoluntaryExit(
preState: var merge.BeaconState, voluntaryExit: SignedVoluntaryExit):
preState: var bellatrix.BeaconState, voluntaryExit: SignedVoluntaryExit):
Result[void, cstring] =
var cache = StateCache()
process_voluntary_exit(

View File

@ -14,7 +14,7 @@ import
chronicles,
# Beacon chain internals
../../../beacon_chain/spec/[forks, state_transition],
../../../beacon_chain/spec/datatypes/merge,
../../../beacon_chain/spec/datatypes/bellatrix,
# Test utilities
../../testutil,
../../helpers/debug_state,
@ -34,8 +34,9 @@ proc runTest(testName, testDir, unitTestName: string) =
test prefix & testName & " - " & unitTestName & preset():
var
preState = newClone(parseTest(testPath/"pre.ssz_snappy", SSZ, merge.BeaconState))
fhPreState = (ref ForkedHashedBeaconState)(mergeData: merge.HashedBeaconState(
preState = newClone(parseTest(
testPath/"pre.ssz_snappy", SSZ, bellatrix.BeaconState))
fhPreState = (ref ForkedHashedBeaconState)(mergeData: bellatrix.HashedBeaconState(
data: preState[], root: hash_tree_root(preState[])),
kind: BeaconStateFork.Bellatrix)
cache = StateCache()
@ -47,7 +48,9 @@ proc runTest(testName, testDir, unitTestName: string) =
if numBlocks > 1:
return
for i in 0 ..< numBlocks:
let blck = parseTest(testPath/"blocks_" & $i & ".ssz_snappy", SSZ, merge.SignedBeaconBlock)
let blck = parseTest(
testPath/"blocks_" & $i & ".ssz_snappy", SSZ,
bellatrix.SignedBeaconBlock)
if hasPostState:
let success = state_transition(
@ -62,7 +65,8 @@ proc runTest(testName, testDir, unitTestName: string) =
"We didn't expect these invalid blocks to be processed"
if hasPostState:
let postState = newClone(parseTest(testPath/"post.ssz_snappy", SSZ, merge.BeaconState))
let postState = newClone(parseTest(
testPath/"post.ssz_snappy", SSZ, bellatrix.BeaconState))
when false:
reportDiff(fhPreState.mergeData.data, postState)
doAssert getStateRoot(fhPreState[]) == postState[].hash_tree_root()

View File

@ -12,7 +12,7 @@ import
os, strutils,
# Beacon chain internals
../../../beacon_chain/spec/[forks, state_transition],
../../../beacon_chain/spec/datatypes/merge,
../../../beacon_chain/spec/datatypes/bellatrix,
# Test utilities
../../testutil,
../fixtures_utils,
@ -28,14 +28,16 @@ proc runTest(identifier: string) =
proc `testImpl _ slots _ identifier`() =
test "Slots - " & identifier:
var
preState = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, merge.BeaconState))
preState = newClone(parseTest(
testDir/"pre.ssz_snappy", SSZ, bellatrix.BeaconState))
fhPreState = (ref ForkedHashedBeaconState)(
mergeData: merge.HashedBeaconState(
mergeData: bellatrix.HashedBeaconState(
data: preState[], root: hash_tree_root(preState[])),
kind: BeaconStateFork.Bellatrix)
cache = StateCache()
info = ForkedEpochInfo()
let postState = newClone(parseTest(testDir/"post.ssz_snappy", SSZ, merge.BeaconState))
let postState = newClone(parseTest(
testDir/"post.ssz_snappy", SSZ, bellatrix.BeaconState))
check:
process_slots(

View File

@ -14,7 +14,7 @@ import
# Third-party
yaml,
# Beacon chain internals
../../beacon_chain/spec/datatypes/merge,
../../beacon_chain/spec/datatypes/bellatrix,
# Status libraries
snappy,
# Test utilities
@ -39,7 +39,7 @@ type
# Note this only tracks HashTreeRoot
# Checking the values against the yaml file is TODO (require more flexible Yaml parser)
proc checkSSZ(T: type merge.SignedBeaconBlock, dir: string, expectedHash: SSZHashTreeRoot) =
proc checkSSZ(T: type bellatrix.SignedBeaconBlock, dir: string, expectedHash: SSZHashTreeRoot) =
# Deserialize into a ref object to not fill Nim stack
let encoded = snappy.decode(
readFileBytes(dir/"serialized.ssz_snappy"), MaxObjectSize)
@ -99,10 +99,10 @@ suite "EF - Bellatrix - SSZ consensus objects " & preset():
of "Attestation": checkSSZ(Attestation, path, hash)
of "AttestationData": checkSSZ(AttestationData, path, hash)
of "AttesterSlashing": checkSSZ(AttesterSlashing, path, hash)
of "BeaconBlock": checkSSZ(merge.BeaconBlock, path, hash)
of "BeaconBlockBody": checkSSZ(merge.BeaconBlockBody, path, hash)
of "BeaconBlock": checkSSZ(bellatrix.BeaconBlock, path, hash)
of "BeaconBlockBody": checkSSZ(bellatrix.BeaconBlockBody, path, hash)
of "BeaconBlockHeader": checkSSZ(BeaconBlockHeader, path, hash)
of "BeaconState": checkSSZ(merge.BeaconState, path, hash)
of "BeaconState": checkSSZ(bellatrix.BeaconState, path, hash)
of "Checkpoint": checkSSZ(Checkpoint, path, hash)
of "ContributionAndProof": checkSSZ(ContributionAndProof, path, hash)
of "Deposit": checkSSZ(Deposit, path, hash)
@ -123,7 +123,8 @@ suite "EF - Bellatrix - SSZ consensus objects " & preset():
of "ProposerSlashing": checkSSZ(ProposerSlashing, path, hash)
of "SignedAggregateAndProof":
checkSSZ(SignedAggregateAndProof, path, hash)
of "SignedBeaconBlock": checkSSZ(merge.SignedBeaconBlock, path, hash)
of "SignedBeaconBlock":
checkSSZ(bellatrix.SignedBeaconBlock, path, hash)
of "SignedBeaconBlockHeader":
checkSSZ(SignedBeaconBlockHeader, path, hash)
of "SignedContributionAndProof":