Skip to content

Commit

Permalink
incorporate epoch proposer slashings ethereum/consensus-specs#762
Browse files Browse the repository at this point in the history
  • Loading branch information
djrtwo committed Mar 12, 2019
1 parent f17fcbf commit f005f85
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion spec_pythonizer/sanity_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ def test_proposer_slashing(state):
)
header_2 = deepcopy(header_1)
header_2.previous_block_root = b'\x02'*32
header_2.slot = slot + 1

proposer_slashing = ProposerSlashing(
proposer_index=validator_index,
Expand Down Expand Up @@ -527,13 +528,14 @@ def sanity_tests():
print("Passed historical batch test\n")
print("done!")


# Monkey patch validator shuffling cache
_get_shuffling = spec.get_shuffling
shuffling_cache = {}
def get_shuffling(seed: Bytes32,
validators: List[Validator],
epoch: Epoch) -> List[List[ValidatorIndex]]:

param_hash = (seed, hash_tree_root(validators, [Validator]), epoch)

if param_hash in shuffling_cache:
Expand All @@ -545,8 +547,10 @@ def get_shuffling(seed: Bytes32,
shuffling_cache[param_hash] = ret
return ret


spec.get_shuffling = get_shuffling


hash_cache = {}
def hash(x):
if x in hash_cache:
Expand All @@ -556,6 +560,7 @@ def hash(x):
hash_cache[x] = ret
return ret


spec.hash = hash

if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions spec_pythonizer/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -2305,8 +2305,8 @@ def process_proposer_slashing(state: BeaconState,
Note that this function mutates ``state``.
"""
proposer = state.validator_registry[proposer_slashing.proposer_index]
# Verify that the slot is the same
assert proposer_slashing.header_1.slot == proposer_slashing.header_2.slot
# Verify that the epoch is the same
assert slot_to_epoch(proposer_slashing.header_1.slot) == slot_to_epoch(proposer_slashing.header_2.slot)
# But the headers are different
assert proposer_slashing.header_1 != proposer_slashing.header_2
# Proposer is not yet slashed
Expand Down

0 comments on commit f005f85

Please sign in to comment.