2019-06-28 13:44:44 +00:00
|
|
|
# beacon_chain
|
2022-01-05 11:07:14 +00:00
|
|
|
# Copyright (c) 2018-2022 Status Research & Development GmbH
|
2019-06-28 13:44:44 +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).
|
2019-06-28 13:44:44 +00:00
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
# State transition - block processing, as described in
|
2022-09-23 07:56:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#block-processing
|
2019-06-28 13:44:44 +00:00
|
|
|
#
|
|
|
|
# The entry point is `process_block` which is at the bottom of this file.
|
|
|
|
#
|
2020-11-04 21:52:47 +00:00
|
|
|
# General notes about the code:
|
2019-06-28 13:44:44 +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
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2022-07-29 10:53:42 +00:00
|
|
|
when (NimMajor, NimMinor) < (1, 4):
|
|
|
|
{.push raises: [Defect].}
|
|
|
|
else:
|
|
|
|
{.push raises: [].}
|
2020-04-22 05:53:02 +00:00
|
|
|
|
2019-12-04 10:49:59 +00:00
|
|
|
import
|
2022-08-31 00:29:03 +00:00
|
|
|
std/[algorithm, sequtils, sets, tables],
|
2021-08-18 18:57:58 +00:00
|
|
|
chronicles, metrics,
|
|
|
|
../extras,
|
2022-01-06 11:25:35 +00:00
|
|
|
./datatypes/[phase0, altair, bellatrix],
|
2021-12-03 14:46:56 +00:00
|
|
|
"."/[beaconstate, eth2_merkleization, helpers, validator, signatures]
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2022-10-27 06:29:24 +00:00
|
|
|
from ./datatypes/capella import
|
|
|
|
BeaconState, MAX_WITHDRAWALS_PER_PAYLOAD, SignedBLSToExecutionChange
|
|
|
|
|
2021-08-12 13:08:20 +00:00
|
|
|
export extras, phase0, altair
|
|
|
|
|
2022-09-23 07:56:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#block-header
|
2020-07-03 17:03:14 +00:00
|
|
|
func process_block_header*(
|
2022-01-30 16:51:04 +00:00
|
|
|
state: var ForkyBeaconState, blck: SomeForkyBeaconBlock, flags: UpdateFlags,
|
2021-12-03 14:46:56 +00:00
|
|
|
cache: var StateCache): Result[void, cstring] =
|
2019-06-28 13:44:44 +00:00
|
|
|
# Verify that the slots match
|
|
|
|
if not (blck.slot == state.slot):
|
2020-07-03 17:03:14 +00:00
|
|
|
return err("process_block_header: slot mismatch")
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2020-05-19 14:37:29 +00:00
|
|
|
# Verify that the block is newer than latest block header
|
|
|
|
if not (blck.slot > state.latest_block_header.slot):
|
2020-07-03 17:03:14 +00:00
|
|
|
return err("process_block_header: block not newer than latest block header")
|
2020-05-19 14:37:29 +00:00
|
|
|
|
2020-03-14 21:54:45 +00:00
|
|
|
# Verify that proposer index is the correct index
|
2021-05-05 06:54:21 +00:00
|
|
|
let proposer_index = get_beacon_proposer_index(state, cache)
|
2020-03-14 21:54:45 +00:00
|
|
|
if proposer_index.isNone:
|
2020-07-03 17:03:14 +00:00
|
|
|
return err("process_block_header: proposer missing")
|
2020-03-14 21:54:45 +00:00
|
|
|
|
2022-05-23 23:39:08 +00:00
|
|
|
if not (blck.proposer_index == proposer_index.get):
|
2020-07-03 17:03:14 +00:00
|
|
|
return err("process_block_header: proposer index incorrect")
|
2020-03-14 21:54:45 +00:00
|
|
|
|
2019-06-28 13:44:44 +00:00
|
|
|
# Verify that the parent matches
|
2020-06-18 05:56:47 +00:00
|
|
|
if not (blck.parent_root == hash_tree_root(state.latest_block_header)):
|
2020-07-03 17:03:14 +00:00
|
|
|
return err("process_block_header: previous block root mismatch")
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2020-09-01 07:49:55 +00:00
|
|
|
# Verify proposer is not slashed
|
2022-05-30 13:30:42 +00:00
|
|
|
if state.validators.item(blck.proposer_index).slashed:
|
2020-09-01 07:49:55 +00:00
|
|
|
return err("process_block_header: proposer slashed")
|
|
|
|
|
2020-03-14 21:54:45 +00:00
|
|
|
# Cache current block as the new latest block
|
2019-06-28 13:44:44 +00:00
|
|
|
state.latest_block_header = BeaconBlockHeader(
|
|
|
|
slot: blck.slot,
|
2020-03-14 21:54:45 +00:00
|
|
|
proposer_index: blck.proposer_index,
|
2019-06-28 13:44:44 +00:00
|
|
|
parent_root: blck.parent_root,
|
2019-07-15 12:57:18 +00:00
|
|
|
# state_root: zeroed, overwritten in the next `process_slot` call
|
2019-06-28 13:44:44 +00:00
|
|
|
body_root: hash_tree_root(blck.body),
|
|
|
|
)
|
|
|
|
|
2020-07-03 17:03:14 +00:00
|
|
|
ok()
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2020-07-03 17:03:14 +00:00
|
|
|
func `xor`[T: array](a, b: T): T =
|
2020-05-28 16:34:59 +00:00
|
|
|
for i in 0..<result.len:
|
|
|
|
result[i] = a[i] xor b[i]
|
|
|
|
|
2022-09-23 07:56:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#randao
|
2019-09-04 13:57:18 +00:00
|
|
|
proc process_randao(
|
2022-02-11 15:58:33 +00:00
|
|
|
state: var ForkyBeaconState, body: SomeForkyBeaconBlockBody, flags: UpdateFlags,
|
2021-12-03 14:46:56 +00:00
|
|
|
cache: var StateCache): Result[void, cstring] =
|
2019-06-28 13:44:44 +00:00
|
|
|
let
|
2021-05-05 06:54:21 +00:00
|
|
|
proposer_index = get_beacon_proposer_index(state, cache)
|
2019-12-04 10:49:59 +00:00
|
|
|
|
|
|
|
if proposer_index.isNone:
|
2021-04-08 10:11:04 +00:00
|
|
|
return err("process_randao: proposer index missing, probably along with any active validators")
|
2019-12-04 10:49:59 +00:00
|
|
|
|
2020-05-26 05:04:24 +00:00
|
|
|
# Verify RANDAO reveal
|
2022-09-28 01:15:10 +00:00
|
|
|
let epoch = state.get_current_epoch()
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2022-09-21 07:38:08 +00:00
|
|
|
if skipRandaoVerification in flags:
|
|
|
|
if body.randao_reveal.toRaw != ValidatorSig.infinity.toRaw:
|
|
|
|
return err("process_randao: expected point-at-infinity for skipRandaoVerification")
|
|
|
|
elif skipBlsValidation notin flags:
|
2022-05-30 13:30:42 +00:00
|
|
|
let proposer_pubkey = state.validators.item(proposer_index.get).pubkey
|
2020-06-16 05:45:04 +00:00
|
|
|
|
2022-09-28 01:15:10 +00:00
|
|
|
# `state_transition.makeBeaconBlock` ensures this is run with a trusted
|
|
|
|
# signature, but unless the full skipBlsValidation is specified, RANDAO
|
|
|
|
# epoch signatures still have to be verified.
|
2020-06-16 05:45:04 +00:00
|
|
|
if not verify_epoch_signature(
|
|
|
|
state.fork, state.genesis_validators_root, epoch, proposer_pubkey,
|
2022-09-28 01:15:10 +00:00
|
|
|
when body.randao_reveal is ValidatorSig:
|
|
|
|
body.randao_reveal
|
|
|
|
else:
|
|
|
|
isomorphicCast[ValidatorSig](body.randao_reveal)):
|
2021-04-08 10:11:04 +00:00
|
|
|
|
|
|
|
return err("process_randao: invalid epoch signature")
|
2019-06-28 13:44:44 +00:00
|
|
|
|
|
|
|
# Mix it in
|
|
|
|
let
|
2019-09-04 13:57:18 +00:00
|
|
|
mix = get_randao_mix(state, epoch)
|
2020-06-16 12:16:43 +00:00
|
|
|
rr = eth2digest(body.randao_reveal.toRaw()).data
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2022-05-30 13:30:42 +00:00
|
|
|
state.randao_mixes.mitem(epoch mod EPOCHS_PER_HISTORICAL_VECTOR).data =
|
2020-05-28 16:34:59 +00:00
|
|
|
mix.data xor rr
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2021-04-08 10:11:04 +00:00
|
|
|
ok()
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2022-09-23 07:56:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#eth1-data
|
2022-02-11 15:58:33 +00:00
|
|
|
func process_eth1_data(state: var ForkyBeaconState, body: SomeForkyBeaconBlockBody): Result[void, cstring]=
|
2021-04-08 10:11:04 +00:00
|
|
|
if not state.eth1_data_votes.add body.eth1_data:
|
|
|
|
# Count is reset in process_final_updates, so this should never happen
|
|
|
|
return err("process_eth1_data: no more room for eth1 data")
|
2020-05-28 16:34:59 +00:00
|
|
|
|
2020-07-26 18:55:48 +00:00
|
|
|
if state.eth1_data_votes.asSeq.count(body.eth1_data).uint64 * 2 >
|
|
|
|
SLOTS_PER_ETH1_VOTING_PERIOD:
|
2019-07-01 09:42:37 +00:00
|
|
|
state.eth1_data = body.eth1_data
|
2021-04-08 10:11:04 +00:00
|
|
|
ok()
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2022-09-23 07:56:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#is_slashable_validator
|
2019-06-28 13:44:44 +00:00
|
|
|
func is_slashable_validator(validator: Validator, epoch: Epoch): bool =
|
|
|
|
# Check if ``validator`` is slashable.
|
|
|
|
(not validator.slashed) and
|
|
|
|
(validator.activation_epoch <= epoch) and
|
|
|
|
(epoch < validator.withdrawable_epoch)
|
|
|
|
|
2022-09-23 07:56:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#proposer-slashings
|
2020-09-24 17:05:49 +00:00
|
|
|
proc check_proposer_slashing*(
|
2021-12-29 02:50:49 +00:00
|
|
|
state: ForkyBeaconState, proposer_slashing: SomeProposerSlashing,
|
2020-12-16 14:36:02 +00:00
|
|
|
flags: UpdateFlags):
|
2022-05-23 23:39:08 +00:00
|
|
|
Result[ValidatorIndex, cstring] =
|
2020-03-14 21:54:45 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
header_1 = proposer_slashing.signed_header_1.message
|
|
|
|
header_2 = proposer_slashing.signed_header_2.message
|
|
|
|
|
|
|
|
# Verify header slots match
|
|
|
|
if not (header_1.slot == header_2.slot):
|
2020-09-24 17:05:49 +00:00
|
|
|
return err("check_proposer_slashing: slot mismatch")
|
2019-09-10 15:29:46 +00:00
|
|
|
|
2020-03-14 21:54:45 +00:00
|
|
|
# Verify header proposer indices match
|
|
|
|
if not (header_1.proposer_index == header_2.proposer_index):
|
2020-09-24 17:05:49 +00:00
|
|
|
return err("check_proposer_slashing: proposer indices mismatch")
|
2020-03-14 21:54:45 +00:00
|
|
|
|
|
|
|
# Verify the headers are different
|
|
|
|
if not (header_1 != header_2):
|
2020-09-24 17:05:49 +00:00
|
|
|
return err("check_proposer_slashing: headers not different")
|
2019-09-10 15:29:46 +00:00
|
|
|
|
2020-03-14 21:54:45 +00:00
|
|
|
# Verify the proposer is slashable
|
2022-05-23 23:39:08 +00:00
|
|
|
if header_1.proposer_index >= state.validators.lenu64:
|
|
|
|
return err("check_proposer_slashing: invalid proposer index")
|
|
|
|
|
2022-05-30 13:30:42 +00:00
|
|
|
let proposer = unsafeAddr state.validators[header_1.proposer_index]
|
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
|
|
|
if not is_slashable_validator(proposer[], get_current_epoch(state)):
|
2020-09-24 17:05:49 +00:00
|
|
|
return err("check_proposer_slashing: slashed proposer")
|
2019-09-10 15:29:46 +00:00
|
|
|
|
2020-03-14 21:54:45 +00:00
|
|
|
# Verify signatures
|
2020-03-05 12:52:10 +00:00
|
|
|
if skipBlsValidation notin flags:
|
2020-09-24 17:05:49 +00:00
|
|
|
for signed_header in [proposer_slashing.signed_header_1,
|
2019-12-16 18:08:50 +00:00
|
|
|
proposer_slashing.signed_header_2]:
|
2020-06-16 05:45:04 +00:00
|
|
|
if not verify_block_signature(
|
|
|
|
state.fork, state.genesis_validators_root, signed_header.message.slot,
|
2021-06-01 11:13:40 +00:00
|
|
|
signed_header.message, proposer[].pubkey,
|
|
|
|
signed_header.signature):
|
2020-09-24 17:05:49 +00:00
|
|
|
return err("check_proposer_slashing: invalid signature")
|
2019-09-10 15:29:46 +00:00
|
|
|
|
2022-05-23 23:39:08 +00:00
|
|
|
# Verified above against state.validators
|
|
|
|
ValidatorIndex.init(header_1.proposer_index)
|
2019-09-10 15:29:46 +00:00
|
|
|
|
2021-11-05 07:34:34 +00:00
|
|
|
proc check_proposer_slashing*(
|
|
|
|
state: var ForkedHashedBeaconState; proposer_slashing: SomeProposerSlashing;
|
2022-05-23 23:39:08 +00:00
|
|
|
flags: UpdateFlags): Result[ValidatorIndex, cstring] =
|
2021-11-05 07:34:34 +00:00
|
|
|
withState(state):
|
2022-08-31 00:29:03 +00:00
|
|
|
check_proposer_slashing(forkyState.data, proposer_slashing, flags)
|
2021-11-05 07:34:34 +00:00
|
|
|
|
2022-09-23 07:56:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#proposer-slashings
|
2020-09-24 17:05:49 +00:00
|
|
|
proc process_proposer_slashing*(
|
2021-11-05 07:34:34 +00:00
|
|
|
cfg: RuntimeConfig, state: var ForkyBeaconState,
|
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
|
|
|
proposer_slashing: SomeProposerSlashing, flags: UpdateFlags,
|
|
|
|
cache: var StateCache):
|
2021-12-03 14:46:56 +00:00
|
|
|
Result[void, cstring] =
|
2022-05-23 23:39:08 +00:00
|
|
|
let proposer_index = ? check_proposer_slashing(state, proposer_slashing, flags)
|
2022-05-25 13:49:29 +00:00
|
|
|
? slash_validator(cfg, state, proposer_index, cache)
|
2020-07-03 17:03:14 +00:00
|
|
|
ok()
|
2019-09-10 15:29:46 +00:00
|
|
|
|
2022-09-23 07:56:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#is_slashable_attestation_data
|
2021-06-03 09:42:25 +00:00
|
|
|
func is_slashable_attestation_data(
|
2019-06-28 13:44:44 +00:00
|
|
|
data_1: AttestationData, data_2: AttestationData): bool =
|
|
|
|
## Check if ``data_1`` and ``data_2`` are slashable according to Casper FFG
|
|
|
|
## rules.
|
|
|
|
|
|
|
|
# Double vote
|
2019-07-02 21:14:55 +00:00
|
|
|
(data_1 != data_2 and data_1.target.epoch == data_2.target.epoch) or
|
2019-06-28 13:44:44 +00:00
|
|
|
# Surround vote
|
2019-07-02 21:14:55 +00:00
|
|
|
(data_1.source.epoch < data_2.source.epoch and
|
|
|
|
data_2.target.epoch < data_1.target.epoch)
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2022-09-23 07:56:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#attester-slashings
|
2020-09-24 17:05:49 +00:00
|
|
|
proc check_attester_slashing*(
|
2021-12-29 02:50:49 +00:00
|
|
|
state: ForkyBeaconState,
|
2021-01-25 18:45:48 +00:00
|
|
|
attester_slashing: SomeAttesterSlashing,
|
2020-12-16 14:36:02 +00:00
|
|
|
flags: UpdateFlags
|
2021-12-03 14:46:56 +00:00
|
|
|
): Result[seq[ValidatorIndex], cstring] =
|
2020-07-03 17:03:14 +00:00
|
|
|
let
|
|
|
|
attestation_1 = attester_slashing.attestation_1
|
|
|
|
attestation_2 = attester_slashing.attestation_2
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2020-07-03 17:03:14 +00:00
|
|
|
if not is_slashable_attestation_data(
|
|
|
|
attestation_1.data, attestation_2.data):
|
|
|
|
return err("Attester slashing: surround or double vote check failed")
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2020-08-13 13:47:06 +00:00
|
|
|
if not is_valid_indexed_attestation(state, attestation_1, flags).isOk():
|
2020-07-03 17:03:14 +00:00
|
|
|
return err("Attester slashing: invalid attestation 1")
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2020-08-13 13:47:06 +00:00
|
|
|
if not is_valid_indexed_attestation(state, attestation_2, flags).isOk():
|
2020-07-03 17:03:14 +00:00
|
|
|
return err("Attester slashing: invalid attestation 2")
|
|
|
|
|
2020-09-24 17:05:49 +00:00
|
|
|
var slashed_indices: seq[ValidatorIndex]
|
2020-07-03 17:03:14 +00:00
|
|
|
|
2021-10-20 11:36:38 +00:00
|
|
|
let attesting_indices_2 = toHashSet(attestation_2.attesting_indices.asSeq)
|
|
|
|
for index in sorted(filterIt(
|
|
|
|
attestation_1.attesting_indices.asSeq, it in attesting_indices_2),
|
|
|
|
system.cmp):
|
2020-07-03 17:03:14 +00:00
|
|
|
if is_slashable_validator(
|
2022-05-30 13:30:42 +00:00
|
|
|
state.validators[index], get_current_epoch(state)):
|
2022-05-23 23:39:08 +00:00
|
|
|
slashed_indices.add ValidatorIndex.init(index).expect(
|
|
|
|
"checked by is_valid_indexed_attestation")
|
|
|
|
|
2020-09-24 17:05:49 +00:00
|
|
|
if slashed_indices.len == 0:
|
2020-07-03 17:03:14 +00:00
|
|
|
return err("Attester slashing: Trying to slash participant(s) twice")
|
2020-09-24 17:05:49 +00:00
|
|
|
|
|
|
|
ok slashed_indices
|
|
|
|
|
2021-11-05 07:34:34 +00:00
|
|
|
proc check_attester_slashing*(
|
|
|
|
state: var ForkedHashedBeaconState; attester_slashing: SomeAttesterSlashing;
|
|
|
|
flags: UpdateFlags): Result[seq[ValidatorIndex], cstring] =
|
|
|
|
withState(state):
|
2022-08-26 22:47:40 +00:00
|
|
|
check_attester_slashing(forkyState.data, attester_slashing, flags)
|
2021-11-05 07:34:34 +00:00
|
|
|
|
2022-09-23 07:56:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#attester-slashings
|
2020-09-24 17:05:49 +00:00
|
|
|
proc process_attester_slashing*(
|
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-11-05 07:34:34 +00:00
|
|
|
state: var ForkyBeaconState,
|
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
|
|
|
attester_slashing: SomeAttesterSlashing,
|
|
|
|
flags: UpdateFlags,
|
|
|
|
cache: var StateCache
|
2021-12-03 14:46:56 +00:00
|
|
|
): Result[void, cstring] =
|
2022-05-23 23:39:08 +00:00
|
|
|
let slashed_attesters =
|
|
|
|
? check_attester_slashing(state, attester_slashing, flags)
|
2020-09-24 17:05:49 +00:00
|
|
|
|
2022-05-23 23:39:08 +00:00
|
|
|
for index in slashed_attesters:
|
2022-05-25 13:49:29 +00:00
|
|
|
? slash_validator(cfg, state, index, cache)
|
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
|
|
|
|
|
|
|
ok()
|
|
|
|
|
2022-05-23 23:39:08 +00:00
|
|
|
func findValidatorIndex*(state: ForkyBeaconState, pubkey: ValidatorPubKey):
|
|
|
|
Opt[ValidatorIndex] =
|
2021-12-29 02:50:49 +00:00
|
|
|
# This linear scan is unfortunate, but should be fairly fast as we do a simple
|
|
|
|
# byte comparison of the key. The alternative would be to build a Table, but
|
|
|
|
# given that each block can hold no more than 16 deposits, it's slower to
|
|
|
|
# build the table and use it for lookups than to scan it like this.
|
|
|
|
# Once we have a reusable, long-lived cache, this should be revisited
|
2022-05-23 23:39:08 +00:00
|
|
|
for vidx in state.validators.vindices:
|
|
|
|
if state.validators.asSeq[vidx].pubkey == pubkey:
|
|
|
|
return Opt[ValidatorIndex].ok(vidx)
|
2021-12-29 02:50:49 +00:00
|
|
|
|
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
|
|
|
proc process_deposit*(cfg: RuntimeConfig,
|
2021-11-05 07:34:34 +00:00
|
|
|
state: var ForkyBeaconState,
|
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
|
|
|
deposit: Deposit,
|
2021-12-03 14:46:56 +00:00
|
|
|
flags: UpdateFlags): Result[void, cstring] =
|
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 an Eth1 deposit, registering a validator or increasing its balance.
|
|
|
|
|
|
|
|
# Verify the Merkle branch
|
|
|
|
if not is_valid_merkle_branch(
|
|
|
|
hash_tree_root(deposit.data),
|
|
|
|
deposit.proof,
|
|
|
|
DEPOSIT_CONTRACT_TREE_DEPTH + 1, # Add 1 for the `List` length mix-in
|
|
|
|
state.eth1_deposit_index,
|
|
|
|
state.eth1_data.deposit_root,
|
|
|
|
):
|
|
|
|
return err("process_deposit: deposit Merkle validation failed")
|
|
|
|
|
|
|
|
# Deposits must be processed in order
|
|
|
|
state.eth1_deposit_index += 1
|
|
|
|
|
|
|
|
let
|
|
|
|
pubkey = deposit.data.pubkey
|
|
|
|
amount = deposit.data.amount
|
2021-12-29 02:50:49 +00:00
|
|
|
index = findValidatorIndex(state, pubkey)
|
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
|
|
|
|
2022-05-23 23:39:08 +00:00
|
|
|
if index.isSome():
|
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
|
|
|
# Increase balance by deposit amount
|
2022-05-23 23:39:08 +00:00
|
|
|
increase_balance(state, index.get(), amount)
|
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
|
|
|
else:
|
|
|
|
# Verify the deposit signature (proof of possession) which is not checked
|
|
|
|
# by the deposit contract
|
2022-05-17 19:56:15 +00:00
|
|
|
if verify_deposit_signature(cfg, deposit.data):
|
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
|
|
|
# New validator! Add validator and balance entries
|
|
|
|
if not state.validators.add(get_validator_from_deposit(deposit.data)):
|
|
|
|
return err("process_deposit: too many validators")
|
|
|
|
if not state.balances.add(amount):
|
|
|
|
static: doAssert state.balances.maxLen == state.validators.maxLen
|
|
|
|
raiseAssert "adding validator succeeded, so should balances"
|
|
|
|
|
2022-10-27 06:29:24 +00:00
|
|
|
when state is altair.BeaconState or state is bellatrix.BeaconState or state is capella.BeaconState:
|
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 not state.previous_epoch_participation.add(ParticipationFlags(0)):
|
|
|
|
return err("process_deposit: too many validators (previous_epoch_participation)")
|
|
|
|
if not state.current_epoch_participation.add(ParticipationFlags(0)):
|
|
|
|
return err("process_deposit: too many validators (current_epoch_participation)")
|
|
|
|
if not state.inactivity_scores.add(0'u64):
|
|
|
|
return err("process_deposit: too many validators (inactivity_scores)")
|
|
|
|
|
|
|
|
doAssert state.validators.len == state.balances.len
|
|
|
|
else:
|
|
|
|
# Deposits may come with invalid signatures - in that case, they are not
|
|
|
|
# turned into a validator but still get processed to keep the deposit
|
|
|
|
# index correct
|
|
|
|
trace "Skipping deposit with invalid signature",
|
|
|
|
deposit = shortLog(deposit.data)
|
2020-09-24 17:05:49 +00:00
|
|
|
|
2020-07-03 17:03:14 +00:00
|
|
|
ok()
|
2019-09-10 22:03:06 +00:00
|
|
|
|
2022-09-23 07:56:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#voluntary-exits
|
2020-09-24 17:05:49 +00:00
|
|
|
proc check_voluntary_exit*(
|
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-11-05 07:34:34 +00:00
|
|
|
state: ForkyBeaconState,
|
2021-01-25 18:45:48 +00:00
|
|
|
signed_voluntary_exit: SomeSignedVoluntaryExit,
|
2022-05-23 23:39:08 +00:00
|
|
|
flags: UpdateFlags): Result[ValidatorIndex, cstring] =
|
2019-09-10 00:14:03 +00:00
|
|
|
|
2019-12-16 18:08:50 +00:00
|
|
|
let voluntary_exit = signed_voluntary_exit.message
|
|
|
|
|
2020-07-26 18:55:48 +00:00
|
|
|
if voluntary_exit.validator_index >= state.validators.lenu64:
|
2022-01-31 11:57:16 +00:00
|
|
|
return err("Exit: invalid validator index")
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2022-05-30 13:30:42 +00:00
|
|
|
let validator = unsafeAddr state.validators[voluntary_exit.validator_index]
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2019-09-10 00:14:03 +00:00
|
|
|
# Verify the validator is active
|
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
|
|
|
if not is_active_validator(validator[], get_current_epoch(state)):
|
2022-01-31 11:57:16 +00:00
|
|
|
return err("Exit: validator not active")
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2020-07-08 20:36:26 +00:00
|
|
|
# Verify exit has not been initiated
|
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
|
|
|
if validator[].exit_epoch != FAR_FUTURE_EPOCH:
|
2022-01-31 11:57:16 +00:00
|
|
|
return err("Exit: validator has exited")
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2020-07-03 17:03:14 +00:00
|
|
|
# Exits must specify an epoch when they become valid; they are not valid
|
|
|
|
# before then
|
2019-12-16 18:08:50 +00:00
|
|
|
if not (get_current_epoch(state) >= voluntary_exit.epoch):
|
2022-01-31 11:57:16 +00:00
|
|
|
return err("Exit: exit epoch not passed")
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2019-09-10 00:14:03 +00:00
|
|
|
# Verify the validator has been active long enough
|
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
|
|
|
if not (get_current_epoch(state) >= validator[].activation_epoch +
|
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.SHARD_COMMITTEE_PERIOD):
|
2022-01-31 11:57:16 +00:00
|
|
|
return err("Exit: not in validator set long enough")
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2019-09-10 00:14:03 +00:00
|
|
|
# Verify signature
|
2020-03-05 12:52:10 +00:00
|
|
|
if skipBlsValidation notin flags:
|
2020-06-16 05:45:04 +00:00
|
|
|
if not verify_voluntary_exit_signature(
|
|
|
|
state.fork, state.genesis_validators_root, voluntary_exit,
|
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
|
|
|
validator[].pubkey, signed_voluntary_exit.signature):
|
2022-01-31 11:57:16 +00:00
|
|
|
return err("Exit: invalid signature")
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2022-05-23 23:39:08 +00:00
|
|
|
# Checked above
|
|
|
|
ValidatorIndex.init(voluntary_exit.validator_index)
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2021-11-05 07:34:34 +00:00
|
|
|
proc check_voluntary_exit*(
|
|
|
|
cfg: RuntimeConfig, state: ForkedHashedBeaconState;
|
|
|
|
signed_voluntary_exit: SomeSignedVoluntaryExit;
|
2022-05-23 23:39:08 +00:00
|
|
|
flags: UpdateFlags): Result[ValidatorIndex, cstring] =
|
2021-11-05 07:34:34 +00:00
|
|
|
withState(state):
|
2022-08-31 11:29:34 +00:00
|
|
|
check_voluntary_exit(cfg, forkyState.data, signed_voluntary_exit, flags)
|
2021-11-05 07:34:34 +00:00
|
|
|
|
2022-09-23 07:56:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#voluntary-exits
|
2020-09-24 17:05:49 +00:00
|
|
|
proc process_voluntary_exit*(
|
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-11-05 07:34:34 +00:00
|
|
|
state: var ForkyBeaconState,
|
2021-01-25 18:45:48 +00:00
|
|
|
signed_voluntary_exit: SomeSignedVoluntaryExit,
|
2020-09-24 17:05:49 +00:00
|
|
|
flags: UpdateFlags,
|
2021-12-03 14:46:56 +00:00
|
|
|
cache: var StateCache): Result[void, cstring] =
|
2022-05-23 23:39:08 +00:00
|
|
|
let exited_validator =
|
|
|
|
? check_voluntary_exit(cfg, state, signed_voluntary_exit, flags)
|
2022-05-25 13:49:29 +00:00
|
|
|
? initiate_validator_exit(cfg, state, exited_validator, cache)
|
2020-09-24 17:05:49 +00:00
|
|
|
ok()
|
|
|
|
|
2022-09-23 07:56:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#operations
|
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
|
|
|
proc process_operations(cfg: RuntimeConfig,
|
2021-11-05 07:34:34 +00:00
|
|
|
state: var ForkyBeaconState,
|
2022-02-11 15:58:33 +00:00
|
|
|
body: SomeForkyBeaconBlockBody,
|
2021-10-13 14:24:36 +00:00
|
|
|
base_reward_per_increment: Gwei,
|
2020-07-07 23:02:14 +00:00
|
|
|
flags: UpdateFlags,
|
2021-12-03 14:46:56 +00:00
|
|
|
cache: var StateCache): Result[void, cstring] =
|
2020-05-22 15:52:07 +00:00
|
|
|
# Verify that outstanding deposits are processed up to the maximum number of
|
|
|
|
# deposits
|
|
|
|
let
|
|
|
|
req_deposits = min(MAX_DEPOSITS,
|
2020-07-13 14:44:58 +00:00
|
|
|
state.eth1_data.deposit_count - state.eth1_deposit_index)
|
2021-07-06 06:19:06 +00:00
|
|
|
|
2020-08-21 13:34:14 +00:00
|
|
|
if state.eth1_data.deposit_count < state.eth1_deposit_index or
|
|
|
|
body.deposits.lenu64 != req_deposits:
|
2020-07-03 17:03:14 +00:00
|
|
|
return err("incorrect number of deposits")
|
2020-05-22 15:52:07 +00:00
|
|
|
|
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
|
|
|
for op in body.proposer_slashings:
|
|
|
|
? process_proposer_slashing(cfg, state, op, flags, cache)
|
|
|
|
for op in body.attester_slashings:
|
|
|
|
? process_attester_slashing(cfg, state, op, flags, cache)
|
|
|
|
for op in body.attestations:
|
2021-10-13 14:24:36 +00:00
|
|
|
? process_attestation(state, op, flags, base_reward_per_increment, cache)
|
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
|
|
|
for op in body.deposits:
|
|
|
|
? process_deposit(cfg, state, op, flags)
|
|
|
|
for op in body.voluntary_exits:
|
|
|
|
? process_voluntary_exit(cfg, state, op, flags, cache)
|
2020-05-22 15:52:07 +00:00
|
|
|
|
2020-07-03 17:03:14 +00:00
|
|
|
ok()
|
2019-09-10 00:14:03 +00:00
|
|
|
|
2022-09-23 07:56:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#sync-committee-processing
|
2021-12-29 02:50:49 +00:00
|
|
|
func get_participant_reward*(total_active_balance: Gwei): Gwei =
|
|
|
|
let
|
|
|
|
total_active_increments =
|
|
|
|
total_active_balance div EFFECTIVE_BALANCE_INCREMENT
|
|
|
|
total_base_rewards =
|
|
|
|
get_base_reward_per_increment(total_active_balance) * total_active_increments
|
|
|
|
max_participant_rewards =
|
|
|
|
total_base_rewards * SYNC_REWARD_WEIGHT div WEIGHT_DENOMINATOR div SLOTS_PER_EPOCH
|
2022-01-17 12:58:33 +00:00
|
|
|
max_participant_rewards div SYNC_COMMITTEE_SIZE
|
2021-12-29 02:50:49 +00:00
|
|
|
|
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.0-alpha.6/specs/altair/beacon-chain.md#sync-committee-processing
|
|
|
|
func get_proposer_reward*(participant_reward: Gwei): Gwei =
|
|
|
|
participant_reward * PROPOSER_WEIGHT div (WEIGHT_DENOMINATOR - PROPOSER_WEIGHT)
|
|
|
|
|
2022-09-23 07:56:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#sync-committee-processing
|
2021-06-14 17:42:46 +00:00
|
|
|
proc process_sync_aggregate*(
|
2022-10-27 06:29:24 +00:00
|
|
|
state: var (altair.BeaconState | bellatrix.BeaconState | capella.BeaconState),
|
2022-01-13 13:46:08 +00:00
|
|
|
sync_aggregate: SomeSyncAggregate, total_active_balance: Gwei,
|
2021-12-09 12:56:54 +00:00
|
|
|
cache: var StateCache):
|
|
|
|
Result[void, cstring] =
|
2021-05-28 15:25:58 +00:00
|
|
|
# Verify sync committee aggregate signature signing over the previous slot
|
|
|
|
# block root
|
2022-01-13 13:46:08 +00:00
|
|
|
when sync_aggregate.sync_committee_signature isnot TrustedSig:
|
speed up epoch processing 6x+ (#3089)
* speed up epoch processing 6x+
This change above all helps contain long replay times on epoch change, reorg
and deep history inspection via REST/RPC
* most effective balances don't actually change due to MAX_EFFECTIVE_BALANCE
* ditto for inactivity scores
* avoid signature check for trusted sync aggregates
pre:
```
./ncli_db --db:mainnet_0/db bench --start-slot=-3200
All time are ms
Average, StdDev, Min, Max, Samples, Test
Validation is turned off meaning that no BLS operations are performed
3468.621, 0.000, 3468.621, 3468.621, 1, Initialize DB
0.357, 0.938, 0.171, 52.752, 3155, Load block from database
15691.471, 0.000, 15691.471, 15691.471, 1, Load state from database
6.100, 9.469, 0.033, 526.816, 3101, Advance slot, non-epoch
579.131, 9.523, 566.936, 610.328, 100, Advance slot, epoch
18.551, 16.317, 12.664, 136.668, 3155, Apply block, no slot processing
0.000, 0.000, 0.000, 0.000, 0, Database load
0.000, 0.000, 0.000, 0.000, 0, Database store
```
post:
```
Average, StdDev, Min, Max, Samples, Test
Validation is turned off meaning that no BLS operations are performed
3488.541, 0.000, 3488.541, 3488.541, 1, Initialize DB
0.369, 1.123, 0.183, 63.208, 3155, Load block from database
13430.642, 0.000, 13430.642, 13430.642, 1, Load state from database
6.522, 1.721, 0.034, 36.708, 3101, Advance slot, non-epoch
89.074, 3.162, 83.573, 101.436, 100, Advance slot, epoch
18.325, 18.346, 13.005, 145.040, 3155, Apply block, no slot processing
0.000, 0.000, 0.000, 0.000, 0, Database load
0.000, 0.000, 0.000, 0.000, 0, Database store
```
* Update beacon_chain/spec/state_transition_block.nim
Co-authored-by: zah <zahary@gmail.com>
* avoid copying validator data in accessor
```
5291.227, 0.000, 5291.227, 5291.227, 1, Initialize DB
0.436, 0.928, 0.138, 51.438, 3155, Load block from database
11962.826, 0.000, 11962.826, 11962.826, 1, Load state from database
6.477, 1.675, 0.037, 34.174, 3101, Advance slot, non-epoch
76.633, 3.705, 71.106, 98.085, 100, Advance slot, epoch
18.301, 18.593, 13.208, 149.153, 3155, Apply block, no slot processing
0.000, 0.000, 0.000, 0.000, 0, Database load
0.000, 0.000, 0.000, 0.000, 0, Database store
```
* work around compiler bug
Co-authored-by: zah <zahary@gmail.com>
2021-11-11 19:24:29 +00:00
|
|
|
var participant_pubkeys: seq[ValidatorPubKey]
|
Speed up altair block processing 2x (#3115)
* Speed up altair block processing >2x
Like #3089, this PR drastially speeds up historical REST queries and
other long state replays.
* cache sync committee validator indices
* use ~80mb less memory for validator pubkey mappings
* batch-verify sync aggregate signature (fixes #2985)
* document sync committee hack with head block vs sync message block
* add batch signature verification failure tests
Before:
```
../env.sh nim c -d:release -r ncli_db --db:mainnet_0/db bench --start-slot:-1000
All time are ms
Average, StdDev, Min, Max, Samples, Test
Validation is turned off meaning that no BLS operations are performed
5830.675, 0.000, 5830.675, 5830.675, 1, Initialize DB
0.481, 1.878, 0.215, 59.167, 981, Load block from database
8422.566, 0.000, 8422.566, 8422.566, 1, Load state from database
6.996, 1.678, 0.042, 14.385, 969, Advance slot, non-epoch
93.217, 8.318, 84.192, 122.209, 32, Advance slot, epoch
20.513, 23.665, 11.510, 201.561, 981, Apply block, no slot processing
0.000, 0.000, 0.000, 0.000, 0, Database load
0.000, 0.000, 0.000, 0.000, 0, Database store
```
After:
```
7081.422, 0.000, 7081.422, 7081.422, 1, Initialize DB
0.553, 2.122, 0.175, 66.692, 981, Load block from database
5439.446, 0.000, 5439.446, 5439.446, 1, Load state from database
6.829, 1.575, 0.043, 12.156, 969, Advance slot, non-epoch
94.716, 2.749, 88.395, 100.026, 32, Advance slot, epoch
11.636, 23.766, 4.889, 205.250, 981, Apply block, no slot processing
0.000, 0.000, 0.000, 0.000, 0, Database load
0.000, 0.000, 0.000, 0.000, 0, Database store
```
* add comment
2021-11-24 12:43:50 +00:00
|
|
|
for i in 0 ..< state.current_sync_committee.pubkeys.len:
|
2022-01-13 13:46:08 +00:00
|
|
|
if sync_aggregate.sync_committee_bits[i]:
|
2022-05-30 13:30:42 +00:00
|
|
|
participant_pubkeys.add state.current_sync_committee.pubkeys.data[i]
|
2021-05-28 15:25:58 +00:00
|
|
|
|
Speed up altair block processing 2x (#3115)
* Speed up altair block processing >2x
Like #3089, this PR drastially speeds up historical REST queries and
other long state replays.
* cache sync committee validator indices
* use ~80mb less memory for validator pubkey mappings
* batch-verify sync aggregate signature (fixes #2985)
* document sync committee hack with head block vs sync message block
* add batch signature verification failure tests
Before:
```
../env.sh nim c -d:release -r ncli_db --db:mainnet_0/db bench --start-slot:-1000
All time are ms
Average, StdDev, Min, Max, Samples, Test
Validation is turned off meaning that no BLS operations are performed
5830.675, 0.000, 5830.675, 5830.675, 1, Initialize DB
0.481, 1.878, 0.215, 59.167, 981, Load block from database
8422.566, 0.000, 8422.566, 8422.566, 1, Load state from database
6.996, 1.678, 0.042, 14.385, 969, Advance slot, non-epoch
93.217, 8.318, 84.192, 122.209, 32, Advance slot, epoch
20.513, 23.665, 11.510, 201.561, 981, Apply block, no slot processing
0.000, 0.000, 0.000, 0.000, 0, Database load
0.000, 0.000, 0.000, 0.000, 0, Database store
```
After:
```
7081.422, 0.000, 7081.422, 7081.422, 1, Initialize DB
0.553, 2.122, 0.175, 66.692, 981, Load block from database
5439.446, 0.000, 5439.446, 5439.446, 1, Load state from database
6.829, 1.575, 0.043, 12.156, 969, Advance slot, non-epoch
94.716, 2.749, 88.395, 100.026, 32, Advance slot, epoch
11.636, 23.766, 4.889, 205.250, 981, Apply block, no slot processing
0.000, 0.000, 0.000, 0.000, 0, Database load
0.000, 0.000, 0.000, 0.000, 0, Database store
```
* add comment
2021-11-24 12:43:50 +00:00
|
|
|
# p2p-interface message validators check for empty sync committees, so it
|
|
|
|
# shouldn't run except as part of test suite.
|
2021-12-09 12:56:54 +00:00
|
|
|
if participant_pubkeys.len == 0:
|
2022-01-13 13:46:08 +00:00
|
|
|
if sync_aggregate.sync_committee_signature != ValidatorSig.infinity():
|
2021-12-09 12:56:54 +00:00
|
|
|
return err("process_sync_aggregate: empty sync aggregates need signature of point at infinity")
|
|
|
|
else:
|
|
|
|
# Empty participants allowed
|
|
|
|
let
|
|
|
|
previous_slot = max(state.slot, Slot(1)) - 1
|
|
|
|
beacon_block_root = get_block_root_at_slot(state, previous_slot)
|
|
|
|
if not verify_sync_committee_signature(
|
|
|
|
state.fork, state.genesis_validators_root, previous_slot,
|
|
|
|
beacon_block_root, participant_pubkeys,
|
2022-01-13 13:46:08 +00:00
|
|
|
sync_aggregate.sync_committee_signature):
|
2021-12-09 12:56:54 +00:00
|
|
|
return err("process_sync_aggregate: invalid signature")
|
2021-05-28 15:25:58 +00:00
|
|
|
|
|
|
|
# Compute participant and proposer rewards
|
|
|
|
let
|
2021-12-29 02:50:49 +00:00
|
|
|
participant_reward = get_participant_reward(total_active_balance)
|
|
|
|
proposer_reward = state_transition_block.get_proposer_reward(participant_reward)
|
2021-10-13 14:24:36 +00:00
|
|
|
proposer_index = get_beacon_proposer_index(state, cache)
|
|
|
|
|
|
|
|
if proposer_index.isNone:
|
|
|
|
# We're processing a block, so this can't happen, in theory (!)
|
|
|
|
return err("process_sync_aggregate: no proposer")
|
2021-05-28 15:25:58 +00:00
|
|
|
|
|
|
|
# Apply participant and proposer rewards
|
Speed up altair block processing 2x (#3115)
* Speed up altair block processing >2x
Like #3089, this PR drastially speeds up historical REST queries and
other long state replays.
* cache sync committee validator indices
* use ~80mb less memory for validator pubkey mappings
* batch-verify sync aggregate signature (fixes #2985)
* document sync committee hack with head block vs sync message block
* add batch signature verification failure tests
Before:
```
../env.sh nim c -d:release -r ncli_db --db:mainnet_0/db bench --start-slot:-1000
All time are ms
Average, StdDev, Min, Max, Samples, Test
Validation is turned off meaning that no BLS operations are performed
5830.675, 0.000, 5830.675, 5830.675, 1, Initialize DB
0.481, 1.878, 0.215, 59.167, 981, Load block from database
8422.566, 0.000, 8422.566, 8422.566, 1, Load state from database
6.996, 1.678, 0.042, 14.385, 969, Advance slot, non-epoch
93.217, 8.318, 84.192, 122.209, 32, Advance slot, epoch
20.513, 23.665, 11.510, 201.561, 981, Apply block, no slot processing
0.000, 0.000, 0.000, 0.000, 0, Database load
0.000, 0.000, 0.000, 0.000, 0, Database store
```
After:
```
7081.422, 0.000, 7081.422, 7081.422, 1, Initialize DB
0.553, 2.122, 0.175, 66.692, 981, Load block from database
5439.446, 0.000, 5439.446, 5439.446, 1, Load state from database
6.829, 1.575, 0.043, 12.156, 969, Advance slot, non-epoch
94.716, 2.749, 88.395, 100.026, 32, Advance slot, epoch
11.636, 23.766, 4.889, 205.250, 981, Apply block, no slot processing
0.000, 0.000, 0.000, 0.000, 0, Database load
0.000, 0.000, 0.000, 0.000, 0, Database store
```
* add comment
2021-11-24 12:43:50 +00:00
|
|
|
let indices = get_sync_committee_cache(state, cache).current_sync_committee
|
2021-05-28 15:25:58 +00:00
|
|
|
|
2021-06-14 17:42:46 +00:00
|
|
|
# TODO could use a sequtils2 zipIt
|
|
|
|
for i in 0 ..< min(
|
2021-10-13 14:24:36 +00:00
|
|
|
state.current_sync_committee.pubkeys.len,
|
2022-01-13 13:46:08 +00:00
|
|
|
sync_aggregate.sync_committee_bits.len):
|
Speed up altair block processing 2x (#3115)
* Speed up altair block processing >2x
Like #3089, this PR drastially speeds up historical REST queries and
other long state replays.
* cache sync committee validator indices
* use ~80mb less memory for validator pubkey mappings
* batch-verify sync aggregate signature (fixes #2985)
* document sync committee hack with head block vs sync message block
* add batch signature verification failure tests
Before:
```
../env.sh nim c -d:release -r ncli_db --db:mainnet_0/db bench --start-slot:-1000
All time are ms
Average, StdDev, Min, Max, Samples, Test
Validation is turned off meaning that no BLS operations are performed
5830.675, 0.000, 5830.675, 5830.675, 1, Initialize DB
0.481, 1.878, 0.215, 59.167, 981, Load block from database
8422.566, 0.000, 8422.566, 8422.566, 1, Load state from database
6.996, 1.678, 0.042, 14.385, 969, Advance slot, non-epoch
93.217, 8.318, 84.192, 122.209, 32, Advance slot, epoch
20.513, 23.665, 11.510, 201.561, 981, Apply block, no slot processing
0.000, 0.000, 0.000, 0.000, 0, Database load
0.000, 0.000, 0.000, 0.000, 0, Database store
```
After:
```
7081.422, 0.000, 7081.422, 7081.422, 1, Initialize DB
0.553, 2.122, 0.175, 66.692, 981, Load block from database
5439.446, 0.000, 5439.446, 5439.446, 1, Load state from database
6.829, 1.575, 0.043, 12.156, 969, Advance slot, non-epoch
94.716, 2.749, 88.395, 100.026, 32, Advance slot, epoch
11.636, 23.766, 4.889, 205.250, 981, Apply block, no slot processing
0.000, 0.000, 0.000, 0.000, 0, Database load
0.000, 0.000, 0.000, 0.000, 0, Database store
```
* add comment
2021-11-24 12:43:50 +00:00
|
|
|
let participant_index = indices[i]
|
2022-01-13 13:46:08 +00:00
|
|
|
if sync_aggregate.sync_committee_bits[i]:
|
2021-10-13 14:24:36 +00:00
|
|
|
increase_balance(state, participant_index, participant_reward)
|
|
|
|
increase_balance(state, proposer_index.get, proposer_reward)
|
2021-05-28 15:25:58 +00:00
|
|
|
else:
|
2021-10-13 14:24:36 +00:00
|
|
|
decrease_balance(state, participant_index, participant_reward)
|
2021-05-28 15:25:58 +00:00
|
|
|
|
|
|
|
ok()
|
|
|
|
|
2022-10-04 16:45:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#process_execution_payload
|
2021-09-27 14:22:58 +00:00
|
|
|
proc process_execution_payload*(
|
2022-10-27 06:29:24 +00:00
|
|
|
state: var bellatrix.BeaconState, payload: bellatrix.ExecutionPayload,
|
|
|
|
notify_new_payload: bellatrix.ExecutePayload): Result[void, cstring] =
|
2021-11-05 16:49:03 +00:00
|
|
|
## Verify consistency of the parent hash with respect to the previous
|
|
|
|
## execution payload header
|
2021-12-14 21:02:29 +00:00
|
|
|
if is_merge_transition_complete(state):
|
2021-09-27 14:22:58 +00:00
|
|
|
if not (payload.parent_hash ==
|
|
|
|
state.latest_execution_payload_header.block_hash):
|
|
|
|
return err("process_execution_payload: payload and state parent hash mismatch")
|
|
|
|
|
2022-03-03 16:08:14 +00:00
|
|
|
# Verify prev_randao
|
|
|
|
if not (payload.prev_randao == get_randao_mix(state, get_current_epoch(state))):
|
2021-09-27 14:22:58 +00:00
|
|
|
return err("process_execution_payload: payload and state randomness mismatch")
|
|
|
|
|
|
|
|
# Verify timestamp
|
|
|
|
if not (payload.timestamp == compute_timestamp_at_slot(state, state.slot)):
|
|
|
|
return err("process_execution_payload: invalid timestamp")
|
|
|
|
|
|
|
|
# Verify the execution payload is valid
|
2022-02-01 07:31:53 +00:00
|
|
|
if not notify_new_payload(payload):
|
2021-09-27 14:22:58 +00:00
|
|
|
return err("process_execution_payload: execution payload invalid")
|
|
|
|
|
|
|
|
# Cache execution payload header
|
2022-10-27 06:29:24 +00:00
|
|
|
state.latest_execution_payload_header = bellatrix.ExecutionPayloadHeader(
|
2021-09-27 14:22:58 +00:00
|
|
|
parent_hash: payload.parent_hash,
|
2022-01-03 12:22:56 +00:00
|
|
|
fee_recipient: payload.fee_recipient,
|
2021-09-27 14:22:58 +00:00
|
|
|
state_root: payload.state_root,
|
2021-12-09 11:18:38 +00:00
|
|
|
receipts_root: payload.receipts_root,
|
2021-09-27 14:22:58 +00:00
|
|
|
logs_bloom: payload.logs_bloom,
|
2022-03-03 16:08:14 +00:00
|
|
|
prev_randao: payload.prev_randao,
|
2021-09-27 14:22:58 +00:00
|
|
|
block_number: payload.block_number,
|
|
|
|
gas_limit: payload.gas_limit,
|
|
|
|
gas_used: payload.gas_used,
|
|
|
|
timestamp: payload.timestamp,
|
|
|
|
base_fee_per_gas: payload.base_fee_per_gas,
|
|
|
|
block_hash: payload.block_hash,
|
2022-01-03 12:22:56 +00:00
|
|
|
extra_data: payload.extra_data,
|
2021-09-27 14:22:58 +00:00
|
|
|
transactions_root: hash_tree_root(payload.transactions))
|
|
|
|
|
|
|
|
ok()
|
|
|
|
|
2022-10-28 08:02:33 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#modified-process_execution_payload
|
2022-10-27 06:29:24 +00:00
|
|
|
proc process_execution_payload*(
|
|
|
|
state: var capella.BeaconState, payload: capella.ExecutionPayload,
|
|
|
|
notify_new_payload: capella.ExecutePayload): Result[void, cstring] =
|
|
|
|
## Verify consistency of the parent hash with respect to the previous
|
|
|
|
## execution payload header
|
|
|
|
if is_merge_transition_complete(state):
|
|
|
|
if not (payload.parent_hash ==
|
|
|
|
state.latest_execution_payload_header.block_hash):
|
|
|
|
return err("process_execution_payload: payload and state parent hash mismatch")
|
|
|
|
|
|
|
|
# Verify prev_randao
|
|
|
|
if not (payload.prev_randao == get_randao_mix(state, get_current_epoch(state))):
|
|
|
|
return err("process_execution_payload: payload and state randomness mismatch")
|
|
|
|
|
|
|
|
# Verify timestamp
|
|
|
|
if not (payload.timestamp == compute_timestamp_at_slot(state, state.slot)):
|
|
|
|
return err("process_execution_payload: invalid timestamp")
|
|
|
|
|
|
|
|
# Verify the execution payload is valid
|
|
|
|
if not notify_new_payload(payload):
|
|
|
|
return err("process_execution_payload: execution payload invalid")
|
|
|
|
|
|
|
|
# Cache execution payload header
|
|
|
|
state.latest_execution_payload_header = capella.ExecutionPayloadHeader(
|
|
|
|
parent_hash: payload.parent_hash,
|
|
|
|
fee_recipient: payload.fee_recipient,
|
|
|
|
state_root: payload.state_root,
|
|
|
|
receipts_root: payload.receipts_root,
|
|
|
|
logs_bloom: payload.logs_bloom,
|
|
|
|
prev_randao: payload.prev_randao,
|
|
|
|
block_number: payload.block_number,
|
|
|
|
gas_limit: payload.gas_limit,
|
|
|
|
gas_used: payload.gas_used,
|
|
|
|
timestamp: payload.timestamp,
|
|
|
|
base_fee_per_gas: payload.base_fee_per_gas,
|
|
|
|
block_hash: payload.block_hash,
|
|
|
|
extra_data: payload.extra_data,
|
|
|
|
transactions_root: hash_tree_root(payload.transactions),
|
|
|
|
withdrawals_root: hash_tree_root(payload.withdrawals)) # [New in Capella]
|
|
|
|
|
|
|
|
ok()
|
|
|
|
|
2022-10-28 08:02:33 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#new-process_bls_to_execution_change
|
2022-10-27 06:29:24 +00:00
|
|
|
proc process_bls_to_execution_change*(
|
|
|
|
state: var capella.BeaconState,
|
|
|
|
signed_address_change: SignedBLSToExecutionChange): Result[void, cstring] =
|
|
|
|
let address_change = signed_address_change.message
|
|
|
|
|
|
|
|
if not (address_change.validator_index < state.validators.lenu64):
|
|
|
|
return err("process_bls_to_execution_change: invalid validator index")
|
|
|
|
|
|
|
|
var withdrawal_credentials =
|
|
|
|
state.validators.item(address_change.validator_index).withdrawal_credentials
|
|
|
|
|
|
|
|
if not (withdrawal_credentials.data[0] == BLS_WITHDRAWAL_PREFIX):
|
|
|
|
return err("process_bls_to_execution_change: invalid withdrawal prefix")
|
|
|
|
|
|
|
|
# TODO what's usual convention here re 32 hardcoded constant?
|
|
|
|
if not (withdrawal_credentials.data.toOpenArray(1, 31) ==
|
|
|
|
eth2digest(address_change.from_bls_pubkey.blob).data.toOpenArray(1, 31)):
|
|
|
|
return err("process_bls_to_execution_change: invalid withdrawal credentials")
|
|
|
|
|
|
|
|
if not verify_bls_to_execution_change_signature(
|
|
|
|
state.fork, state.genesis_validators_root, state.get_current_epoch,
|
|
|
|
signed_address_change, address_change.from_bls_pubkey,
|
|
|
|
signed_address_change.signature):
|
|
|
|
return err("process_bls_to_execution_change: invalid signature")
|
|
|
|
|
|
|
|
withdrawal_credentials.data[0] = ETH1_ADDRESS_WITHDRAWAL_PREFIX
|
|
|
|
withdrawal_credentials.data.fill(1, 11, 0)
|
|
|
|
withdrawal_credentials.data[12..31] =
|
|
|
|
address_change.to_execution_address.data
|
|
|
|
state.validators.mitem(address_change.validator_index).withdrawal_credentials =
|
|
|
|
withdrawal_credentials
|
|
|
|
|
|
|
|
ok()
|
|
|
|
|
2022-10-28 08:02:33 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#new-process_withdrawals
|
2022-10-27 06:29:24 +00:00
|
|
|
func process_withdrawals*(
|
|
|
|
state: var capella.BeaconState, payload: capella.ExecutionPayload):
|
|
|
|
Result[void, cstring] =
|
|
|
|
let
|
|
|
|
num_withdrawals =
|
|
|
|
min(MAX_WITHDRAWALS_PER_PAYLOAD, len(state.withdrawal_queue))
|
|
|
|
dequeued_withdrawals = state.withdrawal_queue.asSeq[0 ..< num_withdrawals]
|
|
|
|
|
|
|
|
if not (len(dequeued_withdrawals) == len(payload.withdrawals)):
|
|
|
|
return err("process_withdrawals: different numbers of dequeued and payload withdrawals")
|
|
|
|
|
|
|
|
for i in 0 ..< len(dequeued_withdrawals):
|
|
|
|
if not (dequeued_withdrawals[i] == payload.withdrawals[i]):
|
|
|
|
return err("process_withdrawals: mismatched queued and payload withdrawals")
|
|
|
|
|
|
|
|
# Remove dequeued withdrawals from state
|
|
|
|
if num_withdrawals > 0:
|
|
|
|
state.withdrawal_queue.asSeq.delete(0, num_withdrawals - 1)
|
|
|
|
state.withdrawal_queue.resetCache()
|
|
|
|
|
|
|
|
ok()
|
|
|
|
|
2022-09-23 07:56:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#block-processing
|
2021-05-28 15:25:58 +00:00
|
|
|
# TODO workaround for https://github.com/nim-lang/Nim/issues/18095
|
|
|
|
# copy of datatypes/phase0.nim
|
|
|
|
type SomePhase0Block =
|
|
|
|
phase0.BeaconBlock | phase0.SigVerifiedBeaconBlock | phase0.TrustedBeaconBlock
|
|
|
|
proc process_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-05-28 15:25:58 +00:00
|
|
|
state: var phase0.BeaconState, blck: SomePhase0Block, flags: UpdateFlags,
|
2021-12-03 14:46:56 +00:00
|
|
|
cache: var StateCache): Result[void, cstring]=
|
2021-05-28 15:25:58 +00:00
|
|
|
## When there's a new block, we need to verify that the block is sane and
|
|
|
|
## update the state accordingly - the state is left in an unknown state when
|
|
|
|
## block application fails (!)
|
|
|
|
|
|
|
|
? process_block_header(state, blck, flags, cache)
|
|
|
|
? process_randao(state, blck.body, flags, cache)
|
|
|
|
? process_eth1_data(state, blck.body)
|
2021-10-13 14:24:36 +00:00
|
|
|
? process_operations(cfg, state, blck.body, 0.Gwei, flags, cache)
|
2021-05-28 15:25:58 +00:00
|
|
|
|
|
|
|
ok()
|
|
|
|
|
2022-09-23 07:56:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#block-processing
|
2021-05-28 15:25:58 +00:00
|
|
|
# TODO workaround for https://github.com/nim-lang/Nim/issues/18095
|
|
|
|
# copy of datatypes/altair.nim
|
|
|
|
type SomeAltairBlock =
|
|
|
|
altair.BeaconBlock | altair.SigVerifiedBeaconBlock | altair.TrustedBeaconBlock
|
2020-03-15 13:01:37 +00:00
|
|
|
proc process_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-05-28 15:25:58 +00:00
|
|
|
state: var altair.BeaconState, blck: SomeAltairBlock, flags: UpdateFlags,
|
2021-12-03 14:46:56 +00:00
|
|
|
cache: var StateCache): Result[void, cstring]=
|
2019-06-28 13:44:44 +00:00
|
|
|
## When there's a new block, we need to verify that the block is sane and
|
2020-11-02 17:34:23 +00:00
|
|
|
## update the state accordingly - the state is left in an unknown state when
|
|
|
|
## block application fails (!)
|
2019-10-21 08:11:54 +00:00
|
|
|
|
2021-04-08 10:11:04 +00:00
|
|
|
? process_block_header(state, blck, flags, cache)
|
|
|
|
? process_randao(state, blck.body, flags, cache)
|
|
|
|
? process_eth1_data(state, blck.body)
|
2021-10-13 14:24:36 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
total_active_balance = get_total_active_balance(state, cache)
|
|
|
|
base_reward_per_increment =
|
|
|
|
get_base_reward_per_increment(total_active_balance)
|
|
|
|
|
|
|
|
? process_operations(
|
|
|
|
cfg, state, blck.body, base_reward_per_increment, flags, cache)
|
|
|
|
? process_sync_aggregate(
|
|
|
|
state, blck.body.sync_aggregate, total_active_balance, cache) # [New in Altair]
|
2019-06-28 13:44:44 +00:00
|
|
|
|
2020-12-02 12:23:10 +00:00
|
|
|
ok()
|
2021-06-04 10:38:00 +00:00
|
|
|
|
2021-09-27 14:22:58 +00:00
|
|
|
# TODO workaround for https://github.com/nim-lang/Nim/issues/18095
|
2022-03-23 12:49:54 +00:00
|
|
|
type SomeBellatrixBlock =
|
2022-01-06 11:25:35 +00:00
|
|
|
bellatrix.BeaconBlock | bellatrix.SigVerifiedBeaconBlock | bellatrix.TrustedBeaconBlock
|
2021-09-27 14:22:58 +00:00
|
|
|
proc process_block*(
|
|
|
|
cfg: RuntimeConfig,
|
2022-03-23 12:49:54 +00:00
|
|
|
state: var bellatrix.BeaconState, blck: SomeBellatrixBlock,
|
|
|
|
flags: UpdateFlags, cache: var StateCache): Result[void, cstring]=
|
2021-09-27 14:22:58 +00:00
|
|
|
## When there's a new block, we need to verify that the block is sane and
|
|
|
|
## update the state accordingly - the state is left in an unknown state when
|
|
|
|
## block application fails (!)
|
|
|
|
|
|
|
|
? process_block_header(state, blck, flags, cache)
|
|
|
|
if is_execution_enabled(state, blck.body):
|
|
|
|
? process_execution_payload(
|
|
|
|
state, blck.body.execution_payload,
|
|
|
|
func(_: ExecutionPayload): bool = true)
|
|
|
|
? process_randao(state, blck.body, flags, cache)
|
|
|
|
? process_eth1_data(state, blck.body)
|
2021-10-13 14:24:36 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
total_active_balance = get_total_active_balance(state, cache)
|
|
|
|
base_reward_per_increment =
|
|
|
|
get_base_reward_per_increment(total_active_balance)
|
|
|
|
? process_operations(
|
|
|
|
cfg, state, blck.body, base_reward_per_increment, flags, cache)
|
|
|
|
? process_sync_aggregate(
|
|
|
|
state, blck.body.sync_aggregate, total_active_balance, cache)
|
2021-09-27 14:22:58 +00:00
|
|
|
|
|
|
|
ok()
|