ncli: altair+ slot and state transitions (#3721)
clearly this doesn't get used a lot :)
This commit is contained in:
parent
83793c3599
commit
2edf33de7d
|
@ -18,7 +18,6 @@ type
|
||||||
slots = "Apply empty slots"
|
slots = "Apply empty slots"
|
||||||
|
|
||||||
NcliConf* = object
|
NcliConf* = object
|
||||||
|
|
||||||
eth2Network* {.
|
eth2Network* {.
|
||||||
desc: "The Eth2 network preset to use"
|
desc: "The Eth2 network preset to use"
|
||||||
name: "network" }: Option[string]
|
name: "network" }: Option[string]
|
||||||
|
@ -99,22 +98,19 @@ proc loadFile(filename: string, T: type): T =
|
||||||
|
|
||||||
proc doTransition(conf: NcliConf) =
|
proc doTransition(conf: NcliConf) =
|
||||||
let
|
let
|
||||||
stateY = (ref ForkedHashedBeaconState)(
|
cfg = getRuntimeConfig(conf.eth2Network)
|
||||||
phase0Data: phase0.HashedBeaconState(
|
stateY = newClone(readSszForkedHashedBeaconState(
|
||||||
data: loadFile(conf.preState, phase0.BeaconState)),
|
cfg, readAllBytes(conf.preState).tryGet()))
|
||||||
kind: BeaconStateFork.Phase0
|
blckX = readSszForkedSignedBeaconBlock(
|
||||||
)
|
cfg, readAllBytes(conf.blck).tryGet())
|
||||||
blckX = loadFile(conf.blck, phase0.SignedBeaconBlock)
|
|
||||||
flags = if not conf.verifyStateRoot: {skipStateRootValidation} else: {}
|
flags = if not conf.verifyStateRoot: {skipStateRootValidation} else: {}
|
||||||
|
|
||||||
setStateRoot(stateY[], hash_tree_root(stateY[].phase0Data.data))
|
|
||||||
|
|
||||||
var
|
var
|
||||||
cache = StateCache()
|
cache = StateCache()
|
||||||
info = ForkedEpochInfo()
|
info = ForkedEpochInfo()
|
||||||
let res = state_transition(
|
let res = withBlck(blckX):
|
||||||
getRuntimeConfig(conf.eth2Network), stateY[], blckX, cache, info,
|
state_transition(
|
||||||
flags, noRollback)
|
cfg, stateY[], blck, cache, info, flags, noRollback)
|
||||||
if res.isErr():
|
if res.isErr():
|
||||||
error "State transition failed", error = res.error()
|
error "State transition failed", error = res.error()
|
||||||
quit 1
|
quit 1
|
||||||
|
@ -131,14 +127,10 @@ proc doSlots(conf: NcliConf) =
|
||||||
|
|
||||||
var timers: array[Timers, RunningStat]
|
var timers: array[Timers, RunningStat]
|
||||||
let
|
let
|
||||||
stateY = withTimerRet(timers[tLoadState]): (ref ForkedHashedBeaconState)(
|
cfg = getRuntimeConfig(conf.eth2Network)
|
||||||
phase0Data: phase0.HashedBeaconState(
|
stateY = withTimerRet(timers[tLoadState]):
|
||||||
data: loadFile(conf.preState2, phase0.BeaconState)),
|
newClone(readSszForkedHashedBeaconState(
|
||||||
kind: BeaconStateFork.Phase0
|
cfg, readAllBytes(conf.preState2).tryGet()))
|
||||||
)
|
|
||||||
|
|
||||||
setStateRoot(stateY[], hash_tree_root(stateY[].phase0Data.data))
|
|
||||||
|
|
||||||
var
|
var
|
||||||
cache = StateCache()
|
cache = StateCache()
|
||||||
info = ForkedEpochInfo()
|
info = ForkedEpochInfo()
|
||||||
|
@ -146,11 +138,11 @@ proc doSlots(conf: NcliConf) =
|
||||||
let isEpoch = (getStateField(stateY[], slot) + 1).is_epoch
|
let isEpoch = (getStateField(stateY[], slot) + 1).is_epoch
|
||||||
withTimer(timers[if isEpoch: tApplyEpochSlot else: tApplySlot]):
|
withTimer(timers[if isEpoch: tApplyEpochSlot else: tApplySlot]):
|
||||||
process_slots(
|
process_slots(
|
||||||
defaultRuntimeConfig, stateY[], getStateField(stateY[], slot) + 1,
|
cfg, stateY[], getStateField(stateY[], slot) + 1,
|
||||||
cache, info, {}).expect("should be able to advance slot")
|
cache, info, {}).expect("should be able to advance slot")
|
||||||
|
|
||||||
withTimer(timers[tSaveState]):
|
withTimer(timers[tSaveState]):
|
||||||
saveSSZFile(conf.postState, stateY[])
|
saveSSZFile(conf.postState2, stateY[])
|
||||||
|
|
||||||
printTimers(false, timers)
|
printTimers(false, timers)
|
||||||
|
|
||||||
|
@ -200,7 +192,8 @@ proc doSSZ(conf: NcliConf) =
|
||||||
of "voluntary_exit": printit(VoluntaryExit)
|
of "voluntary_exit": printit(VoluntaryExit)
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
let conf = NcliConf.load()
|
let
|
||||||
|
conf = NcliConf.load()
|
||||||
|
|
||||||
case conf.cmd:
|
case conf.cmd:
|
||||||
of hashTreeRoot: doSSZ(conf)
|
of hashTreeRoot: doSSZ(conf)
|
||||||
|
|
Loading…
Reference in New Issue