avoid case object transitions for test forked block reading (#4406)

This commit is contained in:
tersec 2022-12-09 08:13:51 +00:00 committed by GitHub
parent 94653b0b71
commit 1e2f9b2fb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 9 deletions

View File

@ -128,34 +128,31 @@ from ../../beacon_chain/spec/datatypes/eip4844 import BeaconState
proc loadForkedState*(
path: string, fork: BeaconStateFork): ref ForkedHashedBeaconState =
# TODO stack usage. newClone and assignClone do not seem to
# prevent temporaries created by case objects
# TODO depends on something like nimOldCaseObjects
let forkedState = new ForkedHashedBeaconState
var forkedState: ref ForkedHashedBeaconState
case fork
of BeaconStateFork.EIP4844:
let state = newClone(parseTest(path, SSZ, eip4844.BeaconState))
forkedState.kind = BeaconStateFork.EIP4844
forkedState = (ref ForkedHashedBeaconState)(kind: BeaconStateFork.EIP4844)
forkedState.eip4844Data.data = state[]
forkedState.eip4844Data.root = hash_tree_root(state[])
of BeaconStateFork.Capella:
let state = newClone(parseTest(path, SSZ, capella.BeaconState))
forkedState.kind = BeaconStateFork.Capella
forkedState = (ref ForkedHashedBeaconState)(kind: BeaconStateFork.Capella)
forkedState.capellaData.data = state[]
forkedState.capellaData.root = hash_tree_root(state[])
of BeaconStateFork.Bellatrix:
let state = newClone(parseTest(path, SSZ, bellatrix.BeaconState))
forkedState.kind = BeaconStateFork.Bellatrix
forkedState = (ref ForkedHashedBeaconState)(kind: BeaconStateFork.Bellatrix)
forkedState.bellatrixData.data = state[]
forkedState.bellatrixData.root = hash_tree_root(state[])
of BeaconStateFork.Altair:
let state = newClone(parseTest(path, SSZ, altair.BeaconState))
forkedState.kind = BeaconStateFork.Altair
forkedState = (ref ForkedHashedBeaconState)(kind: BeaconStateFork.Altair)
forkedState.altairData.data = state[]
forkedState.altairData.root = hash_tree_root(state[])
of BeaconStateFork.Phase0:
let state = newClone(parseTest(path, SSZ, phase0.BeaconState))
forkedState.kind = BeaconStateFork.Phase0
forkedState = (ref ForkedHashedBeaconState)(kind: BeaconStateFork.Phase0)
forkedState.phase0Data.data = state[]
forkedState.phase0Data.root = hash_tree_root(state[])
forkedState