Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport] Modify the record scope of tx-pool reject record and fix rule for orphan tx #4516

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 81 additions & 71 deletions Cargo.lock

Large diffs are not rendered by default.

146 changes: 74 additions & 72 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,77 +23,77 @@ console-subscriber = { version = "0.2.0", optional = true }
[workspace]
# To get a list sorted by dependencies, run devtools/ci/check-cyclic-dependencies.py
members = [
"util",
"util/occupied-capacity/core",
"util/channel",
"util/systemtime",
"util/fixed-hash/core",
"util/build-info",
"util/logger",
"util/logger-config",
"util/metrics-config",
"util/hash",
"util/rational",
"benches",
"db-schema",
"util/spawn",
"util/occupied-capacity/macros",
"util/fixed-hash/macros",
"util/logger-service",
"util/runtime",
"util/stop-handler",
"util/metrics",
"util/metrics-service",
"util/fixed-hash",
"util/occupied-capacity",
"util/crypto",
"util/constant",
"error",
"util/multisig",
"util/gen-types",
"util/migrate/migration-template",
"util/types",
"util/jsonrpc-types",
"freezer",
"resource",
"pow",
"util/dao/utils",
"traits",
"spec",
"util/proposal-table",
"script",
"util/app-config",
"db",
"network",
"miner",
"notify",
"util/memory-tracker",
"db-migration",
"util/network-alert",
"store",
"util/indexer-sync",
"util/indexer",
"util/rich-indexer",
"util/chain-iter",
"util/dao",
"util/test-chain-utils",
"util/reward-calculator",
"util/snapshot",
"util/migrate",
"verification/traits",
"verification",
"verification/contextual",
"tx-pool",
"shared",
"block-filter",
"chain",
"sync",
"util/instrument",
"rpc",
"util/light-client-protocol-server",
"util/launcher",
"devtools/doc/rpc-gen",
"ckb-bin"
"util",
"util/occupied-capacity/core",
"util/channel",
"util/systemtime",
"util/fixed-hash/core",
"util/build-info",
"util/logger",
"util/logger-config",
"util/metrics-config",
"util/hash",
"util/rational",
"benches",
"db-schema",
"util/spawn",
"util/occupied-capacity/macros",
"util/fixed-hash/macros",
"util/logger-service",
"util/runtime",
"util/stop-handler",
"util/metrics",
"util/metrics-service",
"util/fixed-hash",
"util/occupied-capacity",
"util/crypto",
"util/constant",
"error",
"util/multisig",
"util/gen-types",
"util/migrate/migration-template",
"util/types",
"util/jsonrpc-types",
"freezer",
"resource",
"pow",
"util/dao/utils",
"traits",
"spec",
"util/proposal-table",
"script",
"util/app-config",
"db",
"network",
"miner",
"notify",
"util/memory-tracker",
"db-migration",
"util/network-alert",
"store",
"util/indexer-sync",
"util/indexer",
"util/rich-indexer",
"util/chain-iter",
"util/dao",
"util/test-chain-utils",
"util/reward-calculator",
"util/snapshot",
"util/migrate",
"verification/traits",
"verification",
"verification/contextual",
"tx-pool",
"shared",
"block-filter",
"chain",
"sync",
"util/instrument",
"rpc",
"util/light-client-protocol-server",
"util/launcher",
"devtools/doc/rpc-gen",
"ckb-bin",
]

[workspace.dependencies]
Expand All @@ -115,7 +115,9 @@ lto = true
codegen-units = 1

[target.'cfg(all(not(target_env = "msvc"), not(target_os="macos")))'.dependencies]
tikv-jemallocator = { version = "0.5.0", features = ["unprefixed_malloc_on_supported_platforms"] }
tikv-jemallocator = { version = "0.5.0", features = [
"unprefixed_malloc_on_supported_platforms",
] }

