mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-17 00:47:03 +00:00
align process_block(...) name with spec; fix beacon chain proposer index generation when some validators aren't active to fix the two regressing 0.11.0 block sanity tests
This commit is contained in:
parent
75003c22e1
commit
313109c743
@ -140,13 +140,15 @@ OK: 9/9 Fail: 0/9 Skip: 0/9
|
|||||||
+ [Valid] deposit_top_up OK
|
+ [Valid] deposit_top_up OK
|
||||||
+ [Valid] empty_block_transition OK
|
+ [Valid] empty_block_transition OK
|
||||||
+ [Valid] empty_epoch_transition OK
|
+ [Valid] empty_epoch_transition OK
|
||||||
|
+ [Valid] high_proposer_index OK
|
||||||
+ [Valid] historical_batch OK
|
+ [Valid] historical_batch OK
|
||||||
|
+ [Valid] proposer_after_inactive_index OK
|
||||||
+ [Valid] proposer_slashing OK
|
+ [Valid] proposer_slashing OK
|
||||||
+ [Valid] same_slot_block_transition OK
|
+ [Valid] same_slot_block_transition OK
|
||||||
+ [Valid] skipped_slots OK
|
+ [Valid] skipped_slots OK
|
||||||
+ [Valid] voluntary_exit OK
|
+ [Valid] voluntary_exit OK
|
||||||
```
|
```
|
||||||
OK: 17/17 Fail: 0/17 Skip: 0/17
|
OK: 19/19 Fail: 0/19 Skip: 0/19
|
||||||
## Official - Sanity - Slots [Preset: mainnet]
|
## Official - Sanity - Slots [Preset: mainnet]
|
||||||
```diff
|
```diff
|
||||||
+ Slots - double_empty_epoch OK
|
+ Slots - double_empty_epoch OK
|
||||||
@ -158,4 +160,4 @@ OK: 17/17 Fail: 0/17 Skip: 0/17
|
|||||||
OK: 5/5 Fail: 0/5 Skip: 0/5
|
OK: 5/5 Fail: 0/5 Skip: 0/5
|
||||||
|
|
||||||
---TOTAL---
|
---TOTAL---
|
||||||
OK: 108/108 Fail: 0/108 Skip: 0/108
|
OK: 110/110 Fail: 0/110 Skip: 0/110
|
||||||
|
@ -143,13 +143,15 @@ OK: 9/9 Fail: 0/9 Skip: 0/9
|
|||||||
+ [Valid] empty_epoch_transition_not_finalizing OK
|
+ [Valid] empty_epoch_transition_not_finalizing OK
|
||||||
+ [Valid] eth1_data_votes_consensus OK
|
+ [Valid] eth1_data_votes_consensus OK
|
||||||
+ [Valid] eth1_data_votes_no_consensus OK
|
+ [Valid] eth1_data_votes_no_consensus OK
|
||||||
|
+ [Valid] high_proposer_index OK
|
||||||
+ [Valid] historical_batch OK
|
+ [Valid] historical_batch OK
|
||||||
|
+ [Valid] proposer_after_inactive_index OK
|
||||||
+ [Valid] proposer_slashing OK
|
+ [Valid] proposer_slashing OK
|
||||||
+ [Valid] same_slot_block_transition OK
|
+ [Valid] same_slot_block_transition OK
|
||||||
+ [Valid] skipped_slots OK
|
+ [Valid] skipped_slots OK
|
||||||
+ [Valid] voluntary_exit OK
|
+ [Valid] voluntary_exit OK
|
||||||
```
|
```
|
||||||
OK: 20/20 Fail: 0/20 Skip: 0/20
|
OK: 22/22 Fail: 0/22 Skip: 0/22
|
||||||
## Official - Sanity - Slots [Preset: minimal]
|
## Official - Sanity - Slots [Preset: minimal]
|
||||||
```diff
|
```diff
|
||||||
+ Slots - double_empty_epoch OK
|
+ Slots - double_empty_epoch OK
|
||||||
@ -161,4 +163,4 @@ OK: 20/20 Fail: 0/20 Skip: 0/20
|
|||||||
OK: 5/5 Fail: 0/5 Skip: 0/5
|
OK: 5/5 Fail: 0/5 Skip: 0/5
|
||||||
|
|
||||||
---TOTAL---
|
---TOTAL---
|
||||||
OK: 111/111 Fail: 0/111 Skip: 0/111
|
OK: 113/113 Fail: 0/113 Skip: 0/113
|
||||||
|
@ -62,7 +62,9 @@ proc process_block_header*(
|
|||||||
return false
|
return false
|
||||||
|
|
||||||
if not (blck.proposer_index.ValidatorIndex == proposer_index.get):
|
if not (blck.proposer_index.ValidatorIndex == proposer_index.get):
|
||||||
notice "Block header: proposer index incorrect"
|
notice "Block header: proposer index incorrect",
|
||||||
|
block_proposer_index = blck.proposer_index.ValidatorIndex,
|
||||||
|
proposer_index = proposer_index.get
|
||||||
return false
|
return false
|
||||||
|
|
||||||
# Verify that the parent matches
|
# Verify that the parent matches
|
||||||
@ -376,7 +378,8 @@ proc processVoluntaryExits(state: var BeaconState, blck: BeaconBlock, flags: Upd
|
|||||||
return false
|
return false
|
||||||
return true
|
return true
|
||||||
|
|
||||||
proc processBlock*(
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/specs/phase0/beacon-chain.md#block-processing
|
||||||
|
proc process_block*(
|
||||||
state: var BeaconState, blck: BeaconBlock, flags: UpdateFlags,
|
state: var BeaconState, blck: BeaconBlock, flags: UpdateFlags,
|
||||||
stateCache: var StateCache): bool {.nbench.}=
|
stateCache: var StateCache): bool {.nbench.}=
|
||||||
## When there's a new block, we need to verify that the block is sane and
|
## When there's a new block, we need to verify that the block is sane and
|
||||||
@ -411,7 +414,7 @@ proc processBlock*(
|
|||||||
|
|
||||||
# TODO, everything below is now in process_operations
|
# TODO, everything below is now in process_operations
|
||||||
# and implementation is per element instead of the whole seq
|
# and implementation is per element instead of the whole seq
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/specs/phase0/beacon-chain.md#operations
|
||||||
if not processProposerSlashings(state, blck, flags, stateCache):
|
if not processProposerSlashings(state, blck, flags, stateCache):
|
||||||
debug "[Block processing] Proposer slashing failure", slot = shortLog(state.slot)
|
debug "[Block processing] Proposer slashing failure", slot = shortLog(state.slot)
|
||||||
return false
|
return false
|
||||||
|
@ -414,8 +414,6 @@ func process_final_updates*(state: var BeaconState) {.nbench.}=
|
|||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#epoch-processing
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#epoch-processing
|
||||||
proc process_epoch*(state: var BeaconState) {.nbench.}=
|
proc process_epoch*(state: var BeaconState) {.nbench.}=
|
||||||
# @proc are placeholders
|
|
||||||
|
|
||||||
trace "process_epoch",
|
trace "process_epoch",
|
||||||
current_epoch = get_current_epoch(state)
|
current_epoch = get_current_epoch(state)
|
||||||
|
|
||||||
@ -438,19 +436,12 @@ proc process_epoch*(state: var BeaconState) {.nbench.}=
|
|||||||
## get_active_validator_indices(...) usually changes.
|
## get_active_validator_indices(...) usually changes.
|
||||||
clear(per_epoch_cache.beacon_committee_cache)
|
clear(per_epoch_cache.beacon_committee_cache)
|
||||||
|
|
||||||
# @process_reveal_deadlines
|
|
||||||
# @process_challenge_deadlines
|
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#slashings
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#slashings
|
||||||
process_slashings(state)
|
process_slashings(state)
|
||||||
|
|
||||||
# @update_period_committee
|
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#final-updates
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#final-updates
|
||||||
process_final_updates(state)
|
process_final_updates(state)
|
||||||
|
|
||||||
# @after_process_final_updates
|
|
||||||
|
|
||||||
# Once per epoch metrics
|
# Once per epoch metrics
|
||||||
beacon_finalized_epoch.set(state.finalized_checkpoint.epoch.int64)
|
beacon_finalized_epoch.set(state.finalized_checkpoint.epoch.int64)
|
||||||
beacon_finalized_root.set(state.finalized_checkpoint.root.toGaugeValue)
|
beacon_finalized_root.set(state.finalized_checkpoint.root.toGaugeValue)
|
||||||
|
@ -145,7 +145,7 @@ func get_empty_per_epoch_cache*(): StateCache =
|
|||||||
initTable[Epoch, seq[ValidatorIndex]]()
|
initTable[Epoch, seq[ValidatorIndex]]()
|
||||||
result.committee_count_cache = initTable[Epoch, uint64]()
|
result.committee_count_cache = initTable[Epoch, uint64]()
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#compute_proposer_index
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/specs/phase0/beacon-chain.md#compute_proposer_index
|
||||||
func compute_proposer_index(state: BeaconState, indices: seq[ValidatorIndex],
|
func compute_proposer_index(state: BeaconState, indices: seq[ValidatorIndex],
|
||||||
seed: Eth2Digest, stateCache: var StateCache): Option[ValidatorIndex] =
|
seed: Eth2Digest, stateCache: var StateCache): Option[ValidatorIndex] =
|
||||||
# Return from ``indices`` a random index sampled by effective balance.
|
# Return from ``indices`` a random index sampled by effective balance.
|
||||||
@ -154,11 +154,9 @@ func compute_proposer_index(state: BeaconState, indices: seq[ValidatorIndex],
|
|||||||
if len(indices) == 0:
|
if len(indices) == 0:
|
||||||
return none(ValidatorIndex)
|
return none(ValidatorIndex)
|
||||||
|
|
||||||
# TODO fixme; should only be run once per slot and cached
|
|
||||||
# There's exactly one beacon proposer per slot.
|
|
||||||
let
|
let
|
||||||
seq_len = indices.len.uint64
|
seq_len = indices.len.uint64
|
||||||
shuffled_seq = get_shuffled_seq(seed, seq_len)
|
shuffled_seq = mapIt(get_shuffled_seq(seed, seq_len), indices[it])
|
||||||
|
|
||||||
doAssert seq_len == shuffled_seq.len.uint64
|
doAssert seq_len == shuffled_seq.len.uint64
|
||||||
|
|
||||||
@ -178,7 +176,7 @@ func compute_proposer_index(state: BeaconState, indices: seq[ValidatorIndex],
|
|||||||
return some(candidate_index)
|
return some(candidate_index)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#get_beacon_proposer_index
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/specs/phase0/beacon-chain.md#get_beacon_proposer_index
|
||||||
func get_beacon_proposer_index*(state: BeaconState, stateCache: var StateCache):
|
func get_beacon_proposer_index*(state: BeaconState, stateCache: var StateCache):
|
||||||
Option[ValidatorIndex] =
|
Option[ValidatorIndex] =
|
||||||
# Return the beacon proposer index at the current slot.
|
# Return the beacon proposer index at the current slot.
|
||||||
@ -188,6 +186,8 @@ func get_beacon_proposer_index*(state: BeaconState, stateCache: var StateCache):
|
|||||||
buffer[0..31] = get_seed(state, epoch, DOMAIN_BEACON_PROPOSER).data
|
buffer[0..31] = get_seed(state, epoch, DOMAIN_BEACON_PROPOSER).data
|
||||||
buffer[32..39] = int_to_bytes8(state.slot.uint64)
|
buffer[32..39] = int_to_bytes8(state.slot.uint64)
|
||||||
|
|
||||||
|
# TODO fixme; should only be run once per slot and cached
|
||||||
|
# There's exactly one beacon proposer per slot.
|
||||||
let
|
let
|
||||||
seed = eth2hash(buffer)
|
seed = eth2hash(buffer)
|
||||||
indices = get_active_validator_indices(state, epoch)
|
indices = get_active_validator_indices(state, epoch)
|
||||||
|
@ -157,7 +157,7 @@ proc state_transition*(
|
|||||||
# https://github.com/ethereum/eth2.0-specs/issues/293
|
# https://github.com/ethereum/eth2.0-specs/issues/293
|
||||||
var per_epoch_cache = get_empty_per_epoch_cache()
|
var per_epoch_cache = get_empty_per_epoch_cache()
|
||||||
|
|
||||||
if processBlock(state, signedBlock.message, flags, per_epoch_cache):
|
if process_block(state, signedBlock.message, flags, per_epoch_cache):
|
||||||
# This is a bit awkward - at the end of processing we verify that the
|
# This is a bit awkward - at the end of processing we verify that the
|
||||||
# state we arrive at is what the block producer thought it would be -
|
# state we arrive at is what the block producer thought it would be -
|
||||||
# meaning that potentially, it could fail verification
|
# meaning that potentially, it could fail verification
|
||||||
@ -224,7 +224,7 @@ proc state_transition*(
|
|||||||
process_slots(state, signedBlock.message.slot)
|
process_slots(state, signedBlock.message.slot)
|
||||||
var per_epoch_cache = get_empty_per_epoch_cache()
|
var per_epoch_cache = get_empty_per_epoch_cache()
|
||||||
|
|
||||||
if processBlock(state.data, signedBlock.message, flags, per_epoch_cache):
|
if process_block(state.data, signedBlock.message, flags, per_epoch_cache):
|
||||||
if skipStateRootValidation in flags or verifyStateRoot(state.data, signedBlock.message):
|
if skipStateRootValidation in flags or verifyStateRoot(state.data, signedBlock.message):
|
||||||
# State root is what it should be - we're done!
|
# State root is what it should be - we're done!
|
||||||
|
|
||||||
|
@ -70,9 +70,6 @@ suiteReport "Official - Sanity - Blocks " & preset():
|
|||||||
"attester_slashing",
|
"attester_slashing",
|
||||||
# TODO: regression BLS v0.10.1 to fix
|
# TODO: regression BLS v0.10.1 to fix
|
||||||
"expected_deposit_in_block",
|
"expected_deposit_in_block",
|
||||||
# TODO: regressions in 0.11.0 for the moment
|
|
||||||
"high_proposer_index",
|
|
||||||
"proposer_after_inactive_index"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
for kind, path in walkDir(SanityBlocksDir, true):
|
for kind, path in walkDir(SanityBlocksDir, true):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user