assert on missing active validators' attestations when verifying finalization (#1387)

* assert on missing > 10 supposed-to-be-active validators' attestations in finalization verification mode

* clean up state_sim imports
This commit is contained in:
tersec 2020-08-01 18:24:25 +00:00 committed by GitHub
parent 0a96e5f564
commit 85febf072e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 12 deletions

View File

@ -134,16 +134,29 @@ proc process_justification_and_finalization*(state: var BeaconState,
let matching_target_attestations_previous = let matching_target_attestations_previous =
get_matching_target_attestations(state, previous_epoch) # Previous epoch get_matching_target_attestations(state, previous_epoch) # Previous epoch
## This epoch processing is the last time these previous attestations can if verifyFinalization in updateFlags:
## matter -- in the next epoch, they'll be 2 epochs old, when BeaconState # Non-attesting indices in previous epoch
## tracks current_epoch_attestations and previous_epoch_attestations only let missing_all_validators =
## per difference(active_validator_indices,
## https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#attestations toHashSet(mapIt(get_attesting_indices(state,
## and `get_matching_source_attestations(...)` via matching_target_attestations_previous, stateCache), it.uint32)))
## https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#helper-functions-1
## and # testnet0 and testnet1 have 8 non-attesting validators each, by default
## https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#final-updates if missing_all_validators.len > 10:
## after which the state.previous_epoch_attestations is replaced. fatal "Missing too many attesters from previous epoch in verifyFinalization mode",
missing_all_validators
doAssert false
# This epoch processing is the last time these previous attestations can
# matter -- in the next epoch, they'll be 2 epochs old, when BeaconState
# tracks current_epoch_attestations and previous_epoch_attestations only
# per
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#attestations
# and `get_matching_source_attestations(...)` via
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#helper-functions-1
# and
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#final-updates
# after which the state.previous_epoch_attestations is replaced.
let total_active_balance = get_total_active_balance(state, stateCache) let total_active_balance = get_total_active_balance(state, stateCache)
trace "Non-attesting indices in previous epoch", trace "Non-attesting indices in previous epoch",
missing_all_validators= missing_all_validators=

View File

@ -12,9 +12,9 @@ import
confutils, stats, times, confutils, stats, times,
strformat, strformat,
options, sequtils, random, tables, options, sequtils, random, tables,
../tests/[testblockutil], ../tests/testblockutil,
../beacon_chain/spec/[beaconstate, crypto, datatypes, digest, helpers, validator], ../beacon_chain/spec/[beaconstate, crypto, datatypes, digest, helpers, validator],
../beacon_chain/[attestation_pool, extras], ../beacon_chain/extras,
../beacon_chain/ssz/[merkleization, ssz_serialization], ../beacon_chain/ssz/[merkleization, ssz_serialization],
./simutils ./simutils