Fix and add info messages (#1552)

* Display information on journal database on startup.

* Minor restyling.

* Client handles the enode message to avoid repeats.

* Avoid unneeded copies *and* reduce code.

* Fix up typo.
This commit is contained in:
Gav Wood
2016-07-06 18:28:11 +02:00
committed by GitHub
parent 095e51c39c
commit cd7b046d80
8 changed files with 69 additions and 37 deletions

View File

@@ -119,6 +119,7 @@ pub struct Client {
liveness: AtomicBool,
io_channel: IoChannel<NetSyncMessage>,
queue_transactions: AtomicUsize,
previous_enode: Mutex<Option<String>>,
}
const HISTORY: u64 = 1200;
@@ -204,6 +205,7 @@ impl Client {
miner: miner,
io_channel: message_channel,
queue_transactions: AtomicUsize::new(0),
previous_enode: Mutex::new(None),
};
Ok(Arc::new(client))
}
@@ -559,6 +561,18 @@ impl Client {
}
}
}
/// Notify us that the network has been started.
pub fn network_started(&self, url: &String) {
let mut previous_enode = self.previous_enode.lock().unwrap();
if let Some(ref u) = *previous_enode {
if u == url {
return;
}
}
*previous_enode = Some(url.clone());
info!(target: "mode", "Public node URL: {}", url.apply(Colour::White.bold()));
}
}
impl BlockChainClient for Client {

View File

@@ -20,7 +20,6 @@ use std::time::{Instant, Duration};
use util::*;
use util::using_queue::{UsingQueue, GetAction};
use util::Colour::White;
use account_provider::AccountProvider;
use views::{BlockView, HeaderView};
use client::{MiningBlockChainClient, Executive, Executed, EnvInfo, TransactOptions, BlockID, CallAnalytics};
@@ -655,7 +654,7 @@ impl MinerService for Miner {
let n = sealed.header().number();
let h = sealed.header().hash();
try!(chain.import_sealed_block(sealed));
info!(target: "miner", "Mined block imported OK. #{}: {}", paint(White.bold(), format!("{}", n)), paint(White.bold(), h.hex()));
info!(target: "miner", "Mined block imported OK. #{}: {}", format!("{}", n).apply(Colour::White.bold()), h.hex().apply(Colour::White.bold()));
Ok(())
})
}

View File

@@ -17,7 +17,6 @@
//! Creates and registers client and network services.
use util::*;
use util::Colour::{Yellow, White};
use util::panics::*;
use spec::Spec;
use error::*;
@@ -72,7 +71,7 @@ impl ClientService {
try!(net_service.start());
}
info!("Configured for {} using {} engine", paint(White.bold(), spec.name.clone()), paint(Yellow.bold(), spec.engine.name().to_owned()));
info!("Configured for {} using {} engine", spec.name.clone().apply(Colour::White.bold()), spec.engine.name().apply(Colour::Yellow.bold()));
let client = try!(Client::new(config, spec, db_path, miner, net_service.io().channel()));
panic_handler.forward_from(client.deref());
let client_io = Arc::new(ClientIoHandler {
@@ -135,16 +134,14 @@ impl IoHandler<NetSyncMessage> for ClientIoHandler {
#[cfg_attr(feature="dev", allow(single_match))]
fn message(&self, io: &IoContext<NetSyncMessage>, net_message: &NetSyncMessage) {
if let UserMessage(ref message) = *net_message {
match *message {
SyncMessage::BlockVerified => {
self.client.import_verified_blocks(&io.channel());
},
SyncMessage::NewTransactions(ref transactions) => {
self.client.import_queued_transactions(&transactions);
},
_ => {}, // ignore other messages
}
match *net_message {
UserMessage(ref message) => match *message {
SyncMessage::BlockVerified => { self.client.import_verified_blocks(&io.channel()); }
SyncMessage::NewTransactions(ref transactions) => { self.client.import_queued_transactions(&transactions); }
_ => {} // ignore other messages
},
NetworkIoMessage::NetworkStarted(ref url) => { self.client.network_started(url); }
_ => {} // ignore other messages
}
}
}