mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-17 21:08:32 +00:00
Update /validator/subscribe (#969)
* Add progress on duties refactor * Add simple is_aggregator bool to val subscription * Remove unused function
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use super::{
|
||||
Attestation, ChainSpec, Domain, EthSpec, Fork, PublicKey, SecretKey, Signature, SignedRoot,
|
||||
Attestation, ChainSpec, Domain, EthSpec, Fork, PublicKey, SecretKey, SelectionProof, Signature,
|
||||
SignedRoot,
|
||||
};
|
||||
use crate::test_utils::TestRandom;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
@@ -32,20 +33,13 @@ impl<T: EthSpec> AggregateAndProof<T> {
|
||||
fork: &Fork,
|
||||
spec: &ChainSpec,
|
||||
) -> Self {
|
||||
let slot = aggregate.data.slot;
|
||||
|
||||
let domain = spec.get_domain(
|
||||
slot.epoch(T::slots_per_epoch()),
|
||||
Domain::SelectionProof,
|
||||
fork,
|
||||
);
|
||||
|
||||
let message = slot.signing_root(domain);
|
||||
let selection_proof =
|
||||
SelectionProof::new::<T>(aggregate.data.slot, secret_key, fork, spec).into();
|
||||
|
||||
Self {
|
||||
aggregator_index,
|
||||
aggregate,
|
||||
selection_proof: Signature::new(message.as_bytes(), secret_key),
|
||||
selection_proof,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ pub mod indexed_attestation;
|
||||
pub mod pending_attestation;
|
||||
pub mod proposer_slashing;
|
||||
pub mod relative_epoch;
|
||||
pub mod selection_proof;
|
||||
pub mod signed_aggregate_and_proof;
|
||||
pub mod signed_beacon_block;
|
||||
pub mod signed_beacon_block_header;
|
||||
@@ -72,6 +73,7 @@ pub use crate::indexed_attestation::IndexedAttestation;
|
||||
pub use crate::pending_attestation::PendingAttestation;
|
||||
pub use crate::proposer_slashing::ProposerSlashing;
|
||||
pub use crate::relative_epoch::{Error as RelativeEpochError, RelativeEpoch};
|
||||
pub use crate::selection_proof::SelectionProof;
|
||||
pub use crate::signed_aggregate_and_proof::SignedAggregateAndProof;
|
||||
pub use crate::signed_beacon_block::SignedBeaconBlock;
|
||||
pub use crate::signed_beacon_block_header::SignedBeaconBlockHeader;
|
||||
|
||||
42
eth2/types/src/selection_proof.rs
Normal file
42
eth2/types/src/selection_proof.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use crate::{ChainSpec, Domain, EthSpec, Fork, SecretKey, Signature, SignedRoot, Slot};
|
||||
use std::convert::TryInto;
|
||||
use tree_hash::TreeHash;
|
||||
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
pub struct SelectionProof(Signature);
|
||||
|
||||
impl SelectionProof {
|
||||
pub fn new<T: EthSpec>(
|
||||
slot: Slot,
|
||||
secret_key: &SecretKey,
|
||||
fork: &Fork,
|
||||
spec: &ChainSpec,
|
||||
) -> Self {
|
||||
let domain = spec.get_domain(
|
||||
slot.epoch(T::slots_per_epoch()),
|
||||
Domain::SelectionProof,
|
||||
fork,
|
||||
);
|
||||
let message = slot.signing_root(domain);
|
||||
|
||||
Self(Signature::new(message.as_bytes(), secret_key))
|
||||
}
|
||||
|
||||
pub fn is_aggregator(&self, modulo: u64) -> bool {
|
||||
let signature_hash = self.0.tree_hash_root();
|
||||
let signature_hash_int = u64::from_le_bytes(
|
||||
signature_hash[0..8]
|
||||
.as_ref()
|
||||
.try_into()
|
||||
.expect("first 8 bytes of signature should always convert to fixed array"),
|
||||
);
|
||||
|
||||
signature_hash_int % modulo == 0
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Signature> for SelectionProof {
|
||||
fn into(self) -> Signature {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user