mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-30 11:13:34 +00:00
In-memory tree states (#5533)
* Consensus changes
* EF tests
* lcli
* common and watch
* account manager
* cargo
* fork choice
* promise cache
* beacon chain
* interop genesis
* http api
* lighthouse
* op pool
* beacon chain misc
* parallel state cache
* store
* fix issues in store
* IT COMPILES
* Remove some unnecessary module qualification
* Revert Arced pubkey optimization (#5536)
* Merge remote-tracking branch 'origin/unstable' into tree-states-memory
* Fix caching, rebasing and some tests
* Remove unused deps
* Merge remote-tracking branch 'origin/unstable' into tree-states-memory
* Small cleanups
* Revert shuffling cache/promise cache changes
* Fix state advance bugs
* Fix shuffling tests
* Remove some resolved FIXMEs
* Remove StateProcessingStrategy
* Optimise withdrawals calculation
* Don't reorg if state cache is missed
* Remove inconsistent state func
* Fix beta compiler
* Rebase early, rebase often
* Fix state caching behaviour
* Update to milhouse release
* Fix on-disk consensus context format
* Merge remote-tracking branch 'origin/unstable' into tree-states-memory
* Squashed commit of the following:
commit 3a16649023
Author: Michael Sproul <michael@sigmaprime.io>
Date: Thu Apr 18 14:26:09 2024 +1000
Fix on-disk consensus context format
* Keep indexed attestations, thanks Sean
* Merge branch 'on-disk-consensus-context' into tree-states-memory
* Merge branch 'unstable' into tree-states-memory
* Address half of Sean's review
* More simplifications from Sean's review
* Cache state after get_advanced_hot_state
This commit is contained in:
@@ -5,9 +5,7 @@ use beacon_chain::{BeaconChain, BeaconChainError, BeaconChainTypes};
|
||||
use eth2::types::{self as api_types};
|
||||
use slot_clock::SlotClock;
|
||||
use state_processing::state_advance::partial_state_advance;
|
||||
use types::{
|
||||
AttestationDuty, BeaconState, ChainSpec, CloneConfig, Epoch, EthSpec, Hash256, RelativeEpoch,
|
||||
};
|
||||
use types::{AttestationDuty, BeaconState, ChainSpec, Epoch, EthSpec, Hash256, RelativeEpoch};
|
||||
|
||||
/// The struct that is returned to the requesting HTTP client.
|
||||
type ApiDuties = api_types::DutiesResponse<Vec<api_types::AttesterData>>;
|
||||
@@ -90,8 +88,7 @@ fn compute_historic_attester_duties<T: BeaconChainTypes>(
|
||||
if head.beacon_state.current_epoch() <= request_epoch {
|
||||
Some((
|
||||
head.beacon_state_root(),
|
||||
head.beacon_state
|
||||
.clone_with(CloneConfig::committee_caches_only()),
|
||||
head.beacon_state.clone(),
|
||||
execution_status.is_optimistic_or_invalid(),
|
||||
))
|
||||
} else {
|
||||
|
||||
@@ -279,7 +279,7 @@ pub fn get_block_packing_efficiency<T: BeaconChainTypes>(
|
||||
));
|
||||
|
||||
let pre_slot_hook =
|
||||
|state: &mut BeaconState<T::EthSpec>| -> Result<(), PackingEfficiencyError> {
|
||||
|_, state: &mut BeaconState<T::EthSpec>| -> Result<(), PackingEfficiencyError> {
|
||||
// Add attestations to `available_attestations`.
|
||||
handler.lock().add_attestations(state.slot())?;
|
||||
Ok(())
|
||||
|
||||
@@ -61,7 +61,6 @@ use slog::{crit, debug, error, info, warn, Logger};
|
||||
use slot_clock::SlotClock;
|
||||
use ssz::Encode;
|
||||
pub use state_id::StateId;
|
||||
use std::borrow::Cow;
|
||||
use std::future::Future;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use std::path::PathBuf;
|
||||
@@ -864,10 +863,10 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
None
|
||||
};
|
||||
|
||||
let committee_cache = if let Some(ref shuffling) =
|
||||
let committee_cache = if let Some(shuffling) =
|
||||
maybe_cached_shuffling
|
||||
{
|
||||
Cow::Borrowed(&**shuffling)
|
||||
shuffling
|
||||
} else {
|
||||
let possibly_built_cache =
|
||||
match RelativeEpoch::from_epoch(current_epoch, epoch) {
|
||||
@@ -876,16 +875,13 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
relative_epoch,
|
||||
) =>
|
||||
{
|
||||
state
|
||||
.committee_cache(relative_epoch)
|
||||
.map(Cow::Borrowed)
|
||||
state.committee_cache(relative_epoch).cloned()
|
||||
}
|
||||
_ => CommitteeCache::initialized(
|
||||
state,
|
||||
epoch,
|
||||
&chain.spec,
|
||||
)
|
||||
.map(Cow::Owned),
|
||||
),
|
||||
}
|
||||
.map_err(|e| {
|
||||
match e {
|
||||
@@ -933,7 +929,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
{
|
||||
cache_write.insert_committee_cache(
|
||||
shuffling_id,
|
||||
&*possibly_built_cache,
|
||||
&possibly_built_cache,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use safe_arith::SafeArith;
|
||||
use slog::{debug, Logger};
|
||||
use slot_clock::SlotClock;
|
||||
use std::cmp::Ordering;
|
||||
use types::{CloneConfig, Epoch, EthSpec, Hash256, Slot};
|
||||
use types::{Epoch, EthSpec, Hash256, Slot};
|
||||
|
||||
/// The struct that is returned to the requesting HTTP client.
|
||||
type ApiDuties = api_types::DutiesResponse<Vec<api_types::ProposerData>>;
|
||||
@@ -192,8 +192,7 @@ fn compute_historic_proposer_duties<T: BeaconChainTypes>(
|
||||
if head.beacon_state.current_epoch() <= epoch {
|
||||
Some((
|
||||
head.beacon_state_root(),
|
||||
head.beacon_state
|
||||
.clone_with(CloneConfig::committee_caches_only()),
|
||||
head.beacon_state.clone(),
|
||||
execution_status.is_optimistic_or_invalid(),
|
||||
))
|
||||
} else {
|
||||
|
||||
@@ -178,10 +178,7 @@ impl StateId {
|
||||
.head_and_execution_status()
|
||||
.map_err(warp_utils::reject::beacon_chain_error)?;
|
||||
return Ok((
|
||||
cached_head
|
||||
.snapshot
|
||||
.beacon_state
|
||||
.clone_with_only_committee_caches(),
|
||||
cached_head.snapshot.beacon_state.clone(),
|
||||
execution_status.is_optimistic_or_invalid(),
|
||||
false,
|
||||
));
|
||||
|
||||
@@ -128,17 +128,18 @@ async fn attestations_across_fork_with_skip_slots() {
|
||||
let all_validators = harness.get_all_validators();
|
||||
|
||||
let fork_slot = fork_epoch.start_slot(E::slots_per_epoch());
|
||||
let fork_state = harness
|
||||
let mut fork_state = harness
|
||||
.chain
|
||||
.state_at_slot(fork_slot, StateSkipConfig::WithStateRoots)
|
||||
.unwrap();
|
||||
let fork_state_root = fork_state.update_tree_hash_cache().unwrap();
|
||||
|
||||
harness.set_current_slot(fork_slot);
|
||||
|
||||
let attestations = harness.make_attestations(
|
||||
&all_validators,
|
||||
&fork_state,
|
||||
fork_state.canonical_root(),
|
||||
fork_state_root,
|
||||
(*fork_state.get_block_root(fork_slot - 1).unwrap()).into(),
|
||||
fork_slot,
|
||||
);
|
||||
|
||||
@@ -806,7 +806,7 @@ impl ApiTester {
|
||||
let state_opt = state_id.state(&self.chain).ok();
|
||||
let validators: Vec<Validator> = match state_opt.as_ref() {
|
||||
Some((state, _execution_optimistic, _finalized)) => {
|
||||
state.validators().clone().into()
|
||||
state.validators().clone().to_vec()
|
||||
}
|
||||
None => vec![],
|
||||
};
|
||||
@@ -822,7 +822,7 @@ impl ApiTester {
|
||||
ValidatorId::PublicKey(
|
||||
validators
|
||||
.get(i as usize)
|
||||
.map_or(PublicKeyBytes::empty(), |val| val.pubkey.clone()),
|
||||
.map_or(PublicKeyBytes::empty(), |val| val.pubkey),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<ValidatorId>>();
|
||||
@@ -865,7 +865,7 @@ impl ApiTester {
|
||||
if i < state.balances().len() as u64 {
|
||||
validators.push(ValidatorBalanceData {
|
||||
index: i as u64,
|
||||
balance: state.balances()[i as usize],
|
||||
balance: *state.balances().get(i as usize).unwrap(),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -892,7 +892,7 @@ impl ApiTester {
|
||||
.ok()
|
||||
.map(|(state, _execution_optimistic, _finalized)| state);
|
||||
let validators: Vec<Validator> = match state_opt.as_ref() {
|
||||
Some(state) => state.validators().clone().into(),
|
||||
Some(state) => state.validators().to_vec(),
|
||||
None => vec![],
|
||||
};
|
||||
let validator_index_ids = validator_indices
|
||||
@@ -907,7 +907,7 @@ impl ApiTester {
|
||||
ValidatorId::PublicKey(
|
||||
validators
|
||||
.get(i as usize)
|
||||
.map_or(PublicKeyBytes::empty(), |val| val.pubkey.clone()),
|
||||
.map_or(PublicKeyBytes::empty(), |val| val.pubkey),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<ValidatorId>>();
|
||||
@@ -955,7 +955,7 @@ impl ApiTester {
|
||||
if i >= state.validators().len() as u64 {
|
||||
continue;
|
||||
}
|
||||
let validator = state.validators()[i as usize].clone();
|
||||
let validator = state.validators().get(i as usize).unwrap().clone();
|
||||
let status = ValidatorStatus::from_validator(
|
||||
&validator,
|
||||
epoch,
|
||||
@@ -967,7 +967,7 @@ impl ApiTester {
|
||||
{
|
||||
validators.push(ValidatorData {
|
||||
index: i as u64,
|
||||
balance: state.balances()[i as usize],
|
||||
balance: *state.balances().get(i as usize).unwrap(),
|
||||
status,
|
||||
validator,
|
||||
});
|
||||
@@ -995,13 +995,13 @@ impl ApiTester {
|
||||
.ok()
|
||||
.map(|(state, _execution_optimistic, _finalized)| state);
|
||||
let validators = match state_opt.as_ref() {
|
||||
Some(state) => state.validators().clone().into(),
|
||||
Some(state) => state.validators().to_vec(),
|
||||
None => vec![],
|
||||
};
|
||||
|
||||
for (i, validator) in validators.into_iter().enumerate() {
|
||||
let validator_ids = &[
|
||||
ValidatorId::PublicKey(validator.pubkey.clone()),
|
||||
ValidatorId::PublicKey(validator.pubkey),
|
||||
ValidatorId::Index(i as u64),
|
||||
];
|
||||
|
||||
@@ -1025,7 +1025,7 @@ impl ApiTester {
|
||||
|
||||
ValidatorData {
|
||||
index: i as u64,
|
||||
balance: state.balances()[i],
|
||||
balance: *state.balances().get(i).unwrap(),
|
||||
status: ValidatorStatus::from_validator(
|
||||
&validator,
|
||||
epoch,
|
||||
@@ -2360,7 +2360,7 @@ impl ApiTester {
|
||||
.unwrap()
|
||||
{
|
||||
let expected = AttesterData {
|
||||
pubkey: state.validators()[i as usize].pubkey.clone().into(),
|
||||
pubkey: state.validators().get(i as usize).unwrap().pubkey,
|
||||
validator_index: i,
|
||||
committees_at_slot: duty.committees_at_slot,
|
||||
committee_index: duty.index,
|
||||
@@ -2465,7 +2465,7 @@ impl ApiTester {
|
||||
let index = state
|
||||
.get_beacon_proposer_index(slot, &self.chain.spec)
|
||||
.unwrap();
|
||||
let pubkey = state.validators()[index].pubkey.clone().into();
|
||||
let pubkey = state.validators().get(index).unwrap().pubkey;
|
||||
|
||||
ProposerData {
|
||||
pubkey,
|
||||
|
||||
Reference in New Issue
Block a user