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:
Dustin Brody 2020-03-15 14:01:37 +01:00 committed by zah
parent 75003c22e1
commit 313109c743
7 changed files with 21 additions and 26 deletions

View File

@ -140,13 +140,15 @@ OK: 9/9 Fail: 0/9 Skip: 0/9
+ [Valid] deposit_top_up OK
+ [Valid] empty_block_transition OK
+ [Valid] empty_epoch_transition OK
+ [Valid] high_proposer_index OK
+ [Valid] historical_batch OK
+ [Valid] proposer_after_inactive_index OK
+ [Valid] proposer_slashing OK
+ [Valid] same_slot_block_transition OK
+ [Valid] skipped_slots 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]
```diff
+ 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
---TOTAL---
OK: 108/108 Fail: 0/108 Skip: 0/108
OK: 110/110 Fail: 0/110 Skip: 0/110

View File

@ -143,13 +143,15 @@ OK: 9/9 Fail: 0/9 Skip: 0/9
+ [Valid] empty_epoch_transition_not_finalizing OK
+ [Valid] eth1_data_votes_consensus OK
+ [Valid] eth1_data_votes_no_consensus OK
+ [Valid] high_proposer_index OK
+ [Valid] historical_batch OK
+ [Valid] proposer_after_inactive_index OK
+ [Valid] proposer_slashing OK
+ [Valid] same_slot_block_transition OK
+ [Valid] skipped_slots 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]
```diff
+ 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
---TOTAL---
OK: 111/111 Fail: 0/111 Skip: 0/111
OK: 113/113 Fail: 0/113 Skip: 0/113

View File

@ -62,7 +62,9 @@ proc process_block_header*(
return false
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
# Verify that the parent matches
@ -376,7 +378,8 @@ proc processVoluntaryExits(state: var BeaconState, blck: BeaconBlock, flags: Upd
return false
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,
stateCache: var StateCache): bool {.nbench.}=
## 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
# 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):
debug "[Block processing] Proposer slashing failure", slot = shortLog(state.slot)
return false

View File

@ -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
proc process_epoch*(state: var BeaconState) {.nbench.}=
# @proc are placeholders
trace "process_epoch",
current_epoch = get_current_epoch(state)
@ -438,19 +436,12 @@ proc process_epoch*(state: var BeaconState) {.nbench.}=
## get_active_validator_indices(...) usually changes.
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
process_slashings(state)
# @update_period_committee
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#final-updates
process_final_updates(state)
# @after_process_final_updates
# Once per epoch metrics
beacon_finalized_epoch.set(state.finalized_checkpoint.epoch.int64)
beacon_finalized_root.set(state.finalized_checkpoint.root.toGaugeValue)

View File

@ -145,7 +145,7 @@ func get_empty_per_epoch_cache*(): StateCache =
initTable[Epoch, seq[ValidatorIndex]]()
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],
seed: Eth2Digest, stateCache: var StateCache): Option[ValidatorIndex] =
# 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:
return none(ValidatorIndex)
# TODO fixme; should only be run once per slot and cached
# There's exactly one beacon proposer per slot.
let
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
@ -178,7 +176,7 @@ func compute_proposer_index(state: BeaconState, indices: seq[ValidatorIndex],
return some(candidate_index)
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):
Option[ValidatorIndex] =
# 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[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
seed = eth2hash(buffer)
indices = get_active_validator_indices(state, epoch)

View File

@ -157,7 +157,7 @@ proc state_transition*(
# https://github.com/ethereum/eth2.0-specs/issues/293
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
# state we arrive at is what the block producer thought it would be -
# meaning that potentially, it could fail verification
@ -224,7 +224,7 @@ proc state_transition*(
process_slots(state, signedBlock.message.slot)
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):
# State root is what it should be - we're done!

View File

@ -70,9 +70,6 @@ suiteReport "Official - Sanity - Blocks " & preset():
"attester_slashing",
# TODO: regression BLS v0.10.1 to fix
"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):