rename On{Merge,Bellatrix}BlockAdded and Rollback{Merge,Bellatrix}HashedProc (#3321)

This commit is contained in:
tersec 2022-01-26 12:21:29 +00:00 committed by GitHub
parent f70aceef37
commit 2b4a960270
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 26 additions and 24 deletions

View File

@ -29,10 +29,10 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
+ sanity check Altair blocks [Preset: mainnet] OK + sanity check Altair blocks [Preset: mainnet] OK
+ sanity check Altair states [Preset: mainnet] OK + sanity check Altair states [Preset: mainnet] OK
+ sanity check Altair states, reusing buffers [Preset: mainnet] OK + sanity check Altair states, reusing buffers [Preset: mainnet] OK
+ sanity check Merge and cross-fork getState rollback [Preset: mainnet] OK + sanity check Bellatrix and cross-fork getState rollback [Preset: mainnet] OK
+ sanity check Merge blocks [Preset: mainnet] OK + sanity check Bellatrix blocks [Preset: mainnet] OK
+ sanity check Merge states [Preset: mainnet] OK + sanity check Bellatrix states [Preset: mainnet] OK
+ sanity check Merge states, reusing buffers [Preset: mainnet] OK + sanity check Bellatrix states, reusing buffers [Preset: mainnet] OK
+ sanity check genesis roundtrip [Preset: mainnet] OK + sanity check genesis roundtrip [Preset: mainnet] OK
+ sanity check phase 0 blocks [Preset: mainnet] OK + sanity check phase 0 blocks [Preset: mainnet] OK
+ sanity check phase 0 getState rollback [Preset: mainnet] OK + sanity check phase 0 getState rollback [Preset: mainnet] OK
@ -171,8 +171,8 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
```diff ```diff
+ load altair block OK + load altair block OK
+ load altair state OK + load altair state OK
+ load merge block OK + load bellatrix block OK
+ load merge state OK + load bellatrix state OK
+ load phase0 block OK + load phase0 block OK
+ load phase0 state OK + load phase0 state OK
+ should raise on unknown data OK + should raise on unknown data OK

View File

@ -1,5 +1,5 @@
# beacon_chain # beacon_chain
# Copyright (c) 2018-2021 Status Research & Development GmbH # Copyright (c) 2018-2022 Status Research & Development GmbH
# Licensed and distributed under either of # Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * 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). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@ -30,7 +30,7 @@ proc addResolvedHeadBlock(
state: var StateData, state: var StateData,
trustedBlock: ForkyTrustedSignedBeaconBlock, trustedBlock: ForkyTrustedSignedBeaconBlock,
parent: BlockRef, cache: var StateCache, parent: BlockRef, cache: var StateCache,
onBlockAdded: OnPhase0BlockAdded | OnAltairBlockAdded | OnMergeBlockAdded, onBlockAdded: OnPhase0BlockAdded | OnAltairBlockAdded | OnBellatrixBlockAdded,
stateDataDur, sigVerifyDur, stateVerifyDur: Duration stateDataDur, sigVerifyDur, stateVerifyDur: Duration
): BlockRef = ): BlockRef =
doAssert getStateField(state.data, slot) == trustedBlock.message.slot, doAssert getStateField(state.data, slot) == trustedBlock.message.slot,
@ -142,12 +142,14 @@ proc advanceClearanceState*(dag: ChainDAGRef) =
proc addHeadBlock*( proc addHeadBlock*(
dag: ChainDAGRef, verifier: var BatchVerifier, dag: ChainDAGRef, verifier: var BatchVerifier,
signedBlock: ForkySignedBeaconBlock, signedBlock: ForkySignedBeaconBlock,
onBlockAdded: OnPhase0BlockAdded | OnAltairBlockAdded | OnMergeBlockAdded onBlockAdded: OnPhase0BlockAdded | OnAltairBlockAdded |
OnBellatrixBlockAdded
): Result[BlockRef, BlockError] = ): Result[BlockRef, BlockError] =
## Try adding a block to the chain, verifying first that it passes the state ## Try adding a block to the chain, verifying first that it passes the state
## transition function and contains correct cryptographic signature. ## transition function and contains correct cryptographic signature.
## ##
## Cryptographic checks can be skipped by adding skipBLSValidation to dag.updateFlags ## Cryptographic checks can be skipped by adding skipBLSValidation to
## dag.updateFlags
logScope: logScope:
blockRoot = shortLog(signedBlock.root) blockRoot = shortLog(signedBlock.root)
blck = shortLog(signedBlock.message) blck = shortLog(signedBlock.message)

