2023-08-10 12:52:49 +00:00
|
|
|
# beacon_chain
|
2024-01-06 14:26:56 +00:00
|
|
|
# Copyright (c) 2020-2024 Status Research & Development GmbH
|
2023-08-10 12:52:49 +00:00
|
|
|
# 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).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2024-02-24 05:08:22 +00:00
|
|
|
{.push raises: [].}
|
|
|
|
|
2020-07-29 21:19:36 +00:00
|
|
|
import
|
2023-03-29 08:34:22 +00:00
|
|
|
confutils, json_serialization,
|
2022-05-31 07:07:09 +00:00
|
|
|
snappy,
|
2021-11-10 11:39:08 +00:00
|
|
|
../beacon_chain/spec/eth2_apis/eth2_rest_serialization,
|
2023-03-29 08:34:22 +00:00
|
|
|
../beacon_chain/spec/[eth2_ssz_serialization, state_transition]
|
|
|
|
|
|
|
|
from std/os import splitFile
|
|
|
|
from std/stats import RunningStat
|
2024-03-01 04:59:34 +00:00
|
|
|
from std/strutils import cmpIgnoreCase
|
2023-03-29 08:34:22 +00:00
|
|
|
from stew/byteutils import toHex
|
|
|
|
from stew/io2 import readAllBytes
|
|
|
|
from ../beacon_chain/networking/network_metadata import getRuntimeConfig
|
|
|
|
from ../research/simutils import printTimers, withTimer, withTimerRet
|
2020-07-29 21:19:36 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
Cmd* = enum
|
2024-03-01 04:59:34 +00:00
|
|
|
hash_tree_root = "Compute hash tree root of SSZ object"
|
2020-07-29 21:19:36 +00:00
|
|
|
pretty = "Pretty-print SSZ object"
|
|
|
|
transition = "Run state transition function"
|
improve slot processing speeds (#1670)
about 40% better slot processing times (with LTO enabled) - these don't
do BLS but are used
heavily during replay (state transition = slot + block transition)
tests using a recent medalla state and advancing it 1000 slots:
```
./ncli slots --preState2:state-302271-3c1dbf19-c1f944bf.ssz --slot:1000
--postState2:xx.ssz
```
pre:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
39.236, 0.000, 39.236, 39.236, 1,
Load state from file
0.049, 0.002, 0.046, 0.063, 968,
Apply slot
256.504, 81.008, 213.471, 591.902, 32,
Apply epoch slot
28.597, 0.000, 28.597, 28.597, 1,
Save state to file
```
cast:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
37.079, 0.000, 37.079, 37.079, 1,
Load state from file
0.042, 0.002, 0.040, 0.090, 968,
Apply slot
215.552, 68.763, 180.155, 500.103, 32,
Apply epoch slot
25.106, 0.000, 25.106, 25.106, 1,
Save state to file
```
cast+rewards:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
40.049, 0.000, 40.049, 40.049, 1,
Load state from file
0.048, 0.001, 0.045, 0.060, 968,
Apply slot
164.981, 76.273, 142.099, 477.868, 32,
Apply epoch slot
28.498, 0.000, 28.498, 28.498, 1,
Save state to file
```
cast+rewards+shr
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
12.898, 0.000, 12.898, 12.898, 1,
Load state from file
0.039, 0.002, 0.038, 0.054, 968,
Apply slot
139.971, 68.797, 120.088, 428.844, 32,
Apply epoch slot
24.761, 0.000, 24.761, 24.761, 1,
Save state to file
```
2020-09-16 20:59:33 +00:00
|
|
|
slots = "Apply empty slots"
|
2020-07-29 21:19:36 +00:00
|
|
|
|
|
|
|
NcliConf* = object
|
2020-09-01 09:01:57 +00:00
|
|
|
eth2Network* {.
|
|
|
|
desc: "The Eth2 network preset to use"
|
|
|
|
name: "network" }: Option[string]
|
|
|
|
|
2022-08-16 22:17:22 +00:00
|
|
|
printTimes* {.
|
|
|
|
defaultValue: false # false to avoid polluting minimal output
|
|
|
|
name: "print-times"
|
|
|
|
desc: "Print timing information".}: bool
|
|
|
|
|
2020-07-29 21:19:36 +00:00
|
|
|
# TODO confutils argument pragma doesn't seem to do much; also, the cases
|
|
|
|
# are largely equivalent, but this helps create command line usage text
|
|
|
|
case cmd* {.command}: Cmd
|
2024-03-01 04:59:34 +00:00
|
|
|
of hash_tree_root:
|
2020-07-29 21:19:36 +00:00
|
|
|
htrKind* {.
|
|
|
|
argument
|
|
|
|
desc: "kind of SSZ object: attester_slashing, attestation, signed_block, block, block_body, block_header, deposit, deposit_data, eth1_data, state, proposer_slashing, or voluntary_exit"}: string
|
|
|
|
|
|
|
|
htrFile* {.
|
|
|
|
argument
|
|
|
|
desc: "filename of SSZ or JSON-encoded object of which to compute hash tree root"}: string
|
|
|
|
|
|
|
|
of pretty:
|
|
|
|
prettyKind* {.
|
|
|
|
argument
|
|
|
|
desc: "kind of SSZ object: attester_slashing, attestation, signed_block, block, block_body, block_header, deposit, deposit_data, eth1_data, state, proposer_slashing, or voluntary_exit"}: string
|
|
|
|
|
|
|
|
prettyFile* {.
|
|
|
|
argument
|
|
|
|
desc: "filename of SSZ or JSON-encoded object to pretty-print"}: string
|
|
|
|
|
|
|
|
of transition:
|
|
|
|
preState* {.
|
|
|
|
argument
|
|
|
|
desc: "State to which to apply specified block"}: string
|
|
|
|
|
|
|
|
blck* {.
|
|
|
|
argument
|
|
|
|
desc: "Block to apply to preState"}: string
|
|
|
|
|
|
|
|
postState* {.
|
|
|
|
argument
|
|
|
|
desc: "Filename of state resulting from applying blck to preState"}: string
|
|
|
|
|
|
|
|
verifyStateRoot* {.
|
|
|
|
argument
|
|
|
|
desc: "Verify state root (default true)"
|
|
|
|
defaultValue: true}: bool
|
|
|
|
|
improve slot processing speeds (#1670)
about 40% better slot processing times (with LTO enabled) - these don't
do BLS but are used
heavily during replay (state transition = slot + block transition)
tests using a recent medalla state and advancing it 1000 slots:
```
./ncli slots --preState2:state-302271-3c1dbf19-c1f944bf.ssz --slot:1000
--postState2:xx.ssz
```
pre:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
39.236, 0.000, 39.236, 39.236, 1,
Load state from file
0.049, 0.002, 0.046, 0.063, 968,
Apply slot
256.504, 81.008, 213.471, 591.902, 32,
Apply epoch slot
28.597, 0.000, 28.597, 28.597, 1,
Save state to file
```
cast:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
37.079, 0.000, 37.079, 37.079, 1,
Load state from file
0.042, 0.002, 0.040, 0.090, 968,
Apply slot
215.552, 68.763, 180.155, 500.103, 32,
Apply epoch slot
25.106, 0.000, 25.106, 25.106, 1,
Save state to file
```
cast+rewards:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
40.049, 0.000, 40.049, 40.049, 1,
Load state from file
0.048, 0.001, 0.045, 0.060, 968,
Apply slot
164.981, 76.273, 142.099, 477.868, 32,
Apply epoch slot
28.498, 0.000, 28.498, 28.498, 1,
Save state to file
```
cast+rewards+shr
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
12.898, 0.000, 12.898, 12.898, 1,
Load state from file
0.039, 0.002, 0.038, 0.054, 968,
Apply slot
139.971, 68.797, 120.088, 428.844, 32,
Apply epoch slot
24.761, 0.000, 24.761, 24.761, 1,
Save state to file
```
2020-09-16 20:59:33 +00:00
|
|
|
of slots:
|
|
|
|
preState2* {.
|
|
|
|
argument
|
|
|
|
desc: "State to which to apply specified block"}: string
|
|
|
|
|
|
|
|
slot* {.
|
|
|
|
argument
|
|
|
|
desc: "Block to apply to preState"}: uint64
|
|
|
|
|
|
|
|
postState2* {.
|
|
|
|
argument
|
|
|
|
desc: "Filename of state resulting from applying blck to preState"}: string
|
|
|
|
|
2021-06-24 18:34:08 +00:00
|
|
|
template saveSSZFile(filename: string, value: ForkedHashedBeaconState) =
|
2024-02-24 05:08:22 +00:00
|
|
|
try:
|
|
|
|
case value.kind:
|
|
|
|
of ConsensusFork.Phase0: SSZ.saveFile(filename, value.phase0Data.data)
|
|
|
|
of ConsensusFork.Altair: SSZ.saveFile(filename, value.altairData.data)
|
|
|
|
of ConsensusFork.Bellatrix: SSZ.saveFile(filename, value.bellatrixData.data)
|
|
|
|
of ConsensusFork.Capella: SSZ.saveFile(filename, value.capellaData.data)
|
|
|
|
of ConsensusFork.Deneb: SSZ.saveFile(filename, value.denebData.data)
|
2024-04-05 19:30:06 +00:00
|
|
|
of ConsensusFork.Electra: SSZ.saveFile(filename, value.electraData.data)
|
2024-11-13 03:29:14 +00:00
|
|
|
of ConsensusFork.Fulu: SSZ.saveFile(filename, value.fuluData.data)
|
2024-02-24 05:08:22 +00:00
|
|
|
except IOError:
|
|
|
|
raiseAssert "error saving SSZ file"
|
2021-06-24 18:34:08 +00:00
|
|
|
|
2023-08-15 13:28:33 +00:00
|
|
|
proc loadFile(filename: string, bytes: openArray[byte], T: type): T =
|
2022-05-31 07:07:09 +00:00
|
|
|
let
|
|
|
|
ext = splitFile(filename).ext
|
2023-08-15 13:28:33 +00:00
|
|
|
|
2024-02-24 05:08:22 +00:00
|
|
|
try:
|
|
|
|
if cmpIgnoreCase(ext, ".ssz") == 0:
|
|
|
|
SSZ.decode(bytes, T)
|
|
|
|
elif cmpIgnoreCase(ext, ".ssz_snappy") == 0:
|
|
|
|
SSZ.decode(snappy.decode(bytes), T)
|
|
|
|
elif cmpIgnoreCase(ext, ".json") == 0:
|
|
|
|
# JSON.loadFile(file, t)
|
|
|
|
echo "TODO needs porting to RestJson"
|
|
|
|
quit 1
|
|
|
|
else:
|
|
|
|
echo "Unknown file type: ", ext
|
|
|
|
quit 1
|
|
|
|
except CatchableError:
|
|
|
|
echo "failed to load SSZ file"
|
2022-05-31 07:07:09 +00:00
|
|
|
quit 1
|
|
|
|
|
2020-07-29 21:19:36 +00:00
|
|
|
proc doTransition(conf: NcliConf) =
|
2022-08-16 22:17:22 +00:00
|
|
|
type
|
|
|
|
Timers = enum
|
|
|
|
tLoadState = "Load state from file"
|
|
|
|
tTransition = "Apply slot"
|
|
|
|
tSaveState = "Save state to file"
|
|
|
|
var timers: array[Timers, RunningStat]
|
|
|
|
|
2020-07-29 21:19:36 +00:00
|
|
|
let
|
2022-06-09 12:57:33 +00:00
|
|
|
cfg = getRuntimeConfig(conf.eth2Network)
|
2022-08-16 22:17:22 +00:00
|
|
|
stateY = withTimerRet(timers[tLoadState]):
|
2024-02-24 05:08:22 +00:00
|
|
|
try:
|
|
|
|
newClone(readSszForkedHashedBeaconState(
|
|
|
|
cfg, readAllBytes(conf.preState).tryGet()))
|
|
|
|
except CatchableError:
|
|
|
|
raiseAssert "error reading hashed beacon state"
|
|
|
|
blckX =
|
|
|
|
try:
|
|
|
|
readSszForkedSignedBeaconBlock(
|
|
|
|
cfg, readAllBytes(conf.blck).tryGet())
|
|
|
|
except CatchableError:
|
|
|
|
raiseAssert "error reading signed beacon block"
|
2020-07-29 21:19:36 +00:00
|
|
|
flags = if not conf.verifyStateRoot: {skipStateRootValidation} else: {}
|
|
|
|
|
2021-05-07 11:36:21 +00:00
|
|
|
var
|
|
|
|
cache = StateCache()
|
2021-10-13 14:24:36 +00:00
|
|
|
info = ForkedEpochInfo()
|
2022-08-16 22:17:22 +00:00
|
|
|
let res = withTimerRet(timers[tTransition]): withBlck(blckX):
|
2022-06-09 12:57:33 +00:00
|
|
|
state_transition(
|
2023-09-21 10:49:14 +00:00
|
|
|
cfg, stateY[], forkyBlck, cache, info, flags, noRollback)
|
2022-01-17 11:19:58 +00:00
|
|
|
if res.isErr():
|
|
|
|
error "State transition failed", error = res.error()
|
2020-07-29 21:19:36 +00:00
|
|
|
quit 1
|
|
|
|
else:
|
2022-08-16 22:17:22 +00:00
|
|
|
withTimer(timers[tSaveState]):
|
|
|
|
saveSSZFile(conf.postState, stateY[])
|
|
|
|
|
|
|
|
if conf.printTimes:
|
|
|
|
printTimers(false, timers)
|
2020-07-29 21:19:36 +00:00
|
|
|
|
improve slot processing speeds (#1670)
about 40% better slot processing times (with LTO enabled) - these don't
do BLS but are used
heavily during replay (state transition = slot + block transition)
tests using a recent medalla state and advancing it 1000 slots:
```
./ncli slots --preState2:state-302271-3c1dbf19-c1f944bf.ssz --slot:1000
--postState2:xx.ssz
```
pre:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
39.236, 0.000, 39.236, 39.236, 1,
Load state from file
0.049, 0.002, 0.046, 0.063, 968,
Apply slot
256.504, 81.008, 213.471, 591.902, 32,
Apply epoch slot
28.597, 0.000, 28.597, 28.597, 1,
Save state to file
```
cast:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
37.079, 0.000, 37.079, 37.079, 1,
Load state from file
0.042, 0.002, 0.040, 0.090, 968,
Apply slot
215.552, 68.763, 180.155, 500.103, 32,
Apply epoch slot
25.106, 0.000, 25.106, 25.106, 1,
Save state to file
```
cast+rewards:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
40.049, 0.000, 40.049, 40.049, 1,
Load state from file
0.048, 0.001, 0.045, 0.060, 968,
Apply slot
164.981, 76.273, 142.099, 477.868, 32,
Apply epoch slot
28.498, 0.000, 28.498, 28.498, 1,
Save state to file
```
cast+rewards+shr
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
12.898, 0.000, 12.898, 12.898, 1,
Load state from file
0.039, 0.002, 0.038, 0.054, 968,
Apply slot
139.971, 68.797, 120.088, 428.844, 32,
Apply epoch slot
24.761, 0.000, 24.761, 24.761, 1,
Save state to file
```
2020-09-16 20:59:33 +00:00
|
|
|
proc doSlots(conf: NcliConf) =
|
|
|
|
type
|
|
|
|
Timers = enum
|
|
|
|
tLoadState = "Load state from file"
|
|
|
|
tApplySlot = "Apply slot"
|
|
|
|
tApplyEpochSlot = "Apply epoch slot"
|
|
|
|
tSaveState = "Save state to file"
|
|
|
|
|
|
|
|
var timers: array[Timers, RunningStat]
|
|
|
|
let
|
2022-06-09 12:57:33 +00:00
|
|
|
cfg = getRuntimeConfig(conf.eth2Network)
|
|
|
|
stateY = withTimerRet(timers[tLoadState]):
|
2024-02-24 05:08:22 +00:00
|
|
|
try:
|
|
|
|
newClone(readSszForkedHashedBeaconState(
|
|
|
|
cfg, readAllBytes(conf.preState2).tryGet()))
|
|
|
|
except CatchableError:
|
|
|
|
raiseAssert "error reading hashed beacon state"
|
2021-05-07 11:36:21 +00:00
|
|
|
var
|
|
|
|
cache = StateCache()
|
2021-10-13 14:24:36 +00:00
|
|
|
info = ForkedEpochInfo()
|
improve slot processing speeds (#1670)
about 40% better slot processing times (with LTO enabled) - these don't
do BLS but are used
heavily during replay (state transition = slot + block transition)
tests using a recent medalla state and advancing it 1000 slots:
```
./ncli slots --preState2:state-302271-3c1dbf19-c1f944bf.ssz --slot:1000
--postState2:xx.ssz
```
pre:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
39.236, 0.000, 39.236, 39.236, 1,
Load state from file
0.049, 0.002, 0.046, 0.063, 968,
Apply slot
256.504, 81.008, 213.471, 591.902, 32,
Apply epoch slot
28.597, 0.000, 28.597, 28.597, 1,
Save state to file
```
cast:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
37.079, 0.000, 37.079, 37.079, 1,
Load state from file
0.042, 0.002, 0.040, 0.090, 968,
Apply slot
215.552, 68.763, 180.155, 500.103, 32,
Apply epoch slot
25.106, 0.000, 25.106, 25.106, 1,
Save state to file
```
cast+rewards:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
40.049, 0.000, 40.049, 40.049, 1,
Load state from file
0.048, 0.001, 0.045, 0.060, 968,
Apply slot
164.981, 76.273, 142.099, 477.868, 32,
Apply epoch slot
28.498, 0.000, 28.498, 28.498, 1,
Save state to file
```
cast+rewards+shr
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
12.898, 0.000, 12.898, 12.898, 1,
Load state from file
0.039, 0.002, 0.038, 0.054, 968,
Apply slot
139.971, 68.797, 120.088, 428.844, 32,
Apply epoch slot
24.761, 0.000, 24.761, 24.761, 1,
Save state to file
```
2020-09-16 20:59:33 +00:00
|
|
|
for i in 0'u64..<conf.slot:
|
2022-01-11 10:01:54 +00:00
|
|
|
let isEpoch = (getStateField(stateY[], slot) + 1).is_epoch
|
improve slot processing speeds (#1670)
about 40% better slot processing times (with LTO enabled) - these don't
do BLS but are used
heavily during replay (state transition = slot + block transition)
tests using a recent medalla state and advancing it 1000 slots:
```
./ncli slots --preState2:state-302271-3c1dbf19-c1f944bf.ssz --slot:1000
--postState2:xx.ssz
```
pre:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
39.236, 0.000, 39.236, 39.236, 1,
Load state from file
0.049, 0.002, 0.046, 0.063, 968,
Apply slot
256.504, 81.008, 213.471, 591.902, 32,
Apply epoch slot
28.597, 0.000, 28.597, 28.597, 1,
Save state to file
```
cast:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
37.079, 0.000, 37.079, 37.079, 1,
Load state from file
0.042, 0.002, 0.040, 0.090, 968,
Apply slot
215.552, 68.763, 180.155, 500.103, 32,
Apply epoch slot
25.106, 0.000, 25.106, 25.106, 1,
Save state to file
```
cast+rewards:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
40.049, 0.000, 40.049, 40.049, 1,
Load state from file
0.048, 0.001, 0.045, 0.060, 968,
Apply slot
164.981, 76.273, 142.099, 477.868, 32,
Apply epoch slot
28.498, 0.000, 28.498, 28.498, 1,
Save state to file
```
cast+rewards+shr
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
12.898, 0.000, 12.898, 12.898, 1,
Load state from file
0.039, 0.002, 0.038, 0.054, 968,
Apply slot
139.971, 68.797, 120.088, 428.844, 32,
Apply epoch slot
24.761, 0.000, 24.761, 24.761, 1,
Save state to file
```
2020-09-16 20:59:33 +00:00
|
|
|
withTimer(timers[if isEpoch: tApplyEpochSlot else: tApplySlot]):
|
2022-01-17 11:19:58 +00:00
|
|
|
process_slots(
|
2022-06-09 12:57:33 +00:00
|
|
|
cfg, stateY[], getStateField(stateY[], slot) + 1,
|
2022-01-17 11:19:58 +00:00
|
|
|
cache, info, {}).expect("should be able to advance slot")
|
improve slot processing speeds (#1670)
about 40% better slot processing times (with LTO enabled) - these don't
do BLS but are used
heavily during replay (state transition = slot + block transition)
tests using a recent medalla state and advancing it 1000 slots:
```
./ncli slots --preState2:state-302271-3c1dbf19-c1f944bf.ssz --slot:1000
--postState2:xx.ssz
```
pre:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
39.236, 0.000, 39.236, 39.236, 1,
Load state from file
0.049, 0.002, 0.046, 0.063, 968,
Apply slot
256.504, 81.008, 213.471, 591.902, 32,
Apply epoch slot
28.597, 0.000, 28.597, 28.597, 1,
Save state to file
```
cast:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
37.079, 0.000, 37.079, 37.079, 1,
Load state from file
0.042, 0.002, 0.040, 0.090, 968,
Apply slot
215.552, 68.763, 180.155, 500.103, 32,
Apply epoch slot
25.106, 0.000, 25.106, 25.106, 1,
Save state to file
```
cast+rewards:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
40.049, 0.000, 40.049, 40.049, 1,
Load state from file
0.048, 0.001, 0.045, 0.060, 968,
Apply slot
164.981, 76.273, 142.099, 477.868, 32,
Apply epoch slot
28.498, 0.000, 28.498, 28.498, 1,
Save state to file
```
cast+rewards+shr
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
12.898, 0.000, 12.898, 12.898, 1,
Load state from file
0.039, 0.002, 0.038, 0.054, 968,
Apply slot
139.971, 68.797, 120.088, 428.844, 32,
Apply epoch slot
24.761, 0.000, 24.761, 24.761, 1,
Save state to file
```
2020-09-16 20:59:33 +00:00
|
|
|
|
|
|
|
withTimer(timers[tSaveState]):
|
2022-06-09 12:57:33 +00:00
|
|
|
saveSSZFile(conf.postState2, stateY[])
|
improve slot processing speeds (#1670)
about 40% better slot processing times (with LTO enabled) - these don't
do BLS but are used
heavily during replay (state transition = slot + block transition)
tests using a recent medalla state and advancing it 1000 slots:
```
./ncli slots --preState2:state-302271-3c1dbf19-c1f944bf.ssz --slot:1000
--postState2:xx.ssz
```
pre:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
39.236, 0.000, 39.236, 39.236, 1,
Load state from file
0.049, 0.002, 0.046, 0.063, 968,
Apply slot
256.504, 81.008, 213.471, 591.902, 32,
Apply epoch slot
28.597, 0.000, 28.597, 28.597, 1,
Save state to file
```
cast:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
37.079, 0.000, 37.079, 37.079, 1,
Load state from file
0.042, 0.002, 0.040, 0.090, 968,
Apply slot
215.552, 68.763, 180.155, 500.103, 32,
Apply epoch slot
25.106, 0.000, 25.106, 25.106, 1,
Save state to file
```
cast+rewards:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
40.049, 0.000, 40.049, 40.049, 1,
Load state from file
0.048, 0.001, 0.045, 0.060, 968,
Apply slot
164.981, 76.273, 142.099, 477.868, 32,
Apply epoch slot
28.498, 0.000, 28.498, 28.498, 1,
Save state to file
```
cast+rewards+shr
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
12.898, 0.000, 12.898, 12.898, 1,
Load state from file
0.039, 0.002, 0.038, 0.054, 968,
Apply slot
139.971, 68.797, 120.088, 428.844, 32,
Apply epoch slot
24.761, 0.000, 24.761, 24.761, 1,
Save state to file
```
2020-09-16 20:59:33 +00:00
|
|
|
|
2022-08-16 22:17:22 +00:00
|
|
|
if conf.printTimes:
|
|
|
|
printTimers(false, timers)
|
improve slot processing speeds (#1670)
about 40% better slot processing times (with LTO enabled) - these don't
do BLS but are used
heavily during replay (state transition = slot + block transition)
tests using a recent medalla state and advancing it 1000 slots:
```
./ncli slots --preState2:state-302271-3c1dbf19-c1f944bf.ssz --slot:1000
--postState2:xx.ssz
```
pre:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
39.236, 0.000, 39.236, 39.236, 1,
Load state from file
0.049, 0.002, 0.046, 0.063, 968,
Apply slot
256.504, 81.008, 213.471, 591.902, 32,
Apply epoch slot
28.597, 0.000, 28.597, 28.597, 1,
Save state to file
```
cast:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
37.079, 0.000, 37.079, 37.079, 1,
Load state from file
0.042, 0.002, 0.040, 0.090, 968,
Apply slot
215.552, 68.763, 180.155, 500.103, 32,
Apply epoch slot
25.106, 0.000, 25.106, 25.106, 1,
Save state to file
```
cast+rewards:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
40.049, 0.000, 40.049, 40.049, 1,
Load state from file
0.048, 0.001, 0.045, 0.060, 968,
Apply slot
164.981, 76.273, 142.099, 477.868, 32,
Apply epoch slot
28.498, 0.000, 28.498, 28.498, 1,
Save state to file
```
cast+rewards+shr
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
12.898, 0.000, 12.898, 12.898, 1,
Load state from file
0.039, 0.002, 0.038, 0.054, 968,
Apply slot
139.971, 68.797, 120.088, 428.844, 32,
Apply epoch slot
24.761, 0.000, 24.761, 24.761, 1,
Save state to file
```
2020-09-16 20:59:33 +00:00
|
|
|
|
2020-07-29 21:19:36 +00:00
|
|
|
proc doSSZ(conf: NcliConf) =
|
2022-08-16 22:17:22 +00:00
|
|
|
type Timers = enum
|
|
|
|
tLoad = "Load file"
|
|
|
|
tCompute = "Compute"
|
|
|
|
var timers: array[Timers, RunningStat]
|
|
|
|
|
2020-07-29 21:19:36 +00:00
|
|
|
let (kind, file) =
|
|
|
|
case conf.cmd:
|
2024-03-01 04:59:34 +00:00
|
|
|
of hash_tree_root: (conf.htrKind, conf.htrFile)
|
2020-07-29 21:19:36 +00:00
|
|
|
of pretty: (conf.prettyKind, conf.prettyFile)
|
improve slot processing speeds (#1670)
about 40% better slot processing times (with LTO enabled) - these don't
do BLS but are used
heavily during replay (state transition = slot + block transition)
tests using a recent medalla state and advancing it 1000 slots:
```
./ncli slots --preState2:state-302271-3c1dbf19-c1f944bf.ssz --slot:1000
--postState2:xx.ssz
```
pre:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
39.236, 0.000, 39.236, 39.236, 1,
Load state from file
0.049, 0.002, 0.046, 0.063, 968,
Apply slot
256.504, 81.008, 213.471, 591.902, 32,
Apply epoch slot
28.597, 0.000, 28.597, 28.597, 1,
Save state to file
```
cast:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
37.079, 0.000, 37.079, 37.079, 1,
Load state from file
0.042, 0.002, 0.040, 0.090, 968,
Apply slot
215.552, 68.763, 180.155, 500.103, 32,
Apply epoch slot
25.106, 0.000, 25.106, 25.106, 1,
Save state to file
```
cast+rewards:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
40.049, 0.000, 40.049, 40.049, 1,
Load state from file
0.048, 0.001, 0.045, 0.060, 968,
Apply slot
164.981, 76.273, 142.099, 477.868, 32,
Apply epoch slot
28.498, 0.000, 28.498, 28.498, 1,
Save state to file
```
cast+rewards+shr
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
12.898, 0.000, 12.898, 12.898, 1,
Load state from file
0.039, 0.002, 0.038, 0.054, 968,
Apply slot
139.971, 68.797, 120.088, 428.844, 32,
Apply epoch slot
24.761, 0.000, 24.761, 24.761, 1,
Save state to file
```
2020-09-16 20:59:33 +00:00
|
|
|
else:
|
2020-07-29 21:19:36 +00:00
|
|
|
raiseAssert "doSSZ() only implements hashTreeRoot and pretty commands"
|
2023-08-15 13:28:33 +00:00
|
|
|
let bytes = readAllBytes(file).expect("file exists")
|
2020-07-29 21:19:36 +00:00
|
|
|
|
|
|
|
template printit(t: untyped) {.dirty.} =
|
2022-08-16 22:17:22 +00:00
|
|
|
|
|
|
|
let v = withTimerRet(timers[tLoad]):
|
2023-08-15 13:28:33 +00:00
|
|
|
newClone(loadFile(file, bytes, t))
|
2020-07-29 21:19:36 +00:00
|
|
|
|
|
|
|
case conf.cmd:
|
2024-03-01 04:59:34 +00:00
|
|
|
of hash_tree_root:
|
2022-08-16 22:17:22 +00:00
|
|
|
let root = withTimerRet(timers[tCompute]):
|
|
|
|
when t is ForkySignedBeaconBlock:
|
|
|
|
hash_tree_root(v[].message)
|
|
|
|
else:
|
|
|
|
hash_tree_root(v[])
|
|
|
|
|
|
|
|
echo root.data.toHex()
|
2020-07-29 21:19:36 +00:00
|
|
|
of pretty:
|
2021-11-10 11:39:08 +00:00
|
|
|
echo RestJson.encode(v[], pretty = true)
|
improve slot processing speeds (#1670)
about 40% better slot processing times (with LTO enabled) - these don't
do BLS but are used
heavily during replay (state transition = slot + block transition)
tests using a recent medalla state and advancing it 1000 slots:
```
./ncli slots --preState2:state-302271-3c1dbf19-c1f944bf.ssz --slot:1000
--postState2:xx.ssz
```
pre:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
39.236, 0.000, 39.236, 39.236, 1,
Load state from file
0.049, 0.002, 0.046, 0.063, 968,
Apply slot
256.504, 81.008, 213.471, 591.902, 32,
Apply epoch slot
28.597, 0.000, 28.597, 28.597, 1,
Save state to file
```
cast:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
37.079, 0.000, 37.079, 37.079, 1,
Load state from file
0.042, 0.002, 0.040, 0.090, 968,
Apply slot
215.552, 68.763, 180.155, 500.103, 32,
Apply epoch slot
25.106, 0.000, 25.106, 25.106, 1,
Save state to file
```
cast+rewards:
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
40.049, 0.000, 40.049, 40.049, 1,
Load state from file
0.048, 0.001, 0.045, 0.060, 968,
Apply slot
164.981, 76.273, 142.099, 477.868, 32,
Apply epoch slot
28.498, 0.000, 28.498, 28.498, 1,
Save state to file
```
cast+rewards+shr
```
All time are ms
Average, StdDev, Min, Max, Samples,
Test
Validation is turned off meaning that no BLS operations are performed
12.898, 0.000, 12.898, 12.898, 1,
Load state from file
0.039, 0.002, 0.038, 0.054, 968,
Apply slot
139.971, 68.797, 120.088, 428.844, 32,
Apply epoch slot
24.761, 0.000, 24.761, 24.761, 1,
Save state to file
```
2020-09-16 20:59:33 +00:00
|
|
|
else:
|
2020-07-29 21:19:36 +00:00
|
|
|
raiseAssert "doSSZ() only implements hashTreeRoot and pretty commands"
|
|
|
|
|
2022-08-16 22:17:22 +00:00
|
|
|
if conf.printTimes:
|
|
|
|
printTimers(false, timers)
|
2020-07-29 21:19:36 +00:00
|
|
|
|
|
|
|
case kind
|
2024-04-21 05:49:11 +00:00
|
|
|
of "attester_slashing": printit(phase0.AttesterSlashing)
|
2024-04-17 20:44:29 +00:00
|
|
|
of "attestation": printit(phase0.Attestation)
|
2021-11-10 11:39:08 +00:00
|
|
|
of "phase0_signed_block": printit(phase0.SignedBeaconBlock)
|
|
|
|
of "altair_signed_block": printit(altair.SignedBeaconBlock)
|
2022-01-18 16:31:05 +00:00
|
|
|
of "bellatrix_signed_block": printit(bellatrix.SignedBeaconBlock)
|
2023-03-29 08:34:22 +00:00
|
|
|
of "capella_signed_block": printit(capella.SignedBeaconBlock)
|
|
|
|
of "deneb_signed_block": printit(deneb.SignedBeaconBlock)
|
2024-05-21 23:59:11 +00:00
|
|
|
of "electra_signed_block": printit(electra.SignedBeaconBlock)
|
2024-11-13 03:29:14 +00:00
|
|
|
of "fulu_signed_block": printit(fulu.SignedBeaconBlock)
|
2021-11-10 11:39:08 +00:00
|
|
|
of "phase0_block": printit(phase0.BeaconBlock)
|
|
|
|
of "altair_block": printit(altair.BeaconBlock)
|
2022-01-18 16:31:05 +00:00
|
|
|
of "bellatrix_block": printit(bellatrix.BeaconBlock)
|
2023-03-29 08:34:22 +00:00
|
|
|
of "capella_block": printit(capella.BeaconBlock)
|
|
|
|
of "deneb_block": printit(deneb.BeaconBlock)
|
2024-05-21 23:59:11 +00:00
|
|
|
of "electra_block": printit(electra.BeaconBlock)
|
2024-11-13 03:29:14 +00:00
|
|
|
of "fulu_block": printit(fulu.BeaconBlock)
|
2021-11-10 11:39:08 +00:00
|
|
|
of "phase0_block_body": printit(phase0.BeaconBlockBody)
|
|
|
|
of "altair_block_body": printit(altair.BeaconBlockBody)
|
2022-01-18 16:31:05 +00:00
|
|
|
of "bellatrix_block_body": printit(bellatrix.BeaconBlockBody)
|
2023-03-29 08:34:22 +00:00
|
|
|
of "capella_block_body": printit(capella.BeaconBlockBody)
|
|
|
|
of "deneb_block_body": printit(deneb.BeaconBlockBody)
|
2024-05-21 23:59:11 +00:00
|
|
|
of "electra_block_body": printit(electra.BeaconBlockBody)
|
2024-11-13 03:29:14 +00:00
|
|
|
of "fulu_block_body": printit(fulu.BeaconBlockBody)
|
2020-07-29 21:19:36 +00:00
|
|
|
of "block_header": printit(BeaconBlockHeader)
|
|
|
|
of "deposit": printit(Deposit)
|
|
|
|
of "deposit_data": printit(DepositData)
|
|
|
|
of "eth1_data": printit(Eth1Data)
|
2021-11-10 11:39:08 +00:00
|
|
|
of "phase0_state": printit(phase0.BeaconState)
|
2022-08-16 22:17:22 +00:00
|
|
|
of "altair_state": printit(altair.BeaconState)
|
2022-01-18 16:31:05 +00:00
|
|
|
of "bellatrix_state": printit(bellatrix.BeaconState)
|
2023-03-29 08:34:22 +00:00
|
|
|
of "capella_state": printit(capella.BeaconState)
|
|
|
|
of "deneb_state": printit(deneb.BeaconState)
|
2024-05-21 23:59:11 +00:00
|
|
|
of "electra_state": printit(electra.BeaconState)
|
2024-11-13 03:29:14 +00:00
|
|
|
of "fulu_state": printit(fulu.BeaconState)
|
2020-07-29 21:19:36 +00:00
|
|
|
of "proposer_slashing": printit(ProposerSlashing)
|
|
|
|
of "voluntary_exit": printit(VoluntaryExit)
|
|
|
|
|
|
|
|
when isMainModule:
|
2022-06-09 12:57:33 +00:00
|
|
|
let
|
|
|
|
conf = NcliConf.load()
|
2020-07-29 21:19:36 +00:00
|
|
|
|
|
|
|
case conf.cmd:
|
2024-03-01 04:59:34 +00:00
|
|
|
of hash_tree_root: doSSZ(conf)
|
2020-07-29 21:19:36 +00:00
|
|
|
of pretty: doSSZ(conf)
|
|
|
|
of transition: doTransition(conf)
|
2024-04-03 14:43:43 +00:00
|
|
|
of slots: doSlots(conf)
|