From b23ae731f41e710de0d42daab5f468684036309a Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Wed, 26 May 2021 15:45:09 +0800 Subject: [PATCH 1/6] chore: upgrade ckb-system-scripts to v0.5.2 --- Cargo.lock | 24 +++++++++--------------- benches/Cargo.toml | 2 +- resource/Cargo.toml | 4 ++-- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8a7dd70ae9..b7a25ee6cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -579,7 +579,7 @@ name = "ckb-crypto" version = "0.43.0-pre" dependencies = [ "ckb-fixed-hash", - "faster-hex 0.6.0", + "faster-hex", "lazy_static", "rand 0.7.3", "secp256k1", @@ -663,7 +663,7 @@ dependencies = [ name = "ckb-fixed-hash-core" version = "0.43.0-pre" dependencies = [ - "faster-hex 0.6.0", + "faster-hex", "serde", "thiserror", ] @@ -720,7 +720,7 @@ name = "ckb-jsonrpc-types" version = "0.43.0-pre" dependencies = [ "ckb-types", - "faster-hex 0.6.0", + "faster-hex", "jsonrpc-core", "lazy_static", "proptest", @@ -922,7 +922,7 @@ dependencies = [ "ckb-util", "criterion", "faketime", - "faster-hex 0.6.0", + "faster-hex", "futures 0.3.12", "ipnetwork", "lazy_static", @@ -1136,7 +1136,7 @@ dependencies = [ "ckb-types", "ckb-vm", "ckb-vm-definitions", - "faster-hex 0.6.0", + "faster-hex", "goblin", "proptest", "serde", @@ -1345,12 +1345,12 @@ dependencies = [ [[package]] name = "ckb-system-scripts" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "261dd95a93c09ea24397c85b4fbca061e1da2d6573189749aeb99fe840aaf0c9" +checksum = "cfbce46ad2de7563c7e456888d4a29df3d461106a989836c08627d044409e928" dependencies = [ "blake2b-rs", - "faster-hex 0.3.1", + "faster-hex", "includedir", "includedir_codegen", "phf", @@ -2052,12 +2052,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "faster-hex" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5b8cccaafb5aae8c282692e5590f341925edea6c696e8715ff0d973320b2646" - [[package]] name = "faster-hex" version = "0.6.0" @@ -3432,7 +3426,7 @@ checksum = "c58d1147f4d0d51ce72c56a6099ae5dbfd007b250271bb965f82dd10fca2bf02" dependencies = [ "bytes 1.0.1", "cfg-if 1.0.0", - "faster-hex 0.6.0", + "faster-hex", ] [[package]] diff --git a/benches/Cargo.toml b/benches/Cargo.toml index 6a564e568d..61bac9f32f 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -23,7 +23,7 @@ ckb-hash = {path = "../util/hash", version = "= 0.43.0-pre"} ckb-test-chain-utils = { path = "../util/test-chain-utils", version = "= 0.43.0-pre" } ckb-dao-utils = { path = "../util/dao/utils", version = "= 0.43.0-pre" } ckb-dao = { path = "../util/dao", version = "= 0.43.0-pre" } -ckb-system-scripts = { version = "= 0.5.1" } +ckb-system-scripts = { version = "= 0.5.2" } lazy_static = "1.3.0" ckb-crypto = { path = "../util/crypto", version = "= 0.43.0-pre" } ckb-jsonrpc-types = { path = "../util/jsonrpc-types", version = "= 0.43.0-pre" } diff --git a/resource/Cargo.toml b/resource/Cargo.toml index 0cea25da0d..606792716a 100644 --- a/resource/Cargo.toml +++ b/resource/Cargo.toml @@ -16,10 +16,10 @@ includedir = "0.5.0" tempfile = "=3.1.0" serde = { version = "1.0", features = ["derive"] } ckb-types = { path = "../util/types", version = "= 0.43.0-pre" } -ckb-system-scripts = { version = "= 0.5.1" } +ckb-system-scripts = { version = "= 0.5.2" } [build-dependencies] includedir_codegen = "0.5.0" walkdir = "2.1.4" ckb-types = { path = "../util/types", version = "= 0.43.0-pre" } -ckb-system-scripts = { version = "= 0.5.1" } +ckb-system-scripts = { version = "= 0.5.2" } From 1ef6c03b0dd2e8677e2eb46206aeab70e744f609 Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Wed, 26 May 2021 17:25:11 +0800 Subject: [PATCH 2/6] chore: upgrade rocksdb to v6.20.3 --- Cargo.lock | 8 ++++---- db/Cargo.toml | 2 +- db/src/write_batch.rs | 20 ++++++++++++++++---- store/src/write_batch.rs | 20 +++++++------------- util/types/src/extension/shortcuts.rs | 7 +++++++ 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b7a25ee6cc..a217e0e5d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -761,9 +761,9 @@ dependencies = [ [[package]] name = "ckb-librocksdb-sys" -version = "6.11.6" +version = "6.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a78d3b9b5fd3b4990ddd2083f6a6d4389b6c8e603a4f2896914165113beed2d" +checksum = "ffbc8d4e55832ebb78adf5a8ef7303b934983e9fff073c9b49e884c3a2d139f4" dependencies = [ "cc", "glob", @@ -1055,9 +1055,9 @@ dependencies = [ [[package]] name = "ckb-rocksdb" -version = "0.15.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a645f6745c3519bbcbeed80486e59cb3f74d2ac08a1d9621c399b892508aca6e" +checksum = "09bef4a177960f6f137f02c715acf9e374831036170b1862eedfb9ff2642c078" dependencies = [ "ckb-librocksdb-sys", "libc", diff --git a/db/Cargo.toml b/db/Cargo.toml index 28ec6623fd..c2ec95fb72 100644 --- a/db/Cargo.toml +++ b/db/Cargo.toml @@ -13,6 +13,6 @@ ckb-app-config = { path = "../util/app-config", version = "= 0.43.0-pre" } ckb-logger = { path = "../util/logger", version = "= 0.43.0-pre" } ckb-error = { path = "../error", version = "= 0.43.0-pre" } libc = "0.2" -rocksdb = { package = "ckb-rocksdb", version = "=0.15.1", features = ["snappy"] } +rocksdb = { package = "ckb-rocksdb", version ="=0.16.0", features = ["snappy"] } ckb-db-schema = { path = "../db-schema", version = "= 0.43.0-pre" } tempfile = "3.0" diff --git a/db/src/write_batch.rs b/db/src/write_batch.rs index 9bdcac1e32..d12b071116 100644 --- a/db/src/write_batch.rs +++ b/db/src/write_batch.rs @@ -46,11 +46,23 @@ impl RocksDBWriteBatch { /// Removes the database entries in the range ["begin_key", "end_key"), i.e., /// including "begin_key" and excluding "end_key". It is not an error if no /// keys exist in the range ["begin_key", "end_key"). - pub fn delete_range(&mut self, col: Col, from: &[u8], to: &[u8]) -> Result<()> { + pub fn delete_range>( + &mut self, + col: Col, + range: impl Iterator, + ) -> Result<()> { let cf = cf_handle(&self.db, col)?; - self.inner - .delete_range_cf(cf, from, to) - .map_err(internal_error) + + for key in range { + self.inner + .delete_cf(cf, key.as_ref()) + .map_err(internal_error)?; + } + Ok(()) + + // since 6.18 delete_range_cf + // OptimisticTransactionDB now returns error Statuses from calls to DeleteRange() and calls to Write() where the WriteBatch contains a range deletion. + // Previously such operations may have succeeded while not providing the expected transactional guarantees. } /// Clear all updates buffered in this batch. diff --git a/store/src/write_batch.rs b/store/src/write_batch.rs index 2c5b1076b2..ca6aa9c365 100644 --- a/store/src/write_batch.rs +++ b/store/src/write_batch.rs @@ -97,21 +97,15 @@ impl StoreWriteBatch { .build() .as_slice(), )?; - let txs_start_key = packed::TransactionKey::new_builder() - .block_hash(hash.clone()) - .index(0u32.pack()) - .build(); - let txs_end_key = packed::TransactionKey::new_builder() - .block_hash(hash.clone()) - .index(txs_len.pack()) - .build(); + let key_range = (0u32..txs_len).map(|i| { + packed::TransactionKey::new_builder() + .block_hash(hash.clone()) + .index(i.pack()) + .build() + }); - self.inner.delete_range( - COLUMN_BLOCK_BODY, - txs_start_key.as_slice(), - txs_end_key.as_slice(), - )?; + self.inner.delete_range(COLUMN_BLOCK_BODY, key_range)?; Ok(()) } diff --git a/util/types/src/extension/shortcuts.rs b/util/types/src/extension/shortcuts.rs index 5a6a33ed60..f21d795edf 100644 --- a/util/types/src/extension/shortcuts.rs +++ b/util/types/src/extension/shortcuts.rs @@ -288,3 +288,10 @@ impl packed::CompactBlock { .collect() } } + +impl AsRef<[u8]> for packed::TransactionKey { + #[inline] + fn as_ref(&self) -> &[u8] { + self.as_slice() + } +} From 8d40afddd853f16145826a3a13c56ab5e10009cf Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Mon, 7 Jun 2021 21:49:32 +0800 Subject: [PATCH 3/6] feat: filter internal db error --- Cargo.lock | 81 +++++++++++++++++++++++++- Cargo.toml | 1 + chain/Cargo.toml | 5 ++ chain/src/chain.rs | 26 +++++++-- chain/src/tests/dep_cell.rs | 1 - db/src/read_only_db.rs | 3 +- sync/Cargo.toml | 2 + sync/src/synchronizer/block_process.rs | 18 +++--- sync/src/synchronizer/mod.rs | 45 +++++++++++++- sync/src/types/mod.rs | 21 ++++--- sync/src/utils.rs | 13 +++++ 11 files changed, 183 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a217e0e5d4..07748ac00c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -533,6 +533,7 @@ dependencies = [ "ckb-verification-contextual", "ckb-verification-traits", "faketime", + "faux", "lazy_static", "tempfile", ] @@ -1336,6 +1337,7 @@ dependencies = [ "ckb-verification", "ckb-verification-traits", "faketime", + "faux", "futures 0.3.12", "governor", "lru", @@ -1521,7 +1523,7 @@ dependencies = [ "ansi_term 0.11.0", "atty", "bitflags", - "strsim", + "strsim 0.8.0", "textwrap", "unicode-width", "vec_map", @@ -1891,6 +1893,41 @@ dependencies = [ "zeroize", ] +[[package]] +name = "darling" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f2c43f534ea4b0b049015d00269734195e6d3f0f6635cb692251aca6f9f8b3c" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e91455b86830a1c21799d94524df0845183fa55bafd9aa137b01c7d1065fa36" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.10.0", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29b5acf0dea37a7f66f7b25d2c5e93fd46f8f6968b1a5d7a3e02e97768afc95a" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "darwin-libproc" version = "0.1.1" @@ -2058,6 +2095,28 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b02a61fea82de8484f9d7ce99b698b0e190ef8de71035690a961a43d7b18a2ad" +[[package]] +name = "faux" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c3668239842a12c1810beec5afa357caa1aca3ee6b7cd9c60514af9787061f" +dependencies = [ + "faux_macros", + "paste 1.0.5", +] + +[[package]] +name = "faux_macros" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bba2d3cc6542e349914482eea66e5c5cee9c6acd63b8fda73698b974234869f7" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "fdlimit" version = "0.2.1" @@ -2747,6 +2806,12 @@ dependencies = [ "tokio-tls", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "0.2.0" @@ -2893,7 +2958,7 @@ checksum = "c502a5ff9dd2924f1ed32ba96e3b65735d837b4bfd978d3161b1702e66aca4b7" dependencies = [ "jemalloc-sys", "libc", - "paste", + "paste 0.1.6", ] [[package]] @@ -3781,6 +3846,12 @@ dependencies = [ "proc-macro-hack", ] +[[package]] +name = "paste" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" + [[package]] name = "paste-impl" version = "0.1.6" @@ -4672,6 +4743,12 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "subtle" version = "2.3.0" diff --git a/Cargo.toml b/Cargo.toml index 11d784d486..da4700c9e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ build = "build.rs" description = "CKB is the layer 1 of Nervos Network, a public/permissionless blockchain." homepage = "https://github.com/nervosnetwork/ckb" repository = "https://github.com/nervosnetwork/ckb" +resolver = "2" [build-dependencies] ckb-build-info = { path = "util/build-info", version = "= 0.43.0-pre" } diff --git a/chain/Cargo.toml b/chain/Cargo.toml index 209a81f304..09da9aa59b 100644 --- a/chain/Cargo.toml +++ b/chain/Cargo.toml @@ -26,6 +26,7 @@ ckb-error = { path = "../error", version = "= 0.43.0-pre" } ckb-app-config = { path = "../util/app-config", version = "= 0.43.0-pre" } ckb-rust-unstable-port = { path = "../util/rust-unstable-port", version = "= 0.43.0-pre" } ckb-channel = { path = "../util/channel", version = "= 0.43.0-pre" } +faux = { version = "^0.1", optional = true } [dev-dependencies] ckb-test-chain-utils = { path = "../util/test-chain-utils", version = "= 0.43.0-pre" } @@ -35,3 +36,7 @@ ckb-jsonrpc-types = { path = "../util/jsonrpc-types", version = "= 0.43.0-pre" } ckb-network = { path = "../network", version = "= 0.43.0-pre" } lazy_static = "1.4" tempfile = "3.0" + +[features] +default = [] +mock = ["faux"] diff --git a/chain/src/chain.rs b/chain/src/chain.rs index b88efe00e0..055917470a 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -1,4 +1,5 @@ //! CKB chain service. +#![allow(missing_docs)] use ckb_channel::{self as channel, select, Sender}; use ckb_error::{Error, InternalErrorKind}; @@ -35,6 +36,7 @@ type TruncateRequest = Request>; /// The controller is internally reference-counted and can be freely cloned. /// /// A controller can invoke [`ChainService`] methods. +#[cfg_attr(feature = "mock", faux::create)] #[derive(Clone)] pub struct ChainController { process_block_sender: Sender, @@ -44,11 +46,23 @@ pub struct ChainController { impl Drop for ChainController { fn drop(&mut self) { - self.stop.try_send(); + self.stop(); } } +#[cfg_attr(feature = "mock", faux::methods)] impl ChainController { + pub fn new( + process_block_sender: Sender, + truncate_sender: Sender, + stop: StopHandler<()>, + ) -> Self { + ChainController { + process_block_sender, + truncate_sender, + stop, + } + } /// Inserts the block into database. /// /// Expects the block's header to be valid and already verified. @@ -85,6 +99,10 @@ impl ChainController { .into()) }) } + + pub fn stop(&mut self) { + self.stop.try_send(); + } } /// The struct represent fork @@ -218,11 +236,7 @@ impl ChainService { .expect("Start ChainService failed"); let stop = StopHandler::new(SignalSender::Crossbeam(signal_sender), Some(thread)); - ChainController { - process_block_sender, - truncate_sender, - stop, - } + ChainController::new(process_block_sender, truncate_sender, stop) } fn make_fork_for_truncate(&self, target: &HeaderView, current_tip: &HeaderView) -> ForkChanges { diff --git a/chain/src/tests/dep_cell.rs b/chain/src/tests/dep_cell.rs index 1a1cbe7620..23bc05ea1f 100644 --- a/chain/src/tests/dep_cell.rs +++ b/chain/src/tests/dep_cell.rs @@ -556,7 +556,6 @@ fn test_package_txs_with_deps_priority() { } let block: Block = block_template.clone().into(); - println!("block proposal len {}", block.proposals().len()); let block = block.as_advanced_builder().build(); chain_controller .internal_process_block(Arc::new(block), Switch::DISABLE_ALL) diff --git a/db/src/read_only_db.rs b/db/src/read_only_db.rs index aaf3148d41..3ecdd9247c 100644 --- a/db/src/read_only_db.rs +++ b/db/src/read_only_db.rs @@ -23,8 +23,7 @@ impl ReadOnlyDB { |err| { let err_str = err.as_ref(); // notice: err msg difference - if err_str.starts_with("NotFound") - && err_str.ends_with("does not exist") + if err_str.starts_with("IO error: No such file or directory") { Ok(None) } else if err_str.starts_with("Corruption:") { diff --git a/sync/Cargo.toml b/sync/Cargo.toml index a26aa3b69a..049f89c3d4 100644 --- a/sync/Cargo.toml +++ b/sync/Cargo.toml @@ -40,6 +40,8 @@ ckb-test-chain-utils = { path = "../util/test-chain-utils", version = "= 0.43.0- rand = "0.7" ckb-dao = { path = "../util/dao", version = "= 0.43.0-pre" } ckb-dao-utils = { path = "../util/dao/utils", version = "= 0.43.0-pre" } +ckb-chain = { path = "../chain", version = "= 0.43.0-pre", features = ["mock"] } +faux = "^0.1" [features] default = [] diff --git a/sync/src/synchronizer/block_process.rs b/sync/src/synchronizer/block_process.rs index fbb41df462..3526fb1450 100644 --- a/sync/src/synchronizer/block_process.rs +++ b/sync/src/synchronizer/block_process.rs @@ -1,7 +1,4 @@ -use crate::{ - synchronizer::{BlockStatus, Synchronizer}, - Status, StatusCode, -}; +use crate::{synchronizer::Synchronizer, utils::is_internal_db_error, Status, StatusCode}; use ckb_logger::debug; use ckb_network::PeerIndex; use ckb_types::{packed, prelude::*}; @@ -37,12 +34,13 @@ impl<'a> BlockProcess<'a> { if state.new_block_received(&block) { if let Err(err) = self.synchronizer.process_new_block(block.clone()) { - state.insert_block_status(block.hash(), BlockStatus::BLOCK_INVALID); - return StatusCode::BlockIsInvalid.with_context(format!( - "{}, error: {}", - block.hash(), - err, - )); + if !is_internal_db_error(&err) { + return StatusCode::BlockIsInvalid.with_context(format!( + "{}, error: {}", + block.hash(), + err, + )); + } } } diff --git a/sync/src/synchronizer/mod.rs b/sync/src/synchronizer/mod.rs index 2f01723cd9..1880fe19d5 100644 --- a/sync/src/synchronizer/mod.rs +++ b/sync/src/synchronizer/mod.rs @@ -21,7 +21,7 @@ use ckb_constant::sync::{ BAD_MESSAGE_BAN_TIME, CHAIN_SYNC_TIMEOUT, EVICTION_HEADERS_RESPONSE_TIME, INIT_BLOCKS_IN_TRANSIT_PER_PEER, MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT, MAX_TIP_AGE, }; -use ckb_error::AnyError; +use ckb_error::Error as CKBError; use ckb_logger::{debug, error, info, trace, warn}; use ckb_metrics::metrics; use ckb_network::{ @@ -310,7 +310,7 @@ impl Synchronizer { /// Process a new block sync from other peer //TODO: process block which we don't request - pub fn process_new_block(&self, block: core::BlockView) -> Result { + pub fn process_new_block(&self, block: core::BlockView) -> Result { let block_hash = block.hash(); let status = self.shared.active_chain().get_block_status(&block_hash); // NOTE: Filtering `BLOCK_STORED` but not `BLOCK_RECEIVED`, is for avoiding @@ -803,10 +803,11 @@ mod tests { types::{HeaderView, HeadersSyncController, PeerState}, SyncShared, }; - use ckb_chain::chain::ChainService; + use ckb_chain::chain::{ChainController, ChainService}; use ckb_chain_spec::consensus::{Consensus, ConsensusBuilder}; use ckb_constant::sync::MAX_TIP_AGE; use ckb_dao::DaoCalculator; + use ckb_error::InternalErrorKind; use ckb_network::{ bytes::Bytes, Behaviour, CKBProtocolContext, Peer, PeerId, PeerIndex, ProtocolId, SessionType, TargetSession, @@ -1817,4 +1818,42 @@ mod tests { ); } } + + #[test] + fn test_internal_db_error() { + use crate::utils::is_internal_db_error; + + let consensus = Consensus::default(); + let mut builder = SharedBuilder::with_temp_db(); + builder = builder.consensus(consensus); + + let (shared, mut pack) = builder.build().unwrap(); + + let chain_service = ChainService::new(shared.clone(), pack.take_proposal_table()); + let _chain_controller = chain_service.start::<&str>(None); + + let sync_shared = Arc::new(SyncShared::new( + shared, + Default::default(), + pack.take_relay_tx_receiver(), + )); + + let mut chain_controller = ChainController::faux(); + let block = Arc::new(BlockBuilder::default().build()); + + // mock process_block + faux::when!(chain_controller.process_block(Arc::clone(&block))).then_return(Err( + InternalErrorKind::Database.other("mocked db error").into(), + )); + + faux::when!(chain_controller.stop()).then_return(()); + + let synchronizer = Synchronizer::new(chain_controller, sync_shared); + + let status = synchronizer + .shared() + .accept_block(&synchronizer.chain, Arc::clone(&block)); + + assert!(is_internal_db_error(&status.err().unwrap())); + } } diff --git a/sync/src/types/mod.rs b/sync/src/types/mod.rs index b13f234fbc..991697f187 100644 --- a/sync/src/types/mod.rs +++ b/sync/src/types/mod.rs @@ -1,5 +1,6 @@ use crate::block_status::BlockStatus; use crate::orphan_block_pool::OrphanBlockPool; +use crate::utils::is_internal_db_error; use crate::{FAST_INDEX, LOW_INDEX, NORMAL_INDEX, TIME_TRACE_SIZE}; use ckb_app_config::SyncConfig; use ckb_chain::chain::ChainController; @@ -11,7 +12,7 @@ use ckb_constant::sync::{ MAX_BLOCKS_IN_TRANSIT_PER_PEER, MAX_HEADERS_LEN, MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT, POW_INTERVAL, RETRY_ASK_TX_TIMEOUT_INCREASE, SUSPEND_SYNC_TIME, }; -use ckb_error::AnyError; +use ckb_error::Error as CKBError; use ckb_logger::{debug, debug_target, error, trace}; use ckb_metrics::metrics; use ckb_network::{CKBProtocolContext, PeerIndex, SupportProtocols}; @@ -1292,7 +1293,7 @@ impl SyncShared { &self, chain: &ChainController, block: Arc, - ) -> Result { + ) -> Result { // Insert the given block into orphan_block_pool if its parent is not found if !self.is_parent_stored(&block) { debug!( @@ -1349,11 +1350,11 @@ impl SyncShared { } } - fn accept_block( + pub(crate) fn accept_block( &self, chain: &ChainController, block: Arc, - ) -> Result { + ) -> Result { let ret = { let mut assume_valid_target = self.state.assume_valid_target(); if let Some(ref target) = *assume_valid_target { @@ -1370,10 +1371,12 @@ impl SyncShared { chain.process_block(Arc::clone(&block)) } }; - if ret.is_err() { - error!("accept block {:?} {:?}", block, ret); - self.state - .insert_block_status(block.header().hash(), BlockStatus::BLOCK_INVALID); + if let Err(ref error) = ret { + error!("accept block {:?} {}", block, error); + if !is_internal_db_error(&error) { + self.state + .insert_block_status(block.header().hash(), BlockStatus::BLOCK_INVALID); + } } else { // Clear the newly inserted block from block_status_map. // @@ -1385,7 +1388,7 @@ impl SyncShared { self.state.remove_header_view(&block.as_ref().hash()); } - Ok(ret?) + ret } /// Sync a new valid header, try insert to sync state diff --git a/sync/src/utils.rs b/sync/src/utils.rs index 63e6ebd4c7..25e8bbcc2c 100644 --- a/sync/src/utils.rs +++ b/sync/src/utils.rs @@ -1,4 +1,5 @@ use crate::{Status, StatusCode}; +use ckb_error::{Error as CKBError, ErrorKind, InternalError, InternalErrorKind}; use ckb_metrics::metrics; use ckb_network::{CKBProtocolContext, PeerIndex, ProtocolId, SupportProtocols}; use ckb_types::packed::{RelayMessageReader, SyncMessageReader}; @@ -75,3 +76,15 @@ fn item_id(protocol_id: ProtocolId, message: &Message) -> u32 { 0 } } + +/// return whether the error's kind is `InternalErrorKind::Database` +pub(crate) fn is_internal_db_error(error: &CKBError) -> bool { + if error.kind() == ErrorKind::Internal { + return error + .downcast_ref::() + .expect("error kind checked") + .kind() + == InternalErrorKind::Database; + } + false +} From 3a637d5c953b4737a982f0c727b3c303cb1d2d84 Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Fri, 11 Jun 2021 17:29:03 +0800 Subject: [PATCH 4/6] feat(vm): detect asm --- script/Cargo.toml | 2 +- script/build.rs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/script/Cargo.toml b/script/Cargo.toml index af2d05e2c8..da6bfc698b 100644 --- a/script/Cargo.toml +++ b/script/Cargo.toml @@ -10,7 +10,7 @@ homepage = "https://github.com/nervosnetwork/ckb" repository = "https://github.com/nervosnetwork/ckb" [features] -default = ["logging", "asm"] +default = ["logging", "detect-asm"] asm = ["ckb-vm/asm"] detect-asm = ["ckb-vm/detect-asm"] diff --git a/script/build.rs b/script/build.rs index f65eb337ec..7cc0809306 100644 --- a/script/build.rs +++ b/script/build.rs @@ -2,14 +2,15 @@ use std::env; fn main() { - let target_pointer_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap(); let target_family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap_or_default(); + let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default(); let is_windows = target_family == "windows"; let is_unix = target_family == "unix"; - let can_enable_asm = (target_pointer_width == "64") && (is_windows || is_unix); + let is_x86_64 = target_arch == "x86_64"; + let can_enable_asm = is_x86_64 && (is_windows || is_unix); if cfg!(feature = "asm") && (!can_enable_asm) { - panic!("asm feature can only be enabled on 64-bit Linux, macOS and Windows platforms!"); + panic!("asm feature can only be enabled on x86_64 Linux, macOS and Windows platforms!"); } if cfg!(any(feature = "asm", feature = "detect-asm")) && can_enable_asm { From 5ff1a42c4a04f650d4220979419186977168ffa4 Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Fri, 11 Jun 2021 17:29:47 +0800 Subject: [PATCH 5/6] chore: upgrade ring --- Cargo.lock | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 07748ac00c..e1acf82df3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -326,11 +326,11 @@ checksum = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427" [[package]] name = "cc" -version = "1.0.38" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce400c638d48ee0e9ab75aef7997609ec57367ccfe1463f21bf53c3eca67bf46" +checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" dependencies = [ - "rayon", + "jobserver", ] [[package]] @@ -2982,6 +2982,15 @@ dependencies = [ "libc", ] +[[package]] +name = "jobserver" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "972f5ae5d1cb9c6ae417789196c803205313edde988685da5e3aae0827b9e7fd" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" version = "0.3.45" @@ -4412,13 +4421,13 @@ dependencies = [ [[package]] name = "ring" -version = "0.16.12" +version = "0.16.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ba5a8ec64ee89a76c98c549af81ff14813df09c3e6dc4766c3856da48597a0c" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" dependencies = [ "cc", - "lazy_static", "libc", + "once_cell", "spin", "untrusted", "web-sys", @@ -5418,9 +5427,9 @@ checksum = "35581ff83d4101e58b582e607120c7f5ffb17e632a980b1f38334d76b36908b2" [[package]] name = "untrusted" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60369ef7a31de49bcb3f6ca728d4ba7300d9a1658f94c727d4cab8c8d9f4aece" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "uom" From f91703713862b1bb4e5c0cee3aa846d50a774b3f Mon Sep 17 00:00:00 2001 From: ian Date: Sat, 12 Jun 2021 15:00:43 +0800 Subject: [PATCH 6/6] ci: run GitHub Axtions job "ci" for pull request --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9f223c4d06..35d791c1b7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -203,7 +203,7 @@ jobs: - Benchmarks_Test - Integration_Test if: | - contains('bors[bot]', github.actor) && success() + (contains(github.event_name, 'pull_request') || contains('bors[bot]', github.actor)) && success() runs-on: ubuntu-latest steps: - name: CI succeeded