View File

@ -13,7 +13,7 @@ import
../spec/datatypes/[phase0, altair], ../spec/datatypes/[phase0, altair],
../spec/[helpers] ../spec/[helpers]
export chronicles, phase0, altair, merge, helpers export chronicles, phase0, altair, helpers
type type
BlockId* = object BlockId* = object

View File

@ -216,7 +216,7 @@ type
blck: altair.TrustedSignedBeaconBlock, blck: altair.TrustedSignedBeaconBlock,
epochRef: EpochRef) {.gcsafe, raises: [Defect].} epochRef: EpochRef) {.gcsafe, raises: [Defect].}
OnMergeBlockAdded* = proc( OnBellatrixBlockAdded* = proc(
blckRef: BlockRef, blckRef: BlockRef,
blck: bellatrix.TrustedSignedBeaconBlock, blck: bellatrix.TrustedSignedBeaconBlock,
epochRef: EpochRef) {.gcsafe, raises: [Defect].} epochRef: EpochRef) {.gcsafe, raises: [Defect].}

View File

@ -92,9 +92,9 @@ func noRollback*() =
trace "Skipping rollback of broken state" trace "Skipping rollback of broken state"
type type
RollbackHashedProc* = proc(state: var phase0.HashedBeaconState) {.gcsafe, raises: [Defect].} RollbackHashedProc* = proc(state: var phase0.HashedBeaconState) {.gcsafe, raises: [Defect].}
RollbackAltairHashedProc* = proc(state: var altair.HashedBeaconState) {.gcsafe, raises: [Defect].} RollbackAltairHashedProc* = proc(state: var altair.HashedBeaconState) {.gcsafe, raises: [Defect].}
RollbackMergeHashedProc* = proc(state: var bellatrix.HashedBeaconState) {.gcsafe, raises: [Defect].} RollbackBellatrixHashedProc* = proc(state: var bellatrix.HashedBeaconState) {.gcsafe, raises: [Defect].}
# Hashed-state transition functions # Hashed-state transition functions
# --------------------------------------------------------------- # ---------------------------------------------------------------
@ -465,7 +465,7 @@ proc makeBeaconBlock*(
exits: BeaconBlockExits, exits: BeaconBlockExits,
sync_aggregate: SyncAggregate, sync_aggregate: SyncAggregate,
execution_payload: ExecutionPayload, execution_payload: ExecutionPayload,
rollback: RollbackMergeHashedProc, rollback: RollbackBellatrixHashedProc,
cache: var StateCache): Result[bellatrix.BeaconBlock, cstring] = cache: var StateCache): Result[bellatrix.BeaconBlock, cstring] =
## Create a block for the given state. The latest block applied to it will ## Create a block for the given state. The latest block applied to it will
## be used for the parent_root value, and the slot will be take from ## be used for the parent_root value, and the slot will be take from

View File

