From 361d97c54bf0f97dd1a31142186b0ac02e7be83c Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 23 Aug 2021 09:54:00 -0700 Subject: [PATCH] fix bug with proposer search --- .../pyspec/eth2spec/test/helpers/multi_operations.py | 4 ++-- .../eth2spec/test/phase0/sanity/test_blocks_random.py | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py index 54e45b335..c53cc40c7 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/multi_operations.py @@ -150,7 +150,7 @@ def get_random_voluntary_exits(spec, state, to_be_slashed_indices, rng): return prepare_signed_exits(spec, state, exit_indices) -def build_random_block_from_state(spec, state, rng=Random(2188)): +def build_random_block_from_state_for_next_slot(spec, state, rng=Random(2188)): # prepare state for deposits before building block deposits = prepare_state_and_get_random_deposits(spec, state, rng) @@ -177,7 +177,7 @@ def run_test_full_random_operations(spec, state, rng=Random(2080)): # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH - block = build_random_block_from_state(spec, state, rng) + block = build_random_block_from_state_for_next_slot(spec, state, rng) yield 'pre', state diff --git a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py index 7279e19d0..fb7b308f6 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks_random.py @@ -9,7 +9,7 @@ from tests.core.pyspec.eth2spec.test.context import ( zero_activation_threshold, ) from eth2spec.test.helpers.multi_operations import ( - build_random_block_from_state, + build_random_block_from_state_for_next_slot, ) from eth2spec.test.helpers.state import ( next_epoch, @@ -103,13 +103,16 @@ def _random_block(spec, state, _signed_blocks): to produce a block over ``BLOCK_ATTEMPTS`` slots in order to find a valid block in the event that the proposer has already been slashed. """ - block = build_random_block_from_state(spec, state, rng) + temp_state = state.copy() + next_slot(spec, temp_state) for _ in range(BLOCK_ATTEMPTS): - proposer = state.validators[block.proposer_index] + proposer_index = spec.get_beacon_proposer_index(temp_state) + proposer = state.validators[proposer_index] if proposer.slashed: next_slot(spec, state) - block = build_random_block_from_state(spec, state) + next_slot(spec, temp_state) else: + block = build_random_block_from_state_for_next_slot(spec, state) _warn_if_empty_operations(block) return block else: