-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add cached PTC window to the state #4979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6c98625
Add a PTC Lookbehind slice in the state
potuz 37f1c0e
Update specs/gloas/beacon-chain.md
potuz 2bdbf01
Update specs/gloas/beacon-chain.md
potuz fd398a6
lint
potuz 10e5813
Fix off-by-1 issue in process_ptc_lookahead
jtraglia a7bd06c
Make necessary changes to fork specs
jtraglia dc0b3f4
Make some improvements to get_ptc() and add unit tests
jtraglia 72d5acc
Add 3 epochs
potuz bc6b2c5
Refactor process_ptc_lookbehind
jtraglia 6579ca0
Rename ptc_lookbehind to ptc_window
jtraglia b7c1794
Update initialize_ptc_window & fix a test
jtraglia 41d963c
Hardcode ptc_window to be prev/curr/next epochs
jtraglia 31745d0
Add back MIN_SEED_LOOKAHEAD to ptc_window
jtraglia e7b1910
Fix epoch restrictions in paragraph
jtraglia 89ce53b
Fix typo
jtraglia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
tests/core/pyspec/eth_consensus_specs/test/gloas/epoch_processing/test_process_ptc_window.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| from eth_consensus_specs.test.context import ( | ||
| single_phase, | ||
| spec_state_test, | ||
| with_phases, | ||
| ) | ||
| from eth_consensus_specs.test.helpers.constants import GLOAS | ||
| from eth_consensus_specs.test.helpers.epoch_processing import run_epoch_processing_with | ||
|
|
||
|
|
||
| @with_phases([GLOAS]) | ||
| @spec_state_test | ||
| @single_phase | ||
| def test_process_ptc_window__shifts_all_epochs(spec, state): | ||
| """ | ||
| Verify that process_ptc_window shifts prev/curr/next correctly | ||
| and that get_ptc returns the right committees afterwards. | ||
| """ | ||
| spec.process_slots(state, state.slot + 2 * spec.SLOTS_PER_EPOCH - 1) | ||
|
|
||
| SPE = spec.SLOTS_PER_EPOCH | ||
| # Save current and next epoch sections before the shift | ||
| curr_epoch_ptc = list(state.ptc_window[SPE : 2 * SPE]) | ||
| next_epoch_ptc = list(state.ptc_window[2 * SPE : 3 * SPE]) | ||
|
|
||
| yield from run_epoch_processing_with(spec, state, "process_ptc_window") | ||
|
|
||
| # After shift: [curr, next, new_next] | ||
| assert list(state.ptc_window[:SPE]) == curr_epoch_ptc | ||
| assert list(state.ptc_window[SPE : 2 * SPE]) == next_epoch_ptc | ||
|
|
||
| # run_epoch_processing_with does not increment the slot, so do it manually | ||
| state.slot += 1 | ||
|
|
||
| # Now state_epoch = current_epoch + 1 | ||
| # Previous epoch lookup (current_epoch) should hit the first section | ||
| assert spec.get_ptc(state, spec.Slot(state.slot - 1)) == curr_epoch_ptc[-1] | ||
| # Current epoch lookup should hit the second section | ||
| assert spec.get_ptc(state, state.slot) == next_epoch_ptc[0] |
1 change: 1 addition & 0 deletions
1
tests/core/pyspec/eth_consensus_specs/test/gloas/unittests/validator/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
102 changes: 102 additions & 0 deletions
102
tests/core/pyspec/eth_consensus_specs/test/gloas/unittests/validator/test_validator.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| from eth_consensus_specs.test.context import ( | ||
| expect_assertion_error, | ||
| single_phase, | ||
| spec_test, | ||
| with_phases, | ||
| with_state, | ||
| ) | ||
| from eth_consensus_specs.test.helpers.constants import GLOAS | ||
| from eth_consensus_specs.test.helpers.state import next_epoch | ||
|
|
||
|
|
||
| def _compute_first_ptc_assignments(spec, state, epoch): | ||
| assignments = {} | ||
| start_slot = spec.compute_start_slot_at_epoch(epoch) | ||
| for slot in range(start_slot, start_slot + spec.SLOTS_PER_EPOCH): | ||
| for validator_index in spec.compute_ptc(state, spec.Slot(slot)): | ||
| assignments.setdefault(validator_index, spec.Slot(slot)) | ||
| return assignments | ||
|
|
||
|
|
||
| def _run_get_ptc_assignments(spec, state, epoch, valid=True, assignments=None): | ||
| if not valid: | ||
| expect_assertion_error( | ||
| lambda: spec.get_ptc_assignment(state, epoch, spec.ValidatorIndex(0)) | ||
| ) | ||
| return | ||
|
|
||
| if assignments is None: | ||
| assignments = _compute_first_ptc_assignments(spec, state, epoch) | ||
| _assert_get_ptc_assignments(spec, state, epoch, assignments) | ||
|
|
||
|
|
||
| def _assert_get_ptc_assignments(spec, state, epoch, assignments): | ||
| assert len(assignments) > 0 | ||
|
|
||
| for validator_index, expected_slot in assignments.items(): | ||
| assert spec.get_ptc_assignment(state, epoch, validator_index) == expected_slot | ||
|
|
||
| unassigned_validator = next( | ||
| (spec.ValidatorIndex(i) for i in range(len(state.validators)) if i not in assignments), | ||
| None, | ||
| ) | ||
| if unassigned_validator is not None: | ||
| assert spec.get_ptc_assignment(state, epoch, unassigned_validator) is None | ||
|
|
||
|
|
||
| @with_phases([GLOAS]) | ||
| @spec_test | ||
| @with_state | ||
| @single_phase | ||
| def test_get_ptc_assignment__current_epoch_minus_2(spec, state): | ||
| next_epoch(spec, state) | ||
| next_epoch(spec, state) | ||
|
|
||
| epoch = spec.Epoch(spec.get_current_epoch(state) - 2) | ||
| _run_get_ptc_assignments(spec, state, epoch, valid=False) | ||
|
|
||
|
|
||
| @with_phases([GLOAS]) | ||
| @spec_test | ||
| @with_state | ||
| @single_phase | ||
| def test_get_ptc_assignment__current_epoch_minus_1(spec, state): | ||
| previous_epoch = spec.get_current_epoch(state) | ||
| previous_assignments = _compute_first_ptc_assignments(spec, state, previous_epoch) | ||
|
|
||
| next_epoch(spec, state) | ||
|
|
||
| _run_get_ptc_assignments( | ||
| spec, | ||
| state, | ||
| previous_epoch, | ||
| valid=True, | ||
| assignments=previous_assignments, | ||
| ) | ||
|
|
||
|
|
||
| @with_phases([GLOAS]) | ||
| @spec_test | ||
| @with_state | ||
| @single_phase | ||
| def test_get_ptc_assignment__current_epoch(spec, state): | ||
| epoch = spec.get_current_epoch(state) | ||
| _run_get_ptc_assignments(spec, state, epoch, valid=True) | ||
|
|
||
|
|
||
| @with_phases([GLOAS]) | ||
| @spec_test | ||
| @with_state | ||
| @single_phase | ||
| def test_get_ptc_assignment__current_epoch_plus_1(spec, state): | ||
| epoch = spec.Epoch(spec.get_current_epoch(state) + 1) | ||
| _run_get_ptc_assignments(spec, state, epoch, valid=True) | ||
|
|
||
|
|
||
| @with_phases([GLOAS]) | ||
| @spec_test | ||
| @with_state | ||
| @single_phase | ||
| def test_get_ptc_assignment__current_epoch_plus_2(spec, state): | ||
| epoch = spec.Epoch(spec.get_current_epoch(state) + 2) | ||
| _run_get_ptc_assignments(spec, state, epoch, valid=False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.