mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-27 17:53:42 +00:00
Merge remote-tracking branch 'origin/unstable' into tree-states
This commit is contained in:
@@ -35,6 +35,13 @@ use types::{AttestationShufflingId, BeaconStateError, EthSpec, Hash256, Relative
|
||||
/// for some period of time.
|
||||
const MAX_ADVANCE_DISTANCE: u64 = 4;
|
||||
|
||||
/// Similarly for fork choice: avoid the fork choice lookahead during sync.
|
||||
///
|
||||
/// The value is set to 256 since this would be just over one slot (12.8s) when syncing at
|
||||
/// 20 slots/second. Having a single fork-choice run interrupt syncing would have very little
|
||||
/// impact whilst having 8 epochs without a block is a comfortable grace period.
|
||||
const MAX_FORK_CHOICE_DISTANCE: u64 = 256;
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Error {
|
||||
BeaconChain(BeaconChainError),
|
||||
@@ -222,28 +229,33 @@ async fn state_advance_timer<T: BeaconChainTypes>(
|
||||
let log = log.clone();
|
||||
let beacon_chain = beacon_chain.clone();
|
||||
let next_slot = current_slot + 1;
|
||||
executor.spawn_blocking(
|
||||
move || {
|
||||
if let Err(e) = beacon_chain.fork_choice_at_slot(next_slot) {
|
||||
warn!(
|
||||
log,
|
||||
"Error updating fork choice for next slot";
|
||||
"error" => ?e,
|
||||
"slot" => next_slot,
|
||||
);
|
||||
executor.spawn(
|
||||
async move {
|
||||
// Don't run fork choice during sync.
|
||||
if beacon_chain.best_slot() + MAX_FORK_CHOICE_DISTANCE < current_slot {
|
||||
return;
|
||||
}
|
||||
|
||||
// Signal block proposal for the next slot (if it happens to be waiting).
|
||||
if let Some(tx) = &beacon_chain.fork_choice_signal_tx {
|
||||
if let Err(e) = tx.notify_fork_choice_complete(next_slot) {
|
||||
warn!(
|
||||
log,
|
||||
"Error signalling fork choice waiter";
|
||||
"error" => ?e,
|
||||
"slot" => next_slot,
|
||||
);
|
||||
}
|
||||
}
|
||||
beacon_chain.recompute_head_at_slot(next_slot).await;
|
||||
|
||||
// Use a blocking task to avoid blocking the core executor whilst waiting for locks
|
||||
// in `ForkChoiceSignalTx`.
|
||||
beacon_chain.task_executor.clone().spawn_blocking(
|
||||
move || {
|
||||
// Signal block proposal for the next slot (if it happens to be waiting).
|
||||
if let Some(tx) = &beacon_chain.fork_choice_signal_tx {
|
||||
if let Err(e) = tx.notify_fork_choice_complete(next_slot) {
|
||||
warn!(
|
||||
log,
|
||||
"Error signalling fork choice waiter";
|
||||
"error" => ?e,
|
||||
"slot" => next_slot,
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
"fork_choice_advance_signal_tx",
|
||||
);
|
||||
},
|
||||
"fork_choice_advance",
|
||||
);
|
||||
@@ -261,7 +273,7 @@ fn advance_head<T: BeaconChainTypes>(
|
||||
//
|
||||
// Fork-choice is not run *before* this function to avoid unnecessary calls whilst syncing.
|
||||
{
|
||||
let head_slot = beacon_chain.head_info()?.slot;
|
||||
let head_slot = beacon_chain.best_slot();
|
||||
|
||||
// Don't run this when syncing or if lagging too far behind.
|
||||
if head_slot + MAX_ADVANCE_DISTANCE < current_slot {
|
||||
@@ -272,12 +284,14 @@ fn advance_head<T: BeaconChainTypes>(
|
||||
}
|
||||
}
|
||||
|
||||
let head_info = beacon_chain.head_info()?;
|
||||
let head_block_root = head_info.block_root;
|
||||
let (head_block_root, head_block_state_root) = {
|
||||
let snapshot = beacon_chain.head_snapshot();
|
||||
(snapshot.beacon_block_root, snapshot.beacon_state_root())
|
||||
};
|
||||
|
||||
let (head_state_root, mut state) = beacon_chain
|
||||
.store
|
||||
.get_advanced_state(head_block_root, current_slot, head_info.state_root)?
|
||||
.get_advanced_state(head_block_root, current_slot, head_block_state_root)?
|
||||
.ok_or(Error::HeadMissingFromSnapshotCache(head_block_root))?;
|
||||
|
||||
if state.slot() == current_slot + 1 {
|
||||
|
||||
Reference in New Issue
Block a user