mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-20 22:38:34 +00:00
De-dup attestation constructor logic
This commit is contained in:
@@ -4,6 +4,7 @@ use super::{
|
||||
SignedRoot,
|
||||
};
|
||||
use crate::test_utils::TestRandom;
|
||||
use crate::Attestation;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use superstruct::superstruct;
|
||||
@@ -88,28 +89,39 @@ impl<E: EthSpec> AggregateAndProof<E> {
|
||||
genesis_validators_root: Hash256,
|
||||
spec: &ChainSpec,
|
||||
) -> Self {
|
||||
let selection_proof = selection_proof
|
||||
.unwrap_or_else(|| {
|
||||
SelectionProof::new::<E>(
|
||||
aggregate.data().slot,
|
||||
secret_key,
|
||||
fork,
|
||||
genesis_validators_root,
|
||||
spec,
|
||||
)
|
||||
})
|
||||
.into();
|
||||
let selection_proof = selection_proof.unwrap_or_else(|| {
|
||||
SelectionProof::new::<E>(
|
||||
aggregate.data().slot,
|
||||
secret_key,
|
||||
fork,
|
||||
genesis_validators_root,
|
||||
spec,
|
||||
)
|
||||
});
|
||||
|
||||
Self::from_attestation(
|
||||
aggregator_index,
|
||||
aggregate.clone_as_attestation(),
|
||||
selection_proof,
|
||||
)
|
||||
}
|
||||
|
||||
/// Produces a new `AggregateAndProof` given a `selection_proof`
|
||||
pub fn from_attestation(
|
||||
aggregator_index: u64,
|
||||
aggregate: Attestation<E>,
|
||||
selection_proof: SelectionProof,
|
||||
) -> Self {
|
||||
match aggregate {
|
||||
AttestationRef::Base(attestation) => Self::Base(AggregateAndProofBase {
|
||||
Attestation::Base(aggregate) => Self::Base(AggregateAndProofBase {
|
||||
aggregator_index,
|
||||
aggregate: attestation.clone(),
|
||||
selection_proof,
|
||||
aggregate,
|
||||
selection_proof: selection_proof.into(),
|
||||
}),
|
||||
AttestationRef::Electra(attestation) => Self::Electra(AggregateAndProofElectra {
|
||||
Attestation::Electra(aggregate) => Self::Electra(AggregateAndProofElectra {
|
||||
aggregator_index,
|
||||
aggregate: attestation.clone(),
|
||||
selection_proof,
|
||||
aggregate,
|
||||
selection_proof: selection_proof.into(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,17 +83,19 @@ impl<E: EthSpec> SignedAggregateAndProof<E> {
|
||||
);
|
||||
let signing_message = message.signing_root(domain);
|
||||
|
||||
match message {
|
||||
Self::from_aggregate_and_proof(message, secret_key.sign(signing_message))
|
||||
}
|
||||
|
||||
/// Produces a new `SignedAggregateAndProof` given a `signature` of `aggregate`
|
||||
pub fn from_aggregate_and_proof(aggregate: AggregateAndProof<E>, signature: Signature) -> Self {
|
||||
match aggregate {
|
||||
AggregateAndProof::Base(message) => {
|
||||
SignedAggregateAndProof::Base(SignedAggregateAndProofBase {
|
||||
message,
|
||||
signature: secret_key.sign(signing_message),
|
||||
})
|
||||
SignedAggregateAndProof::Base(SignedAggregateAndProofBase { message, signature })
|
||||
}
|
||||
AggregateAndProof::Electra(message) => {
|
||||
SignedAggregateAndProof::Electra(SignedAggregateAndProofElectra {
|
||||
message,
|
||||
signature: secret_key.sign(signing_message),
|
||||
signature,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user