mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 11:41:51 +00:00
Update Syncing logic (#1042)
* Prevent duplicate parent block lookups * Updates logic for handling re-status'd peers * Allow block lookup if the block is close to head * Correct ordering of sync logs * Remove comments in block processer, clean up sim
This commit is contained in:
@@ -4,9 +4,9 @@
|
||||
//! with this struct to to simplify the logic of the other layers of sync.
|
||||
|
||||
use super::chain::{ChainSyncingState, SyncingChain};
|
||||
use crate::router::processor::PeerSyncInfo;
|
||||
use crate::sync::manager::SyncMessage;
|
||||
use crate::sync::network_context::SyncNetworkContext;
|
||||
use crate::sync::PeerSyncInfo;
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||
use eth2_libp2p::{types::SyncState, NetworkGlobals, PeerId};
|
||||
use slog::{debug, error, info};
|
||||
@@ -110,10 +110,9 @@ impl<T: BeaconChainTypes> ChainCollection<T> {
|
||||
}
|
||||
|
||||
/// Updates the global sync state and logs any changes.
|
||||
fn update_sync_state(&mut self, state: RangeSyncState) {
|
||||
pub fn update_sync_state(&mut self) {
|
||||
// if there is no range sync occurring, the state is either synced or not based on
|
||||
// connected peers.
|
||||
self.state = state;
|
||||
|
||||
if self.state == RangeSyncState::Idle {
|
||||
// there is no range sync, let the state of peers determine the global node sync state
|
||||
@@ -150,7 +149,8 @@ impl<T: BeaconChainTypes> ChainCollection<T> {
|
||||
if let RangeSyncState::Head { .. } = self.state {
|
||||
if self.head_chains.is_empty() {
|
||||
// Update the global network state to either synced or stalled.
|
||||
self.update_sync_state(RangeSyncState::Idle);
|
||||
self.state = RangeSyncState::Idle;
|
||||
self.update_sync_state();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,13 +165,14 @@ impl<T: BeaconChainTypes> ChainCollection<T> {
|
||||
.head_info()
|
||||
.map(|info| info.slot)
|
||||
.unwrap_or_else(|_| Slot::from(0u64));
|
||||
|
||||
// NOTE: This will modify the /node/syncing API to show current slot for all fields
|
||||
// while we update peers to look for new potentially HEAD chains.
|
||||
let temp_head_state = RangeSyncState::Head {
|
||||
start_slot: current_slot,
|
||||
head_slot: current_slot,
|
||||
};
|
||||
self.update_sync_state(temp_head_state);
|
||||
self.state = temp_head_state;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +250,7 @@ impl<T: BeaconChainTypes> ChainCollection<T> {
|
||||
head_slot: chain.target_head_slot,
|
||||
head_root: chain.target_head_root,
|
||||
};
|
||||
self.update_sync_state(state);
|
||||
self.state = state;
|
||||
|
||||
// Stop the current chain from syncing
|
||||
self.finalized_chains[index].stop_syncing();
|
||||
@@ -269,11 +270,11 @@ impl<T: BeaconChainTypes> ChainCollection<T> {
|
||||
head_slot: chain.target_head_slot,
|
||||
head_root: chain.target_head_root,
|
||||
};
|
||||
self.update_sync_state(state);
|
||||
self.state = state;
|
||||
} else {
|
||||
// There are no finalized chains, update the state.
|
||||
if self.head_chains.is_empty() {
|
||||
self.update_sync_state(RangeSyncState::Idle);
|
||||
self.state = RangeSyncState::Idle;
|
||||
} else {
|
||||
// for the syncing API, we find the minimal start_slot and the maximum
|
||||
// target_slot of all head chains to report back.
|
||||
@@ -291,7 +292,7 @@ impl<T: BeaconChainTypes> ChainCollection<T> {
|
||||
start_slot: min_slot,
|
||||
head_slot: max_slot,
|
||||
};
|
||||
self.update_sync_state(head_state);
|
||||
self.state = head_state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,10 +42,10 @@
|
||||
use super::chain::{ChainId, ProcessingResult};
|
||||
use super::chain_collection::{ChainCollection, RangeSyncState};
|
||||
use super::BatchId;
|
||||
use crate::router::processor::PeerSyncInfo;
|
||||
use crate::sync::block_processor::BatchProcessResult;
|
||||
use crate::sync::manager::SyncMessage;
|
||||
use crate::sync::network_context::SyncNetworkContext;
|
||||
use crate::sync::PeerSyncInfo;
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||
use eth2_libp2p::rpc::RequestId;
|
||||
use eth2_libp2p::{NetworkGlobals, PeerId};
|
||||
@@ -169,6 +169,7 @@ impl<T: BeaconChainTypes> RangeSync<T> {
|
||||
|
||||
// check if the new peer's addition will favour a new syncing chain.
|
||||
self.chains.update_finalized(network);
|
||||
self.chains.update_sync_state();
|
||||
} else {
|
||||
// there is no finalized chain that matches this peer's last finalized target
|
||||
// create a new finalized chain
|
||||
@@ -182,6 +183,7 @@ impl<T: BeaconChainTypes> RangeSync<T> {
|
||||
self.sync_send.clone(),
|
||||
);
|
||||
self.chains.update_finalized(network);
|
||||
self.chains.update_sync_state();
|
||||
}
|
||||
} else {
|
||||
if self.chains.is_finalizing_sync() {
|
||||
@@ -215,6 +217,7 @@ impl<T: BeaconChainTypes> RangeSync<T> {
|
||||
);
|
||||
}
|
||||
self.chains.update_finalized(network);
|
||||
self.chains.update_sync_state();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,15 +275,17 @@ impl<T: BeaconChainTypes> RangeSync<T> {
|
||||
Some((index, ProcessingResult::RemoveChain)) => {
|
||||
let chain = self.chains.remove_finalized_chain(index);
|
||||
debug!(self.log, "Finalized chain removed"; "start_slot" => chain.start_slot.as_u64(), "end_slot" => chain.target_head_slot.as_u64());
|
||||
// the chain is complete, re-status it's peers
|
||||
chain.status_peers(network);
|
||||
|
||||
// update the state of the collection
|
||||
self.chains.update_finalized(network);
|
||||
|
||||
// set the state to a head sync, to inform the manager that we are awaiting a
|
||||
// the chain is complete, re-status it's peers
|
||||
chain.status_peers(network);
|
||||
|
||||
// set the state to a head sync if there are no finalized chains, to inform the manager that we are awaiting a
|
||||
// head chain.
|
||||
self.chains.set_head_sync();
|
||||
// Update the global variables
|
||||
self.chains.update_sync_state();
|
||||
|
||||
// if there are no more finalized chains, re-status all known peers awaiting a head
|
||||
// sync
|
||||
@@ -312,6 +317,8 @@ impl<T: BeaconChainTypes> RangeSync<T> {
|
||||
|
||||
// update the state of the collection
|
||||
self.chains.update_finalized(network);
|
||||
// update the global state and log any change
|
||||
self.chains.update_sync_state();
|
||||
}
|
||||
Some((_, ProcessingResult::KeepChain)) => {}
|
||||
None => {
|
||||
@@ -339,6 +346,8 @@ impl<T: BeaconChainTypes> RangeSync<T> {
|
||||
|
||||
// update the state of the collection
|
||||
self.chains.update_finalized(network);
|
||||
// update the global state and inform the user
|
||||
self.chains.update_sync_state();
|
||||
}
|
||||
|
||||
/// When a peer gets removed, both the head and finalized chains need to be searched to check which pool the peer is in. The chain may also have a batch or batches awaiting
|
||||
|
||||
Reference in New Issue
Block a user