-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Root next_sync_committee in attested_header
#2932
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
8 commits
Select commit
Hold shift + click to select a range
c4dbd24
Root `next_sync_committee` in `attested_header`
etan-status c67ad59
Reorder helpers to group ones operating on updates
etan-status aa8caee
Add `compute_sync_committee_period_at_slot`
etan-status 35f5010
More concise finality ranking
etan-status fa85648
`==` on new line
etan-status 33f572c
More concise sync committee finality ranking
etan-status 2ddb383
Extend documentation for forced updates
etan-status b7a0e53
Prefix update `period` variables
etan-status 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
Empty file.
132 changes: 132 additions & 0 deletions
132
tests/core/pyspec/eth2spec/test/altair/sync_protocol/test_update_ranking.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,132 @@ | ||
| from eth2spec.test.context import ( | ||
| spec_state_test, | ||
| with_presets, | ||
| with_altair_and_later, | ||
| ) | ||
| from eth2spec.test.helpers.attestations import ( | ||
| next_slots_with_attestations, | ||
| state_transition_with_full_block, | ||
| ) | ||
| from eth2spec.test.helpers.constants import MINIMAL | ||
| from eth2spec.test.helpers.light_client import ( | ||
| get_sync_aggregate, | ||
| signed_block_to_header, | ||
| ) | ||
| from eth2spec.test.helpers.state import ( | ||
| next_slots, | ||
| ) | ||
| from eth2spec.test.helpers.merkle import build_proof | ||
| from math import floor | ||
|
|
||
|
|
||
| def create_update(spec, test, with_next_sync_committee, with_finality, participation_rate): | ||
| attested_state, attested_block, finalized_block = test | ||
| num_participants = floor(spec.SYNC_COMMITTEE_SIZE * participation_rate) | ||
|
|
||
| attested_header = signed_block_to_header(spec, attested_block) | ||
|
|
||
| if with_next_sync_committee: | ||
| next_sync_committee = attested_state.next_sync_committee | ||
| next_sync_committee_branch = build_proof(attested_state.get_backing(), spec.NEXT_SYNC_COMMITTEE_INDEX) | ||
| else: | ||
| next_sync_committee = spec.SyncCommittee() | ||
| next_sync_committee_branch = [spec.Bytes32() for _ in range(spec.floorlog2(spec.NEXT_SYNC_COMMITTEE_INDEX))] | ||
|
|
||
| if with_finality: | ||
| finalized_header = signed_block_to_header(spec, finalized_block) | ||
| finality_branch = build_proof(attested_state.get_backing(), spec.FINALIZED_ROOT_INDEX) | ||
| else: | ||
| finalized_header = spec.BeaconBlockHeader() | ||
| finality_branch = [spec.Bytes32() for _ in range(spec.floorlog2(spec.FINALIZED_ROOT_INDEX))] | ||
|
|
||
| sync_aggregate, signature_slot = get_sync_aggregate(spec, attested_state, num_participants) | ||
|
|
||
| return spec.LightClientUpdate( | ||
| attested_header=attested_header, | ||
| next_sync_committee=next_sync_committee, | ||
| next_sync_committee_branch=next_sync_committee_branch, | ||
| finalized_header=finalized_header, | ||
| finality_branch=finality_branch, | ||
| sync_aggregate=sync_aggregate, | ||
| signature_slot=signature_slot, | ||
| ) | ||
|
|
||
|
|
||
| @with_altair_and_later | ||
| @spec_state_test | ||
| @with_presets([MINIMAL], reason="too slow") | ||
| def test_update_ranking(spec, state): | ||
| # Set up blocks and states: | ||
| # - `sig_finalized` / `sig_attested` --> Only signature in next sync committee period | ||
| # - `att_finalized` / `att_attested` --> Attested header also in next sync committee period | ||
| # - `fin_finalized` / `fin_attested` --> Finalized header also in next sync committee period | ||
| # - `lat_finalized` / `lat_attested` --> Like `fin`, but at a later `attested_header.slot` | ||
| next_slots(spec, state, spec.compute_start_slot_at_epoch(spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD - 3) - 1) | ||
| sig_finalized_block = state_transition_with_full_block(spec, state, True, True) | ||
| _, _, state = next_slots_with_attestations(spec, state, spec.SLOTS_PER_EPOCH - 1, True, True) | ||
| att_finalized_block = state_transition_with_full_block(spec, state, True, True) | ||
| _, _, state = next_slots_with_attestations(spec, state, 2 * spec.SLOTS_PER_EPOCH - 2, True, True) | ||
| sig_attested_block = state_transition_with_full_block(spec, state, True, True) | ||
| sig_attested_state = state.copy() | ||
| att_attested_block = state_transition_with_full_block(spec, state, True, True) | ||
| att_attested_state = state.copy() | ||
| fin_finalized_block = att_attested_block | ||
| _, _, state = next_slots_with_attestations(spec, state, 2 * spec.SLOTS_PER_EPOCH - 1, True, True) | ||
| fin_attested_block = state_transition_with_full_block(spec, state, True, True) | ||
| fin_attested_state = state.copy() | ||
| lat_finalized_block = fin_finalized_block | ||
| lat_attested_block = state_transition_with_full_block(spec, state, True, True) | ||
| lat_attested_state = state.copy() | ||
| sig = (sig_attested_state, sig_attested_block, sig_finalized_block) | ||
| att = (att_attested_state, att_attested_block, att_finalized_block) | ||
| fin = (fin_attested_state, fin_attested_block, fin_finalized_block) | ||
| lat = (lat_attested_state, lat_attested_block, lat_finalized_block) | ||
|
|
||
| # Create updates (in descending order of quality) | ||
| updates = [ | ||
| # Updates with sync committee finality | ||
| create_update(spec, sig, with_next_sync_committee=0, with_finality=1, participation_rate=1.0), | ||
| create_update(spec, fin, with_next_sync_committee=1, with_finality=1, participation_rate=1.0), | ||
| create_update(spec, lat, with_next_sync_committee=1, with_finality=1, participation_rate=1.0), | ||
| create_update(spec, sig, with_next_sync_committee=0, with_finality=1, participation_rate=0.8), | ||
| create_update(spec, fin, with_next_sync_committee=1, with_finality=1, participation_rate=0.8), | ||
| create_update(spec, lat, with_next_sync_committee=1, with_finality=1, participation_rate=0.8), | ||
|
|
||
| # Updates without sync committee finality | ||
| create_update(spec, att, with_next_sync_committee=1, with_finality=1, participation_rate=1.0), | ||
| create_update(spec, att, with_next_sync_committee=1, with_finality=1, participation_rate=0.8), | ||
|
|
||
| # Updates without indication of any finality | ||
| create_update(spec, sig, with_next_sync_committee=0, with_finality=0, participation_rate=1.0), | ||
| create_update(spec, att, with_next_sync_committee=1, with_finality=0, participation_rate=1.0), | ||
| create_update(spec, fin, with_next_sync_committee=1, with_finality=0, participation_rate=1.0), | ||
| create_update(spec, lat, with_next_sync_committee=1, with_finality=0, participation_rate=1.0), | ||
| create_update(spec, sig, with_next_sync_committee=0, with_finality=0, participation_rate=0.8), | ||
| create_update(spec, att, with_next_sync_committee=1, with_finality=0, participation_rate=0.8), | ||
| create_update(spec, fin, with_next_sync_committee=1, with_finality=0, participation_rate=0.8), | ||
| create_update(spec, lat, with_next_sync_committee=1, with_finality=0, participation_rate=0.8), | ||
|
|
||
| # Updates with low sync committee participation | ||
| create_update(spec, sig, with_next_sync_committee=0, with_finality=1, participation_rate=0.4), | ||
| create_update(spec, fin, with_next_sync_committee=1, with_finality=1, participation_rate=0.4), | ||
| create_update(spec, lat, with_next_sync_committee=1, with_finality=1, participation_rate=0.4), | ||
| create_update(spec, att, with_next_sync_committee=1, with_finality=1, participation_rate=0.4), | ||
| create_update(spec, sig, with_next_sync_committee=0, with_finality=0, participation_rate=0.4), | ||
| create_update(spec, att, with_next_sync_committee=1, with_finality=0, participation_rate=0.4), | ||
| create_update(spec, fin, with_next_sync_committee=1, with_finality=0, participation_rate=0.4), | ||
| create_update(spec, lat, with_next_sync_committee=1, with_finality=0, participation_rate=0.4), | ||
|
|
||
| # Updates with very low sync committee participation | ||
| create_update(spec, sig, with_next_sync_committee=0, with_finality=1, participation_rate=0.2), | ||
| create_update(spec, fin, with_next_sync_committee=1, with_finality=1, participation_rate=0.2), | ||
| create_update(spec, lat, with_next_sync_committee=1, with_finality=1, participation_rate=0.2), | ||
| create_update(spec, att, with_next_sync_committee=1, with_finality=1, participation_rate=0.2), | ||
| create_update(spec, sig, with_next_sync_committee=0, with_finality=0, participation_rate=0.2), | ||
| create_update(spec, att, with_next_sync_committee=1, with_finality=0, participation_rate=0.2), | ||
| create_update(spec, fin, with_next_sync_committee=1, with_finality=0, participation_rate=0.2), | ||
| create_update(spec, lat, with_next_sync_committee=1, with_finality=0, participation_rate=0.2), | ||
| ] | ||
| yield "updates", updates | ||
|
|
||
| for i in range(len(updates) - 1): | ||
| assert spec.is_better_update(updates[i], updates[i + 1]) |
Oops, something went wrong.
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.