mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-22 06:14:38 +00:00
superstruct the AttesterSlashing (#5636)
* `superstruct` Attester Fork Variants * Push a little further * Deal with Encode / Decode of AttesterSlashing * not so sure about this.. * Stop Encode/Decode Bounds from Propagating Out * Tons of Changes.. * More Conversions to AttestationRef * Add AsReference trait (#15) * Add AsReference trait * Fix some snafus * Got it Compiling! :D * Got Tests Building * Get beacon chain tests compiling --------- Co-authored-by: Michael Sproul <micsproul@gmail.com>
This commit is contained in:
@@ -388,7 +388,12 @@ async fn invalid_attestation_no_committee_for_index() {
|
||||
.clone()
|
||||
.deconstruct()
|
||||
.0;
|
||||
head_block.to_mut().body_mut().attestations_mut()[0]
|
||||
head_block
|
||||
.to_mut()
|
||||
.body_mut()
|
||||
.attestations_mut()
|
||||
.next()
|
||||
.unwrap()
|
||||
.data_mut()
|
||||
.index += 1;
|
||||
let mut ctxt = ConsensusContext::new(state.slot());
|
||||
@@ -423,10 +428,21 @@ async fn invalid_attestation_wrong_justified_checkpoint() {
|
||||
.clone()
|
||||
.deconstruct()
|
||||
.0;
|
||||
let old_justified_checkpoint = head_block.body().attestations()[0].data().source;
|
||||
let old_justified_checkpoint = head_block
|
||||
.body()
|
||||
.attestations()
|
||||
.next()
|
||||
.unwrap()
|
||||
.data()
|
||||
.source;
|
||||
let mut new_justified_checkpoint = old_justified_checkpoint;
|
||||
new_justified_checkpoint.epoch += Epoch::new(1);
|
||||
head_block.to_mut().body_mut().attestations_mut()[0]
|
||||
head_block
|
||||
.to_mut()
|
||||
.body_mut()
|
||||
.attestations_mut()
|
||||
.next()
|
||||
.unwrap()
|
||||
.data_mut()
|
||||
.source = new_justified_checkpoint;
|
||||
|
||||
@@ -467,7 +483,12 @@ async fn invalid_attestation_bad_aggregation_bitfield_len() {
|
||||
.clone()
|
||||
.deconstruct()
|
||||
.0;
|
||||
*head_block.to_mut().body_mut().attestations_mut()[0]
|
||||
*head_block
|
||||
.to_mut()
|
||||
.body_mut()
|
||||
.attestations_mut()
|
||||
.next()
|
||||
.unwrap()
|
||||
.aggregation_bits_base_mut()
|
||||
.unwrap() = Bitfield::with_capacity(spec.target_committee_size).unwrap();
|
||||
|
||||
@@ -502,8 +523,13 @@ async fn invalid_attestation_bad_signature() {
|
||||
.clone()
|
||||
.deconstruct()
|
||||
.0;
|
||||
*head_block.to_mut().body_mut().attestations_mut()[0].signature_mut() =
|
||||
AggregateSignature::empty();
|
||||
*head_block
|
||||
.to_mut()
|
||||
.body_mut()
|
||||
.attestations_mut()
|
||||
.next()
|
||||
.unwrap()
|
||||
.signature_mut() = AggregateSignature::empty();
|
||||
|
||||
let mut ctxt = ConsensusContext::new(state.slot());
|
||||
let result = process_operations::process_attestations(
|
||||
@@ -538,9 +564,14 @@ async fn invalid_attestation_included_too_early() {
|
||||
.clone()
|
||||
.deconstruct()
|
||||
.0;
|
||||
let new_attesation_slot = head_block.body().attestations()[0].data().slot
|
||||
let new_attesation_slot = head_block.body().attestations().next().unwrap().data().slot
|
||||
+ Slot::new(MainnetEthSpec::slots_per_epoch());
|
||||
head_block.to_mut().body_mut().attestations_mut()[0]
|
||||
head_block
|
||||
.to_mut()
|
||||
.body_mut()
|
||||
.attestations_mut()
|
||||
.next()
|
||||
.unwrap()
|
||||
.data_mut()
|
||||
.slot = new_attesation_slot;
|
||||
|
||||
@@ -581,9 +612,14 @@ async fn invalid_attestation_included_too_late() {
|
||||
.clone()
|
||||
.deconstruct()
|
||||
.0;
|
||||
let new_attesation_slot = head_block.body().attestations()[0].data().slot
|
||||
let new_attesation_slot = head_block.body().attestations().next().unwrap().data().slot
|
||||
- Slot::new(MainnetEthSpec::slots_per_epoch());
|
||||
head_block.to_mut().body_mut().attestations_mut()[0]
|
||||
head_block
|
||||
.to_mut()
|
||||
.body_mut()
|
||||
.attestations_mut()
|
||||
.next()
|
||||
.unwrap()
|
||||
.data_mut()
|
||||
.slot = new_attesation_slot;
|
||||
|
||||
@@ -621,7 +657,12 @@ async fn invalid_attestation_target_epoch_slot_mismatch() {
|
||||
.clone()
|
||||
.deconstruct()
|
||||
.0;
|
||||
head_block.to_mut().body_mut().attestations_mut()[0]
|
||||
head_block
|
||||
.to_mut()
|
||||
.body_mut()
|
||||
.attestations_mut()
|
||||
.next()
|
||||
.unwrap()
|
||||
.data_mut()
|
||||
.target
|
||||
.epoch += Epoch::new(1);
|
||||
@@ -657,7 +698,7 @@ async fn valid_insert_attester_slashing() {
|
||||
let mut ctxt = ConsensusContext::new(state.slot());
|
||||
let result = process_operations::process_attester_slashings(
|
||||
&mut state,
|
||||
&[attester_slashing],
|
||||
[attester_slashing.to_ref()].into_iter(),
|
||||
VerifySignatures::True,
|
||||
&mut ctxt,
|
||||
&spec,
|
||||
@@ -673,13 +714,20 @@ async fn invalid_attester_slashing_not_slashable() {
|
||||
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT).await;
|
||||
|
||||
let mut attester_slashing = harness.make_attester_slashing(vec![1, 2]);
|
||||
attester_slashing.attestation_1 = attester_slashing.attestation_2.clone();
|
||||
match &mut attester_slashing {
|
||||
AttesterSlashing::Base(ref mut attester_slashing) => {
|
||||
attester_slashing.attestation_1 = attester_slashing.attestation_2.clone();
|
||||
}
|
||||
AttesterSlashing::Electra(ref mut attester_slashing) => {
|
||||
attester_slashing.attestation_1 = attester_slashing.attestation_2.clone();
|
||||
}
|
||||
}
|
||||
|
||||
let mut state = harness.get_current_state();
|
||||
let mut ctxt = ConsensusContext::new(state.slot());
|
||||
let result = process_operations::process_attester_slashings(
|
||||
&mut state,
|
||||
&[attester_slashing],
|
||||
[attester_slashing.to_ref()].into_iter(),
|
||||
VerifySignatures::True,
|
||||
&mut ctxt,
|
||||
&spec,
|
||||
@@ -701,16 +749,20 @@ async fn invalid_attester_slashing_1_invalid() {
|
||||
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT).await;
|
||||
|
||||
let mut attester_slashing = harness.make_attester_slashing(vec![1, 2]);
|
||||
*attester_slashing
|
||||
.attestation_1
|
||||
.attesting_indices_base_mut()
|
||||
.unwrap() = VariableList::from(vec![2, 1]);
|
||||
match &mut attester_slashing {
|
||||
AttesterSlashing::Base(ref mut attester_slashing) => {
|
||||
attester_slashing.attestation_1.attesting_indices = VariableList::from(vec![2, 1]);
|
||||
}
|
||||
AttesterSlashing::Electra(ref mut attester_slashing) => {
|
||||
attester_slashing.attestation_1.attesting_indices = VariableList::from(vec![2, 1]);
|
||||
}
|
||||
}
|
||||
|
||||
let mut state = harness.get_current_state();
|
||||
let mut ctxt = ConsensusContext::new(state.slot());
|
||||
let result = process_operations::process_attester_slashings(
|
||||
&mut state,
|
||||
&[attester_slashing],
|
||||
[attester_slashing.to_ref()].into_iter(),
|
||||
VerifySignatures::True,
|
||||
&mut ctxt,
|
||||
&spec,
|
||||
@@ -735,16 +787,20 @@ async fn invalid_attester_slashing_2_invalid() {
|
||||
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT).await;
|
||||
|
||||
let mut attester_slashing = harness.make_attester_slashing(vec![1, 2]);
|
||||
*attester_slashing
|
||||
.attestation_2
|
||||
.attesting_indices_base_mut()
|
||||
.unwrap() = VariableList::from(vec![2, 1]);
|
||||
match &mut attester_slashing {
|
||||
AttesterSlashing::Base(ref mut attester_slashing) => {
|
||||
attester_slashing.attestation_2.attesting_indices = VariableList::from(vec![2, 1]);
|
||||
}
|
||||
AttesterSlashing::Electra(ref mut attester_slashing) => {
|
||||
attester_slashing.attestation_2.attesting_indices = VariableList::from(vec![2, 1]);
|
||||
}
|
||||
}
|
||||
|
||||
let mut state = harness.get_current_state();
|
||||
let mut ctxt = ConsensusContext::new(state.slot());
|
||||
let result = process_operations::process_attester_slashings(
|
||||
&mut state,
|
||||
&[attester_slashing],
|
||||
[attester_slashing.to_ref()].into_iter(),
|
||||
VerifySignatures::True,
|
||||
&mut ctxt,
|
||||
&spec,
|
||||
|
||||
Reference in New Issue
Block a user