perform slashing check before mutation (#1594)

avoid copy of validator as well
This commit is contained in:
Jacek Sieka 2020-09-01 09:49:55 +02:00 committed by GitHub
parent 02ddc41960
commit 124ec4b737
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 5 deletions

View File

@ -62,6 +62,10 @@ func process_block_header*(
if not (blck.parent_root == hash_tree_root(state.latest_block_header)):
return err("process_block_header: previous block root mismatch")
# Verify proposer is not slashed
if state.validators[proposer_index.get].slashed:
return err("process_block_header: proposer slashed")
# Cache current block as the new latest block
state.latest_block_header = BeaconBlockHeader(
slot: blck.slot,
@ -71,11 +75,6 @@ func process_block_header*(
body_root: hash_tree_root(blck.body),
)
# Verify proposer is not slashed
let proposer = state.validators[proposer_index.get]
if proposer.slashed:
return err("process_block_header: proposer slashed")
ok()
func `xor`[T: array](a, b: T): T =