@ -364,7 +364,7 @@ MIN_GENESIS_TIME: 0
GENESIS_DELAY: 10 GENESIS_DELAY: 10
DEPOSIT_CONTRACT_ADDRESS: ${DEPOSIT_CONTRACT_ADDRESS} DEPOSIT_CONTRACT_ADDRESS: ${DEPOSIT_CONTRACT_ADDRESS}
ETH1_FOLLOW_DISTANCE: 1 ETH1_FOLLOW_DISTANCE: 1
ALTAIR_FORK_EPOCH: 2 ALTAIR_FORK_EPOCH: 1
EOF EOF
dump_logs() { dump_logs() {

View File

@ -169,7 +169,7 @@ suite "Beacon chain DB" & preset():
db.close() db.close()
test "sanity check Merge blocks" & preset(): test "sanity check Bellatrix blocks" & preset():
var db = BeaconChainDB.new("", inMemory = true) var db = BeaconChainDB.new("", inMemory = true)
let let
@ -244,7 +244,7 @@ suite "Beacon chain DB" & preset():
db.close() db.close()
test "sanity check Merge states" & preset(): test "sanity check Bellatrix states" & preset():
var db = makeTestDB(SLOTS_PER_EPOCH) var db = makeTestDB(SLOTS_PER_EPOCH)
for state in testStatesBellatrix: for state in testStatesBellatrix:
@ -302,7 +302,7 @@ suite "Beacon chain DB" & preset():
db.close() db.close()
test "sanity check Merge states, reusing buffers" & preset(): test "sanity check Bellatrix states, reusing buffers" & preset():
var db = makeTestDB(SLOTS_PER_EPOCH) var db = makeTestDB(SLOTS_PER_EPOCH)
let stateBuffer = (bellatrix.BeaconStateRef)() let stateBuffer = (bellatrix.BeaconStateRef)()
@ -371,7 +371,7 @@ suite "Beacon chain DB" & preset():
state[].kind == BeaconStateFork.Phase0 state[].kind == BeaconStateFork.Phase0
state[].phase0Data.data.slot != 10.Slot state[].phase0Data.data.slot != 10.Slot
test "sanity check Merge and cross-fork getState rollback" & preset(): test "sanity check Bellatrix and cross-fork getState rollback" & preset():
var var
db = makeTestDB(SLOTS_PER_EPOCH) db = makeTestDB(SLOTS_PER_EPOCH)
validatorMonitor = newClone(ValidatorMonitor.init()) validatorMonitor = newClone(ValidatorMonitor.init())

View File

@ -57,7 +57,7 @@ suite "Forked SSZ readers":
expect(SszError): expect(SszError):
testHashedBeaconState(bellatrix.BeaconState, cfg.ALTAIR_FORK_EPOCH.start_slot) testHashedBeaconState(bellatrix.BeaconState, cfg.ALTAIR_FORK_EPOCH.start_slot)
test "load merge state": test "load bellatrix state":
testHashedBeaconState(bellatrix.BeaconState, cfg.MERGE_FORK_EPOCH.start_slot) testHashedBeaconState(bellatrix.BeaconState, cfg.MERGE_FORK_EPOCH.start_slot)
expect(SszError): expect(SszError):
@ -88,7 +88,7 @@ suite "Forked SSZ readers":
testTrustedSignedBeaconBlock( testTrustedSignedBeaconBlock(
bellatrix.TrustedSignedBeaconBlock, cfg.ALTAIR_FORK_EPOCH.start_slot) bellatrix.TrustedSignedBeaconBlock, cfg.ALTAIR_FORK_EPOCH.start_slot)
test "load merge block": test "load bellatrix block":
testTrustedSignedBeaconBlock( testTrustedSignedBeaconBlock(
bellatrix.TrustedSignedBeaconBlock, cfg.MERGE_FORK_EPOCH.start_slot) bellatrix.TrustedSignedBeaconBlock, cfg.MERGE_FORK_EPOCH.start_slot)

View File

@ -204,7 +204,7 @@ suite "Gossip validation - Extra": # Not based on preset config
const nilCallback = OnAltairBlockAdded(nil) const nilCallback = OnAltairBlockAdded(nil)
dag.addHeadBlock(verifier, blck.altairData, nilCallback) dag.addHeadBlock(verifier, blck.altairData, nilCallback)
of BeaconBlockFork.Bellatrix: of BeaconBlockFork.Bellatrix:
const nilCallback = OnMergeBlockAdded(nil) const nilCallback = OnBellatrixBlockAdded(nil)
dag.addHeadBlock(verifier, blck.bellatrixData, nilCallback) dag.addHeadBlock(verifier, blck.bellatrixData, nilCallback)
check: added.isOk() check: added.isOk()
dag.updateHead(added[], quarantine[]) dag.updateHead(added[], quarantine[])