Add logger to sync module
This commit is contained in:
parent
6e10ce93d4
commit
b30d72501c
@ -65,7 +65,7 @@ impl MessageHandler {
|
|||||||
|
|
||||||
// Initialise sync and begin processing in thread
|
// Initialise sync and begin processing in thread
|
||||||
// generate the Message handler
|
// generate the Message handler
|
||||||
let sync = SimpleSync::new(beacon_chain.clone());
|
let sync = SimpleSync::new(beacon_chain.clone(), &log);
|
||||||
|
|
||||||
let mut handler = MessageHandler {
|
let mut handler = MessageHandler {
|
||||||
// TODO: The handler may not need a chain, perhaps only sync?
|
// TODO: The handler may not need a chain, perhaps only sync?
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use crate::beacon_chain::BeaconChain;
|
use crate::beacon_chain::BeaconChain;
|
||||||
use libp2p::rpc::HelloMessage;
|
use libp2p::rpc::HelloMessage;
|
||||||
use libp2p::PeerId;
|
use libp2p::PeerId;
|
||||||
|
use slog::{debug, o};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{Epoch, Hash256, Slot};
|
use types::{Epoch, Hash256, Slot};
|
||||||
@ -36,11 +37,14 @@ pub struct SimpleSync {
|
|||||||
latest_finalized_epoch: Epoch,
|
latest_finalized_epoch: Epoch,
|
||||||
/// The latest block of the syncing chain.
|
/// The latest block of the syncing chain.
|
||||||
latest_block: Hash256,
|
latest_block: Hash256,
|
||||||
|
/// Sync logger.
|
||||||
|
log: slog::Logger,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SimpleSync {
|
impl SimpleSync {
|
||||||
pub fn new(beacon_chain: Arc<BeaconChain>) -> Self {
|
pub fn new(beacon_chain: Arc<BeaconChain>, log: &slog::Logger) -> Self {
|
||||||
let state = beacon_chain.get_state();
|
let state = beacon_chain.get_state();
|
||||||
|
let sync_logger = log.new(o!("Service"=> "Sync"));
|
||||||
SimpleSync {
|
SimpleSync {
|
||||||
chain: beacon_chain.clone(),
|
chain: beacon_chain.clone(),
|
||||||
known_peers: HashMap::new(),
|
known_peers: HashMap::new(),
|
||||||
@ -48,6 +52,7 @@ impl SimpleSync {
|
|||||||
network_id: beacon_chain.get_spec().network_id,
|
network_id: beacon_chain.get_spec().network_id,
|
||||||
latest_finalized_epoch: state.finalized_epoch,
|
latest_finalized_epoch: state.finalized_epoch,
|
||||||
latest_block: state.finalized_root, //TODO: Build latest block function into Beacon chain and correct this
|
latest_block: state.finalized_root, //TODO: Build latest block function into Beacon chain and correct this
|
||||||
|
log: sync_logger,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +92,9 @@ impl SimpleSync {
|
|||||||
best_slot: hello_message.best_slot,
|
best_slot: hello_message.best_slot,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
debug!(self.log, "Handshake successful. Peer: {:?}", peer_id);
|
||||||
self.known_peers.insert(peer_id, peer_info);
|
self.known_peers.insert(peer_id, peer_info);
|
||||||
|
|
||||||
//TODO: Start syncing
|
//TODO: Start syncing
|
||||||
|
|
||||||
true
|
true
|
||||||
|
Loading…
Reference in New Issue
Block a user