mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-17 11:52:42 +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:
@@ -1492,7 +1492,8 @@ where
|
||||
) -> AttesterSlashing<E> {
|
||||
let fork = self.chain.canonical_head.cached_head().head_fork();
|
||||
|
||||
let mut attestation_1 = IndexedAttestation::Base(IndexedAttestationBase {
|
||||
// TODO(electra): consider making this test fork-agnostic
|
||||
let mut attestation_1 = IndexedAttestationBase {
|
||||
attesting_indices: VariableList::new(validator_indices).unwrap(),
|
||||
data: AttestationData {
|
||||
slot: Slot::new(0),
|
||||
@@ -1508,36 +1509,37 @@ where
|
||||
},
|
||||
},
|
||||
signature: AggregateSignature::infinity(),
|
||||
});
|
||||
};
|
||||
|
||||
let mut attestation_2 = attestation_1.clone();
|
||||
attestation_2.data_mut().index += 1;
|
||||
attestation_2.data_mut().source.epoch = source2.unwrap_or(Epoch::new(0));
|
||||
attestation_2.data_mut().target.epoch = target2.unwrap_or(fork.epoch);
|
||||
attestation_2.data.index += 1;
|
||||
attestation_2.data.source.epoch = source2.unwrap_or(Epoch::new(0));
|
||||
attestation_2.data.target.epoch = target2.unwrap_or(fork.epoch);
|
||||
|
||||
for attestation in &mut [&mut attestation_1, &mut attestation_2] {
|
||||
// TODO(electra) we could explore iter mut here
|
||||
for i in attestation.attesting_indices_to_vec() {
|
||||
let sk = &self.validator_keypairs[i as usize].sk;
|
||||
for i in attestation.attesting_indices.iter() {
|
||||
let sk = &self.validator_keypairs[*i as usize].sk;
|
||||
|
||||
let genesis_validators_root = self.chain.genesis_validators_root;
|
||||
|
||||
let domain = self.chain.spec.get_domain(
|
||||
attestation.data().target.epoch,
|
||||
attestation.data.target.epoch,
|
||||
Domain::BeaconAttester,
|
||||
&fork,
|
||||
genesis_validators_root,
|
||||
);
|
||||
let message = attestation.data().signing_root(domain);
|
||||
let message = attestation.data.signing_root(domain);
|
||||
|
||||
attestation.signature_mut().add_assign(&sk.sign(message));
|
||||
attestation.signature.add_assign(&sk.sign(message));
|
||||
}
|
||||
}
|
||||
|
||||
AttesterSlashing {
|
||||
// TODO(electra): fix this test
|
||||
AttesterSlashing::Base(AttesterSlashingBase {
|
||||
attestation_1,
|
||||
attestation_2,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn make_attester_slashing_different_indices(
|
||||
@@ -1559,43 +1561,45 @@ where
|
||||
},
|
||||
};
|
||||
|
||||
let mut attestation_1 = IndexedAttestation::Base(IndexedAttestationBase {
|
||||
// TODO(electra): make this test fork-agnostic
|
||||
let mut attestation_1 = IndexedAttestationBase {
|
||||
attesting_indices: VariableList::new(validator_indices_1).unwrap(),
|
||||
data: data.clone(),
|
||||
signature: AggregateSignature::infinity(),
|
||||
});
|
||||
};
|
||||
|
||||
let mut attestation_2 = IndexedAttestation::Base(IndexedAttestationBase {
|
||||
let mut attestation_2 = IndexedAttestationBase {
|
||||
attesting_indices: VariableList::new(validator_indices_2).unwrap(),
|
||||
data,
|
||||
signature: AggregateSignature::infinity(),
|
||||
});
|
||||
};
|
||||
|
||||
attestation_2.data_mut().index += 1;
|
||||
attestation_2.data.index += 1;
|
||||
|
||||
let fork = self.chain.canonical_head.cached_head().head_fork();
|
||||
for attestation in &mut [&mut attestation_1, &mut attestation_2] {
|
||||
for i in attestation.attesting_indices_to_vec() {
|
||||
let sk = &self.validator_keypairs[i as usize].sk;
|
||||
for i in attestation.attesting_indices.iter() {
|
||||
let sk = &self.validator_keypairs[*i as usize].sk;
|
||||
|
||||
let genesis_validators_root = self.chain.genesis_validators_root;
|
||||
|
||||
let domain = self.chain.spec.get_domain(
|
||||
attestation.data().target.epoch,
|
||||
attestation.data.target.epoch,
|
||||
Domain::BeaconAttester,
|
||||
&fork,
|
||||
genesis_validators_root,
|
||||
);
|
||||
let message = attestation.data().signing_root(domain);
|
||||
let message = attestation.data.signing_root(domain);
|
||||
|
||||
attestation.signature_mut().add_assign(&sk.sign(message));
|
||||
attestation.signature.add_assign(&sk.sign(message));
|
||||
}
|
||||
}
|
||||
|
||||
AttesterSlashing {
|
||||
// TODO(electra): fix this test
|
||||
AttesterSlashing::Base(AttesterSlashingBase {
|
||||
attestation_1,
|
||||
attestation_2,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn make_proposer_slashing(&self, validator_index: u64) -> ProposerSlashing {
|
||||
|
||||
Reference in New Issue
Block a user