2018-08-21 16:21:45 +00:00
|
|
|
# beacon_chain
|
2021-02-25 13:37:22 +00:00
|
|
|
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
2018-08-21 16:21:45 +00:00
|
|
|
# Licensed and distributed under either of
|
2019-11-25 15:30:02 +00:00
|
|
|
# * 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).
|
2018-08-21 16:21:45 +00:00
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2018-12-04 18:45:30 +00:00
|
|
|
# State transition, as described in
|
2021-09-30 01:07:24 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
2018-08-21 16:21:45 +00:00
|
|
|
#
|
2020-11-04 21:52:47 +00:00
|
|
|
# The entry point is `state_transition` which is at the bottom of the file!
|
2018-12-04 18:45:30 +00:00
|
|
|
#
|
2020-11-04 21:52:47 +00:00
|
|
|
# General notes about the code:
|
2018-12-04 18:45:30 +00:00
|
|
|
# * Weird styling - the sections taken from the spec use python styling while
|
|
|
|
# the others use NEP-1 - helps grepping identifiers in spec
|
2020-11-04 21:52:47 +00:00
|
|
|
# * When updating the code, add TODO sections to mark where there are clear
|
|
|
|
# improvements to be made - other than that, keep things similar to spec unless
|
|
|
|
# motivated by security or performance considerations
|
performance fixes (#2259)
* performance fixes
* don't mark tree cache as dirty on read-only List accesses
* store only blob in memory for keys and signatures, parse blob lazily
* compare public keys by blob instead of parsing / converting to raw
* compare Eth2Digest using non-constant-time comparison
* avoid some unnecessary validator copying
This branch will in particular speed up deposit processing which has
been slowing down block replay.
Pre (mainnet, 1600 blocks):
```
All time are ms
Average, StdDev, Min, Max, Samples, Test
Validation is turned off meaning that no BLS operations are performed
3450.269, 0.000, 3450.269, 3450.269, 1, Initialize DB
0.417, 0.822, 0.036, 21.098, 1400, Load block from database
16.521, 0.000, 16.521, 16.521, 1, Load state from database
27.906, 50.846, 8.104, 1507.633, 1350, Apply block
52.617, 37.029, 20.640, 135.938, 50, Apply epoch block
```
Post:
```
3502.715, 0.000, 3502.715, 3502.715, 1, Initialize DB
0.080, 0.560, 0.035, 21.015, 1400, Load block from database
17.595, 0.000, 17.595, 17.595, 1, Load state from database
15.706, 11.028, 8.300, 107.537, 1350, Apply block
33.217, 12.622, 17.331, 60.580, 50, Apply epoch block
```
* more perf fixes
* load EpochRef cache into StateCache more aggressively
* point out security concern with public key cache
* reuse proposer index from state when processing block
* avoid genericAssign in a few more places
* don't parse key when signature is unparseable
* fix `==` overload for Eth2Digest
* preallocate validator list when getting active validators
* speed up proposer index calculation a little bit
* reuse cache when replaying blocks in ncli_db
* avoid a few more copying loops
```
Average, StdDev, Min, Max, Samples, Test
Validation is turned off meaning that no BLS operations are performed
3279.158, 0.000, 3279.158, 3279.158, 1, Initialize DB
0.072, 0.357, 0.035, 13.400, 1400, Load block from database
17.295, 0.000, 17.295, 17.295, 1, Load state from database
5.918, 9.896, 0.198, 98.028, 1350, Apply block
15.888, 10.951, 7.902, 39.535, 50, Apply epoch block
0.000, 0.000, 0.000, 0.000, 0, Database block store
```
* clear full balance cache before processing rewards and penalties
```
All time are ms
Average, StdDev, Min, Max, Samples, Test
Validation is turned off meaning that no BLS operations are performed
3947.901, 0.000, 3947.901, 3947.901, 1, Initialize DB
0.124, 0.506, 0.026, 202.370, 363345, Load block from database
97.614, 0.000, 97.614, 97.614, 1, Load state from database
0.186, 0.188, 0.012, 99.561, 357262, Advance slot, non-epoch
14.161, 5.966, 1.099, 395.511, 11524, Advance slot, epoch
1.372, 4.170, 0.017, 276.401, 363345, Apply block, no slot processing
0.000, 0.000, 0.000, 0.000, 0, Database block store
```
2021-01-25 12:04:18 +00:00
|
|
|
#
|
|
|
|
# Performance notes:
|
|
|
|
# * The state transition is used in two contexts: to verify that incoming blocks
|
|
|
|
# are correct and to replay existing blocks from database. Incoming blocks
|
|
|
|
# are processed one-by-one while replay happens multiple blocks at a time.
|
|
|
|
# * Although signature verification is the slowest operation in the state
|
|
|
|
# state transition, we skip it during replay - this is also when we repeatedly
|
|
|
|
# call the state transition, making the non-signature part of the code
|
|
|
|
# important from a performance point of view.
|
|
|
|
# * It's important to start with a prefilled cache - generating the shuffled
|
|
|
|
# list of active validators is generally very slow.
|
|
|
|
# * Throughout, the code is affected by inefficient for loop codegen, meaning
|
|
|
|
# that we have to iterate over indices and pick out the value manually:
|
|
|
|
# https://github.com/nim-lang/Nim/issues/14421
|
|
|
|
# * Throughout, we're affected by inefficient `let` borrowing, meaning we
|
|
|
|
# often have to take the address of a sequence item due to the above - look
|
|
|
|
# for `let ... = unsafeAddr sequence[idx]`
|
|
|
|
# * Throughout, we're affected by the overloading rules that prefer a `var`
|
|
|
|
# overload to a non-var overload - look for `asSeq()` - when the `var`
|
|
|
|
# overload is used, the hash tree cache is cleared, which, aside from being
|
|
|
|
# slow itself, causes additional processing to recalculate the merkle tree.
|
2018-08-21 16:21:45 +00:00
|
|
|
|
2020-04-22 05:53:02 +00:00
|
|
|
{.push raises: [Defect].}
|
|
|
|
|
2018-09-26 16:26:39 +00:00
|
|
|
import
|
2020-11-27 22:16:13 +00:00
|
|
|
std/tables,
|
2020-04-11 17:41:50 +00:00
|
|
|
chronicles,
|
2020-05-03 17:44:04 +00:00
|
|
|
stew/results,
|
2021-08-12 13:08:20 +00:00
|
|
|
metrics,
|
|
|
|
../extras,
|
2021-09-27 14:22:58 +00:00
|
|
|
./datatypes/[phase0, altair, merge],
|
2021-08-12 13:08:20 +00:00
|
|
|
"."/[
|
2021-08-18 18:57:58 +00:00
|
|
|
beaconstate, eth2_merkleization, forks, helpers, signatures,
|
|
|
|
state_transition_block, state_transition_epoch, validator],
|
2020-06-23 13:54:24 +00:00
|
|
|
../../nbench/bench_lab
|
2018-12-13 16:00:55 +00:00
|
|
|
|
2021-08-12 13:08:20 +00:00
|
|
|
export extras, phase0, altair
|
|
|
|
|
2021-09-27 14:22:58 +00:00
|
|
|
type Foo = phase0.SignedBeaconBlock | altair.SignedBeaconBlock | phase0.TrustedSignedBeaconBlock | altair.TrustedSignedBeaconBlock | phase0.SigVerifiedSignedBeaconBlock | altair.SigVerifiedSignedBeaconBlock | merge.TrustedSignedBeaconBlock | merge.SigVerifiedSignedBeaconBlock | merge.SignedBeaconBlock
|
2021-05-28 15:25:58 +00:00
|
|
|
|
2021-09-30 01:07:24 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
2021-06-03 09:42:25 +00:00
|
|
|
proc verify_block_signature(
|
2021-05-28 15:25:58 +00:00
|
|
|
#state: SomeBeaconState, signed_block: SomeSomeSignedBeaconBlock): bool {.nbench.} =
|
|
|
|
state: SomeBeaconState, signed_block: Foo): bool {.nbench.} =
|
|
|
|
#state: SomeBeaconState, signed_block: phase0.SomeSignedBeaconBlock | altair.SomeSignedBeaconBlock): bool {.nbench.} =
|
2020-06-16 05:45:04 +00:00
|
|
|
let
|
|
|
|
proposer_index = signed_block.message.proposer_index
|
2020-07-26 18:55:48 +00:00
|
|
|
if proposer_index >= state.validators.lenu64:
|
2020-04-09 09:41:02 +00:00
|
|
|
notice "Invalid proposer index in block",
|
2020-06-16 05:45:04 +00:00
|
|
|
blck = shortLog(signed_block.message)
|
2020-04-09 09:41:02 +00:00
|
|
|
return false
|
|
|
|
|
2020-06-16 05:45:04 +00:00
|
|
|
if not verify_block_signature(
|
|
|
|
state.fork, state.genesis_validators_root, signed_block.message.slot,
|
|
|
|
signed_block.message, state.validators[proposer_index].pubkey,
|
|
|
|
signed_block.signature):
|
2020-04-09 09:41:02 +00:00
|
|
|
notice "Block: signature verification failed",
|
2020-06-16 05:45:04 +00:00
|
|
|
blck = shortLog(signedBlock)
|
2020-04-09 09:41:02 +00:00
|
|
|
return false
|
|
|
|
|
|
|
|
true
|
|
|
|
|
2021-09-30 01:07:24 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
2021-09-27 14:22:58 +00:00
|
|
|
proc verifyStateRoot(state: SomeBeaconState, blck: phase0.BeaconBlock or phase0.SigVerifiedBeaconBlock or altair.BeaconBlock or altair.SigVerifiedBeaconBlock or merge.BeaconBlock or merge.SigVerifiedBeaconBlock or merge.TrustedBeaconBlock): bool =
|
2019-09-05 19:52:34 +00:00
|
|
|
# This is inlined in state_transition(...) in spec.
|
2019-03-25 16:46:31 +00:00
|
|
|
let state_root = hash_tree_root(state)
|
2018-12-21 22:37:46 +00:00
|
|
|
if state_root != blck.state_root:
|
2019-01-25 17:35:22 +00:00
|
|
|
notice "Block: root verification failed",
|
2020-06-25 10:23:10 +00:00
|
|
|
block_state_root = shortLog(blck.state_root), state_root = shortLog(state_root)
|
2018-12-21 22:37:46 +00:00
|
|
|
false
|
|
|
|
else:
|
|
|
|
true
|
|
|
|
|
2021-06-03 09:42:25 +00:00
|
|
|
func verifyStateRoot(state: phase0.BeaconState, blck: phase0.TrustedBeaconBlock): bool =
|
2020-06-25 10:23:10 +00:00
|
|
|
# This is inlined in state_transition(...) in spec.
|
|
|
|
true
|
|
|
|
|
2021-06-04 10:38:00 +00:00
|
|
|
func verifyStateRoot(state: altair.BeaconState, blck: altair.TrustedBeaconBlock): bool =
|
|
|
|
# This is inlined in state_transition(...) in spec.
|
|
|
|
true
|
|
|
|
|
2021-09-27 14:22:58 +00:00
|
|
|
func verifyStateRoot(state: merge.BeaconState, blck: merge.TrustedBeaconBlock): bool =
|
|
|
|
# This is inlined in state_transition(...) in spec.
|
|
|
|
true
|
|
|
|
|
2021-06-04 10:38:00 +00:00
|
|
|
# one of these can happen on the fork block itself (it's a phase 0 block which
|
|
|
|
# creates an Altair state)
|
|
|
|
func verifyStateRoot(state: altair.BeaconState, blck: phase0.TrustedBeaconBlock): bool =
|
|
|
|
# This is inlined in state_transition(...) in spec.
|
|
|
|
true
|
|
|
|
|
2021-09-27 14:22:58 +00:00
|
|
|
func verifyStateRoot(state: merge.BeaconState, blck: phase0.TrustedBeaconBlock): bool =
|
|
|
|
# This is inlined in state_transition(...) in spec.
|
|
|
|
true
|
|
|
|
|
|
|
|
func verifyStateRoot(state: merge.BeaconState, blck: altair.TrustedBeaconBlock): bool =
|
|
|
|
# This is inlined in state_transition(...) in spec.
|
|
|
|
true
|
|
|
|
|
2021-06-04 10:38:00 +00:00
|
|
|
func verifyStateRoot(state: phase0.BeaconState, blck: altair.TrustedBeaconBlock): bool =
|
|
|
|
# This is inlined in state_transition(...) in spec.
|
|
|
|
true
|
|
|
|
|
2020-04-26 19:13:33 +00:00
|
|
|
type
|
2021-06-29 15:09:29 +00:00
|
|
|
RollbackProc* = proc() {.gcsafe, raises: [Defect].}
|
2020-04-26 19:13:33 +00:00
|
|
|
|
2021-06-29 15:09:29 +00:00
|
|
|
func noRollback*() =
|
|
|
|
trace "Skipping rollback of broken state"
|
2020-04-26 19:13:33 +00:00
|
|
|
|
2020-04-30 06:44:19 +00:00
|
|
|
type
|
2021-09-30 01:07:24 +00:00
|
|
|
RollbackHashedProc* = proc(state: var phase0.HashedBeaconState) {.gcsafe, raises: [Defect].}
|
2021-06-21 08:35:24 +00:00
|
|
|
RollbackAltairHashedProc* = proc(state: var altair.HashedBeaconState) {.gcsafe, raises: [Defect].}
|
2021-09-30 01:07:24 +00:00
|
|
|
RollbackMergeHashedProc* = proc(state: var merge.HashedBeaconState) {.gcsafe, raises: [Defect].}
|
2018-12-27 20:14:37 +00:00
|
|
|
|
2019-07-15 21:10:40 +00:00
|
|
|
# Hashed-state transition functions
|
|
|
|
# ---------------------------------------------------------------
|
2019-05-04 14:10:45 +00:00
|
|
|
|
2021-09-30 01:07:24 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.0.1/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
2021-05-05 06:54:21 +00:00
|
|
|
func process_slot*(
|
2021-05-28 15:25:58 +00:00
|
|
|
state: var SomeBeaconState, pre_state_root: Eth2Digest) {.nbench.} =
|
2021-05-05 06:54:21 +00:00
|
|
|
# `process_slot` is the first stage of per-slot processing - it is run for
|
|
|
|
# every slot, including epoch slots - it does not however update the slot
|
|
|
|
# number! `pre_state_root` refers to the state root of the incoming
|
|
|
|
# state before any slot processing has been done.
|
|
|
|
|
2019-06-14 07:50:14 +00:00
|
|
|
# Cache state root
|
2021-05-05 06:54:21 +00:00
|
|
|
state.state_roots[state.slot mod SLOTS_PER_HISTORICAL_ROOT] = pre_state_root
|
2019-05-04 14:10:45 +00:00
|
|
|
|
2019-06-14 07:50:14 +00:00
|
|
|
# Cache latest block header state root
|
2021-05-05 06:54:21 +00:00
|
|
|
if state.latest_block_header.state_root == ZERO_HASH:
|
|
|
|
state.latest_block_header.state_root = pre_state_root
|
2019-05-04 14:10:45 +00:00
|
|
|
|
2019-06-14 07:50:14 +00:00
|
|
|
# Cache block root
|
2021-05-05 06:54:21 +00:00
|
|
|
state.block_roots[state.slot mod SLOTS_PER_HISTORICAL_ROOT] =
|
|
|
|
hash_tree_root(state.latest_block_header)
|
2019-05-04 14:10:45 +00:00
|
|
|
|
2020-09-08 11:32:43 +00:00
|
|
|
func clear_epoch_from_cache(cache: var StateCache, epoch: Epoch) =
|
|
|
|
cache.shuffled_active_validator_indices.del epoch
|
|
|
|
let
|
|
|
|
start_slot = epoch.compute_start_slot_at_epoch
|
|
|
|
end_slot = (epoch + 1).compute_start_slot_at_epoch
|
|
|
|
|
|
|
|
for i in start_slot ..< end_slot:
|
|
|
|
cache.beacon_proposer_indices.del i
|
|
|
|
|
2021-09-30 01:07:24 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.0.1/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
2020-10-15 12:28:44 +00:00
|
|
|
proc advance_slot(
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
cfg: RuntimeConfig,
|
2021-05-28 15:25:58 +00:00
|
|
|
state: var SomeBeaconState, previous_slot_state_root: Eth2Digest,
|
2021-05-07 11:36:21 +00:00
|
|
|
flags: UpdateFlags, cache: var StateCache, rewards: var RewardInfo) {.nbench.} =
|
2021-05-05 06:54:21 +00:00
|
|
|
# Do the per-slot and potentially the per-epoch processing, then bump the
|
|
|
|
# slot number - we've now arrived at the slot state on top of which a block
|
|
|
|
# optionally can be applied.
|
|
|
|
process_slot(state, previous_slot_state_root)
|
|
|
|
|
2021-05-07 11:36:21 +00:00
|
|
|
rewards.statuses.setLen(0)
|
|
|
|
rewards.total_balances = TotalBalances()
|
|
|
|
|
2021-05-05 06:54:21 +00:00
|
|
|
let is_epoch_transition = (state.slot + 1).isEpoch
|
2020-05-03 17:44:04 +00:00
|
|
|
if is_epoch_transition:
|
|
|
|
# Note: Genesis epoch = 0, no need to test if before Genesis
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
process_epoch(cfg, state, flags, cache, rewards)
|
2021-05-05 06:54:21 +00:00
|
|
|
clear_epoch_from_cache(cache, (state.slot + 1).compute_epoch_at_slot)
|
2020-09-07 15:04:33 +00:00
|
|
|
|
2021-05-05 06:54:21 +00:00
|
|
|
state.slot += 1
|
2020-05-03 17:44:04 +00:00
|
|
|
|
2021-06-03 09:42:25 +00:00
|
|
|
func noRollback*(state: var phase0.HashedBeaconState) =
|
2021-06-21 08:35:24 +00:00
|
|
|
trace "Skipping rollback of broken phase 0 state"
|
|
|
|
|
|
|
|
func noRollback*(state: var altair.HashedBeaconState) =
|
|
|
|
trace "Skipping rollback of broken Altair state"
|
2019-05-04 14:10:45 +00:00
|
|
|
|
2021-09-30 01:07:24 +00:00
|
|
|
func noRollback*(state: var merge.HashedBeaconState) =
|
|
|
|
trace "Skipping rollback of broken Merge state"
|
|
|
|
|
|
|
|
proc maybeUpgradeStateToAltair(
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
cfg: RuntimeConfig, state: var ForkedHashedBeaconState) =
|
2021-06-11 17:51:46 +00:00
|
|
|
# Both process_slots() and state_transition_block() call this, so only run it
|
|
|
|
# once by checking for existing fork.
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
if getStateField(state, slot).epoch == cfg.ALTAIR_FORK_EPOCH and
|
2021-06-04 10:38:00 +00:00
|
|
|
state.beaconStateFork == forkPhase0:
|
2021-08-10 20:46:35 +00:00
|
|
|
var newState = upgrade_to_altair(cfg, state.hbsPhase0.data)
|
2021-06-11 17:51:46 +00:00
|
|
|
state = (ref ForkedHashedBeaconState)(
|
2021-06-04 10:38:00 +00:00
|
|
|
beaconStateFork: forkAltair,
|
|
|
|
hbsAltair: altair.HashedBeaconState(
|
2021-06-11 17:51:46 +00:00
|
|
|
root: hash_tree_root(newState[]), data: newState[]))[]
|
2021-06-04 10:38:00 +00:00
|
|
|
|
2021-09-30 01:07:24 +00:00
|
|
|
func maybeUpgradeStateToMerge(
|
|
|
|
cfg: RuntimeConfig, state: var ForkedHashedBeaconState) =
|
|
|
|
# Both process_slots() and state_transition_block() call this, so only run it
|
|
|
|
# once by checking for existing fork.
|
|
|
|
if getStateField(state, slot).epoch == cfg.MERGE_FORK_EPOCH and
|
|
|
|
state.beaconStateFork == forkAltair:
|
|
|
|
var newState = upgrade_to_merge(cfg, state.hbsAltair.data)
|
|
|
|
state = (ref ForkedHashedBeaconState)(
|
|
|
|
beaconStateFork: forkMerge,
|
|
|
|
hbsMerge: merge.HashedBeaconState(
|
|
|
|
root: hash_tree_root(newState[]), data: newState[]))[]
|
|
|
|
|
|
|
|
proc maybeUpgradeState*(
|
|
|
|
cfg: RuntimeConfig, state: var ForkedHashedBeaconState) =
|
|
|
|
cfg.maybeUpgradeStateToAltair(state)
|
|
|
|
cfg.maybeUpgradeStateToMerge(state)
|
|
|
|
|
2021-06-11 17:51:46 +00:00
|
|
|
proc process_slots*(
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
cfg: RuntimeConfig, state: var ForkedHashedBeaconState, slot: Slot,
|
|
|
|
cache: var StateCache, rewards: var RewardInfo, flags: UpdateFlags): bool {.nbench.} =
|
2021-06-11 17:51:46 +00:00
|
|
|
if not (getStateField(state, slot) < slot):
|
|
|
|
if slotProcessed notin flags or getStateField(state, slot) != slot:
|
|
|
|
notice "Unusual request for a slot in the past",
|
|
|
|
state_root = shortLog(getStateRoot(state)),
|
|
|
|
current_slot = getStateField(state, slot),
|
|
|
|
target_slot = slot
|
|
|
|
return false
|
2021-06-04 10:38:00 +00:00
|
|
|
|
|
|
|
# Update the state so its slot matches that of the block
|
|
|
|
while getStateField(state, slot) < slot:
|
2021-09-28 18:08:03 +00:00
|
|
|
withState(state):
|
2021-06-04 10:38:00 +00:00
|
|
|
advance_slot(
|
2021-09-28 18:08:03 +00:00
|
|
|
cfg, state.data, state.root, flags, cache, rewards)
|
2021-06-04 10:38:00 +00:00
|
|
|
|
2021-06-11 17:51:46 +00:00
|
|
|
if skipLastStateRootCalculation notin flags or
|
2021-09-28 18:08:03 +00:00
|
|
|
state.data.slot < slot:
|
2021-06-11 17:51:46 +00:00
|
|
|
# Don't update state root for the slot of the block if going to process
|
|
|
|
# block after
|
2021-09-28 18:08:03 +00:00
|
|
|
state.root = hash_tree_root(state.data)
|
2021-06-04 10:38:00 +00:00
|
|
|
|
2021-09-30 01:07:24 +00:00
|
|
|
maybeUpgradeState(cfg, state)
|
2021-06-04 10:38:00 +00:00
|
|
|
|
|
|
|
true
|
|
|
|
|
2021-06-11 17:51:46 +00:00
|
|
|
proc state_transition_block_aux(
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
cfg: RuntimeConfig,
|
2021-06-04 10:38:00 +00:00
|
|
|
state: var SomeHashedBeaconState,
|
|
|
|
signedBlock: phase0.SignedBeaconBlock | phase0.SigVerifiedSignedBeaconBlock |
|
2021-06-21 08:35:24 +00:00
|
|
|
phase0.TrustedSignedBeaconBlock | altair.SignedBeaconBlock |
|
2021-09-27 14:22:58 +00:00
|
|
|
altair.SigVerifiedSignedBeaconBlock | altair.TrustedSignedBeaconBlock |
|
|
|
|
merge.TrustedSignedBeaconBlock | merge.SigVerifiedSignedBeaconBlock |
|
|
|
|
merge.SignedBeaconBlock,
|
2021-06-11 17:51:46 +00:00
|
|
|
cache: var StateCache, flags: UpdateFlags): bool {.nbench.} =
|
2020-04-30 06:44:19 +00:00
|
|
|
# Block updates - these happen when there's a new block being suggested
|
|
|
|
# by the block proposer. Every actor in the network will update its state
|
|
|
|
# according to the contents of this block - but first they will validate
|
|
|
|
# that the block is sane.
|
2021-05-05 06:54:21 +00:00
|
|
|
if not (skipBLSValidation in flags or
|
|
|
|
verify_block_signature(state.data, signedBlock)):
|
|
|
|
return false
|
|
|
|
|
|
|
|
trace "state_transition: processing block, signature passed",
|
|
|
|
signature = shortLog(signedBlock.signature),
|
|
|
|
blockRoot = shortLog(signedBlock.root)
|
|
|
|
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
let res = process_block(cfg, state.data, signedBlock.message, flags, cache)
|
2021-05-05 06:54:21 +00:00
|
|
|
|
|
|
|
if not res.isOk():
|
|
|
|
debug "state_transition: process_block failed",
|
|
|
|
blck = shortLog(signedBlock.message),
|
|
|
|
slot = state.data.slot,
|
|
|
|
eth1_deposit_index = state.data.eth1_deposit_index,
|
|
|
|
deposit_root = shortLog(state.data.eth1_data.deposit_root),
|
|
|
|
error = res.error
|
|
|
|
return false
|
|
|
|
|
|
|
|
if not (skipStateRootValidation in flags or
|
|
|
|
verifyStateRoot(state.data, signedBlock.message)):
|
|
|
|
return false
|
|
|
|
|
|
|
|
# only blocks currently being produced have an empty state root - we use a
|
|
|
|
# separate function for those
|
|
|
|
doAssert signedBlock.message.state_root != Eth2Digest(),
|
|
|
|
"see makeBeaconBlock for block production"
|
|
|
|
state.root = signedBlock.message.state_root
|
|
|
|
|
|
|
|
true
|
2020-05-22 14:21:22 +00:00
|
|
|
|
2021-06-11 17:51:46 +00:00
|
|
|
type
|
|
|
|
RollbackForkedHashedProc* =
|
|
|
|
proc(state: var ForkedHashedBeaconState) {.gcsafe, raises: [Defect].}
|
|
|
|
|
|
|
|
func noRollback*(state: var ForkedHashedBeaconState) =
|
|
|
|
trace "Skipping rollback of broken state"
|
|
|
|
|
2021-06-04 10:38:00 +00:00
|
|
|
proc state_transition_block*(
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
cfg: RuntimeConfig,
|
2021-06-04 10:38:00 +00:00
|
|
|
state: var ForkedHashedBeaconState,
|
|
|
|
signedBlock: phase0.SignedBeaconBlock | phase0.SigVerifiedSignedBeaconBlock |
|
|
|
|
phase0.TrustedSignedBeaconBlock |
|
2021-07-14 12:18:52 +00:00
|
|
|
altair.SignedBeaconBlock | altair.SigVerifiedSignedBeaconBlock |
|
2021-09-27 14:22:58 +00:00
|
|
|
altair.TrustedSignedBeaconBlock | merge.TrustedSignedBeaconBlock |
|
|
|
|
merge.SigVerifiedSignedBeaconBlock | merge.SignedBeaconBlock,
|
2021-06-04 10:38:00 +00:00
|
|
|
cache: var StateCache, flags: UpdateFlags,
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
rollback: RollbackForkedHashedProc): bool {.nbench.} =
|
2021-06-04 10:38:00 +00:00
|
|
|
## `rollback` is called if the transition fails and the given state has been
|
|
|
|
## partially changed. If a temporary state was given to `state_transition`,
|
|
|
|
## it is safe to use `noRollback` and leave it broken, else the state
|
|
|
|
## object should be rolled back to a consistent state. If the transition fails
|
|
|
|
## before the state has been updated, `rollback` will not be called.
|
2021-06-11 17:51:46 +00:00
|
|
|
doAssert not rollback.isNil, "use noRollback if it's ok to mess up state"
|
2021-06-04 10:38:00 +00:00
|
|
|
|
|
|
|
# Ensure state_transition_block()-only callers trigger this
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
maybeUpgradeStateToAltair(cfg, state)
|
2021-06-04 10:38:00 +00:00
|
|
|
|
2021-09-28 18:08:03 +00:00
|
|
|
let success = withState(state):
|
|
|
|
state_transition_block_aux(cfg, state, signedBlock, cache, flags)
|
2021-06-11 17:51:46 +00:00
|
|
|
|
|
|
|
if not success:
|
|
|
|
rollback(state)
|
|
|
|
return false
|
|
|
|
|
|
|
|
true
|
2021-06-04 10:38:00 +00:00
|
|
|
|
2021-06-03 09:42:25 +00:00
|
|
|
proc state_transition*(
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
cfg: RuntimeConfig,
|
2021-06-04 10:38:00 +00:00
|
|
|
state: var ForkedHashedBeaconState,
|
|
|
|
signedBlock: phase0.SignedBeaconBlock | phase0.SigVerifiedSignedBeaconBlock |
|
2021-07-14 12:18:52 +00:00
|
|
|
phase0.TrustedSignedBeaconBlock | altair.SignedBeaconBlock |
|
2021-09-27 14:22:58 +00:00
|
|
|
altair.TrustedSignedBeaconBlock | merge.TrustedSignedBeaconBlock |
|
|
|
|
merge.SignedBeaconBlock,
|
2021-06-03 09:42:25 +00:00
|
|
|
cache: var StateCache, rewards: var RewardInfo, flags: UpdateFlags,
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
rollback: RollbackForkedHashedProc): bool {.nbench.} =
|
2021-06-04 10:38:00 +00:00
|
|
|
## Apply a block to the state, advancing the slot counter as necessary. The
|
|
|
|
## given state must be of a lower slot, or, in case the `slotProcessed` flag
|
|
|
|
## is set, can be the slot state of the same slot as the block (where the
|
|
|
|
## slot state is the state without any block applied). To create a slot state,
|
|
|
|
## advance the state corresponding to the the parent block using
|
|
|
|
## `process_slots`.
|
|
|
|
##
|
|
|
|
## To run the state transition function in preparation for block production,
|
|
|
|
## use `makeBeaconBlock` instead.
|
|
|
|
##
|
|
|
|
## `rollback` is called if the transition fails and the given state has been
|
|
|
|
## partially changed. If a temporary state was given to `state_transition`,
|
|
|
|
## it is safe to use `noRollback` and leave it broken, else the state
|
|
|
|
## object should be rolled back to a consistent state. If the transition fails
|
|
|
|
## before the state has been updated, `rollback` will not be called.
|
2021-06-11 17:51:46 +00:00
|
|
|
if not process_slots(
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
cfg, state, signedBlock.message.slot, cache, rewards,
|
|
|
|
flags + {skipLastStateRootCalculation}):
|
2021-06-03 09:42:25 +00:00
|
|
|
return false
|
2021-06-04 10:38:00 +00:00
|
|
|
state_transition_block(
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
cfg, state, signedBlock, cache, flags, rollback)
|
2021-06-03 09:42:25 +00:00
|
|
|
|
2021-09-30 01:07:24 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.0.1/specs/phase0/validator.md#preparing-for-a-beaconblock
|
2021-09-29 12:10:44 +00:00
|
|
|
template partialBeaconBlock(
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
cfg: RuntimeConfig,
|
2021-05-28 15:25:58 +00:00
|
|
|
state: var phase0.HashedBeaconState,
|
2020-05-22 14:21:22 +00:00
|
|
|
proposer_index: ValidatorIndex,
|
|
|
|
parent_root: Eth2Digest,
|
|
|
|
randao_reveal: ValidatorSig,
|
|
|
|
eth1_data: Eth1Data,
|
2020-06-29 17:30:19 +00:00
|
|
|
graffiti: GraffitiBytes,
|
2020-05-22 14:21:22 +00:00
|
|
|
attestations: seq[Attestation],
|
|
|
|
deposits: seq[Deposit],
|
2020-10-07 16:57:21 +00:00
|
|
|
proposerSlashings: seq[ProposerSlashing],
|
|
|
|
attesterSlashings: seq[AttesterSlashing],
|
|
|
|
voluntaryExits: seq[SignedVoluntaryExit],
|
2021-09-29 12:10:44 +00:00
|
|
|
sync_aggregate: SyncAggregate,
|
|
|
|
executionPayload: ExecutionPayload): phase0.BeaconBlock =
|
|
|
|
phase0.BeaconBlock(
|
2020-05-22 14:21:22 +00:00
|
|
|
slot: state.data.slot,
|
|
|
|
proposer_index: proposer_index.uint64,
|
|
|
|
parent_root: parent_root,
|
2021-05-28 15:25:58 +00:00
|
|
|
body: phase0.BeaconBlockBody(
|
2020-05-22 14:21:22 +00:00
|
|
|
randao_reveal: randao_reveal,
|
|
|
|
eth1_data: eth1data,
|
|
|
|
graffiti: graffiti,
|
2020-10-07 16:57:21 +00:00
|
|
|
proposer_slashings: List[ProposerSlashing, Limit MAX_PROPOSER_SLASHINGS](
|
|
|
|
proposerSlashings),
|
|
|
|
attester_slashings: List[AttesterSlashing, Limit MAX_ATTESTER_SLASHINGS](
|
|
|
|
attesterSlashings),
|
2020-07-13 14:44:58 +00:00
|
|
|
attestations: List[Attestation, Limit MAX_ATTESTATIONS](attestations),
|
2020-10-07 16:57:21 +00:00
|
|
|
deposits: List[Deposit, Limit MAX_DEPOSITS](deposits),
|
|
|
|
voluntary_exits:
|
|
|
|
List[SignedVoluntaryExit, Limit MAX_VOLUNTARY_EXITS](voluntaryExits)))
|
2020-05-22 14:21:22 +00:00
|
|
|
|
2021-09-29 12:10:44 +00:00
|
|
|
proc makeBeaconBlock*(
|
|
|
|
cfg: RuntimeConfig,
|
|
|
|
state: var phase0.HashedBeaconState,
|
|
|
|
proposer_index: ValidatorIndex,
|
|
|
|
parent_root: Eth2Digest,
|
|
|
|
randao_reveal: ValidatorSig,
|
|
|
|
eth1_data: Eth1Data,
|
|
|
|
graffiti: GraffitiBytes,
|
|
|
|
attestations: seq[Attestation],
|
|
|
|
deposits: seq[Deposit],
|
|
|
|
proposerSlashings: seq[ProposerSlashing],
|
|
|
|
attesterSlashings: seq[AttesterSlashing],
|
|
|
|
voluntaryExits: seq[SignedVoluntaryExit],
|
|
|
|
sync_aggregate: SyncAggregate,
|
|
|
|
executionPayload: ExecutionPayload,
|
|
|
|
rollback: RollbackHashedProc,
|
|
|
|
cache: var StateCache): Result[phase0.BeaconBlock, string] =
|
|
|
|
## Create a block for the given state. The last block applied to it must be
|
|
|
|
## the one identified by parent_root and process_slots must be called up to
|
|
|
|
## the slot for which a block is to be created.
|
|
|
|
|
|
|
|
# To create a block, we'll first apply a partial block to the state, skipping
|
|
|
|
# some validations.
|
|
|
|
|
2021-09-30 01:07:24 +00:00
|
|
|
var blck = partialBeaconBlock(cfg, state, proposer_index, parent_root,
|
|
|
|
randao_reveal, eth1_data, graffiti, attestations, deposits,
|
2021-09-29 12:10:44 +00:00
|
|
|
proposerSlashings, attesterSlashings, voluntaryExits,
|
|
|
|
sync_aggregate, executionPayload)
|
|
|
|
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
let res = process_block(cfg, state.data, blck, {skipBlsValidation}, cache)
|
2020-05-22 14:21:22 +00:00
|
|
|
|
2020-12-02 12:23:10 +00:00
|
|
|
if res.isErr:
|
|
|
|
warn "Unable to apply new block to state",
|
|
|
|
blck = shortLog(blck),
|
|
|
|
slot = state.data.slot,
|
|
|
|
eth1_deposit_index = state.data.eth1_deposit_index,
|
|
|
|
deposit_root = shortLog(state.data.eth1_data.deposit_root),
|
|
|
|
error = res.error
|
2020-05-22 14:21:22 +00:00
|
|
|
rollback(state)
|
2021-08-27 09:00:06 +00:00
|
|
|
return err("Unable to apply new block to state: " & $res.error())
|
2020-05-22 14:21:22 +00:00
|
|
|
|
|
|
|
state.root = hash_tree_root(state.data)
|
|
|
|
blck.state_root = state.root
|
2021-08-27 09:00:06 +00:00
|
|
|
ok(blck)
|
2021-06-21 08:35:24 +00:00
|
|
|
|
2021-09-30 01:07:24 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.0-alpha.7/specs/altair/validator.md#preparing-a-beaconblock
|
2021-09-29 12:10:44 +00:00
|
|
|
template partialBeaconBlock(
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
cfg: RuntimeConfig,
|
2021-06-21 08:35:24 +00:00
|
|
|
state: var altair.HashedBeaconState,
|
|
|
|
proposer_index: ValidatorIndex,
|
|
|
|
parent_root: Eth2Digest,
|
|
|
|
randao_reveal: ValidatorSig,
|
|
|
|
eth1_data: Eth1Data,
|
|
|
|
graffiti: GraffitiBytes,
|
|
|
|
attestations: seq[Attestation],
|
|
|
|
deposits: seq[Deposit],
|
|
|
|
proposerSlashings: seq[ProposerSlashing],
|
|
|
|
attesterSlashings: seq[AttesterSlashing],
|
|
|
|
voluntaryExits: seq[SignedVoluntaryExit],
|
2021-08-29 14:50:21 +00:00
|
|
|
sync_aggregate: SyncAggregate,
|
2021-09-29 12:10:44 +00:00
|
|
|
executionPayload: ExecutionPayload): altair.BeaconBlock =
|
|
|
|
altair.BeaconBlock(
|
2021-06-21 08:35:24 +00:00
|
|
|
slot: state.data.slot,
|
|
|
|
proposer_index: proposer_index.uint64,
|
|
|
|
parent_root: parent_root,
|
|
|
|
body: altair.BeaconBlockBody(
|
|
|
|
randao_reveal: randao_reveal,
|
|
|
|
eth1_data: eth1data,
|
|
|
|
graffiti: graffiti,
|
|
|
|
proposer_slashings: List[ProposerSlashing, Limit MAX_PROPOSER_SLASHINGS](
|
|
|
|
proposerSlashings),
|
|
|
|
attester_slashings: List[AttesterSlashing, Limit MAX_ATTESTER_SLASHINGS](
|
|
|
|
attesterSlashings),
|
|
|
|
attestations: List[Attestation, Limit MAX_ATTESTATIONS](attestations),
|
|
|
|
deposits: List[Deposit, Limit MAX_DEPOSITS](deposits),
|
|
|
|
voluntary_exits:
|
2021-07-27 14:04:41 +00:00
|
|
|
List[SignedVoluntaryExit, Limit MAX_VOLUNTARY_EXITS](voluntaryExits),
|
2021-08-29 14:50:21 +00:00
|
|
|
sync_aggregate: sync_aggregate))
|
2021-06-21 08:35:24 +00:00
|
|
|
|
2021-09-29 12:10:44 +00:00
|
|
|
proc makeBeaconBlock*(
|
|
|
|
cfg: RuntimeConfig,
|
|
|
|
state: var altair.HashedBeaconState,
|
|
|
|
proposer_index: ValidatorIndex,
|
|
|
|
parent_root: Eth2Digest,
|
|
|
|
randao_reveal: ValidatorSig,
|
|
|
|
eth1_data: Eth1Data,
|
|
|
|
graffiti: GraffitiBytes,
|
|
|
|
attestations: seq[Attestation],
|
|
|
|
deposits: seq[Deposit],
|
|
|
|
proposerSlashings: seq[ProposerSlashing],
|
|
|
|
attesterSlashings: seq[AttesterSlashing],
|
|
|
|
voluntaryExits: seq[SignedVoluntaryExit],
|
|
|
|
sync_aggregate: SyncAggregate,
|
|
|
|
executionPayload: ExecutionPayload,
|
|
|
|
rollback: RollbackAltairHashedProc,
|
|
|
|
cache: var StateCache): Result[altair.BeaconBlock, string] =
|
|
|
|
## Create a block for the given state. The last block applied to it must be
|
|
|
|
## the one identified by parent_root and process_slots must be called up to
|
|
|
|
## the slot for which a block is to be created.
|
|
|
|
|
|
|
|
# To create a block, we'll first apply a partial block to the state, skipping
|
|
|
|
# some validations.
|
|
|
|
|
|
|
|
var blck = partialBeaconBlock(cfg, state, proposer_index, parent_root,
|
|
|
|
randao_reveal, eth1_data, graffiti, attestations, deposits,
|
|
|
|
proposerSlashings, attesterSlashings, voluntaryExits,
|
|
|
|
sync_aggregate, executionPayload)
|
|
|
|
|
Implement split preset/config support (#2710)
* Implement split preset/config support
This is the initial bulk refactor to introduce runtime config values in
a number of places, somewhat replacing the existing mechanism of loading
network metadata.
It still needs more work, this is the initial refactor that introduces
runtime configuration in some of the places that need it.
The PR changes the way presets and constants work, to match the spec. In
particular, a "preset" now refers to the compile-time configuration
while a "cfg" or "RuntimeConfig" is the dynamic part.
A single binary can support either mainnet or minimal, but not both.
Support for other presets has been removed completely (can be readded,
in case there's need).
There's a number of outstanding tasks:
* `SECONDS_PER_SLOT` still needs fixing
* loading custom runtime configs needs redoing
* checking constants against YAML file
* yeerongpilly support
`build/nimbus_beacon_node --network=yeerongpilly --discv5:no --log-level=DEBUG`
* load fork epoch from config
* fix fork digest sent in status
* nicer error string for request failures
* fix tools
* one more
* fixup
* fixup
* fixup
* use "standard" network definition folder in local testnet
Files are loaded from their standard locations, including genesis etc,
to conform to the format used in the `eth2-networks` repo.
* fix launch scripts, allow unknown config values
* fix base config of rest test
* cleanups
* bundle mainnet config using common loader
* fix spec links and names
* only include supported preset in binary
* drop yeerongpilly, add altair-devnet-0, support boot_enr.yaml
2021-07-12 13:01:38 +00:00
|
|
|
let res = process_block(cfg, state.data, blck, {skipBlsValidation}, cache)
|
2021-06-21 08:35:24 +00:00
|
|
|
|
|
|
|
if res.isErr:
|
|
|
|
warn "Unable to apply new block to state",
|
|
|
|
blck = shortLog(blck),
|
|
|
|
slot = state.data.slot,
|
|
|
|
eth1_deposit_index = state.data.eth1_deposit_index,
|
|
|
|
deposit_root = shortLog(state.data.eth1_data.deposit_root),
|
|
|
|
error = res.error
|
|
|
|
rollback(state)
|
2021-08-27 09:00:06 +00:00
|
|
|
return err("Unable to apply new block to state: " & $res.error())
|
2021-06-21 08:35:24 +00:00
|
|
|
|
|
|
|
state.root = hash_tree_root(state.data)
|
|
|
|
blck.state_root = state.root
|
2021-08-27 09:00:06 +00:00
|
|
|
ok(blck)
|
2021-09-29 12:10:44 +00:00
|
|
|
|
2021-09-30 01:07:24 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/merge/validator.md#block-proposal
|
|
|
|
template partialBeaconBlock(
|
|
|
|
cfg: RuntimeConfig,
|
|
|
|
state: var merge.HashedBeaconState,
|
|
|
|
proposer_index: ValidatorIndex,
|
|
|
|
parent_root: Eth2Digest,
|
|
|
|
randao_reveal: ValidatorSig,
|
|
|
|
eth1_data: Eth1Data,
|
|
|
|
graffiti: GraffitiBytes,
|
|
|
|
attestations: seq[Attestation],
|
|
|
|
deposits: seq[Deposit],
|
|
|
|
proposerSlashings: seq[ProposerSlashing],
|
|
|
|
attesterSlashings: seq[AttesterSlashing],
|
|
|
|
voluntaryExits: seq[SignedVoluntaryExit],
|
|
|
|
sync_aggregate: SyncAggregate,
|
|
|
|
executionPayload: ExecutionPayload): merge.BeaconBlock =
|
|
|
|
merge.BeaconBlock(
|
|
|
|
slot: state.data.slot,
|
|
|
|
proposer_index: proposer_index.uint64,
|
|
|
|
parent_root: parent_root,
|
|
|
|
body: merge.BeaconBlockBody(
|
|
|
|
randao_reveal: randao_reveal,
|
|
|
|
eth1_data: eth1data,
|
|
|
|
graffiti: graffiti,
|
|
|
|
proposer_slashings: List[ProposerSlashing, Limit MAX_PROPOSER_SLASHINGS](
|
|
|
|
proposerSlashings),
|
|
|
|
attester_slashings: List[AttesterSlashing, Limit MAX_ATTESTER_SLASHINGS](
|
|
|
|
attesterSlashings),
|
|
|
|
attestations: List[Attestation, Limit MAX_ATTESTATIONS](attestations),
|
|
|
|
deposits: List[Deposit, Limit MAX_DEPOSITS](deposits),
|
|
|
|
voluntary_exits:
|
|
|
|
List[SignedVoluntaryExit, Limit MAX_VOLUNTARY_EXITS](voluntaryExits),
|
|
|
|
sync_aggregate: sync_aggregate))
|
|
|
|
|
|
|
|
proc makeBeaconBlock*(
|
|
|
|
cfg: RuntimeConfig,
|
|
|
|
state: var merge.HashedBeaconState,
|
|
|
|
proposer_index: ValidatorIndex,
|
|
|
|
parent_root: Eth2Digest,
|
|
|
|
randao_reveal: ValidatorSig,
|
|
|
|
eth1_data: Eth1Data,
|
|
|
|
graffiti: GraffitiBytes,
|
|
|
|
attestations: seq[Attestation],
|
|
|
|
deposits: seq[Deposit],
|
|
|
|
proposerSlashings: seq[ProposerSlashing],
|
|
|
|
attesterSlashings: seq[AttesterSlashing],
|
|
|
|
voluntaryExits: seq[SignedVoluntaryExit],
|
|
|
|
sync_aggregate: SyncAggregate,
|
|
|
|
executionPayload: ExecutionPayload,
|
|
|
|
rollback: RollbackMergeHashedProc,
|
|
|
|
cache: var StateCache): Result[merge.BeaconBlock, string] =
|
|
|
|
## Create a block for the given state. The last block applied to it must be
|
|
|
|
## the one identified by parent_root and process_slots must be called up to
|
|
|
|
## the slot for which a block is to be created.
|
|
|
|
|
|
|
|
# To create a block, we'll first apply a partial block to the state, skipping
|
|
|
|
# some validations.
|
|
|
|
|
|
|
|
var blck = partialBeaconBlock(cfg, state, proposer_index, parent_root,
|
|
|
|
randao_reveal, eth1_data, graffiti, attestations, deposits,
|
|
|
|
proposerSlashings, attesterSlashings, voluntaryExits,
|
|
|
|
sync_aggregate, executionPayload)
|
|
|
|
|
|
|
|
let res = process_block(cfg, state.data, blck, {skipBlsValidation}, cache)
|
|
|
|
|
|
|
|
if res.isErr:
|
|
|
|
warn "Unable to apply new block to state",
|
|
|
|
blck = shortLog(blck),
|
|
|
|
slot = state.data.slot,
|
|
|
|
eth1_deposit_index = state.data.eth1_deposit_index,
|
|
|
|
deposit_root = shortLog(state.data.eth1_data.deposit_root),
|
|
|
|
error = res.error
|
|
|
|
rollback(state)
|
|
|
|
return err("Unable to apply new block to state: " & $res.error())
|
|
|
|
|
|
|
|
state.root = hash_tree_root(state.data)
|
|
|
|
blck.state_root = state.root
|
|
|
|
ok(blck)
|
|
|
|
|
2021-09-29 12:10:44 +00:00
|
|
|
proc makeBeaconBlock*(
|
|
|
|
cfg: RuntimeConfig,
|
|
|
|
state: var ForkedHashedBeaconState,
|
|
|
|
proposer_index: ValidatorIndex,
|
|
|
|
parent_root: Eth2Digest,
|
|
|
|
randao_reveal: ValidatorSig,
|
|
|
|
eth1_data: Eth1Data,
|
|
|
|
graffiti: GraffitiBytes,
|
|
|
|
attestations: seq[Attestation],
|
|
|
|
deposits: seq[Deposit],
|
|
|
|
proposerSlashings: seq[ProposerSlashing],
|
|
|
|
attesterSlashings: seq[AttesterSlashing],
|
|
|
|
voluntaryExits: seq[SignedVoluntaryExit],
|
|
|
|
sync_aggregate: SyncAggregate,
|
|
|
|
executionPayload: ExecutionPayload,
|
|
|
|
rollback: RollbackForkedHashedProc,
|
|
|
|
cache: var StateCache): Result[ForkedBeaconBlock, string] =
|
|
|
|
## Create a block for the given state. The last block applied to it must be
|
|
|
|
## the one identified by parent_root and process_slots must be called up to
|
|
|
|
## the slot for which a block is to be created.
|
|
|
|
|
|
|
|
template makeBeaconBlock(kind: untyped): Result[ForkedBeaconBlock, string] =
|
|
|
|
# To create a block, we'll first apply a partial block to the state, skipping
|
|
|
|
# some validations.
|
|
|
|
|
|
|
|
var blck =
|
|
|
|
ForkedBeaconBlock.init(
|
|
|
|
partialBeaconBlock(cfg, state.`hbs kind`, proposer_index, parent_root,
|
|
|
|
randao_reveal, eth1_data, graffiti, attestations, deposits,
|
|
|
|
proposerSlashings, attesterSlashings, voluntaryExits,
|
|
|
|
sync_aggregate, executionPayload))
|
|
|
|
|
|
|
|
let res = process_block(cfg, state.`hbs kind`.data, blck.`kind Block`,
|
|
|
|
{skipBlsValidation}, cache)
|
|
|
|
|
|
|
|
if res.isErr:
|
|
|
|
warn "Unable to apply new block to state",
|
|
|
|
blck = shortLog(blck),
|
|
|
|
slot = state.`hbs kind`.data.slot,
|
|
|
|
eth1_deposit_index = state.`hbs kind`.data.eth1_deposit_index,
|
|
|
|
deposit_root = shortLog(state.`hbs kind`.data.eth1_data.deposit_root),
|
|
|
|
error = res.error
|
|
|
|
rollback(state)
|
|
|
|
return err("Unable to apply new block to state: " & $res.error())
|
|
|
|
|
|
|
|
state.`hbs kind`.root = hash_tree_root(state.`hbs kind`.data)
|
|
|
|
blck.`kind Block`.state_root = state.`hbs kind`.root
|
|
|
|
ok(blck)
|
|
|
|
|
|
|
|
case state.beaconStateFork
|
|
|
|
of forkPhase0: makeBeaconBlock(phase0)
|
2021-09-30 01:07:24 +00:00
|
|
|
of forkAltair: makeBeaconBlock(altair)
|
|
|
|
of forkMerge: makeBeaconBlock(merge)
|