-
Notifications
You must be signed in to change notification settings - Fork 1k
Add attestations test with payload_present in op pool
#9531
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
Open
chong-he
wants to merge
11
commits into
sigp:unstable
Choose a base branch
from
chong-he:test-for-op-pool
base: unstable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
16f1b15
add payload_present index test
chong-he ce4683e
add more packing assert
chong-he f138693
revise test
chong-he 93a1d6c
clarify comment
chong-he a66ea0e
add comment
chong-he c0704a3
revise comments
chong-he ba32d37
include attestation
chong-he 99490a7
revert modified test
chong-he 08128a3
change RECENT_FORKS_BEFORE_GLOAS to gloas
chong-he 52a759a
revise makefile
chong-he b612047
fix makefile
chong-he 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -900,7 +900,8 @@ mod release_tests { | |
| use super::attestation::earliest_attestation_validators; | ||
| use super::*; | ||
| use beacon_chain::test_utils::{ | ||
| BeaconChainHarness, EphemeralHarnessType, RelativeSyncCommittee, test_spec, | ||
| BeaconChainHarness, EphemeralHarnessType, MakeAttestationOptions, RelativeSyncCommittee, | ||
| test_spec, | ||
| }; | ||
| use bls::Keypair; | ||
| use maplit::hashset; | ||
|
|
@@ -2454,6 +2455,16 @@ mod release_tests { | |
| } | ||
| } | ||
|
|
||
| // Insert one more distinct PayloadAttestationMessage at a different slot | ||
| let new_slot = Slot::new(0); | ||
| let validator_index = 0; | ||
| let msg = make_payload_attestation_message(new_slot, validator_index, parent_root); | ||
| op_pool.insert_payload_attestation_message(msg).unwrap(); | ||
|
|
||
| // The op pool has a total of (4+1) distinct PayloadAttestationMessage | ||
| // 4 from Slot 1 and 1 from Slot 0 | ||
| assert_eq!(op_pool.payload_attestation_messages.read().len(), 5); | ||
|
|
||
| // When: we pack attestations for block production at slot 2. | ||
| let mut advanced_state = state.clone(); | ||
| state_processing::state_advance::complete_state_advance( | ||
|
|
@@ -2468,11 +2479,116 @@ mod release_tests { | |
| .unwrap(); | ||
|
|
||
| // Then: one attestation per combo, sorted by participation (most first). | ||
| assert_eq!(attestations.len(), 4); | ||
| // Only MaxPayloadAttestations (4) can be packed | ||
| // payload_attestation from Slot 0 is ignored and not packed | ||
| assert_eq!( | ||
| attestations.len(), | ||
| MinimalEthSpec::max_payload_attestations() | ||
| ); | ||
| let bit_counts: Vec<_> = attestations | ||
| .iter() | ||
| .map(|a| a.aggregation_bits.num_set_bits()) | ||
| .collect(); | ||
| assert_eq!(bit_counts, vec![3, 2, 1, 1]); | ||
| } | ||
|
|
||
| /// Test when payload_present is true and the slot is not the head slot, `index` in AttestationData = 1 (for Gloas) | ||
| /// If payload_present is false, `index` = 0 | ||
| /// https://github.com/ethereum/consensus-specs/blame/6b2201c3c25603f24ae967a92bbce5340d672c5c/specs/gloas/validator.md#L97-L111 | ||
| #[tokio::test] | ||
| async fn attestation_payload_present_changes_index_field() { | ||
| let spec = test_spec::<MinimalEthSpec>(); | ||
| if spec.gloas_fork_epoch.is_none() { | ||
| return; | ||
| } | ||
|
|
||
| let num_validators = 64; | ||
| let harness = get_harness::<MinimalEthSpec>(num_validators, Some(spec.clone())); | ||
| let all_validators: Vec<usize> = (0..num_validators).collect(); | ||
|
|
||
| harness | ||
| .add_attested_blocks_at_slots( | ||
| harness.get_current_state(), | ||
| &[Slot::new(1)], | ||
| &all_validators, | ||
| ) | ||
| .await; | ||
|
|
||
| let head = harness.chain.canonical_head.cached_head(); | ||
| let state = &head.snapshot.beacon_state; | ||
| let state_root = head.head_state_root(); | ||
| let head_block_root = head.head_block_root(); | ||
|
|
||
| let attestations_at_head = harness.make_unaggregated_attestations( | ||
| &all_validators, | ||
| state, | ||
| state_root, | ||
| head_block_root.into(), | ||
| Slot::new(1), | ||
| ); | ||
|
|
||
| // when block.slot == current slot, index should always be 0 | ||
| // https://github.com/ethereum/consensus-specs/blame/6b2201c3c25603f24ae967a92bbce5340d672c5c/specs/gloas/validator.md#L104-L105 | ||
| for committee_attestations in &attestations_at_head { | ||
| for (attestation, _subnetid) in committee_attestations { | ||
| assert_eq!( | ||
| attestation.data().index, | ||
| 0, | ||
| "Attestation at head slot should always have index=0" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // Advance to slot 2 without producing a block (skipped slot). | ||
| harness.advance_slot(); | ||
|
|
||
| let attestations_with_payload_present = harness.make_unaggregated_attestations( | ||
| &all_validators, | ||
| state, | ||
| state_root, | ||
| head_block_root.into(), | ||
| Slot::new(2), | ||
| ); | ||
|
|
||
| // head_block is still Slot 1 (since Slot 2 is a skipped slot) | ||
| // block.slot (Slot 1) != current_slot (Slot 2) | ||
| // With payload_present and attesting at Slot 2, index = 1 | ||
| for committee_attestations in &attestations_with_payload_present { | ||
| for (attestation, _subnetid) in committee_attestations { | ||
| assert_eq!( | ||
| attestation.data().index, | ||
| 1, | ||
| "Attestation after head slot should have index=1 when payload_present=true" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // Create attestations at Slot 2 without payload_present | ||
| let fork = spec.fork_at_epoch(Slot::new(2).epoch(MinimalEthSpec::slots_per_epoch())); | ||
| let (attestations_no_payload_present, _attesters) = harness.make_attestations_with_opts( | ||
| &all_validators, | ||
| state, | ||
| state_root, | ||
| head_block_root.into(), | ||
| Slot::new(2), | ||
| MakeAttestationOptions { | ||
| limit: None, | ||
| fork, | ||
| payload_present_override: Some(false), | ||
| }, | ||
| ); | ||
|
|
||
| // Without payload_present, index = 0 | ||
| for (committee_attestations, _signed_aggregate_and_proof) in | ||
| &attestations_no_payload_present | ||
| { | ||
| for (attestation, _subnetid) in committee_attestations { | ||
| assert_eq!( | ||
| attestation.data().index, | ||
| 0, | ||
| "Attestation after head slot should have index=0 when payload_present=false" | ||
| ); | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Next steps should be:
I think this implies there are a few variations of this test:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably need this issue resolved at the spec level first 😅 |
||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this sort of test that checks we don't include payload attestations from old slots, should be a small separate test from the one testing the cap.