-
Notifications
You must be signed in to change notification settings - Fork 781
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 by Bors] - Add gossip conditions from spec v0.12.3 #1667
Closed
Closed
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
448de01
Add gossip conditions from spec issue 2001
paulhauner 0de67a8
Add tests for issue 2030 changes
paulhauner 5aa9d4b
Fix network compile errors
paulhauner 64b79c9
Add more detail to tests, change error type
paulhauner 09aafe7
Fix comment wording
paulhauner 62fad43
Revisit target block check
paulhauner 64fb53b
Add reference to PR
paulhauner 105ba06
Add ignore for rustsec advisory
paulhauner 03dd25d
Fix typo
paulhauner 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 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 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 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 | ||||
---|---|---|---|---|---|---|
|
@@ -11,13 +11,15 @@ use beacon_chain::{ | |||||
BeaconChain, BeaconChainTypes, | ||||||
}; | ||||||
use int_to_bytes::int_to_bytes32; | ||||||
use state_processing::per_slot_processing; | ||||||
use state_processing::{ | ||||||
per_block_processing::errors::AttestationValidationError, per_slot_processing, | ||||||
}; | ||||||
use store::config::StoreConfig; | ||||||
use tree_hash::TreeHash; | ||||||
use types::{ | ||||||
test_utils::generate_deterministic_keypair, AggregateSignature, Attestation, EthSpec, Hash256, | ||||||
Keypair, MainnetEthSpec, SecretKey, SelectionProof, SignedAggregateAndProof, SignedBeaconBlock, | ||||||
SubnetId, Unsigned, | ||||||
test_utils::generate_deterministic_keypair, AggregateSignature, Attestation, BeaconStateError, | ||||||
BitList, EthSpec, Hash256, Keypair, MainnetEthSpec, SecretKey, SelectionProof, | ||||||
SignedAggregateAndProof, SignedBeaconBlock, SubnetId, Unsigned, | ||||||
}; | ||||||
|
||||||
pub type E = MainnetEthSpec; | ||||||
|
@@ -582,6 +584,31 @@ fn unaggregated_gossip_verification() { | |||||
}; | ||||||
} | ||||||
|
||||||
/* | ||||||
* The following test ensures: | ||||||
* | ||||||
* Spec v0.12.3 | ||||||
* | ||||||
* The committee index is within the expected range -- i.e. `data.index < | ||||||
* get_committee_count_per_slot(state, data.target.epoch)`. | ||||||
*/ | ||||||
assert_invalid!( | ||||||
"attestation with invalid committee index", | ||||||
{ | ||||||
let mut a = valid_attestation.clone(); | ||||||
a.data.index = harness | ||||||
.chain | ||||||
.head() | ||||||
.unwrap() | ||||||
.beacon_state | ||||||
.get_committee_count_at_slot(a.data.slot) | ||||||
.unwrap(); | ||||||
a | ||||||
}, | ||||||
subnet_id, | ||||||
AttnError::NoCommitteeForSlotAndIndex { .. } | ||||||
); | ||||||
|
||||||
/* | ||||||
* The following test ensures: | ||||||
* | ||||||
|
@@ -642,6 +669,7 @@ fn unaggregated_gossip_verification() { | |||||
{ | ||||||
let mut a = valid_attestation.clone(); | ||||||
a.data.slot = early_slot; | ||||||
a.data.target.epoch = early_slot.epoch(E::slots_per_epoch()); | ||||||
a | ||||||
}, | ||||||
subnet_id, | ||||||
|
@@ -654,6 +682,27 @@ fn unaggregated_gossip_verification() { | |||||
if attestation_slot == early_slot && earliest_permissible_slot == current_slot - E::slots_per_epoch() - 1 | ||||||
); | ||||||
|
||||||
/* | ||||||
* The following test ensures: | ||||||
* | ||||||
* Spec v0.12.3 | ||||||
* | ||||||
* The attestation's epoch matches its target -- i.e. `attestation.data.target.epoch == | ||||||
* compute_epoch_at_slot(attestation.data.slot)` | ||||||
* | ||||||
*/ | ||||||
|
||||||
assert_invalid!( | ||||||
"attestation without invalid target epoch", | ||||||
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.
Suggested change
|
||||||
{ | ||||||
let mut a = valid_attestation.clone(); | ||||||
a.data.target.epoch += 1; | ||||||
a | ||||||
}, | ||||||
subnet_id, | ||||||
AttnError::InvalidTargetEpoch { .. } | ||||||
); | ||||||
|
||||||
/* | ||||||
* The following two tests ensure: | ||||||
* | ||||||
|
@@ -694,6 +743,32 @@ fn unaggregated_gossip_verification() { | |||||
AttnError::NotExactlyOneAggregationBitSet(2) | ||||||
); | ||||||
|
||||||
/* | ||||||
* The following test ensures: | ||||||
* | ||||||
* Spec v0.12.3 | ||||||
* | ||||||
* The number of aggregation bits matches the committee size -- i.e. | ||||||
* `len(attestation.aggregation_bits) == len(get_beacon_committee(state, data.slot, | ||||||
* data.index))`. | ||||||
*/ | ||||||
assert_invalid!( | ||||||
"attestation with invalid bitfield", | ||||||
{ | ||||||
let mut a = valid_attestation.clone(); | ||||||
let bits = a.aggregation_bits.iter().collect::<Vec<_>>(); | ||||||
a.aggregation_bits = BitList::with_capacity(bits.len() + 1).unwrap(); | ||||||
for (i, bit) in bits.into_iter().enumerate() { | ||||||
a.aggregation_bits.set(i, bit).unwrap(); | ||||||
} | ||||||
a | ||||||
}, | ||||||
subnet_id, | ||||||
AttnError::Invalid(AttestationValidationError::BeaconStateError( | ||||||
BeaconStateError::InvalidBitfield | ||||||
)) | ||||||
); | ||||||
|
||||||
/* | ||||||
* The following test ensures that: | ||||||
* | ||||||
|
@@ -717,6 +792,26 @@ fn unaggregated_gossip_verification() { | |||||
if beacon_block_root == unknown_root | ||||||
); | ||||||
|
||||||
/* | ||||||
* The following test ensures that: | ||||||
* | ||||||
* Spec v0.12.3 | ||||||
* | ||||||
* The attestation's target block is an ancestor of the block named in the LMD vote | ||||||
*/ | ||||||
|
||||||
let unknown_root = Hash256::from_low_u64_le(424242); | ||||||
assert_invalid!( | ||||||
"attestation with invalid target root", | ||||||
{ | ||||||
let mut a = valid_attestation.clone(); | ||||||
a.data.target.root = unknown_root; | ||||||
a | ||||||
}, | ||||||
subnet_id, | ||||||
AttnError::InvalidTargetRoot { .. } | ||||||
); | ||||||
|
||||||
/* | ||||||
* The following test ensures that: | ||||||
* | ||||||
|
This file contains 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 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 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.
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.
Glad we finally got this one haha