mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-19 12:56:12 +00:00
Merge unstable (needs a few more fixes)
This commit is contained in:
@@ -2,6 +2,7 @@ pub use crate::persisted_beacon_chain::PersistedBeaconChain;
|
||||
pub use crate::{
|
||||
beacon_chain::{BEACON_CHAIN_DB_KEY, ETH1_CACHE_DB_KEY, FORK_CHOICE_DB_KEY, OP_POOL_DB_KEY},
|
||||
migrate::MigratorConfig,
|
||||
validator_monitor::DEFAULT_INDIVIDUAL_TRACKING_THRESHOLD,
|
||||
BeaconChainError, NotifyExecutionLayer, ProduceBlockVerification,
|
||||
};
|
||||
use crate::{
|
||||
@@ -32,7 +33,7 @@ use rand::SeedableRng;
|
||||
use rayon::prelude::*;
|
||||
use sensitive_url::SensitiveUrl;
|
||||
use slog::Logger;
|
||||
use slot_clock::TestingSlotClock;
|
||||
use slot_clock::{SlotClock, TestingSlotClock};
|
||||
use state_processing::per_block_processing::compute_timestamp_at_slot;
|
||||
use state_processing::state_advance::complete_state_advance;
|
||||
use std::borrow::Cow;
|
||||
@@ -469,7 +470,7 @@ where
|
||||
log.clone(),
|
||||
5,
|
||||
)))
|
||||
.monitor_validators(true, vec![], log);
|
||||
.monitor_validators(true, vec![], DEFAULT_INDIVIDUAL_TRACKING_THRESHOLD, log);
|
||||
|
||||
builder = if let Some(mutator) = self.initial_mutator {
|
||||
mutator(builder)
|
||||
@@ -527,10 +528,9 @@ pub struct BeaconChainHarness<T: BeaconChainTypes> {
|
||||
pub rng: Mutex<StdRng>,
|
||||
}
|
||||
|
||||
pub type HarnessAttestations<E> = Vec<(
|
||||
Vec<(Attestation<E>, SubnetId)>,
|
||||
Option<SignedAggregateAndProof<E>>,
|
||||
)>;
|
||||
pub type CommitteeAttestations<E> = Vec<(Attestation<E>, SubnetId)>;
|
||||
pub type HarnessAttestations<E> =
|
||||
Vec<(CommitteeAttestations<E>, Option<SignedAggregateAndProof<E>>)>;
|
||||
|
||||
pub type HarnessSyncContributions<E> = Vec<(
|
||||
Vec<(SyncCommitteeMessage, usize)>,
|
||||
@@ -779,6 +779,21 @@ where
|
||||
sk.sign(message)
|
||||
}
|
||||
|
||||
/// Sign a beacon block using the proposer's key.
|
||||
pub fn sign_beacon_block(
|
||||
&self,
|
||||
block: BeaconBlock<E>,
|
||||
state: &BeaconState<E>,
|
||||
) -> SignedBeaconBlock<E> {
|
||||
let proposer_index = block.proposer_index() as usize;
|
||||
block.sign(
|
||||
&self.validator_keypairs[proposer_index].sk,
|
||||
&state.fork(),
|
||||
state.genesis_validators_root(),
|
||||
&self.spec,
|
||||
)
|
||||
}
|
||||
|
||||
/// Produces an "unaggregated" attestation for the given `slot` and `index` that attests to
|
||||
/// `beacon_block_root`. The provided `state` should match the `block.state_root` for the
|
||||
/// `block` identified by `beacon_block_root`.
|
||||
@@ -850,13 +865,35 @@ where
|
||||
state_root: Hash256,
|
||||
head_block_root: SignedBeaconBlockHash,
|
||||
attestation_slot: Slot,
|
||||
) -> Vec<Vec<(Attestation<E>, SubnetId)>> {
|
||||
) -> Vec<CommitteeAttestations<E>> {
|
||||
self.make_unaggregated_attestations_with_limit(
|
||||
attesting_validators,
|
||||
state,
|
||||
state_root,
|
||||
head_block_root,
|
||||
attestation_slot,
|
||||
None,
|
||||
)
|
||||
.0
|
||||
}
|
||||
|
||||
pub fn make_unaggregated_attestations_with_limit(
|
||||
&self,
|
||||
attesting_validators: &[usize],
|
||||
state: &BeaconState<E>,
|
||||
state_root: Hash256,
|
||||
head_block_root: SignedBeaconBlockHash,
|
||||
attestation_slot: Slot,
|
||||
limit: Option<usize>,
|
||||
) -> (Vec<CommitteeAttestations<E>>, Vec<usize>) {
|
||||
let committee_count = state.get_committee_count_at_slot(state.slot()).unwrap();
|
||||
let fork = self
|
||||
.spec
|
||||
.fork_at_epoch(attestation_slot.epoch(E::slots_per_epoch()));
|
||||
|
||||
state
|
||||
let attesters = Mutex::new(vec![]);
|
||||
|
||||
let attestations = state
|
||||
.get_beacon_committees_at_slot(attestation_slot)
|
||||
.expect("should get committees")
|
||||
.iter()
|
||||
@@ -868,6 +905,15 @@ where
|
||||
if !attesting_validators.contains(validator_index) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut attesters = attesters.lock();
|
||||
if let Some(limit) = limit {
|
||||
if attesters.len() >= limit {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
attesters.push(*validator_index);
|
||||
|
||||
let mut attestation = self
|
||||
.produce_unaggregated_attestation_for_block(
|
||||
attestation_slot,
|
||||
@@ -908,9 +954,19 @@ where
|
||||
|
||||
Some((attestation, subnet_id))
|
||||
})
|
||||
.collect()
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.collect()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let attesters = attesters.into_inner();
|
||||
if let Some(limit) = limit {
|
||||
assert_eq!(
|
||||
limit,
|
||||
attesters.len(),
|
||||
"failed to generate `limit` attestations"
|
||||
);
|
||||
}
|
||||
(attestations, attesters)
|
||||
}
|
||||
|
||||
/// A list of sync messages for the given state.
|
||||
@@ -1003,13 +1059,38 @@ where
|
||||
block_hash: SignedBeaconBlockHash,
|
||||
slot: Slot,
|
||||
) -> HarnessAttestations<E> {
|
||||
let unaggregated_attestations = self.make_unaggregated_attestations(
|
||||
self.make_attestations_with_limit(
|
||||
attesting_validators,
|
||||
state,
|
||||
state_root,
|
||||
block_hash,
|
||||
slot,
|
||||
);
|
||||
None,
|
||||
)
|
||||
.0
|
||||
}
|
||||
|
||||
/// Produce exactly `limit` attestations.
|
||||
///
|
||||
/// Return attestations and vec of validator indices that attested.
|
||||
pub fn make_attestations_with_limit(
|
||||
&self,
|
||||
attesting_validators: &[usize],
|
||||
state: &BeaconState<E>,
|
||||
state_root: Hash256,
|
||||
block_hash: SignedBeaconBlockHash,
|
||||
slot: Slot,
|
||||
limit: Option<usize>,
|
||||
) -> (HarnessAttestations<E>, Vec<usize>) {
|
||||
let (unaggregated_attestations, attesters) = self
|
||||
.make_unaggregated_attestations_with_limit(
|
||||
attesting_validators,
|
||||
state,
|
||||
state_root,
|
||||
block_hash,
|
||||
slot,
|
||||
limit,
|
||||
);
|
||||
let fork = self.spec.fork_at_epoch(slot.epoch(E::slots_per_epoch()));
|
||||
|
||||
let aggregated_attestations: Vec<Option<SignedAggregateAndProof<E>>> =
|
||||
@@ -1028,7 +1109,7 @@ where
|
||||
.committee
|
||||
.iter()
|
||||
.find(|&validator_index| {
|
||||
if !attesting_validators.contains(validator_index) {
|
||||
if !attesters.contains(validator_index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1079,10 +1160,13 @@ where
|
||||
})
|
||||
.collect();
|
||||
|
||||
unaggregated_attestations
|
||||
.into_iter()
|
||||
.zip(aggregated_attestations)
|
||||
.collect()
|
||||
(
|
||||
unaggregated_attestations
|
||||
.into_iter()
|
||||
.zip(aggregated_attestations)
|
||||
.collect(),
|
||||
attesters,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn make_sync_contributions(
|
||||
@@ -1369,7 +1453,7 @@ where
|
||||
let proposer_index = state.get_beacon_proposer_index(slot, &self.spec).unwrap();
|
||||
|
||||
let signed_block = block.sign(
|
||||
&self.validator_keypairs[proposer_index as usize].sk,
|
||||
&self.validator_keypairs[proposer_index].sk,
|
||||
&state.fork(),
|
||||
state.genesis_validators_root(),
|
||||
&self.spec,
|
||||
@@ -1735,6 +1819,12 @@ where
|
||||
self.chain.slot_clock.advance_slot();
|
||||
}
|
||||
|
||||
/// Advance the clock to `lookahead` before the start of `slot`.
|
||||
pub fn advance_to_slot_lookahead(&self, slot: Slot, lookahead: Duration) {
|
||||
let time = self.chain.slot_clock.start_of(slot).unwrap() - lookahead;
|
||||
self.chain.slot_clock.set_current_time(time);
|
||||
}
|
||||
|
||||
/// Deprecated: Use make_block() instead
|
||||
///
|
||||
/// Returns a newly created block, signed by the proposer for the given slot.
|
||||
|
||||
Reference in New Issue
Block a user