Skip to content

Commit

Permalink
Merge branch 'develop' into zhangsoledad/tweak_max_ancestors_count
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangsoledad authored Jun 20, 2024
2 parents 6619344 + 60b1654 commit 10794e2
Show file tree
Hide file tree
Showing 36 changed files with 417 additions and 259 deletions.
148 changes: 79 additions & 69 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
4 changes: 2 additions & 2 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ ckb-types = { path = "../util/types", version = "= 0.117.0-pre" }
ckb-shared = { path = "../shared", version = "= 0.117.0-pre" }
ckb-store = { path = "../store", version = "= 0.117.0-pre" }
ckb-chain-spec = { path = "../spec", version = "= 0.117.0-pre" }
rand = "0.7"
ckb-hash = {path = "../util/hash", version = "= 0.117.0-pre"}
rand = "0.8"
ckb-hash = { path = "../util/hash", version = "= 0.117.0-pre" }
ckb-test-chain-utils = { path = "../util/test-chain-utils", version = "= 0.117.0-pre" }
ckb-dao-utils = { path = "../util/dao/utils", version = "= 0.117.0-pre" }
ckb-dao = { path = "../util/dao", version = "= 0.117.0-pre" }
Expand Down
8 changes: 4 additions & 4 deletions miner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ ckb-types = { path = "../util/types", version = "= 0.117.0-pre" }
ckb-channel = { path = "../util/channel", version = "= 0.117.0-pre" }
ckb-hash = { path = "../util/hash", version = "= 0.117.0-pre" }
ckb-pow = { path = "../pow", version = "= 0.117.0-pre" }
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-pre" }
hyper = { version = "0.14", features = ["client", "http2", "http1", "server"] }
hyper = { version = "0.14", features = ["client", "http2", "http1", "server"] }
hyper-tls = "0.5"
futures = "0.3"
lru = "0.7.1"
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
32 changes: 22 additions & 10 deletions network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,51 @@ edition = "2021"
description = "ckb network implementation"
homepage = "https://github.com/nervosnetwork/ckb"
repository = "https://github.com/nervosnetwork/ckb"
exclude = [ "fuzz" ]
exclude = ["fuzz"]

[dependencies]
rand = "0.7"
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
ckb-util = { path = "../util", version = "= 0.117.0-pre" }
ckb-stop-handler = { path = "../util/stop-handler", version = "= 0.117.0-pre" }
ckb-logger = { path = "../util/logger", version = "= 0.117.0-pre" }
ckb-app-config = { path = "../util/app-config", version = "= 0.117.0-pre" }
ckb-metrics = {path = "../util/metrics", version = "= 0.117.0-pre"}
ckb-metrics = { path = "../util/metrics", version = "= 0.117.0-pre" }
tokio = { version = "1", features = ["sync", "macros"] }
tokio-util = { version = "0.7", features = ["codec"] }
futures = "0.3"
ckb-systemtime = {path = "../util/systemtime", version = "= 0.117.0-pre"}
ckb-systemtime = { path = "../util/systemtime", version = "= 0.117.0-pre" }
lazy_static = { version = "1.3.0", optional = true }
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-pre"}
secp256k1 = {version = "0.24", features = ["recovery"], optional = true }
ckb-hash = { path = "../util/hash", version = "= 0.117.0-pre" }
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-pre" }
ipnetwork = "0.18"
serde_json = "1.0"
bloom-filters = "0.1"
ckb-spawn = { path = "../util/spawn", version = "= 0.117.0-pre" }
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"]
with_dns_seeding = ["lazy_static", "bs58", "faster-hex", "trust-dns-resolver", "secp256k1"]
with_dns_seeding = [
"lazy_static",
"bs58",
"faster-hex",
"trust-dns-resolver",
"secp256k1",
]
fuzz = []

[dev-dependencies]
Expand All @@ -50,7 +60,9 @@ criterion = "0.5"
proptest = "1.0"
num_cpus = "1.10"
once_cell = "1.8.0"
ckb-systemtime = {path = "../util/systemtime", version = "= 0.117.0-pre", features = ["enable_faketime"]}
ckb-systemtime = { path = "../util/systemtime", version = "= 0.117.0-pre", features = [
"enable_faketime",
] }

[[bench]]
name = "peer_store"
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
10 changes: 7 additions & 3 deletions sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ itertools.workspace = true

[dev-dependencies]
ckb-test-chain-utils = { path = "../util/test-chain-utils", version = "= 0.117.0-pre" }
rand = "0.7"
rand = "0.8"
ckb-dao = { path = "../util/dao", version = "= 0.117.0-pre" }
ckb-dao-utils = { path = "../util/dao/utils", version = "= 0.117.0-pre" }
ckb-reward-calculator = { path = "../util/reward-calculator", version = "= 0.117.0-pre" }
ckb-chain = { path = "../chain", version = "= 0.117.0-pre", features = ["mock"] }
ckb-chain = { path = "../chain", version = "= 0.117.0-pre", features = [
"mock",
] }
faux = "^0.1"
once_cell = "1.8.0"
ckb-systemtime = { path = "../util/systemtime", version = "= 0.117.0-pre", features = ["enable_faketime"] }
ckb-systemtime = { path = "../util/systemtime", version = "= 0.117.0-pre", features = [
"enable_faketime",
] }
ckb-proposal-table = { path = "../util/proposal-table", version = "= 0.117.0-pre" }

[features]
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
Loading

0 comments on commit 10794e2

Please sign in to comment.