Add logger to sync module

This commit is contained in:
Age Manning 2019-03-19 21:55:57 +11:00
parent 6e10ce93d4
commit b30d72501c
No known key found for this signature in database
GPG Key ID: 05EED64B79E06A93
2 changed files with 9 additions and 2 deletions

View File

@ -65,7 +65,7 @@ impl MessageHandler {
// Initialise sync and begin processing in thread
// generate the Message handler
let sync = SimpleSync::new(beacon_chain.clone());
let sync = SimpleSync::new(beacon_chain.clone(), &log);
let mut handler = MessageHandler {
// TODO: The handler may not need a chain, perhaps only sync?

View File

@ -1,6 +1,7 @@
use crate::beacon_chain::BeaconChain;
use libp2p::rpc::HelloMessage;
use libp2p::PeerId;
use slog::{debug, o};
use std::collections::HashMap;
use std::sync::Arc;
use types::{Epoch, Hash256, Slot};
@ -36,11 +37,14 @@ pub struct SimpleSync {
latest_finalized_epoch: Epoch,
/// The latest block of the syncing chain.
latest_block: Hash256,
/// Sync logger.
log: slog::Logger,
}
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 sync_logger = log.new(o!("Service"=> "Sync"));
SimpleSync {
chain: beacon_chain.clone(),
known_peers: HashMap::new(),
@ -48,6 +52,7 @@ impl SimpleSync {
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
log: sync_logger,
}
}
@ -87,7 +92,9 @@ impl SimpleSync {
best_slot: hello_message.best_slot,
};
debug!(self.log, "Handshake successful. Peer: {:?}", peer_id);
self.known_peers.insert(peer_id, peer_info);
//TODO: Start syncing
true