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 Mamy Ratsimbazafy
parent 1fefe2bb19
commit 174e21eb17
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)): if not (blck.parent_root == hash_tree_root(state.latest_block_header)):
return err("process_block_header: previous block root mismatch") 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 # Cache current block as the new latest block
state.latest_block_header = BeaconBlockHeader( state.latest_block_header = BeaconBlockHeader(
slot: blck.slot, slot: blck.slot,
@ -71,11 +75,6 @@ func process_block_header*(
body_root: hash_tree_root(blck.body), 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() ok()
func `xor`[T: array](a, b: T): T = func `xor`[T: array](a, b: T): T =