[features]
default = []
Expand Down
2 changes: 1 addition & 1 deletion benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ckb-types = { path = "../util/types", version = "= 0.117.0-rc3" }
ckb-shared = { path = "../shared", version = "= 0.117.0-rc3" }
ckb-store = { path = "../store", version = "= 0.117.0-rc3" }
ckb-chain-spec = { path = "../spec", version = "= 0.117.0-rc3" }
rand = "0.7"
rand = "0.8"
ckb-hash = {path = "../util/hash", version = "= 0.117.0-rc3"}
ckb-test-chain-utils = { path = "../util/test-chain-utils", version = "= 0.117.0-rc3" }
ckb-dao-utils = { path = "../util/dao/utils", version = "= 0.117.0-rc3" }
Expand Down
6 changes: 3 additions & 3 deletions miner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ ckb-types = { path = "../util/types", version = "= 0.117.0-rc3" }
ckb-channel = { path = "../util/channel", version = "= 0.117.0-rc3" }
ckb-hash = { path = "../util/hash", version = "= 0.117.0-rc3" }
ckb-pow = { path = "../pow", version = "= 0.117.0-rc3" }
rand = "0.7"
rand_distr = "0.3"
rand = "0.8"
rand_distr = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
ckb-jsonrpc-types = { path = "../util/jsonrpc-types", version = "= 0.117.0-rc3" }
Expand All @@ -31,4 +31,4 @@ console = ">=0.9.1, <1.0.0"
eaglesong = "0.1"
base64 = "0.21.0"
jsonrpc-core = "18.0"
tokio = { version = "1", features = ["sync"] }
tokio = { version = "1", features = ["sync"] }
2 changes: 1 addition & 1 deletion miner/src/worker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn partition_nonce(id: u128, total: u128) -> Range<u128> {
fn nonce_generator(range: Range<u128>) -> impl FnMut() -> u128 {
let mut rng = rand::thread_rng();
let Range { start, end } = range;
move || rng.gen_range(start, end)
move || rng.gen_range(start..end)
}

const PROGRESS_BAR_TEMPLATE: &str = "{prefix:.bold.dim} {spinner:.green} [{elapsed_precise}] {msg}";
Expand Down
12 changes: 8 additions & 4 deletions network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ homepage = "https://github.com/nervosnetwork/ckb"
repository = "https://github.com/nervosnetwork/ckb"

[dependencies]
rand = "0.7"
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
ckb-util = { path = "../util", version = "= 0.117.0-rc3" }
ckb-stop-handler = { path = "../util/stop-handler", version = "= 0.117.0-rc3" }
Expand All @@ -25,18 +25,22 @@ bs58 = { version = "0.4.0", optional = true }
sentry = { version = "0.26.0", optional = true }
faster-hex = { version = "0.6", optional = true }
ckb-hash = {path = "../util/hash", version = "= 0.117.0-rc3"}
secp256k1 = {version = "0.24", features = ["recovery"], optional = true }
secp256k1 = { version = "0.29", features = ["recovery"], optional = true }
trust-dns-resolver = { version = "0.20", optional = true }
snap = "1"
ckb-types = { path = "../util/types", version = "= 0.117.0-rc3" }
ipnetwork = "0.18"
serde_json = "1.0"
bloom-filters = "0.1"
ckb-spawn = { path = "../util/spawn", version = "= 0.117.0-rc3" }
socket2 = "0.4"
socket2 = "0.5"
bitflags = "1.0"

p2p = { version="0.4.0", package="tentacle", features = ["upnp", "parking_lot", "openssl-vendored"] }
p2p = { version = "0.6.1", package = "tentacle", features = [
"upnp",
"parking_lot",
"openssl-vendored",
] }

[features]
with_sentry = ["sentry"]
Expand Down
6 changes: 3 additions & 3 deletions network/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use p2p::{
context::{ServiceContext, SessionContext},
error::{DialerErrorKind, HandshakeErrorKind, ProtocolHandleErrorKind, SendErrorKind},
multiaddr::{Multiaddr, Protocol},
secio::{self, error::SecioError, PeerId},
secio::{self, error::SecioError, PeerId, SecioKeyPair},
service::{
ProtocolHandle, Service, ServiceAsyncControl, ServiceError, ServiceEvent, TargetProtocol,
TargetSession,
Expand Down Expand Up @@ -762,7 +762,7 @@ impl ServiceHandle for EventHandler {

/// Ckb network service, use to start p2p network
pub struct NetworkService {
p2p_service: Service<EventHandler>,
p2p_service: Service<EventHandler, SecioKeyPair>,
network_state: Arc<NetworkState>,
ping_controller: Option<Sender<()>>,
// Background services
Expand Down Expand Up @@ -890,7 +890,7 @@ impl NetworkService {
network_state: Arc::clone(&network_state),
};
service_builder = service_builder
.key_pair(network_state.local_private_key.clone())
.handshake_type(network_state.local_private_key.clone().into())
.upnp(config.upnp)
.yamux_config(yamux_config)
.forever(true)
Expand Down
2 changes: 1 addition & 1 deletion network/src/peer_store/addr_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl AddrManager {
for i in 0..self.random_ids.len() {
// reuse the for loop to shuffle random ids
// https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
let j = rng.gen_range(i, self.random_ids.len());
let j = rng.gen_range(i..self.random_ids.len());
self.swap_random_id(j, i);
let addr_info: AddrInfo = self.id_to_info[&self.random_ids[i]].to_owned();
if let Some(socket_addr) = multiaddr_to_socketaddr(&addr_info.addr) {
Expand Down
2 changes: 1 addition & 1 deletion network/src/protocols/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ fn net_service_start(
.insert_protocol(feeler_meta);

let mut p2p_service = service_builder
.key_pair(network_state.local_private_key().clone())
.handshake_type(network_state.local_private_key().clone().into())
.upnp(config.upnp)
.forever(true)
.build(EventHandler {
Expand Down
2 changes: 1 addition & 1 deletion network/src/services/dns_seeding/seed_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl SeedRecord {

let data = Self::data_to_sign(ip, port, peer_id.as_ref(), valid_until);
let hash = blake2b_256(data);
let message = Message::from_slice(&hash).expect("create message error");
let message = Message::from_digest_slice(&hash).expect("create message error");

if let Ok(pubkey) = SECP256K1.recover_ecdsa(&message, &signature) {
Ok(SeedRecord {
Expand Down
2 changes: 1 addition & 1 deletion network/src/services/dns_seeding/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl SeedRecord {

let data = Self::data_to_sign(self.ip, self.port, self.peer_id.as_ref(), self.valid_until);
let hash = blake2b_256(&data);
let message = Message::from_slice(&hash).expect("create message error");
let message = Message::from_digest_slice(&hash).expect("create message error");

let signature = SECP256K1.sign_ecdsa_recoverable(&message, privkey);
let (recid, signed_data) = signature.serialize_compact();
Expand Down
5 changes: 1 addition & 4 deletions shared/src/shared_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,7 @@ fn register_tx_pool_callback(tx_pool_builder: &mut TxPoolServiceBuilder, notify:
move |tx_pool: &mut TxPool, entry: &TxEntry, reject: Reject| {
let tx_hash = entry.transaction().hash();
// record recent reject
if matches!(
reject,
Reject::Resolve(..) | Reject::RBFRejected(..) | Reject::Invalidated(..)
) {
if reject.should_recorded() {
if let Some(ref mut recent_reject) = tx_pool.recent_reject {
if let Err(e) = recent_reject.put(&tx_hash, reject.clone()) {
error!("record recent_reject failed {} {} {}", tx_hash, reject, e);
Expand Down
2 changes: 1 addition & 1 deletion sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ itertools.workspace = true

[dev-dependencies]
ckb-test-chain-utils = { path = "../util/test-chain-utils", version = "= 0.117.0-rc3" }
rand = "0.7"
rand = "0.8"
ckb-dao = { path = "../util/dao", version = "= 0.117.0-rc3" }
ckb-dao-utils = { path = "../util/dao/utils", version = "= 0.117.0-rc3" }
ckb-reward-calculator = { path = "../util/reward-calculator", version = "= 0.117.0-rc3" }
Expand Down
11 changes: 11 additions & 0 deletions sync/src/relayer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,17 @@ impl Relayer {
TxVerificationResult::Reject { tx_hash } => {
self.shared.state().remove_from_known_txs(&tx_hash);
}
TxVerificationResult::UnknownParents { peer, parents } => {
let tx_hashes: Vec<_> = {
let mut tx_filter = self.shared.state().tx_filter();
tx_filter.remove_expired();
parents
.into_iter()
.filter(|tx_hash| !tx_filter.contains(tx_hash))
.collect()
};
self.shared.state().add_ask_for_txs(peer, tx_hashes);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion sync/src/tests/net_time_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn net_service_start() -> Node {
);

let mut p2p_service = service_builder
.key_pair(network_state.local_private_key().clone())
.handshake_type(network_state.local_private_key().clone().into())
.upnp(config.upnp)
.forever(true)
.build(EventHandler::new(Arc::clone(&network_state)));
Expand Down
4 changes: 2 additions & 2 deletions sync/src/tests/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ fn test_get_ancestor_use_skip_list() {
header
};
for _ in 0..100 {
let from: u64 = rng.gen_range(0, SKIPLIST_LENGTH);
let to: u64 = rng.gen_range(0, from + 1);
let from: u64 = rng.gen_range(0..SKIPLIST_LENGTH);
let to: u64 = rng.gen_range(0..=from);
let view_from = &header_map[&hashes[&from]];
let view_to = &header_map[&hashes[&to]];
let view_0 = &header_map[&hashes[&0]];
Expand Down
9 changes: 7 additions & 2 deletions test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ckb-error = { path = "../error", version = "= 0.117.0-rc3" }
ckb-constant = { path = "../util/constant", version = "= 0.117.0-rc3" }
tempfile = "3"
reqwest = { version = "=0.11.20", features = ["blocking", "json"] }
rand = "0.7"
rand = "0.8"
ckb-systemtime = { path = "../util/systemtime", version = "= 0.117.0-rc3" }
serde_json = "1.0"
lazy_static = "1.4.0"
Expand All @@ -44,7 +44,12 @@ log = "0.4"
nix = { version = "0.24.0", default-features = false, features = ["signal"] }

[target.'cfg(target_os="windows")'.dependencies]
windows-sys = { version = "0.52", features = ["Win32_Foundation", "Win32_System_Threading", "Win32_Security", "Win32_System_Console"] }
windows-sys = { version = "0.52", features = [
"Win32_Foundation",
"Win32_System_Threading",
"Win32_Security",
"Win32_System_Console",
] }

# Prevent this from interfering with workspaces
[workspace]
Expand Down
1 change: 1 addition & 0 deletions test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ fn all_specs() -> Vec<Box<dyn Spec>> {
Box::new(TxPoolOrphanNormal),
Box::new(TxPoolOrphanReverse),
Box::new(TxPoolOrphanUnordered),
Box::new(TxPoolOrphanPartialInputUnknown),
Box::new(TxPoolOrphanDoubleSpend),
Box::new(OrphanTxRejected),
Box::new(GetRawTxPool),
Expand Down
Loading
Loading