From b34a0c0067a6171a022e42be82841c96dcb1c9dc Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Tue, 2 Apr 2019 19:18:08 +0800 Subject: [PATCH 1/9] fix: temp fix tx relay flood --- rpc/src/module/pool.rs | 5 ++++- shared/src/chain_state.rs | 13 +++++++++++-- shared/src/tx_pool/types.rs | 2 ++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/rpc/src/module/pool.rs b/rpc/src/module/pool.rs index e499ebc3cc..cf9e7392fb 100644 --- a/rpc/src/module/pool.rs +++ b/rpc/src/module/pool.rs @@ -47,7 +47,10 @@ impl PoolRpc for PoolRpcImpl { Ok(cycles) => Some(cycles), }; let entry = PoolEntry::new(tx.clone(), 0, cycles); - chain_state.mut_tx_pool().enqueue_tx(entry); + if !chain_state.mut_tx_pool().enqueue_tx(entry) { + // Duplicate tx + return Ok(tx_hash); + } cycles }; match cycles { diff --git a/shared/src/chain_state.rs b/shared/src/chain_state.rs index 03f20a50c1..adff0b2052 100644 --- a/shared/src/chain_state.rs +++ b/shared/src/chain_state.rs @@ -104,7 +104,12 @@ impl ChainState { let short_id = tx.proposal_short_id(); let rtx = self.resolve_tx_from_pool(&tx, &tx_pool); let verify_result = self.verify_rtx(&rtx, max_cycles); + let tx_hash = tx.hash(); if self.contains_proposal_id(&short_id) { + if !self.filter.insert(tx_hash.clone()) { + trace!(target: "tx_pool", "discarding already known transaction {:#x}", tx_hash); + return Err(PoolError::Duplicate); + } let entry = PoolEntry::new(tx, 0, verify_result.map(Some).unwrap_or(None)); self.staging_tx(&mut tx_pool, entry, max_cycles)?; Ok(verify_result.map_err(PoolError::InvalidTx)?) @@ -113,12 +118,16 @@ impl ChainState { Ok(cycles) => { // enqueue tx with cycles let entry = PoolEntry::new(tx, 0, Some(cycles)); - tx_pool.enqueue_tx(entry); + if !tx_pool.enqueue_tx(entry) { + return Err(PoolError::Duplicate); + } Ok(cycles) } Err(TransactionError::UnknownInput) => { let entry = PoolEntry::new(tx, 0, None); - tx_pool.enqueue_tx(entry); + if !tx_pool.enqueue_tx(entry) { + return Err(PoolError::Duplicate); + } Err(PoolError::InvalidTx(TransactionError::UnknownInput)) } Err(err) => Err(PoolError::InvalidTx(err)), diff --git a/shared/src/tx_pool/types.rs b/shared/src/tx_pool/types.rs index d6ff0b313a..64cd81d0cd 100644 --- a/shared/src/tx_pool/types.rs +++ b/shared/src/tx_pool/types.rs @@ -79,6 +79,8 @@ pub enum PoolError { TimeOut, /// BlockNumber is not right InvalidBlockNumber, + /// Duplicate tx + Duplicate, } impl fmt::Display for PoolError { From f55cec5eff1166bada042c67408c1d447bb368ce Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Wed, 3 Apr 2019 14:21:32 +0800 Subject: [PATCH 2/9] feat: experimental deadlock detection --- Cargo.lock | 36 ++++++++++++++++++++++++++++++++++++ src/helper.rs | 38 ++++++++++++++++++++++++++++++++++++++ src/main.rs | 2 +- src/subcommand/run.rs | 4 +++- src/system.rs | 16 ---------------- util/Cargo.toml | 2 +- util/src/lib.rs | 4 +++- 7 files changed, 82 insertions(+), 20 deletions(-) create mode 100644 src/helper.rs delete mode 100644 src/system.rs diff --git a/Cargo.lock b/Cargo.lock index aa2b3ee70a..8d4fef42d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1141,6 +1141,11 @@ name = "faster-hex" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "fixedbitset" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "flatbuffers" version = "0.5.0" @@ -1978,6 +1983,11 @@ dependencies = [ "vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ordermap" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "owning_ref" version = "0.4.0" @@ -2027,10 +2037,13 @@ name = "parking_lot_core" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "thread-id 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2044,6 +2057,15 @@ name = "percent-encoding" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "petgraph" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "phf" version = "0.7.24" @@ -2915,6 +2937,16 @@ dependencies = [ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "thread-id" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "thread_local" version = "0.3.6" @@ -3526,6 +3558,7 @@ dependencies = [ "checksum faketime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17087bd8c5a4a3e8bd40ecd9d3bda587459abcf67ca94211df09ec8451404cf8" "checksum faster-hex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ea2e4ecc921ec2cbb8b10f0d400fe448554779d2ac5e0bfbb065836d9d8483a" "checksum faster-hex 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b8cccaafb5aae8c282692e5590f341925edea6c696e8715ff0d973320b2646" +"checksum fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33" "checksum flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea0c34f669be9911826facafe996adfda978aeee67285a13556869e2d8b8331f" "checksum flatbuffers-verifier 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c0118b65128a67eb0eeb805f6032d37325659e42198b3d3f34f205eddda73bd1" "checksum flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f87e68aa82b2de08a6e037f1385455759df6e445a8df5e005b4297191dbf18aa" @@ -3612,6 +3645,7 @@ dependencies = [ "checksum openssl 0.10.20 (registry+https://github.com/rust-lang/crates.io-index)" = "5a0d6b781aac4ac1bd6cafe2a2f0ad8c16ae8e1dd5184822a16c50139f8838d9" "checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" "checksum openssl-sys 0.9.43 (registry+https://github.com/rust-lang/crates.io-index)" = "33c86834957dd5b915623e94f2f4ab2c70dd8f6b70679824155d5ae21dbd495d" +"checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063" "checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" "checksum parity-multiaddr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "61ae6944d4435d41f4d0f12108c5cbb9207cbb14bc8f2b4984c6e930dc9c8e41" "checksum parity-multihash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e8eab0287ccde7821e337a124dc5a4f1d6e4c25d10cc91e3f9361615dd95076" @@ -3619,6 +3653,7 @@ dependencies = [ "checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" "checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" +"checksum petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3659d1ee90221741f65dd128d9998311b0e40c5d3c23a62445938214abce4f" "checksum phf 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "b3da44b85f8e8dfaec21adae67f95d93244b2ecf6ad2a692320598dcc8e6dd18" "checksum phf_codegen 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "b03e85129e324ad4166b06b2c7491ae27fe3ec353af72e72cd1654c7225d517e" "checksum phf_generator 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "09364cc93c159b8b06b1f4dd8a4398984503483891b0c26b867cf431fb132662" @@ -3711,6 +3746,7 @@ dependencies = [ "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72b620c5ea021d75a735c943269bb07d30c9b77d6ac6b236bc8b5c496ef05625" "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +"checksum thread-id 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7fbf4c9d56b320106cd64fd024dadfa0be7cb4706725fc44a7d7ce952d820c1" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e9175261fbdb60781fcd388a4d6cc7e14764a2b629a7ad94abb439aed223a44f" diff --git a/src/helper.rs b/src/helper.rs new file mode 100644 index 0000000000..3f860a9298 --- /dev/null +++ b/src/helper.rs @@ -0,0 +1,38 @@ +use ckb_util::{parking_lot::deadlock, Condvar, Mutex}; +use log::warn; +use std::sync::Arc; +use std::thread; +use std::time::Duration; + +pub fn wait_for_exit() { + let exit = Arc::new((Mutex::new(()), Condvar::new())); + + // Handle possible exits + let e = Arc::<(Mutex<()>, Condvar)>::clone(&exit); + let _ = ctrlc::set_handler(move || { + e.1.notify_all(); + }); + + // Wait for signal + let mut l = exit.0.lock(); + exit.1.wait(&mut l); +} + +pub fn deadlock_detection() { + thread::spawn(move || loop { + thread::sleep(Duration::from_secs(10)); + let deadlocks = deadlock::check_deadlock(); + if deadlocks.is_empty() { + continue; + } + + warn!("{} deadlocks detected", deadlocks.len()); + for (i, threads) in deadlocks.iter().enumerate() { + warn!("Deadlock #{}", i); + for t in threads { + warn!("Thread Id {:#?}", t.thread_id()); + warn!("{:#?}", t.backtrace()); + } + } + }); +} diff --git a/src/main.rs b/src/main.rs index 4fe998233a..6ae1a79485 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ +mod helper; mod setup; mod subcommand; -mod system; use setup::{cli, ExitCode, Setup}; diff --git a/src/subcommand/run.rs b/src/subcommand/run.rs index b78215ab4b..6d5b2d6415 100644 --- a/src/subcommand/run.rs +++ b/src/subcommand/run.rs @@ -1,5 +1,5 @@ +use crate::helper::{deadlock_detection, wait_for_exit}; use crate::setup::{ExitCode, RunArgs}; -use crate::system::wait_for_exit; use ckb_chain::chain::{ChainBuilder, ChainController}; use ckb_db::diskdb::RocksDB; use ckb_miner::BlockAssembler; @@ -15,6 +15,8 @@ use log::info; use std::sync::Arc; pub fn run(args: RunArgs) -> Result<(), ExitCode> { + deadlock_detection(); + let shared = SharedBuilder::>::default() .consensus(args.consensus) .db(&args.config.db) diff --git a/src/system.rs b/src/system.rs deleted file mode 100644 index e02ee7d760..0000000000 --- a/src/system.rs +++ /dev/null @@ -1,16 +0,0 @@ -use ckb_util::{Condvar, Mutex}; -use std::sync::Arc; - -pub fn wait_for_exit() { - let exit = Arc::new((Mutex::new(()), Condvar::new())); - - // Handle possible exits - let e = Arc::<(Mutex<()>, Condvar)>::clone(&exit); - let _ = ctrlc::set_handler(move || { - e.1.notify_all(); - }); - - // Wait for signal - let mut l = exit.0.lock(); - exit.1.wait(&mut l); -} diff --git a/util/Cargo.toml b/util/Cargo.toml index 504b766886..c127b8cfc0 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -6,4 +6,4 @@ authors = ["Nervos Core Dev "] edition = "2018" [dependencies] -parking_lot = "0.7" +parking_lot = {version = "0.7", features = ["deadlock_detection"]} diff --git a/util/src/lib.rs b/util/src/lib.rs index 7774644263..bf111fca80 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -1,7 +1,9 @@ mod unstable; pub use crate::unstable::{TryFrom, TryInto}; -pub use parking_lot::{Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard}; +pub use parking_lot::{ + self, Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard, +}; /// Helper macro for reducing boilerplate code for matching `Option` together /// with early return. From 9995c5c755411be8585e5b91264663fad0aa4da8 Mon Sep 17 00:00:00 2001 From: Linfeng Qian Date: Wed, 3 Apr 2019 15:30:11 +0800 Subject: [PATCH 3/9] fix: Network error handling --- network/src/network.rs | 62 +++++++++++++++---------- network/src/protocols/mod.rs | 12 +++++ shared/src/chain_state.rs | 4 +- sync/src/relayer/transaction_process.rs | 3 +- 4 files changed, 54 insertions(+), 27 deletions(-) diff --git a/network/src/network.rs b/network/src/network.rs index 1b1a6fed10..2a7117383c 100644 --- a/network/src/network.rs +++ b/network/src/network.rs @@ -338,33 +338,47 @@ pub struct EventHandler { } impl ServiceHandle for EventHandler { - fn handle_error(&mut self, _context: &mut ServiceContext, error: ServiceError) { + fn handle_error(&mut self, context: &mut ServiceContext, error: ServiceError) { warn!(target: "network", "p2p service error: {:?}", error); - if let ServiceError::DialerError { - ref address, - ref error, - } = error - { - debug!(target: "network", "add self address: {:?}", address); - if error == &P2pError::ConnectSelf { - let addr = address - .iter() - .filter(|proto| match proto { - multiaddr::Protocol::P2p(_) => false, - _ => true, - }) - .collect(); - self.network_state - .listened_addresses - .write() - .insert(addr, std::u8::MAX); + match error { + ServiceError::DialerError { + ref address, + ref error, + } => { + debug!(target: "network", "add self address: {:?}", address); + if error == &P2pError::ConnectSelf { + let addr = address + .iter() + .filter(|proto| match proto { + multiaddr::Protocol::P2p(_) => false, + _ => true, + }) + .collect(); + self.network_state + .listened_addresses + .write() + .insert(addr, std::u8::MAX); + } + if let Some(peer_id) = extract_peer_id(address) { + self.network_state + .failed_dials + .write() + .insert(peer_id, Instant::now()); + } } - if let Some(peer_id) = extract_peer_id(address) { - self.network_state - .failed_dials - .write() - .insert(peer_id, Instant::now()); + ServiceError::ProtocolError { id, .. } => { + if let Err(err) = context.control().disconnect(id) { + warn!(target: "network", "send disconnect task(session_id={}) failed, error={:?}", id, err); + } + } + ServiceError::MuxerError { + session_context, .. + } => { + if let Err(err) = context.control().disconnect(session_context.id) { + warn!(target: "network", "send disconnect task(session_id={}) failed, error={:?}", session_context.id, err); + } } + _ => {} } } diff --git a/network/src/protocols/mod.rs b/network/src/protocols/mod.rs index 47679622a7..00ff013628 100644 --- a/network/src/protocols/mod.rs +++ b/network/src/protocols/mod.rs @@ -20,6 +20,10 @@ use p2p::{ }; use std::sync::Arc; use std::time::{Duration, Instant}; +use tokio::codec::length_delimited; + +// Max message frame length: 20MB +const MAX_FRAME_LENGTH: usize = 20 * 1024 * 1024; pub type ProtocolVersion = u32; @@ -76,6 +80,13 @@ impl CKBProtocol { MetaBuilder::default() .id(self.id) .name(move |_| protocol_name.clone()) + .codec(|| { + Box::new( + length_delimited::Builder::new() + .max_frame_length(MAX_FRAME_LENGTH) + .new_codec(), + ) + }) .support_versions(supported_versions) .service_handle(move || { let handler = CKBHandler::new(self.id, self.network_state, self.handler); @@ -337,6 +348,7 @@ impl CKBProtocolContext for DefaultCKBProtocolContext { .network_state .get_peer_id(peer_index) .ok_or_else(|| PeerError::IndexNotFound(peer_index))?; + let session_id = self .network_state .peers_registry diff --git a/shared/src/chain_state.rs b/shared/src/chain_state.rs index adff0b2052..807640a60e 100644 --- a/shared/src/chain_state.rs +++ b/shared/src/chain_state.rs @@ -12,7 +12,7 @@ use ckb_core::transaction::{OutPoint, ProposalShortId, Transaction}; use ckb_core::Cycle; use ckb_verification::{TransactionError, TransactionVerifier}; use fnv::FnvHashSet; -use log::error; +use log::{error, trace}; use lru_cache::LruCache; use numext_fixed_hash::H256; use numext_fixed_uint::U256; @@ -106,7 +106,7 @@ impl ChainState { let verify_result = self.verify_rtx(&rtx, max_cycles); let tx_hash = tx.hash(); if self.contains_proposal_id(&short_id) { - if !self.filter.insert(tx_hash.clone()) { + if !tx_pool.filter.insert(tx_hash.clone()) { trace!(target: "tx_pool", "discarding already known transaction {:#x}", tx_hash); return Err(PoolError::Duplicate); } diff --git a/sync/src/relayer/transaction_process.rs b/sync/src/relayer/transaction_process.rs index 1903d76fa8..8101301527 100644 --- a/sync/src/relayer/transaction_process.rs +++ b/sync/src/relayer/transaction_process.rs @@ -73,7 +73,8 @@ where } } Err(PoolError::InvalidTx(TransactionError::UnknownInput)) - | Err(PoolError::InvalidTx(TransactionError::Conflict)) => { + | Err(PoolError::InvalidTx(TransactionError::Conflict)) + | Err(PoolError::Duplicate) => { // this error may occured when peer's tip is different with us, // we can't proof peer is bad so just ignore this debug!(target: "relay", "peer {} relay a conflict or missing input tx: {:?}", self.peer, tx); From 52c529ecff80fd4051e26a1ab8344a749368c50d Mon Sep 17 00:00:00 2001 From: Linfeng Qian Date: Wed, 3 Apr 2019 16:11:10 +0800 Subject: [PATCH 4/9] fix: Temporary remove peer eviction logic --- sync/src/synchronizer/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sync/src/synchronizer/mod.rs b/sync/src/synchronizer/mod.rs index 8f31860a28..71edba4e5a 100644 --- a/sync/src/synchronizer/mod.rs +++ b/sync/src/synchronizer/mod.rs @@ -629,9 +629,10 @@ impl Synchronizer { } for peer in eviction { warn!(target: "sync", "timeout eviction peer={}", peer); - // Do not connect this peer in 3 minutes - nc.ban_peer(peer, Duration::from_secs(180)); - nc.disconnect(peer); + + // FIXME: learn how bitcoin handle this evicted peer, then fix this. + // nc.ban_peer(peer, Duration::from_secs(180)); + // nc.disconnect(peer); } } From 973b8aac3511b226edf7073780cf2cac38f29dd0 Mon Sep 17 00:00:00 2001 From: Linfeng Qian Date: Thu, 4 Apr 2019 14:18:54 +0800 Subject: [PATCH 5/9] fix: Uncomment eviction disconnect code --- sync/src/synchronizer/mod.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sync/src/synchronizer/mod.rs b/sync/src/synchronizer/mod.rs index 71edba4e5a..aa452947bc 100644 --- a/sync/src/synchronizer/mod.rs +++ b/sync/src/synchronizer/mod.rs @@ -628,11 +628,8 @@ impl Synchronizer { } } for peer in eviction { - warn!(target: "sync", "timeout eviction peer={}", peer); - - // FIXME: learn how bitcoin handle this evicted peer, then fix this. - // nc.ban_peer(peer, Duration::from_secs(180)); - // nc.disconnect(peer); + info!(target: "sync", "timeout eviction peer={}", peer); + nc.disconnect(peer); } } From b00844bede5802875c53b02a2dcce81086686b64 Mon Sep 17 00:00:00 2001 From: Linfeng Qian Date: Thu, 4 Apr 2019 17:38:21 +0800 Subject: [PATCH 6/9] fix: Remove sender when channel disconnected --- network/src/protocols/discovery.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/network/src/protocols/discovery.rs b/network/src/protocols/discovery.rs index 87b24ec204..b6d97f96dc 100644 --- a/network/src/protocols/discovery.rs +++ b/network/src/protocols/discovery.rs @@ -126,6 +126,7 @@ impl ServiceProtocol for DiscoveryProtocol { } else { warn!(target: "network", "other channel error: {:?}", err); } + self.discovery_senders.remove(&session.id); } } } From 4648db29cc001320619d161fbfc02fac626dd2b4 Mon Sep 17 00:00:00 2001 From: Linfeng Qian Date: Thu, 4 Apr 2019 18:00:05 +0800 Subject: [PATCH 7/9] chore: Downgrade some log level from debug to trace --- network/src/protocols/mod.rs | 4 ++-- sync/src/synchronizer/block_fetcher.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/network/src/protocols/mod.rs b/network/src/protocols/mod.rs index 00ff013628..f7b3c9083c 100644 --- a/network/src/protocols/mod.rs +++ b/network/src/protocols/mod.rs @@ -11,7 +11,7 @@ use crate::{ NetworkState, PeerIndex, ProtocolContext, ProtocolContextMutRef, ServiceControl, SessionInfo, }; use bytes::Bytes; -use log::{debug, error, info, warn}; +use log::{trace, debug, error, info, warn}; use p2p::{ builder::MetaBuilder, service::{ProtocolHandle, ProtocolMeta}, @@ -242,7 +242,7 @@ impl ServiceProtocol for CKBHandler { .map(|peer_index| (peer_id, peer_index)) }) { - debug!( + trace!( target: "network", "ckb protocol received, addr: {}, protocol: {}, peer_id: {:?}", session.address, diff --git a/sync/src/synchronizer/block_fetcher.rs b/sync/src/synchronizer/block_fetcher.rs index 51b852e412..3477fb66f4 100644 --- a/sync/src/synchronizer/block_fetcher.rs +++ b/sync/src/synchronizer/block_fetcher.rs @@ -10,7 +10,7 @@ use ckb_shared::index::ChainIndex; use ckb_traits::ChainProvider; use ckb_util::try_option; use faketime::unix_time_as_millis; -use log::debug; +use log::{debug, trace}; use numext_fixed_hash::H256; use numext_fixed_uint::U256; use std::cmp; @@ -48,7 +48,7 @@ where .or_insert_with(Default::default); if inflight.timestamp < unix_time_as_millis().saturating_sub(BLOCK_DOWNLOAD_TIMEOUT) { - debug!(target: "sync", "[block downloader] inflight block download timeout"); + trace!(target: "sync", "[block downloader] inflight block download timeout"); inflight.clear(); } @@ -123,7 +123,7 @@ where } pub fn fetch(self) -> Option> { - debug!(target: "sync", "[block downloader] BlockFetcher process"); + trace!(target: "sync", "[block downloader] BlockFetcher process"); if self.initial_and_check_inflight() { debug!(target: "sync", "[block downloader] inflight count reach limit"); @@ -133,7 +133,7 @@ where let best_known_header = match self.peer_best_known_header() { Some(best_known_header) => best_known_header, _ => { - debug!(target: "sync", "[block downloader] peer_best_known_header not found peer={}", self.peer); + trace!(target: "sync", "[block downloader] peer_best_known_header not found peer={}", self.peer); return None; } }; From 66ac6a1308b1740301340998e8c6c77824d40814 Mon Sep 17 00:00:00 2001 From: piaoliu <441594700@qq.com> Date: Fri, 5 Apr 2019 13:37:46 +0800 Subject: [PATCH 8/9] fix: upgrage p2p dependence, fix cpu abnormal occupation --- Cargo.lock | 44 ++++++++++++++++++++++---------------------- network/Cargo.toml | 10 +++++----- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8d4fef42d3..6d4258e3a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -514,11 +514,11 @@ dependencies = [ "snap 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "stop-handler 0.9.0-pre", "tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "tentacle 0.2.0-alpha.1 (git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec)", - "tentacle-discovery 0.1.0 (git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec)", - "tentacle-identify 0.1.0 (git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec)", - "tentacle-ping 0.2.0 (git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec)", - "tentacle-secio 0.1.0 (git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec)", + "tentacle 0.2.0-alpha.1 (git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95)", + "tentacle-discovery 0.1.0 (git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95)", + "tentacle-identify 0.1.0 (git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95)", + "tentacle-ping 0.2.0 (git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95)", + "tentacle-secio 0.1.0 (git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95)", "tokio 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (git+https://github.com/paritytech/unsigned-varint)", ] @@ -2823,23 +2823,23 @@ dependencies = [ [[package]] name = "tentacle" version = "0.2.0-alpha.1" -source = "git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec#ab661f065dc8667a04f12122250f5fb759872dec" +source = "git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95#53cb765b94041543a9c8582aa4d0d34fb2ac6d95" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-multiaddr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tentacle-secio 0.1.0 (git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec)", + "tentacle-secio 0.1.0 (git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95)", "tokio 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-threadpool 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-yamux 0.1.4 (git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec)", + "tokio-yamux 0.1.4 (git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95)", ] [[package]] name = "tentacle-discovery" version = "0.1.0" -source = "git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec#ab661f065dc8667a04f12122250f5fb759872dec" +source = "git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95#53cb765b94041543a9c8582aa4d0d34fb2ac6d95" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2850,7 +2850,7 @@ dependencies = [ "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", - "tentacle 0.2.0-alpha.1 (git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec)", + "tentacle 0.2.0-alpha.1 (git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95)", "tokio 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", "trust-dns 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2858,32 +2858,32 @@ dependencies = [ [[package]] name = "tentacle-identify" version = "0.1.0" -source = "git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec#ab661f065dc8667a04f12122250f5fb759872dec" +source = "git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95#53cb765b94041543a9c8582aa4d0d34fb2ac6d95" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tentacle 0.2.0-alpha.1 (git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec)", + "tentacle 0.2.0-alpha.1 (git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95)", "tokio 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tentacle-ping" version = "0.2.0" -source = "git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec#ab661f065dc8667a04f12122250f5fb759872dec" +source = "git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95#53cb765b94041543a9c8582aa4d0d34fb2ac6d95" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "generic-channel 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tentacle 0.2.0-alpha.1 (git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec)", + "tentacle 0.2.0-alpha.1 (git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95)", ] [[package]] name = "tentacle-secio" version = "0.1.0" -source = "git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec#ab661f065dc8667a04f12122250f5fb759872dec" +source = "git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95#53cb765b94041543a9c8582aa4d0d34fb2ac6d95" dependencies = [ "aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3163,7 +3163,7 @@ dependencies = [ [[package]] name = "tokio-yamux" version = "0.1.4" -source = "git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec#ab661f065dc8667a04f12122250f5fb759872dec" +source = "git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95#53cb765b94041543a9c8582aa4d0d34fb2ac6d95" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3737,11 +3737,11 @@ dependencies = [ "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" "checksum tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b86c784c88d98c801132806dadd3819ed29d8600836c4088e855cdf3e178ed8a" -"checksum tentacle 0.2.0-alpha.1 (git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec)" = "" -"checksum tentacle-discovery 0.1.0 (git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec)" = "" -"checksum tentacle-identify 0.1.0 (git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec)" = "" -"checksum tentacle-ping 0.2.0 (git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec)" = "" -"checksum tentacle-secio 0.1.0 (git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec)" = "" +"checksum tentacle 0.2.0-alpha.1 (git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95)" = "" +"checksum tentacle-discovery 0.1.0 (git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95)" = "" +"checksum tentacle-identify 0.1.0 (git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95)" = "" +"checksum tentacle-ping 0.2.0 (git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95)" = "" +"checksum tentacle-secio 0.1.0 (git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95)" = "" "checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72b620c5ea021d75a735c943269bb07d30c9b77d6ac6b236bc8b5c496ef05625" @@ -3765,7 +3765,7 @@ dependencies = [ "checksum tokio-trace-core 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "350c9edade9830dc185ae48ba45667a445ab59f6167ef6d0254ec9d2430d9dd3" "checksum tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "66268575b80f4a4a710ef83d087fdfeeabdce9b74c797535fbac18a2cb906e92" "checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445" -"checksum tokio-yamux 0.1.4 (git+https://github.com/nervosnetwork/p2p?rev=ab661f065dc8667a04f12122250f5fb759872dec)" = "" +"checksum tokio-yamux 0.1.4 (git+https://github.com/nervosnetwork/p2p?rev=53cb765b94041543a9c8582aa4d0d34fb2ac6d95)" = "" "checksum toml 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "87c5890a989fa47ecdc7bcb4c63a77a82c18f306714104b1decfd722db17b39e" "checksum trust-dns 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "65096825b064877da37eeeb9a83390bd23433eabfc503a6476dc5b1949034aa7" "checksum trust-dns-proto 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "09144f0992b0870fa8d2972cc069cbf1e3c0fda64d1f3d45c4d68d0e0b52ad4e" diff --git a/network/Cargo.toml b/network/Cargo.toml index 5d7c770be8..75c5afa6fb 100644 --- a/network/Cargo.toml +++ b/network/Cargo.toml @@ -23,11 +23,11 @@ tokio = "0.1.18" futures = "0.1" snap = "0.2" crossbeam-channel = "0.3" -p2p = { git = "https://github.com/nervosnetwork/p2p", rev="ab661f065dc8667a04f12122250f5fb759872dec", package="tentacle" } -secio = { git = "https://github.com/nervosnetwork/p2p", rev="ab661f065dc8667a04f12122250f5fb759872dec", package="tentacle-secio" } -p2p-ping = { git = "https://github.com/nervosnetwork/p2p", rev="ab661f065dc8667a04f12122250f5fb759872dec", package="tentacle-ping" } -p2p-discovery = { git = "https://github.com/nervosnetwork/p2p", rev="ab661f065dc8667a04f12122250f5fb759872dec", package="tentacle-discovery" } -p2p-identify = { git = "https://github.com/nervosnetwork/p2p", rev="ab661f065dc8667a04f12122250f5fb759872dec", package="tentacle-identify" } +p2p = { git = "https://github.com/nervosnetwork/p2p", rev="53cb765b94041543a9c8582aa4d0d34fb2ac6d95", package="tentacle" } +secio = { git = "https://github.com/nervosnetwork/p2p", rev="53cb765b94041543a9c8582aa4d0d34fb2ac6d95", package="tentacle-secio" } +p2p-ping = { git = "https://github.com/nervosnetwork/p2p", rev="53cb765b94041543a9c8582aa4d0d34fb2ac6d95", package="tentacle-ping" } +p2p-discovery = { git = "https://github.com/nervosnetwork/p2p", rev="53cb765b94041543a9c8582aa4d0d34fb2ac6d95", package="tentacle-discovery" } +p2p-identify = { git = "https://github.com/nervosnetwork/p2p", rev="53cb765b94041543a9c8582aa4d0d34fb2ac6d95", package="tentacle-identify" } faketime = "0.2.0" rusqlite = {version = "0.16.0", features = ["bundled"]} lazy_static = "1.3.0" From 0aefcc9822d87645819d814a2a9ac7aacfd761e1 Mon Sep 17 00:00:00 2001 From: Linfeng Qian Date: Tue, 9 Apr 2019 11:31:04 +0800 Subject: [PATCH 9/9] fix: rustfmt --- network/src/protocols/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/src/protocols/mod.rs b/network/src/protocols/mod.rs index f7b3c9083c..2cc61791b3 100644 --- a/network/src/protocols/mod.rs +++ b/network/src/protocols/mod.rs @@ -11,7 +11,7 @@ use crate::{ NetworkState, PeerIndex, ProtocolContext, ProtocolContextMutRef, ServiceControl, SessionInfo, }; use bytes::Bytes; -use log::{trace, debug, error, info, warn}; +use log::{debug, error, info, trace, warn}; use p2p::{ builder::MetaBuilder, service::{ProtocolHandle, ProtocolMeta},