From 17c55bb6bca175ef7c969abcdee9e2b053eff7f1 Mon Sep 17 00:00:00 2001 From: Michael Sutton Date: Wed, 28 Jun 2023 18:00:30 +0300 Subject: [PATCH] Testnet11 crucial bug fixes and patches (#215) * make sure all crates use workspace tokio * checked sub just in case (minor) * fix race condition deadlock with header processor commit_header * daa is not monotonic hence this can overflow * optimize is_nearly_synced * limit max db open files to 500 * add overflow-checks to release build * minor * fix yet another overflow * increase orphan_resolution_range * edit link to point at to latest release * rothschild: do not burst after a pause * reduce log verbosity for chain negotiation restart * improve header strings * bump version to 0.1.2 * one more potential overflow based on daa --------- Co-authored-by: Tiram <18632023+tiram88@users.noreply.github.com> --- Cargo.lock | 115 ++++++++++-------- Cargo.toml | 53 ++++---- consensus/core/src/errors/block.rs | 6 +- consensus/core/src/errors/consensus.rs | 9 +- consensus/src/consensus/mod.rs | 11 +- consensus/src/pipeline/deps_manager.rs | 2 +- consensus/src/pipeline/mod.rs | 14 +-- consensus/src/processes/sync/mod.rs | 14 +-- database/src/db.rs | 3 + docs/testnet11.md | 2 +- indexes/core/Cargo.toml | 1 - indexes/processor/Cargo.toml | 2 +- mining/src/mempool/model/orphan_pool.rs | 4 +- mining/src/mempool/model/transactions_pool.rs | 6 +- protocol/flows/Cargo.toml | 2 +- protocol/flows/src/flow_context.rs | 3 +- protocol/flows/src/v5/ibd/negotiate.rs | 7 +- protocol/p2p/Cargo.toml | 2 +- rothschild/src/main.rs | 2 +- rpc/grpc/client/Cargo.toml | 2 +- rpc/grpc/core/Cargo.toml | 2 +- rpc/grpc/server/Cargo.toml | 2 +- 22 files changed, 147 insertions(+), 117 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0636c1677d..6b244fd4dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -86,7 +86,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3203e79f4dd9bdda415ed03cf14dae5a2bf775c683a00f94e9cd1faf0f596e5" dependencies = [ "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -204,7 +204,7 @@ checksum = "e4655ae1a7b0cdf149156f780c5bf3f1352bc53cbd9e0a361a7ef7b22947e965" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -221,7 +221,7 @@ checksum = "b84f9ebcc6c1f5b8cb160f6990096a5c127f423fcb6e1ccc46c370cbdfb75dfc" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -330,7 +330,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn", + "syn 1.0.109", ] [[package]] @@ -409,7 +409,7 @@ dependencies = [ "borsh-schema-derive-internal", "proc-macro-crate", "proc-macro2", - "syn", + "syn 1.0.109", ] [[package]] @@ -420,7 +420,7 @@ checksum = "5449c28a7b352f2d1e592a8a28bf139bc71afb0764a14f3c02500935d8c44065" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -431,7 +431,7 @@ checksum = "cdbd5696d8bfa21d53d9fe39a714a18538bad11492a42d066dbbc395fb1951c0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -592,7 +592,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -815,7 +815,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" dependencies = [ "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -852,7 +852,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn", + "syn 1.0.109", ] [[package]] @@ -869,7 +869,7 @@ checksum = "0b75aed41bb2e6367cae39e6326ef817a851db13c13e4f3263714ca3cfb8de56" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -880,7 +880,7 @@ checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -893,7 +893,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn", + "syn 1.0.109", ] [[package]] @@ -975,7 +975,7 @@ dependencies = [ "base64 0.13.1", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -992,7 +992,7 @@ checksum = "c375b9c5eadb68d0a6efee2999fef292f45854c3444c86f09d8ab086ba942b0e" dependencies = [ "num-traits", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1139,7 +1139,7 @@ checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1470,7 +1470,7 @@ checksum = "4d56984da2d4c9d6d7de8463892e65a9354f4238f641c246fe99176150e97bb8" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "uuid 0.8.2", ] @@ -2088,7 +2088,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn", + "syn 1.0.109", ] [[package]] @@ -2533,7 +2533,7 @@ checksum = "73fd9dc7072de7168cbdaba9125e8f742cd3a965aa12bde994b4611a174488d8" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -2835,7 +2835,7 @@ checksum = "6cea6089666c59f944aaf46cab9d2ae1bff85e01c42c49a29e78ece5d39b5abd" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -2892,7 +2892,7 @@ checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -2940,7 +2940,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ebcd279d20a4a0a2404a33056388e950504d891c855c7975b9a8fef75f3bf04" dependencies = [ "proc-macro2", - "syn", + "syn 1.0.109", ] [[package]] @@ -2961,7 +2961,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "version_check", ] @@ -2978,9 +2978,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.51" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" dependencies = [ "unicode-ident", ] @@ -3012,7 +3012,7 @@ dependencies = [ "prost", "prost-types", "regex", - "syn", + "syn 1.0.109", "tempfile", "which", ] @@ -3027,7 +3027,7 @@ dependencies = [ "itertools 0.10.5", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3041,9 +3041,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.23" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" dependencies = [ "proc-macro2", ] @@ -3416,7 +3416,7 @@ checksum = "1ef476a5790f0f6decbc66726b6e5d63680ed518283e64c7df415989d880954f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3624,6 +3624,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2efbeae7acf4eabd6bcdcbd11c92f45231ddda7539edc7806bd1a04a03b24616" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "sync_wrapper" version = "0.1.2" @@ -3684,7 +3695,7 @@ checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3736,21 +3747,20 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.26.0" +version = "1.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64" +checksum = "94d7b1cfd2aa4011f2de74c2c4c63665e27a71006b0a192dcd2710272e73dfa2" dependencies = [ "autocfg", "bytes", "libc", - "memchr", "mio", "num_cpus", "pin-project-lite", "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -3765,13 +3775,13 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.8.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.22", ] [[package]] @@ -3872,7 +3882,7 @@ dependencies = [ "proc-macro2", "prost-build", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3927,7 +3937,7 @@ checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -4160,7 +4170,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-shared", ] @@ -4194,7 +4204,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4308,6 +4318,15 @@ dependencies = [ "windows-targets 0.42.1", ] +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.0", +] + [[package]] name = "windows-targets" version = "0.42.1" @@ -4430,7 +4449,7 @@ checksum = "7acbe1707662eb8888c69bbd8e38a9648168360cf71f26631a947099cc6fa4a2" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -4471,7 +4490,7 @@ dependencies = [ "proc-macro2", "quote", "sha2 0.10.6", - "syn", + "syn 1.0.109", "workflow-macro-tools", ] @@ -4518,7 +4537,7 @@ dependencies = [ "parse-variants", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -4572,7 +4591,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -4599,7 +4618,7 @@ dependencies = [ "proc-macro2", "quote", "sha2 0.10.6", - "syn", + "syn 1.0.109", "workflow-macro-tools", ] @@ -4652,7 +4671,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a364b7d952..c7a70cffb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ members = [ ] [workspace.package] -version = "0.1.1" +version = "0.1.2" authors = ["Kaspa developers"] license = "MIT/Apache-2.0" edition = "2021" @@ -65,33 +65,33 @@ kaspa-p2p-flows = { path = "protocol/flows" } kaspa-p2p-lib = { path = "protocol/p2p" } kaspa-testing-integration = { path = "testing/integration" } kaspa-utxoindex = { path = "indexes/utxoindex" } -kaspa-rpc-service = { version = "0.1.1", path = "rpc/service" } +kaspa-rpc-service = { version = "0.1.2", path = "rpc/service" } # published -kaspa-addresses = { version = "0.1.1", path = "crypto/addresses" } -kaspa-bip32 = { version = "0.1.1", path = "wallet/bip32" } -kaspa-consensus = { version = "0.1.1", path = "consensus" } -kaspa-consensus-core = { version = "0.1.1", path = "consensus/core" } -kaspa-consensus-notify = { version = "0.1.1", path = "consensus/notify" } -kaspa-core = { version = "0.1.1", path = "core" } -kaspa-database = { version = "0.1.1", path = "database" } -kaspa-grpc-client = { version = "0.1.1", path = "rpc/grpc/client" } -kaspa-grpc-core = { version = "0.1.1", path = "rpc/grpc/core" } -kaspa-hashes = { version = "0.1.1", path = "crypto/hashes" } -kaspa-math = { version = "0.1.1", path = "math" } -kaspa-merkle = { version = "0.1.1", path = "crypto/merkle" } -kaspa-muhash = { version = "0.1.1", path = "crypto/muhash" } -kaspa-notify = { version = "0.1.1", path = "notify" } -kaspa-pow = { version = "0.1.1", path = "consensus/pow" } -kaspa-rpc-core = { version = "0.1.1", path = "rpc/core" } -kaspa-rpc-macros = { version = "0.1.1", path = "rpc/macros" } -kaspa-txscript = { version = "0.1.1", path = "crypto/txscript" } -kaspa-txscript-errors = { version = "0.1.1", path = "crypto/txscript/errors" } -kaspa-utils = { version = "0.1.1", path = "utils" } -kaspa-wallet-core = { version = "0.1.1", path = "wallet/core" } -kaspa-wasm = { version = "0.1.1", path = "wasm" } -kaspa-wrpc-client = { version = "0.1.1", path = "rpc/wrpc/client" } -kaspa-wrpc-wasm = { version = "0.1.1", path = "rpc/wrpc/wasm" } +kaspa-addresses = { version = "0.1.2", path = "crypto/addresses" } +kaspa-bip32 = { version = "0.1.2", path = "wallet/bip32" } +kaspa-consensus = { version = "0.1.2", path = "consensus" } +kaspa-consensus-core = { version = "0.1.2", path = "consensus/core" } +kaspa-consensus-notify = { version = "0.1.2", path = "consensus/notify" } +kaspa-core = { version = "0.1.2", path = "core" } +kaspa-database = { version = "0.1.2", path = "database" } +kaspa-grpc-client = { version = "0.1.2", path = "rpc/grpc/client" } +kaspa-grpc-core = { version = "0.1.2", path = "rpc/grpc/core" } +kaspa-hashes = { version = "0.1.2", path = "crypto/hashes" } +kaspa-math = { version = "0.1.2", path = "math" } +kaspa-merkle = { version = "0.1.2", path = "crypto/merkle" } +kaspa-muhash = { version = "0.1.2", path = "crypto/muhash" } +kaspa-notify = { version = "0.1.2", path = "notify" } +kaspa-pow = { version = "0.1.2", path = "consensus/pow" } +kaspa-rpc-core = { version = "0.1.2", path = "rpc/core" } +kaspa-rpc-macros = { version = "0.1.2", path = "rpc/macros" } +kaspa-txscript = { version = "0.1.2", path = "crypto/txscript" } +kaspa-txscript-errors = { version = "0.1.2", path = "crypto/txscript/errors" } +kaspa-utils = { version = "0.1.2", path = "utils" } +kaspa-wallet-core = { version = "0.1.2", path = "wallet/core" } +kaspa-wasm = { version = "0.1.2", path = "wasm" } +kaspa-wrpc-client = { version = "0.1.2", path = "rpc/wrpc/client" } +kaspa-wrpc-wasm = { version = "0.1.2", path = "rpc/wrpc/wasm" } # not published kaspa-grpc-server = { path = "rpc/grpc/server" } @@ -177,3 +177,4 @@ workflow-terminal = { version = "0.3.10" } [profile.release] lto = "thin" strip = true +overflow-checks = true diff --git a/consensus/core/src/errors/block.rs b/consensus/core/src/errors/block.rs index f3236a4d42..e78d0f0f88 100644 --- a/consensus/core/src/errors/block.rs +++ b/consensus/core/src/errors/block.rs @@ -115,16 +115,16 @@ pub enum RuleError { #[error("wrong coinbase subsidy: expected {0} but got {1}")] WrongSubsidy(u64, u64), - #[error("Transaction {0} is found more than once in the block")] + #[error("transaction {0} is found more than once in the block")] DuplicateTransactions(TransactionId), #[error("block has invalid proof-of-work")] InvalidPoW, - #[error("Expected header pruning point is {0} but got {1}")] + #[error("expected header pruning point is {0} but got {1}")] WrongHeaderPruningPoint(Hash, Hash), - #[error("Expected indirect parents {0} but got {1}")] + #[error("expected indirect parents {0} but got {1}")] UnexpectedIndirectParents(TwoDimVecDisplay, TwoDimVecDisplay), #[error("block {0} UTXO commitment is invalid - block header indicates {1}, but calculated value is {2}")] diff --git a/consensus/core/src/errors/consensus.rs b/consensus/core/src/errors/consensus.rs index c7544969a5..51d8b3f4d0 100644 --- a/consensus/core/src/errors/consensus.rs +++ b/consensus/core/src/errors/consensus.rs @@ -5,9 +5,12 @@ use super::{difficulty::DifficultyError, sync::SyncManagerError, traversal::Trav #[derive(Error, Debug, Clone)] pub enum ConsensusError { - #[error("couldn't find block {0}")] + #[error("cannot find full block {0}")] BlockNotFound(Hash), + #[error("cannot find header {0}")] + HeaderNotFound(Hash), + #[error("block {0} is invalid")] InvalidBlock(Hash), @@ -20,10 +23,10 @@ pub enum ConsensusError { #[error("pruning point is not at sufficient depth from virtual, cannot obtain its final anticone at this stage")] PruningPointInsufficientDepth, - #[error("sync manager error")] + #[error("sync manager error: {0}")] SyncManagerError(#[from] SyncManagerError), - #[error("traversal error")] + #[error("traversal error: {0}")] TraversalError(#[from] TraversalError), #[error("difficulty error: {0}")] diff --git a/consensus/src/consensus/mod.rs b/consensus/src/consensus/mod.rs index 1696cca78c..0e42ce9737 100644 --- a/consensus/src/consensus/mod.rs +++ b/consensus/src/consensus/mod.rs @@ -321,6 +321,7 @@ impl Consensus { } } + /// Validates that a valid block *header* exists for `hash` fn validate_block_exists(&self, hash: Hash) -> Result<(), ConsensusError> { if match self.statuses_store.read().get(hash).unwrap_option() { Some(status) => status.is_valid(), @@ -328,7 +329,7 @@ impl Consensus { } { Ok(()) } else { - Err(ConsensusError::BlockNotFound(hash)) + Err(ConsensusError::HeaderNotFound(hash)) } } @@ -419,7 +420,9 @@ impl ConsensusApi for Consensus { fn is_nearly_synced(&self) -> bool { // See comment within `config.is_nearly_synced` - self.config.is_nearly_synced(self.get_sink_timestamp(), self.headers_store.get_daa_score(self.get_sink()).unwrap()) + let sink = self.get_sink(); + let compact = self.headers_store.get_compact_header_data(sink).unwrap(); + self.config.is_nearly_synced(compact.timestamp, compact.daa_score) } fn get_virtual_chain_from_block(&self, hash: Hash) -> ConsensusResult { @@ -595,7 +598,7 @@ impl ConsensusApi for Consensus { fn get_block_even_if_header_only(&self, hash: Hash) -> ConsensusResult { let Some(status) = self.statuses_store.read().get(hash).unwrap_option().filter(|&status| status.has_block_header()) else { - return Err(ConsensusError::BlockNotFound(hash)); + return Err(ConsensusError::HeaderNotFound(hash)); }; Ok(Block { header: self.headers_store.get_header(hash).unwrap(), @@ -605,7 +608,7 @@ impl ConsensusApi for Consensus { fn get_ghostdag_data(&self, hash: Hash) -> ConsensusResult { match self.get_block_status(hash) { - None => return Err(ConsensusError::BlockNotFound(hash)), + None => return Err(ConsensusError::HeaderNotFound(hash)), Some(BlockStatus::StatusInvalid) => return Err(ConsensusError::InvalidBlock(hash)), _ => {} }; diff --git a/consensus/src/pipeline/deps_manager.rs b/consensus/src/pipeline/deps_manager.rs index 989066d2ba..0a4333eb1a 100644 --- a/consensus/src/pipeline/deps_manager.rs +++ b/consensus/src/pipeline/deps_manager.rs @@ -164,7 +164,7 @@ impl BlockTaskDependencyManager { Self { pending: Mutex::new(HashMap::new()), idle_signal: Condvar::new() } } - /// Registers the `(task, result_transmitters)` pair as a pending task. If a task with the same + /// Registers the `(task, result_transmitter)` pair as a pending task. If a task with the same /// hash is already pending and has a corresponding internal task group, the task group is updated /// with the additional task and the function returns `None` indicating that the task shall /// not be queued for processing yet. The function is expected to be called by a single worker diff --git a/consensus/src/pipeline/mod.rs b/consensus/src/pipeline/mod.rs index 0e49f0d327..2c17551ffe 100644 --- a/consensus/src/pipeline/mod.rs +++ b/consensus/src/pipeline/mod.rs @@ -48,13 +48,13 @@ impl core::ops::Sub for &ProcessingCountersSnapshot { fn sub(self, rhs: Self) -> Self::Output { Self::Output { - blocks_submitted: self.blocks_submitted - rhs.blocks_submitted, - header_counts: self.header_counts - rhs.header_counts, - dep_counts: self.dep_counts - rhs.dep_counts, - body_counts: self.body_counts - rhs.body_counts, - txs_counts: self.txs_counts - rhs.txs_counts, - chain_block_counts: self.chain_block_counts - rhs.chain_block_counts, - mass_counts: self.mass_counts - rhs.mass_counts, + blocks_submitted: self.blocks_submitted.checked_sub(rhs.blocks_submitted).unwrap_or_default(), + header_counts: self.header_counts.checked_sub(rhs.header_counts).unwrap_or_default(), + dep_counts: self.dep_counts.checked_sub(rhs.dep_counts).unwrap_or_default(), + body_counts: self.body_counts.checked_sub(rhs.body_counts).unwrap_or_default(), + txs_counts: self.txs_counts.checked_sub(rhs.txs_counts).unwrap_or_default(), + chain_block_counts: self.chain_block_counts.checked_sub(rhs.chain_block_counts).unwrap_or_default(), + mass_counts: self.mass_counts.checked_sub(rhs.mass_counts).unwrap_or_default(), } } } diff --git a/consensus/src/processes/sync/mod.rs b/consensus/src/processes/sync/mod.rs index 9a5c3509f3..8ce2dace04 100644 --- a/consensus/src/processes/sync/mod.rs +++ b/consensus/src/processes/sync/mod.rs @@ -119,23 +119,21 @@ impl< } pub fn create_headers_selected_chain_block_locator(&self, low: Option, high: Option) -> SyncManagerResult> { - let sc_read_guard = self.selected_chain_store.read(); - let hst_read_guard = self.header_selected_tip_store.read(); - let pp_read_guard = self.pruning_point_store.read(); + let low = low.unwrap_or_else(|| self.pruning_point_store.read().get().unwrap().pruning_point); + let high = high.unwrap_or_else(|| self.header_selected_tip_store.read().get().unwrap().hash); - let low = low.unwrap_or_else(|| pp_read_guard.get().unwrap().pruning_point); - let high = high.unwrap_or_else(|| hst_read_guard.get().unwrap().hash); + let sc_read = self.selected_chain_store.read(); if low == high { return Ok(vec![low]); } - let low_index = match sc_read_guard.get_by_hash(low).unwrap_option() { + let low_index = match sc_read.get_by_hash(low).unwrap_option() { Some(index) => index, None => return Err(SyncManagerError::BlockNotInSelectedParentChain(low)), }; - let high_index = match sc_read_guard.get_by_hash(high).unwrap_option() { + let high_index = match sc_read.get_by_hash(high).unwrap_option() { Some(index) => index, None => return Err(SyncManagerError::BlockNotInSelectedParentChain(high)), }; @@ -148,7 +146,7 @@ impl< let mut step = 1; let mut current_index = high_index; while current_index > low_index { - locator.push(sc_read_guard.get_by_index(current_index).unwrap()); + locator.push(sc_read.get_by_index(current_index).unwrap()); if current_index < step { break; } diff --git a/database/src/db.rs b/database/src/db.rs index fa31043d1f..2b72b7e326 100644 --- a/database/src/db.rs +++ b/database/src/db.rs @@ -10,6 +10,9 @@ pub fn open_db(db_path: PathBuf, create_if_missing: bool, parallelism: usize) -> if parallelism > 1 { opts.increase_parallelism(parallelism as i32); } + // In most linux environments the limit is set to 1024, so we use 500 to give sufficient slack. + // TODO: fine-tune this parameter and additional parameters related to max file size + opts.set_max_open_files(500); opts.create_if_missing(create_if_missing); let db = Arc::new(DB::open(&opts, db_path.to_str().unwrap()).unwrap()); db diff --git a/docs/testnet11.md b/docs/testnet11.md index 9d86991bc1..db9e55fbac 100644 --- a/docs/testnet11.md +++ b/docs/testnet11.md @@ -36,7 +36,7 @@ Testnet11 uses a dedicated P2P port (16311) so that nodes from the usual tesnet We reiterate that only the included miner should be used to maintain a level playing field. First, we set-up a node: -1. Download and extract the [rusty-kaspa binaries](https://github.com/kaspanet/rusty-kaspa/releases/tag/v0.1.1). Alternatively, you can compile it from source yourself by following the instructions [here](https://github.com/kaspanet/rusty-kaspa/blob/master/README.md). The rest of the instructions are written assuming the former option. If you choose to locally compile the code, replace any command of the form `` `` with ``cargo run --bin --release -- `` (see example in the next item). All actions described below should be performed on a command line window where you navigated to the directory into which the binaries were extracted. +1. Download and extract the [rusty-kaspa binaries](https://github.com/kaspanet/rusty-kaspa/releases). Alternatively, you can compile it from source yourself by following the instructions [here](https://github.com/kaspanet/rusty-kaspa/blob/master/README.md). The rest of the instructions are written assuming the former option. If you choose to locally compile the code, replace any command of the form `` `` with ``cargo run --bin --release -- `` (see example in the next item). All actions described below should be performed on a command line window where you navigated to the directory into which the binaries were extracted. 2. Start the ``kaspad`` client with ``utxoindex`` enabled: ``` diff --git a/indexes/core/Cargo.toml b/indexes/core/Cargo.toml index 036b191ebe..8a41fc712d 100644 --- a/indexes/core/Cargo.toml +++ b/indexes/core/Cargo.toml @@ -20,7 +20,6 @@ futures = "0.3.25" triggered = "0.1" derive_more.workspace = true paste = "1.0.11" -# tokio = { version = "1.21.2", features = [ "rt-multi-thread", "macros", "signal" ]} [dev-dependencies] # parking_lot.workspace = true diff --git a/indexes/processor/Cargo.toml b/indexes/processor/Cargo.toml index de8c233f98..7a9e3eb96a 100644 --- a/indexes/processor/Cargo.toml +++ b/indexes/processor/Cargo.toml @@ -26,7 +26,7 @@ futures = "0.3.25" triggered = "0.1" derive_more.workspace = true paste = "1.0.11" -tokio = { version = "1.21.2", features = [ "rt-multi-thread", "macros", "signal" ]} +tokio = { workspace = true, features = [ "rt-multi-thread", "macros", "signal" ]} [dev-dependencies] kaspa-consensus.workspace = true diff --git a/mining/src/mempool/model/orphan_pool.rs b/mining/src/mempool/model/orphan_pool.rs index 11b2067ec5..327f831064 100644 --- a/mining/src/mempool/model/orphan_pool.rs +++ b/mining/src/mempool/model/orphan_pool.rs @@ -216,7 +216,7 @@ impl OrphanPool { pub(crate) fn expire_low_priority_transactions(&mut self, consensus: &dyn ConsensusApi) -> RuleResult<()> { let virtual_daa_score = consensus.get_virtual_daa_score(); - if virtual_daa_score - self.last_expire_scan < self.config.orphan_expire_scan_interval_daa_score { + if virtual_daa_score < self.last_expire_scan + self.config.orphan_expire_scan_interval_daa_score { return Ok(()); } @@ -227,7 +227,7 @@ impl OrphanPool { .values() .filter_map(|x| { if (x.priority == Priority::Low) - && virtual_daa_score - x.added_at_daa_score > self.config.orphan_expire_interval_daa_score + && virtual_daa_score > x.added_at_daa_score + self.config.orphan_expire_interval_daa_score { Some(x.id()) } else { diff --git a/mining/src/mempool/model/transactions_pool.rs b/mining/src/mempool/model/transactions_pool.rs index db7c4440c2..98de0b2d6b 100644 --- a/mining/src/mempool/model/transactions_pool.rs +++ b/mining/src/mempool/model/transactions_pool.rs @@ -167,10 +167,10 @@ impl TransactionsPool { && virtual_daa_score > x.added_at_daa_score + self.config.transaction_expire_interval_daa_score { debug!( - "Removing transaction {}, because it expired, DAAScore moved by {}, expire interval: {}", + "Removing transaction {}, because it expired, virtual DAA score is {} and expire limit is {}", x.id(), - virtual_daa_score - x.added_at_daa_score, - self.config.transaction_expire_interval_daa_score + virtual_daa_score, + x.added_at_daa_score + self.config.transaction_expire_interval_daa_score ); Some(x.id()) } else { diff --git a/protocol/flows/Cargo.toml b/protocol/flows/Cargo.toml index 2d328677ee..e26af60622 100644 --- a/protocol/flows/Cargo.toml +++ b/protocol/flows/Cargo.toml @@ -31,7 +31,7 @@ indexmap.workspace = true async-trait.workspace = true futures = { version = "0.3", default-features = false, features = ["alloc"] } -tokio = { version = "1.21.2", features = [ +tokio = { workspace = true, features = [ "rt-multi-thread", "macros", "signal", diff --git a/protocol/flows/src/flow_context.rs b/protocol/flows/src/flow_context.rs index 871f0a022f..5e41d2238c 100644 --- a/protocol/flows/src/flow_context.rs +++ b/protocol/flows/src/flow_context.rs @@ -183,8 +183,7 @@ impl FlowContext { ) -> Self { let hub = Hub::new(); - // TODO: initial experiments show that this value is good for high bps as well so for now we avoid the log - let orphan_resolution_range = BASELINE_ORPHAN_RESOLUTION_RANGE; // + f64::log2(config.bps() as f64).round() as u32 + let orphan_resolution_range = BASELINE_ORPHAN_RESOLUTION_RANGE + (config.bps() as f64).log(3.0).min(2.0) as u32; // The maximum amount of orphans allowed in the orphans pool. This number is an // approximation of how many orphans there can possibly be on average. diff --git a/protocol/flows/src/v5/ibd/negotiate.rs b/protocol/flows/src/v5/ibd/negotiate.rs index e0ca69d3c4..c02c45f9e6 100644 --- a/protocol/flows/src/v5/ibd/negotiate.rs +++ b/protocol/flows/src/v5/ibd/negotiate.rs @@ -128,7 +128,12 @@ impl IbdFlow { self.router, negotiation_restart_counter ))); } - warn!("IBD chain negotiation with syncer {} restarted {} times", self.router, negotiation_restart_counter); + if negotiation_restart_counter > self.ctx.config.bps() { + // bps is just an intuitive threshold here + warn!("IBD chain negotiation with syncer {} restarted {} times", self.router, negotiation_restart_counter); + } else { + debug!("IBD chain negotiation with syncer {} restarted {} times", self.router, negotiation_restart_counter); + } // An empty locator signals that the syncer chain was modified and no longer contains one of // the queried hashes, so we restart the search. We use a shorter timeout here to avoid a timeout attack diff --git a/protocol/p2p/Cargo.toml b/protocol/p2p/Cargo.toml index 2eb3e91dea..19bbe091b5 100644 --- a/protocol/p2p/Cargo.toml +++ b/protocol/p2p/Cargo.toml @@ -36,7 +36,7 @@ borsh.workspace = true futures = { version = "0.3", default-features = false, features = ["alloc"] } prost = "0.11" ctrlc = "3.2" -tokio = { version = "1.21.2", features = [ +tokio = { workspace = true, features = [ "rt-multi-thread", "macros", "signal", diff --git a/rothschild/src/main.rs b/rothschild/src/main.rs index 21a376d2a8..9f863b4c64 100644 --- a/rothschild/src/main.rs +++ b/rothschild/src/main.rs @@ -129,7 +129,7 @@ async fn main() { let mut utxos = refresh_utxos(&rpc_client, kaspa_addr.clone(), &mut pending, coinbase_maturity).await; let mut ticker = interval(Duration::from_secs_f64(1.0 / (args.tps.min(100) as f64))); - ticker.set_missed_tick_behavior(MissedTickBehavior::Burst); + ticker.set_missed_tick_behavior(MissedTickBehavior::Delay); let mut maximize_inputs = false; let mut last_refresh = unix_now(); diff --git a/rpc/grpc/client/Cargo.toml b/rpc/grpc/client/Cargo.toml index 07c37567e2..a8e0aeb343 100644 --- a/rpc/grpc/client/Cargo.toml +++ b/rpc/grpc/client/Cargo.toml @@ -23,7 +23,7 @@ futures = { version = "0.3" } tonic = { version = "0.9", features = ["gzip"] } prost = { version = "0.11" } h2 = "0.3" -tokio = { version = "1.0", features = ["rt-multi-thread", "macros", "sync", "time"] } +tokio = { workspace = true, features = ["rt-multi-thread", "macros", "sync", "time"] } tokio-stream = "0.1" async-stream = "0.3" triggered = "0.1" diff --git a/rpc/grpc/core/Cargo.toml b/rpc/grpc/core/Cargo.toml index 4dff306be9..5090cd3859 100644 --- a/rpc/grpc/core/Cargo.toml +++ b/rpc/grpc/core/Cargo.toml @@ -21,7 +21,7 @@ futures = { version = "0.3" } tonic = { version = "0.9.1", features = ["tls", "gzip"] } prost = { version = "0.11" } h2 = "0.3" -tokio = { version = "1.0", features = ["rt-multi-thread", "macros", "sync", "time"] } +tokio = { workspace = true, features = ["rt-multi-thread", "macros", "sync", "time"] } tokio-stream = "0.1" async-stream = "0.3" triggered = "0.1" diff --git a/rpc/grpc/server/Cargo.toml b/rpc/grpc/server/Cargo.toml index 0695786a72..9fc74d0324 100644 --- a/rpc/grpc/server/Cargo.toml +++ b/rpc/grpc/server/Cargo.toml @@ -27,7 +27,7 @@ futures = { version = "0.3" } tonic = { version = "0.9", features = ["gzip"] } prost = { version = "0.11" } h2 = "0.3" -tokio = { version = "1.0", features = ["rt-multi-thread", "macros", "sync", "time"] } +tokio = { workspace = true, features = ["rt-multi-thread", "macros", "sync", "time"] } tokio-stream = "0.1" async-stream = "0.3" triggered = "0.1"