mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2025-01-16 08:58:20 +00:00
Enable syncing state when new peer connects
This commit is contained in:
parent
0a8b0069dc
commit
dc014d07bc
@ -110,9 +110,10 @@ fn network_service(
|
||||
loop {
|
||||
match libp2p_service.poll() {
|
||||
Ok(Async::Ready(Some(Libp2pEvent::RPC(peer_id, rpc_event)))) => {
|
||||
debug!(
|
||||
trace!(
|
||||
libp2p_service.log,
|
||||
"RPC Event: RPC message received: {:?}", rpc_event
|
||||
"RPC Event: RPC message received: {:?}",
|
||||
rpc_event
|
||||
);
|
||||
message_handler_send
|
||||
.send(HandlerMessage::RPC(peer_id, rpc_event))
|
||||
|
@ -6,6 +6,9 @@ use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use types::{Epoch, Hash256, Slot};
|
||||
|
||||
/// The number of slots that we can import blocks ahead of us, before going into full Sync mode.
|
||||
const SLOT_IMPORT_TOLERANCE: u64 = 100;
|
||||
|
||||
/// Keeps track of syncing information for known connected peers.
|
||||
pub struct PeerSyncInfo {
|
||||
latest_finalized_root: Hash256,
|
||||
@ -15,6 +18,7 @@ pub struct PeerSyncInfo {
|
||||
}
|
||||
|
||||
/// The current syncing state.
|
||||
#[derive(PartialEq)]
|
||||
pub enum SyncState {
|
||||
Idle,
|
||||
Downloading,
|
||||
@ -36,7 +40,7 @@ pub struct SimpleSync {
|
||||
/// The latest epoch of the syncing chain.
|
||||
latest_finalized_epoch: Epoch,
|
||||
/// The latest block of the syncing chain.
|
||||
latest_block: Hash256,
|
||||
latest_slot: Slot,
|
||||
/// Sync logger.
|
||||
log: slog::Logger,
|
||||
}
|
||||
@ -51,7 +55,7 @@ impl SimpleSync {
|
||||
state: SyncState::Idle,
|
||||
network_id: beacon_chain.get_spec().network_id,
|
||||
latest_finalized_epoch: state.finalized_epoch,
|
||||
latest_block: state.finalized_root, //TODO: Build latest block function into Beacon chain and correct this
|
||||
latest_slot: state.slot - 1, //TODO: Build latest block function into Beacon chain and correct this
|
||||
log: sync_logger,
|
||||
}
|
||||
}
|
||||
@ -95,7 +99,13 @@ impl SimpleSync {
|
||||
debug!(self.log, "Handshake successful. Peer: {:?}", peer_id);
|
||||
self.known_peers.insert(peer_id, peer_info);
|
||||
|
||||
//TODO: Start syncing
|
||||
// set state to sync
|
||||
if self.state == SyncState::Idle
|
||||
&& hello_message.best_slot > self.latest_slot + SLOT_IMPORT_TOLERANCE
|
||||
{
|
||||
self.state = SyncState::Downloading;
|
||||
//TODO: Start requesting blocks from known peers. Ideally in batches
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user