From f866dfad16eb54d67d36a127435d81fa00b39680 Mon Sep 17 00:00:00 2001 From: Michael Sutton Date: Thu, 5 Sep 2024 14:04:16 +0300 Subject: [PATCH 1/8] Various miscellaneous changes towards 0.15.1 RC2 (#543) * infrequent logs should be debug * cleanup some todos * when a network starts, genesis has a body, so there's no need for a special exception * remove unneeded method and add an error just in case it is added in the future * count and log chain disqualified blocks * count and log mempool evictions * bump version to 0.14.5 --- Cargo.lock | 114 +++++++++--------- Cargo.toml | 112 ++++++++--------- consensus/core/src/api/counters.rs | 4 + consensus/core/src/errors/block.rs | 4 + .../body_validation_in_context.rs | 15 +-- .../src/pipeline/body_processor/processor.rs | 4 +- .../pipeline/header_processor/processor.rs | 3 - consensus/src/pipeline/monitor.rs | 9 +- .../pipeline/virtual_processor/processor.rs | 16 ++- .../virtual_processor/utxo_validation.rs | 1 - crypto/txscript/src/caches.rs | 4 +- kaspad/src/daemon.rs | 8 +- mining/src/lib.rs | 23 ++-- .../validate_and_insert_transaction.rs | 36 +++--- mining/src/monitor.rs | 6 + 15 files changed, 190 insertions(+), 169 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c288179944..d1ebf9cfac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2393,7 +2393,7 @@ dependencies = [ [[package]] name = "kaspa-addresses" -version = "0.14.3" +version = "0.14.5" dependencies = [ "borsh", "criterion", @@ -2410,7 +2410,7 @@ dependencies = [ [[package]] name = "kaspa-addressmanager" -version = "0.14.3" +version = "0.14.5" dependencies = [ "borsh", "igd-next", @@ -2433,14 +2433,14 @@ dependencies = [ [[package]] name = "kaspa-alloc" -version = "0.14.3" +version = "0.14.5" dependencies = [ "mimalloc", ] [[package]] name = "kaspa-bip32" -version = "0.14.3" +version = "0.14.5" dependencies = [ "borsh", "bs58", @@ -2467,7 +2467,7 @@ dependencies = [ [[package]] name = "kaspa-cli" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-trait", "borsh", @@ -2514,7 +2514,7 @@ dependencies = [ [[package]] name = "kaspa-connectionmanager" -version = "0.14.3" +version = "0.14.5" dependencies = [ "duration-string", "futures-util", @@ -2531,7 +2531,7 @@ dependencies = [ [[package]] name = "kaspa-consensus" -version = "0.14.3" +version = "0.14.5" dependencies = [ "arc-swap", "async-channel 2.3.1", @@ -2574,7 +2574,7 @@ dependencies = [ [[package]] name = "kaspa-consensus-client" -version = "0.14.3" +version = "0.14.5" dependencies = [ "ahash", "cfg-if 1.0.0", @@ -2602,7 +2602,7 @@ dependencies = [ [[package]] name = "kaspa-consensus-core" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-trait", "bincode", @@ -2640,7 +2640,7 @@ dependencies = [ [[package]] name = "kaspa-consensus-notify" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-channel 2.3.1", "cfg-if 1.0.0", @@ -2659,7 +2659,7 @@ dependencies = [ [[package]] name = "kaspa-consensus-wasm" -version = "0.14.3" +version = "0.14.5" dependencies = [ "cfg-if 1.0.0", "faster-hex", @@ -2683,7 +2683,7 @@ dependencies = [ [[package]] name = "kaspa-consensusmanager" -version = "0.14.3" +version = "0.14.5" dependencies = [ "duration-string", "futures", @@ -2701,7 +2701,7 @@ dependencies = [ [[package]] name = "kaspa-core" -version = "0.14.3" +version = "0.14.5" dependencies = [ "cfg-if 1.0.0", "ctrlc", @@ -2719,7 +2719,7 @@ dependencies = [ [[package]] name = "kaspa-daemon" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-trait", "borsh", @@ -2741,7 +2741,7 @@ dependencies = [ [[package]] name = "kaspa-database" -version = "0.14.3" +version = "0.14.5" dependencies = [ "bincode", "enum-primitive-derive", @@ -2763,7 +2763,7 @@ dependencies = [ [[package]] name = "kaspa-grpc-client" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-channel 2.3.1", "async-stream", @@ -2794,7 +2794,7 @@ dependencies = [ [[package]] name = "kaspa-grpc-core" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-channel 2.3.1", "async-stream", @@ -2823,7 +2823,7 @@ dependencies = [ [[package]] name = "kaspa-grpc-server" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-channel 2.3.1", "async-stream", @@ -2858,7 +2858,7 @@ dependencies = [ [[package]] name = "kaspa-hashes" -version = "0.14.3" +version = "0.14.5" dependencies = [ "blake2b_simd", "borsh", @@ -2879,7 +2879,7 @@ dependencies = [ [[package]] name = "kaspa-index-core" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-channel 2.3.1", "async-trait", @@ -2898,7 +2898,7 @@ dependencies = [ [[package]] name = "kaspa-index-processor" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-channel 2.3.1", "async-trait", @@ -2926,7 +2926,7 @@ dependencies = [ [[package]] name = "kaspa-math" -version = "0.14.3" +version = "0.14.5" dependencies = [ "borsh", "criterion", @@ -2947,14 +2947,14 @@ dependencies = [ [[package]] name = "kaspa-merkle" -version = "0.14.3" +version = "0.14.5" dependencies = [ "kaspa-hashes", ] [[package]] name = "kaspa-metrics-core" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-trait", "borsh", @@ -2970,7 +2970,7 @@ dependencies = [ [[package]] name = "kaspa-mining" -version = "0.14.3" +version = "0.14.5" dependencies = [ "criterion", "futures-util", @@ -2997,7 +2997,7 @@ dependencies = [ [[package]] name = "kaspa-mining-errors" -version = "0.14.3" +version = "0.14.5" dependencies = [ "kaspa-consensus-core", "thiserror", @@ -3005,7 +3005,7 @@ dependencies = [ [[package]] name = "kaspa-muhash" -version = "0.14.3" +version = "0.14.5" dependencies = [ "criterion", "kaspa-hashes", @@ -3018,7 +3018,7 @@ dependencies = [ [[package]] name = "kaspa-notify" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-channel 2.3.1", "async-trait", @@ -3054,7 +3054,7 @@ dependencies = [ [[package]] name = "kaspa-p2p-flows" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-trait", "chrono", @@ -3085,7 +3085,7 @@ dependencies = [ [[package]] name = "kaspa-p2p-lib" -version = "0.14.3" +version = "0.14.5" dependencies = [ "borsh", "ctrlc", @@ -3116,7 +3116,7 @@ dependencies = [ [[package]] name = "kaspa-perf-monitor" -version = "0.14.3" +version = "0.14.5" dependencies = [ "kaspa-core", "log", @@ -3128,7 +3128,7 @@ dependencies = [ [[package]] name = "kaspa-pow" -version = "0.14.3" +version = "0.14.5" dependencies = [ "criterion", "js-sys", @@ -3144,7 +3144,7 @@ dependencies = [ [[package]] name = "kaspa-rpc-core" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-channel 2.3.1", "async-trait", @@ -3186,7 +3186,7 @@ dependencies = [ [[package]] name = "kaspa-rpc-macros" -version = "0.14.3" +version = "0.14.5" dependencies = [ "convert_case 0.6.0", "proc-macro-error", @@ -3198,7 +3198,7 @@ dependencies = [ [[package]] name = "kaspa-rpc-service" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-trait", "kaspa-addresses", @@ -3227,7 +3227,7 @@ dependencies = [ [[package]] name = "kaspa-testing-integration" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-channel 2.3.1", "async-trait", @@ -3287,7 +3287,7 @@ dependencies = [ [[package]] name = "kaspa-txscript" -version = "0.14.3" +version = "0.14.5" dependencies = [ "blake2b_simd", "borsh", @@ -3319,7 +3319,7 @@ dependencies = [ [[package]] name = "kaspa-txscript-errors" -version = "0.14.3" +version = "0.14.5" dependencies = [ "secp256k1", "thiserror", @@ -3327,7 +3327,7 @@ dependencies = [ [[package]] name = "kaspa-utils" -version = "0.14.3" +version = "0.14.5" dependencies = [ "arc-swap", "async-channel 2.3.1", @@ -3363,7 +3363,7 @@ dependencies = [ [[package]] name = "kaspa-utils-tower" -version = "0.14.3" +version = "0.14.5" dependencies = [ "cfg-if 1.0.0", "futures", @@ -3377,7 +3377,7 @@ dependencies = [ [[package]] name = "kaspa-utxoindex" -version = "0.14.3" +version = "0.14.5" dependencies = [ "futures", "kaspa-consensus", @@ -3398,7 +3398,7 @@ dependencies = [ [[package]] name = "kaspa-wallet" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-std", "async-trait", @@ -3410,7 +3410,7 @@ dependencies = [ [[package]] name = "kaspa-wallet-cli-wasm" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-trait", "js-sys", @@ -3424,7 +3424,7 @@ dependencies = [ [[package]] name = "kaspa-wallet-core" -version = "0.14.3" +version = "0.14.5" dependencies = [ "aes", "ahash", @@ -3505,7 +3505,7 @@ dependencies = [ [[package]] name = "kaspa-wallet-keys" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-trait", "borsh", @@ -3538,7 +3538,7 @@ dependencies = [ [[package]] name = "kaspa-wallet-macros" -version = "0.14.3" +version = "0.14.5" dependencies = [ "convert_case 0.5.0", "proc-macro-error", @@ -3551,7 +3551,7 @@ dependencies = [ [[package]] name = "kaspa-wallet-pskt" -version = "0.14.3" +version = "0.14.5" dependencies = [ "bincode", "derive_builder", @@ -3578,7 +3578,7 @@ dependencies = [ [[package]] name = "kaspa-wasm" -version = "0.14.3" +version = "0.14.5" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -3606,7 +3606,7 @@ dependencies = [ [[package]] name = "kaspa-wasm-core" -version = "0.14.3" +version = "0.14.5" dependencies = [ "faster-hex", "hexplay", @@ -3617,7 +3617,7 @@ dependencies = [ [[package]] name = "kaspa-wrpc-client" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-std", "async-trait", @@ -3652,7 +3652,7 @@ dependencies = [ [[package]] name = "kaspa-wrpc-example-subscriber" -version = "0.14.3" +version = "0.14.5" dependencies = [ "ctrlc", "futures", @@ -3667,7 +3667,7 @@ dependencies = [ [[package]] name = "kaspa-wrpc-proxy" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-trait", "clap 4.5.16", @@ -3686,7 +3686,7 @@ dependencies = [ [[package]] name = "kaspa-wrpc-server" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-trait", "borsh", @@ -3714,7 +3714,7 @@ dependencies = [ [[package]] name = "kaspa-wrpc-wasm" -version = "0.14.3" +version = "0.14.5" dependencies = [ "ahash", "async-std", @@ -3743,7 +3743,7 @@ dependencies = [ [[package]] name = "kaspad" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-channel 2.3.1", "cfg-if 1.0.0", @@ -5188,7 +5188,7 @@ dependencies = [ [[package]] name = "rothschild" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-channel 2.3.1", "clap 4.5.16", @@ -5665,7 +5665,7 @@ dependencies = [ [[package]] name = "simpa" -version = "0.14.3" +version = "0.14.5" dependencies = [ "async-channel 2.3.1", "cfg-if 1.0.0", diff --git a/Cargo.toml b/Cargo.toml index 0a6799e43d..0fdc4a499f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,7 +62,7 @@ members = [ [workspace.package] rust-version = "1.80.0" -version = "0.14.3" +version = "0.14.5" authors = ["Kaspa developers"] license = "ISC" repository = "https://github.com/kaspanet/rusty-kaspa" @@ -79,61 +79,61 @@ include = [ ] [workspace.dependencies] -# kaspa-testing-integration = { version = "0.14.3", path = "testing/integration" } -kaspa-addresses = { version = "0.14.3", path = "crypto/addresses" } -kaspa-addressmanager = { version = "0.14.3", path = "components/addressmanager" } -kaspa-bip32 = { version = "0.14.3", path = "wallet/bip32" } -kaspa-cli = { version = "0.14.3", path = "cli" } -kaspa-connectionmanager = { version = "0.14.3", path = "components/connectionmanager" } -kaspa-consensus = { version = "0.14.3", path = "consensus" } -kaspa-consensus-core = { version = "0.14.3", path = "consensus/core" } -kaspa-consensus-client = { version = "0.14.3", path = "consensus/client" } -kaspa-consensus-notify = { version = "0.14.3", path = "consensus/notify" } -kaspa-consensus-wasm = { version = "0.14.3", path = "consensus/wasm" } -kaspa-consensusmanager = { version = "0.14.3", path = "components/consensusmanager" } -kaspa-core = { version = "0.14.3", path = "core" } -kaspa-daemon = { version = "0.14.3", path = "daemon" } -kaspa-database = { version = "0.14.3", path = "database" } -kaspa-grpc-client = { version = "0.14.3", path = "rpc/grpc/client" } -kaspa-grpc-core = { version = "0.14.3", path = "rpc/grpc/core" } -kaspa-grpc-server = { version = "0.14.3", path = "rpc/grpc/server" } -kaspa-hashes = { version = "0.14.3", path = "crypto/hashes" } -kaspa-index-core = { version = "0.14.3", path = "indexes/core" } -kaspa-index-processor = { version = "0.14.3", path = "indexes/processor" } -kaspa-math = { version = "0.14.3", path = "math" } -kaspa-merkle = { version = "0.14.3", path = "crypto/merkle" } -kaspa-metrics-core = { version = "0.14.3", path = "metrics/core" } -kaspa-mining = { version = "0.14.3", path = "mining" } -kaspa-mining-errors = { version = "0.14.3", path = "mining/errors" } -kaspa-muhash = { version = "0.14.3", path = "crypto/muhash" } -kaspa-notify = { version = "0.14.3", path = "notify" } -kaspa-p2p-flows = { version = "0.14.3", path = "protocol/flows" } -kaspa-p2p-lib = { version = "0.14.3", path = "protocol/p2p" } -kaspa-perf-monitor = { version = "0.14.3", path = "metrics/perf_monitor" } -kaspa-pow = { version = "0.14.3", path = "consensus/pow" } -kaspa-rpc-core = { version = "0.14.3", path = "rpc/core" } -kaspa-rpc-macros = { version = "0.14.3", path = "rpc/macros" } -kaspa-rpc-service = { version = "0.14.3", path = "rpc/service" } -kaspa-txscript = { version = "0.14.3", path = "crypto/txscript" } -kaspa-txscript-errors = { version = "0.14.3", path = "crypto/txscript/errors" } -kaspa-utils = { version = "0.14.3", path = "utils" } -kaspa-utils-tower = { version = "0.14.3", path = "utils/tower" } -kaspa-utxoindex = { version = "0.14.3", path = "indexes/utxoindex" } -kaspa-wallet = { version = "0.14.3", path = "wallet/native" } -kaspa-wallet-cli-wasm = { version = "0.14.3", path = "wallet/wasm" } -kaspa-wallet-keys = { version = "0.14.3", path = "wallet/keys" } -kaspa-wallet-pskt = { version = "0.14.3", path = "wallet/pskt" } -kaspa-wallet-core = { version = "0.14.3", path = "wallet/core" } -kaspa-wallet-macros = { version = "0.14.3", path = "wallet/macros" } -kaspa-wasm = { version = "0.14.3", path = "wasm" } -kaspa-wasm-core = { version = "0.14.3", path = "wasm/core" } -kaspa-wrpc-client = { version = "0.14.3", path = "rpc/wrpc/client" } -kaspa-wrpc-proxy = { version = "0.14.3", path = "rpc/wrpc/proxy" } -kaspa-wrpc-server = { version = "0.14.3", path = "rpc/wrpc/server" } -kaspa-wrpc-wasm = { version = "0.14.3", path = "rpc/wrpc/wasm" } -kaspa-wrpc-example-subscriber = { version = "0.14.3", path = "rpc/wrpc/examples/subscriber" } -kaspad = { version = "0.14.3", path = "kaspad" } -kaspa-alloc = { version = "0.14.3", path = "utils/alloc" } +# kaspa-testing-integration = { version = "0.14.5", path = "testing/integration" } +kaspa-addresses = { version = "0.14.5", path = "crypto/addresses" } +kaspa-addressmanager = { version = "0.14.5", path = "components/addressmanager" } +kaspa-bip32 = { version = "0.14.5", path = "wallet/bip32" } +kaspa-cli = { version = "0.14.5", path = "cli" } +kaspa-connectionmanager = { version = "0.14.5", path = "components/connectionmanager" } +kaspa-consensus = { version = "0.14.5", path = "consensus" } +kaspa-consensus-core = { version = "0.14.5", path = "consensus/core" } +kaspa-consensus-client = { version = "0.14.5", path = "consensus/client" } +kaspa-consensus-notify = { version = "0.14.5", path = "consensus/notify" } +kaspa-consensus-wasm = { version = "0.14.5", path = "consensus/wasm" } +kaspa-consensusmanager = { version = "0.14.5", path = "components/consensusmanager" } +kaspa-core = { version = "0.14.5", path = "core" } +kaspa-daemon = { version = "0.14.5", path = "daemon" } +kaspa-database = { version = "0.14.5", path = "database" } +kaspa-grpc-client = { version = "0.14.5", path = "rpc/grpc/client" } +kaspa-grpc-core = { version = "0.14.5", path = "rpc/grpc/core" } +kaspa-grpc-server = { version = "0.14.5", path = "rpc/grpc/server" } +kaspa-hashes = { version = "0.14.5", path = "crypto/hashes" } +kaspa-index-core = { version = "0.14.5", path = "indexes/core" } +kaspa-index-processor = { version = "0.14.5", path = "indexes/processor" } +kaspa-math = { version = "0.14.5", path = "math" } +kaspa-merkle = { version = "0.14.5", path = "crypto/merkle" } +kaspa-metrics-core = { version = "0.14.5", path = "metrics/core" } +kaspa-mining = { version = "0.14.5", path = "mining" } +kaspa-mining-errors = { version = "0.14.5", path = "mining/errors" } +kaspa-muhash = { version = "0.14.5", path = "crypto/muhash" } +kaspa-notify = { version = "0.14.5", path = "notify" } +kaspa-p2p-flows = { version = "0.14.5", path = "protocol/flows" } +kaspa-p2p-lib = { version = "0.14.5", path = "protocol/p2p" } +kaspa-perf-monitor = { version = "0.14.5", path = "metrics/perf_monitor" } +kaspa-pow = { version = "0.14.5", path = "consensus/pow" } +kaspa-rpc-core = { version = "0.14.5", path = "rpc/core" } +kaspa-rpc-macros = { version = "0.14.5", path = "rpc/macros" } +kaspa-rpc-service = { version = "0.14.5", path = "rpc/service" } +kaspa-txscript = { version = "0.14.5", path = "crypto/txscript" } +kaspa-txscript-errors = { version = "0.14.5", path = "crypto/txscript/errors" } +kaspa-utils = { version = "0.14.5", path = "utils" } +kaspa-utils-tower = { version = "0.14.5", path = "utils/tower" } +kaspa-utxoindex = { version = "0.14.5", path = "indexes/utxoindex" } +kaspa-wallet = { version = "0.14.5", path = "wallet/native" } +kaspa-wallet-cli-wasm = { version = "0.14.5", path = "wallet/wasm" } +kaspa-wallet-keys = { version = "0.14.5", path = "wallet/keys" } +kaspa-wallet-pskt = { version = "0.14.5", path = "wallet/pskt" } +kaspa-wallet-core = { version = "0.14.5", path = "wallet/core" } +kaspa-wallet-macros = { version = "0.14.5", path = "wallet/macros" } +kaspa-wasm = { version = "0.14.5", path = "wasm" } +kaspa-wasm-core = { version = "0.14.5", path = "wasm/core" } +kaspa-wrpc-client = { version = "0.14.5", path = "rpc/wrpc/client" } +kaspa-wrpc-proxy = { version = "0.14.5", path = "rpc/wrpc/proxy" } +kaspa-wrpc-server = { version = "0.14.5", path = "rpc/wrpc/server" } +kaspa-wrpc-wasm = { version = "0.14.5", path = "rpc/wrpc/wasm" } +kaspa-wrpc-example-subscriber = { version = "0.14.5", path = "rpc/wrpc/examples/subscriber" } +kaspad = { version = "0.14.5", path = "kaspad" } +kaspa-alloc = { version = "0.14.5", path = "utils/alloc" } # external aes = "0.8.3" diff --git a/consensus/core/src/api/counters.rs b/consensus/core/src/api/counters.rs index 5faee5bc3b..0297dab265 100644 --- a/consensus/core/src/api/counters.rs +++ b/consensus/core/src/api/counters.rs @@ -9,6 +9,7 @@ pub struct ProcessingCounters { pub body_counts: AtomicU64, pub txs_counts: AtomicU64, pub chain_block_counts: AtomicU64, + pub chain_disqualified_counts: AtomicU64, pub mass_counts: AtomicU64, } @@ -22,6 +23,7 @@ impl ProcessingCounters { body_counts: self.body_counts.load(Ordering::Relaxed), txs_counts: self.txs_counts.load(Ordering::Relaxed), chain_block_counts: self.chain_block_counts.load(Ordering::Relaxed), + chain_disqualified_counts: self.chain_disqualified_counts.load(Ordering::Relaxed), mass_counts: self.mass_counts.load(Ordering::Relaxed), } } @@ -36,6 +38,7 @@ pub struct ProcessingCountersSnapshot { pub body_counts: u64, pub txs_counts: u64, pub chain_block_counts: u64, + pub chain_disqualified_counts: u64, pub mass_counts: u64, } @@ -51,6 +54,7 @@ impl core::ops::Sub for &ProcessingCountersSnapshot { body_counts: self.body_counts.saturating_sub(rhs.body_counts), txs_counts: self.txs_counts.saturating_sub(rhs.txs_counts), chain_block_counts: self.chain_block_counts.saturating_sub(rhs.chain_block_counts), + chain_disqualified_counts: self.chain_disqualified_counts.saturating_sub(rhs.chain_disqualified_counts), mass_counts: self.mass_counts.saturating_sub(rhs.mass_counts), } } diff --git a/consensus/core/src/errors/block.rs b/consensus/core/src/errors/block.rs index 9aab18905f..f5c235476a 100644 --- a/consensus/core/src/errors/block.rs +++ b/consensus/core/src/errors/block.rs @@ -147,6 +147,10 @@ pub enum RuleError { #[error("DAA window data has only {0} entries")] InsufficientDaaWindowSize(usize), + + /// Currently this error is never created because it is impossible to submit such a block + #[error("cannot add block body to a pruned block")] + PrunedBlock, } pub type BlockProcessResult = std::result::Result; diff --git a/consensus/src/pipeline/body_processor/body_validation_in_context.rs b/consensus/src/pipeline/body_processor/body_validation_in_context.rs index 042410fa85..aa2f345b36 100644 --- a/consensus/src/pipeline/body_processor/body_validation_in_context.rs +++ b/consensus/src/pipeline/body_processor/body_validation_in_context.rs @@ -14,14 +14,7 @@ impl BlockBodyProcessor { pub fn validate_body_in_context(self: &Arc, block: &Block) -> BlockProcessResult<()> { self.check_parent_bodies_exist(block)?; self.check_coinbase_blue_score_and_subsidy(block)?; - self.check_block_transactions_in_context(block)?; - self.check_block_is_not_pruned(block) - } - - fn check_block_is_not_pruned(self: &Arc, _block: &Block) -> BlockProcessResult<()> { - // TODO: In kaspad code it checks that the block is not in the past of the current tips. - // We should decide what's the best indication that a block was pruned. - Ok(()) + self.check_block_transactions_in_context(block) } fn check_block_transactions_in_context(self: &Arc, block: &Block) -> BlockProcessResult<()> { @@ -36,12 +29,6 @@ impl BlockBodyProcessor { } fn check_parent_bodies_exist(self: &Arc, block: &Block) -> BlockProcessResult<()> { - // TODO: Skip this check for blocks in PP anticone that comes as part of the pruning proof. - - if block.header.direct_parents().len() == 1 && block.header.direct_parents()[0] == self.genesis.hash { - return Ok(()); - } - let statuses_read_guard = self.statuses_store.read(); let missing: Vec = block .header diff --git a/consensus/src/pipeline/body_processor/processor.rs b/consensus/src/pipeline/body_processor/processor.rs index ae9c07b8a4..4191a01cec 100644 --- a/consensus/src/pipeline/body_processor/processor.rs +++ b/consensus/src/pipeline/body_processor/processor.rs @@ -201,8 +201,7 @@ impl BlockBodyProcessor { // transactions that fits the merkle root. // PrunedBlock - PrunedBlock is an error that rejects a block body and // not the block as a whole, so we shouldn't mark it as invalid. - // TODO: implement the last part. - if !matches!(e, RuleError::BadMerkleRoot(_, _) | RuleError::MissingParents(_)) { + if !matches!(e, RuleError::BadMerkleRoot(_, _) | RuleError::MissingParents(_) | RuleError::PrunedBlock) { self.statuses_store.write().set(block.hash(), BlockStatus::StatusInvalid).unwrap(); } return Err(e); @@ -226,7 +225,6 @@ impl BlockBodyProcessor { fn validate_body(self: &Arc, block: &Block, is_trusted: bool) -> BlockProcessResult { let mass = self.validate_body_in_isolation(block)?; if !is_trusted { - // TODO: Check that it's safe to skip this check if the block is trusted. self.validate_body_in_context(block)?; } Ok(mass) diff --git a/consensus/src/pipeline/header_processor/processor.rs b/consensus/src/pipeline/header_processor/processor.rs index d1b74aeb5c..6c93b91d9c 100644 --- a/consensus/src/pipeline/header_processor/processor.rs +++ b/consensus/src/pipeline/header_processor/processor.rs @@ -308,8 +308,6 @@ impl HeaderProcessor { // Runs partial header validation for trusted blocks (currently validates only header-in-isolation and computes GHOSTDAG). fn validate_trusted_header(&self, header: &Arc
) -> BlockProcessResult { - // TODO: For now we skip most validations for trusted blocks, but in the future we should - // employ some validations to avoid spam etc. let block_level = self.validate_header_in_isolation(header)?; let mut ctx = self.build_processing_context(header, block_level); self.ghostdag(&mut ctx); @@ -407,7 +405,6 @@ impl HeaderProcessor { && reachability::is_chain_ancestor_of(&staging, pp, ctx.hash).unwrap() { // Hint reachability about the new tip. - // TODO: identify a disqualified hst and make sure to use sink instead reachability::hint_virtual_selected_parent(&mut staging, ctx.hash).unwrap(); hst_write.set_batch(&mut batch, SortableBlock::new(ctx.hash, header.blue_work)).unwrap(); } diff --git a/consensus/src/pipeline/monitor.rs b/consensus/src/pipeline/monitor.rs index 600059f0a9..ca370a2f88 100644 --- a/consensus/src/pipeline/monitor.rs +++ b/consensus/src/pipeline/monitor.rs @@ -5,7 +5,7 @@ use kaspa_core::{ service::{AsyncService, AsyncServiceFuture}, tick::{TickReason, TickService}, }, - trace, + trace, warn, }; use std::{ sync::Arc, @@ -62,6 +62,13 @@ impl ConsensusMonitor { if delta.body_counts != 0 { delta.mass_counts as f64 / delta.body_counts as f64 } else{ 0f64 }, ); + if delta.chain_disqualified_counts > 0 { + warn!( + "Consensus detected UTXO-invalid blocks which are disqualified from the virtual selected chain (possibly due to inheritance): {} disqualified vs. {} valid chain blocks", + delta.chain_disqualified_counts, delta.chain_block_counts + ); + } + last_snapshot = snapshot; last_log_time = now; } diff --git a/consensus/src/pipeline/virtual_processor/processor.rs b/consensus/src/pipeline/virtual_processor/processor.rs index 163e888936..dfb7394b80 100644 --- a/consensus/src/pipeline/virtual_processor/processor.rs +++ b/consensus/src/pipeline/virtual_processor/processor.rs @@ -383,10 +383,12 @@ impl VirtualStateProcessor { // Walk back up to the new virtual selected parent candidate let mut chain_block_counter = 0; + let mut chain_disqualified_counter = 0; for (selected_parent, current) in self.reachability_service.forward_chain_iterator(split_point, to, true).tuple_windows() { if selected_parent != diff_point { // This indicates that the selected parent is disqualified, propagate up and continue self.statuses_store.write().set(current, StatusDisqualifiedFromChain).unwrap(); + chain_disqualified_counter += 1; continue; } @@ -416,6 +418,7 @@ impl VirtualStateProcessor { if let Err(rule_error) = res { info!("Block {} is disqualified from virtual chain: {}", current, rule_error); self.statuses_store.write().set(current, StatusDisqualifiedFromChain).unwrap(); + chain_disqualified_counter += 1; } else { debug!("VIRTUAL PROCESSOR, UTXO validated for {current}"); @@ -434,6 +437,9 @@ impl VirtualStateProcessor { } // Report counters self.counters.chain_block_counts.fetch_add(chain_block_counter, Ordering::Relaxed); + if chain_disqualified_counter > 0 { + self.counters.chain_disqualified_counts.fetch_add(chain_disqualified_counter, Ordering::Relaxed); + } diff_point } @@ -559,7 +565,7 @@ impl VirtualStateProcessor { finality_point: Hash, pruning_point: Hash, ) -> (Hash, VecDeque) { - // TODO: tests + // TODO (relaxed): additional tests let mut heap = tips .into_iter() @@ -621,7 +627,7 @@ impl VirtualStateProcessor { mut candidates: VecDeque, pruning_point: Hash, ) -> (Vec, GhostdagData) { - // TODO: tests + // TODO (relaxed): additional tests // Mergeset increasing might traverse DAG areas which are below the finality point and which theoretically // can borderline with pruned data, hence we acquire the prune lock to ensure data consistency. Note that @@ -670,7 +676,7 @@ impl VirtualStateProcessor { MergesetIncreaseResult::Rejected { new_candidate } => { // If we already have a candidate in the past of new candidate then skip. if self.reachability_service.is_any_dag_ancestor(&mut candidates.iter().copied(), new_candidate) { - continue; // TODO: not sure this test is needed if candidates invariant as antichain is kept + continue; // TODO (optimization): not sure this check is needed if candidates invariant as antichain is kept } // Remove all candidates which are in the future of the new candidate candidates.retain(|&h| !self.reachability_service.is_dag_ancestor_of(new_candidate, h)); @@ -860,7 +866,7 @@ impl VirtualStateProcessor { build_mode: TemplateBuildMode, ) -> Result { // - // TODO: tests + // TODO (relaxed): additional tests // // We call for the initial tx batch before acquiring the virtual read lock, @@ -1048,7 +1054,7 @@ impl VirtualStateProcessor { ); } - // TODO: rename to reflect finalizing pruning point utxoset state and importing *to* virtual utxoset + /// Finalizes the pruning point utxoset state and imports the pruning point utxoset *to* virtual utxoset pub fn import_pruning_point_utxo_set( &self, new_pruning_point: Hash, diff --git a/consensus/src/pipeline/virtual_processor/utxo_validation.rs b/consensus/src/pipeline/virtual_processor/utxo_validation.rs index 999cd1c545..306f81446c 100644 --- a/consensus/src/pipeline/virtual_processor/utxo_validation.rs +++ b/consensus/src/pipeline/virtual_processor/utxo_validation.rs @@ -267,7 +267,6 @@ impl VirtualStateProcessor { for i in 0..mutable_tx.tx.inputs.len() { if mutable_tx.entries[i].is_some() { // We prefer a previously populated entry if such exists - // TODO: consider re-checking the utxo view to get the most up-to-date entry (since DAA score can change) continue; } if let Some(entry) = utxo_view.get(&mutable_tx.tx.inputs[i].previous_outpoint) { diff --git a/crypto/txscript/src/caches.rs b/crypto/txscript/src/caches.rs index 3f76b25750..b3911fcf40 100644 --- a/crypto/txscript/src/caches.rs +++ b/crypto/txscript/src/caches.rs @@ -87,8 +87,8 @@ impl core::ops::Sub for &TxScriptCacheCountersSnapshot { fn sub(self, rhs: Self) -> Self::Output { Self::Output { - insert_counts: self.insert_counts.checked_sub(rhs.insert_counts).unwrap_or_default(), - get_counts: self.get_counts.checked_sub(rhs.get_counts).unwrap_or_default(), + insert_counts: self.insert_counts.saturating_sub(rhs.insert_counts), + get_counts: self.get_counts.saturating_sub(rhs.get_counts), } } } diff --git a/kaspad/src/daemon.rs b/kaspad/src/daemon.rs index c13ed1c38a..4175206eb5 100644 --- a/kaspad/src/daemon.rs +++ b/kaspad/src/daemon.rs @@ -6,7 +6,7 @@ use kaspa_consensus_core::{ errors::config::{ConfigError, ConfigResult}, }; use kaspa_consensus_notify::{root::ConsensusNotificationRoot, service::NotifyService}; -use kaspa_core::{core::Core, info, trace}; +use kaspa_core::{core::Core, debug, info}; use kaspa_core::{kaspad_env::version, task::tick::TickService}; use kaspa_database::prelude::CachePolicy; use kaspa_grpc_server::service::GrpcService; @@ -400,10 +400,10 @@ do you confirm? (answer y/n or pass --yes to the Kaspad command line to confirm .with_tick_service(tick_service.clone()); let perf_monitor = if args.perf_metrics { let cb = move |counters: CountersSnapshot| { - trace!("[{}] {}", kaspa_perf_monitor::SERVICE_NAME, counters.to_process_metrics_display()); - trace!("[{}] {}", kaspa_perf_monitor::SERVICE_NAME, counters.to_io_metrics_display()); + debug!("[{}] {}", kaspa_perf_monitor::SERVICE_NAME, counters.to_process_metrics_display()); + debug!("[{}] {}", kaspa_perf_monitor::SERVICE_NAME, counters.to_io_metrics_display()); #[cfg(feature = "heap")] - trace!("[{}] heap stats: {:?}", kaspa_perf_monitor::SERVICE_NAME, dhat::HeapStats::get()); + debug!("[{}] heap stats: {:?}", kaspa_perf_monitor::SERVICE_NAME, dhat::HeapStats::get()); }; Arc::new(perf_monitor_builder.with_fetch_cb(cb).build()) } else { diff --git a/mining/src/lib.rs b/mining/src/lib.rs index 745fb63f97..141d9d2836 100644 --- a/mining/src/lib.rs +++ b/mining/src/lib.rs @@ -30,6 +30,7 @@ pub struct MiningCounters { pub low_priority_tx_counts: AtomicU64, pub block_tx_counts: AtomicU64, pub tx_accepted_counts: AtomicU64, + pub tx_evicted_counts: AtomicU64, pub input_counts: AtomicU64, pub output_counts: AtomicU64, @@ -48,6 +49,7 @@ impl Default for MiningCounters { low_priority_tx_counts: Default::default(), block_tx_counts: Default::default(), tx_accepted_counts: Default::default(), + tx_evicted_counts: Default::default(), input_counts: Default::default(), output_counts: Default::default(), ready_txs_sample: Default::default(), @@ -66,6 +68,7 @@ impl MiningCounters { low_priority_tx_counts: self.low_priority_tx_counts.load(Ordering::Relaxed), block_tx_counts: self.block_tx_counts.load(Ordering::Relaxed), tx_accepted_counts: self.tx_accepted_counts.load(Ordering::Relaxed), + tx_evicted_counts: self.tx_evicted_counts.load(Ordering::Relaxed), input_counts: self.input_counts.load(Ordering::Relaxed), output_counts: self.output_counts.load(Ordering::Relaxed), ready_txs_sample: self.ready_txs_sample.load(Ordering::Relaxed), @@ -101,6 +104,7 @@ pub struct MempoolCountersSnapshot { pub low_priority_tx_counts: u64, pub block_tx_counts: u64, pub tx_accepted_counts: u64, + pub tx_evicted_counts: u64, pub input_counts: u64, pub output_counts: u64, pub ready_txs_sample: u64, @@ -151,13 +155,14 @@ impl core::ops::Sub for &MempoolCountersSnapshot { fn sub(self, rhs: Self) -> Self::Output { Self::Output { - elapsed_time: self.elapsed_time.checked_sub(rhs.elapsed_time).unwrap_or_default(), - high_priority_tx_counts: self.high_priority_tx_counts.checked_sub(rhs.high_priority_tx_counts).unwrap_or_default(), - low_priority_tx_counts: self.low_priority_tx_counts.checked_sub(rhs.low_priority_tx_counts).unwrap_or_default(), - block_tx_counts: self.block_tx_counts.checked_sub(rhs.block_tx_counts).unwrap_or_default(), - tx_accepted_counts: self.tx_accepted_counts.checked_sub(rhs.tx_accepted_counts).unwrap_or_default(), - input_counts: self.input_counts.checked_sub(rhs.input_counts).unwrap_or_default(), - output_counts: self.output_counts.checked_sub(rhs.output_counts).unwrap_or_default(), + elapsed_time: self.elapsed_time.saturating_sub(rhs.elapsed_time), + high_priority_tx_counts: self.high_priority_tx_counts.saturating_sub(rhs.high_priority_tx_counts), + low_priority_tx_counts: self.low_priority_tx_counts.saturating_sub(rhs.low_priority_tx_counts), + block_tx_counts: self.block_tx_counts.saturating_sub(rhs.block_tx_counts), + tx_accepted_counts: self.tx_accepted_counts.saturating_sub(rhs.tx_accepted_counts), + tx_evicted_counts: self.tx_evicted_counts.saturating_sub(rhs.tx_evicted_counts), + input_counts: self.input_counts.saturating_sub(rhs.input_counts), + output_counts: self.output_counts.saturating_sub(rhs.output_counts), ready_txs_sample: (self.ready_txs_sample + rhs.ready_txs_sample) / 2, txs_sample: (self.txs_sample + rhs.txs_sample) / 2, orphans_sample: (self.orphans_sample + rhs.orphans_sample) / 2, @@ -177,8 +182,8 @@ impl core::ops::Sub for &P2pTxCountSample { fn sub(self, rhs: Self) -> Self::Output { Self::Output { - elapsed_time: self.elapsed_time.checked_sub(rhs.elapsed_time).unwrap_or_default(), - low_priority_tx_counts: self.low_priority_tx_counts.checked_sub(rhs.low_priority_tx_counts).unwrap_or_default(), + elapsed_time: self.elapsed_time.saturating_sub(rhs.elapsed_time), + low_priority_tx_counts: self.low_priority_tx_counts.saturating_sub(rhs.low_priority_tx_counts), } } } diff --git a/mining/src/mempool/validate_and_insert_transaction.rs b/mining/src/mempool/validate_and_insert_transaction.rs index 3eddac459c..69e08019b6 100644 --- a/mining/src/mempool/validate_and_insert_transaction.rs +++ b/mining/src/mempool/validate_and_insert_transaction.rs @@ -1,3 +1,5 @@ +use std::sync::atomic::Ordering; + use crate::mempool::{ errors::{RuleError, RuleResult}, model::{ @@ -84,21 +86,27 @@ impl Mempool { // Before adding the transaction, check if there is room in the pool let transaction_size = transaction.mempool_estimated_bytes(); let txs_to_remove = self.transaction_pool.limit_transaction_count(&transaction, transaction_size)?; - for x in txs_to_remove.iter() { - self.remove_transaction(x, true, TxRemovalReason::MakingRoom, format!(" for {}", transaction_id).as_str())?; - // self.transaction_pool.limit_transaction_count(&transaction) returns the - // smallest prefix of `ready_transactions` (sorted by ascending fee-rate) - // that makes enough room for `transaction`, but since each call to `self.remove_transaction` - // also removes all transactions dependant on `x` we might already have sufficient space, so - // we constantly check the break condition. - // - // Note that self.transaction_pool.len() < self.config.maximum_transaction_count means we have - // at least one available slot in terms of the count limit - if self.transaction_pool.len() < self.config.maximum_transaction_count - && self.transaction_pool.get_estimated_size() + transaction_size <= self.config.mempool_size_limit - { - break; + if !txs_to_remove.is_empty() { + let transaction_pool_len_before = self.transaction_pool.len(); + for x in txs_to_remove.iter() { + self.remove_transaction(x, true, TxRemovalReason::MakingRoom, format!(" for {}", transaction_id).as_str())?; + // self.transaction_pool.limit_transaction_count(&transaction) returns the + // smallest prefix of `ready_transactions` (sorted by ascending fee-rate) + // that makes enough room for `transaction`, but since each call to `self.remove_transaction` + // also removes all transactions dependant on `x` we might already have sufficient space, so + // we constantly check the break condition. + // + // Note that self.transaction_pool.len() < self.config.maximum_transaction_count means we have + // at least one available slot in terms of the count limit + if self.transaction_pool.len() < self.config.maximum_transaction_count + && self.transaction_pool.get_estimated_size() + transaction_size <= self.config.mempool_size_limit + { + break; + } } + self.counters + .tx_evicted_counts + .fetch_add(transaction_pool_len_before.saturating_sub(self.transaction_pool.len()) as u64, Ordering::Relaxed); } assert!( diff --git a/mining/src/monitor.rs b/mining/src/monitor.rs index 876ce9b7a6..74449424c1 100644 --- a/mining/src/monitor.rs +++ b/mining/src/monitor.rs @@ -69,6 +69,12 @@ impl MiningMonitor { let feerate_estimations = self.mining_manager.clone().get_realtime_feerate_estimations().await; debug!("Realtime feerate estimations: {}", feerate_estimations); } + if delta.tx_evicted_counts > 0 { + info!( + "Mempool stats: {} transactions were evicted from the mempool in favor of incoming higher feerate transactions", + delta.tx_evicted_counts + ); + } if tx_script_cache_snapshot != last_tx_script_cache_snapshot { debug!( "UTXO set stats: {} spent, {} created ({} signatures validated, {} cache hits, {:.2} hit ratio)", From b04092e41e3c86c9bf7d7f7733eaabd563131eb7 Mon Sep 17 00:00:00 2001 From: aspect Date: Thu, 5 Sep 2024 18:00:24 +0300 Subject: [PATCH 2/8] add proxy limit field to sysinfo (#544) --- rpc/core/src/model/message.rs | 11 ++++-- rpc/core/src/model/tests.rs | 1 + rpc/grpc/core/proto/rpc.proto | 1 + rpc/grpc/core/src/convert/message.rs | 2 ++ rpc/service/src/service.rs | 1 + utils/src/sysinfo.rs | 50 ++++++++++++++++++++++++++-- 6 files changed, 61 insertions(+), 5 deletions(-) diff --git a/rpc/core/src/model/message.rs b/rpc/core/src/model/message.rs index 779f7593a9..ba8d6abf76 100644 --- a/rpc/core/src/model/message.rs +++ b/rpc/core/src/model/message.rs @@ -1899,6 +1899,7 @@ pub struct GetSystemInfoResponse { pub cpu_physical_cores: u16, pub total_memory: u64, pub fd_limit: u32, + pub proxy_socket_limit_per_cpu_core: Option, } impl std::fmt::Debug for GetSystemInfoResponse { @@ -1910,19 +1911,21 @@ impl std::fmt::Debug for GetSystemInfoResponse { .field("cpu_physical_cores", &self.cpu_physical_cores) .field("total_memory", &self.total_memory) .field("fd_limit", &self.fd_limit) + .field("proxy_socket_limit_per_cpu_core", &self.proxy_socket_limit_per_cpu_core) .finish() } } impl Serializer for GetSystemInfoResponse { fn serialize(&self, writer: &mut W) -> std::io::Result<()> { - store!(u16, &1, writer)?; + store!(u16, &2, writer)?; store!(String, &self.version, writer)?; store!(Option>, &self.system_id, writer)?; store!(Option>, &self.git_hash, writer)?; store!(u16, &self.cpu_physical_cores, writer)?; store!(u64, &self.total_memory, writer)?; store!(u32, &self.fd_limit, writer)?; + store!(Option, &self.proxy_socket_limit_per_cpu_core, writer)?; Ok(()) } @@ -1930,7 +1933,7 @@ impl Serializer for GetSystemInfoResponse { impl Deserializer for GetSystemInfoResponse { fn deserialize(reader: &mut R) -> std::io::Result { - let _version = load!(u16, reader)?; + let payload_version = load!(u16, reader)?; let version = load!(String, reader)?; let system_id = load!(Option>, reader)?; let git_hash = load!(Option>, reader)?; @@ -1938,7 +1941,9 @@ impl Deserializer for GetSystemInfoResponse { let total_memory = load!(u64, reader)?; let fd_limit = load!(u32, reader)?; - Ok(Self { version, system_id, git_hash, cpu_physical_cores, total_memory, fd_limit }) + let proxy_socket_limit_per_cpu_core = if payload_version > 1 { load!(Option, reader)? } else { None }; + + Ok(Self { version, system_id, git_hash, cpu_physical_cores, total_memory, fd_limit, proxy_socket_limit_per_cpu_core }) } } diff --git a/rpc/core/src/model/tests.rs b/rpc/core/src/model/tests.rs index 11ebe7de10..d931f5ac23 100644 --- a/rpc/core/src/model/tests.rs +++ b/rpc/core/src/model/tests.rs @@ -970,6 +970,7 @@ mod mockery { cpu_physical_cores: mock(), total_memory: mock(), fd_limit: mock(), + proxy_socket_limit_per_cpu_core: mock(), } } } diff --git a/rpc/grpc/core/proto/rpc.proto b/rpc/grpc/core/proto/rpc.proto index 0147e15e21..7a38f88525 100644 --- a/rpc/grpc/core/proto/rpc.proto +++ b/rpc/grpc/core/proto/rpc.proto @@ -851,6 +851,7 @@ message GetSystemInfoResponseMessage{ uint32 coreNum = 4; uint64 totalMemory = 5; uint32 fdLimit = 6; + uint32 proxySocketLimitPerCpuCore = 7; RPCError error = 1000; } diff --git a/rpc/grpc/core/src/convert/message.rs b/rpc/grpc/core/src/convert/message.rs index a04f9c863a..c0e75cf036 100644 --- a/rpc/grpc/core/src/convert/message.rs +++ b/rpc/grpc/core/src/convert/message.rs @@ -480,6 +480,7 @@ from!(item: RpcResult<&kaspa_rpc_core::GetSystemInfoResponse>, protowire::GetSys total_memory : item.total_memory, core_num : item.cpu_physical_cores as u32, fd_limit : item.fd_limit, + proxy_socket_limit_per_cpu_core : item.proxy_socket_limit_per_cpu_core.unwrap_or_default(), error: None, } }); @@ -962,6 +963,7 @@ try_from!(item: &protowire::GetSystemInfoResponseMessage, RpcResult 0).then_some(item.proxy_socket_limit_per_cpu_core), } }); diff --git a/rpc/service/src/service.rs b/rpc/service/src/service.rs index d498f522f6..2c22fd6bb1 100644 --- a/rpc/service/src/service.rs +++ b/rpc/service/src/service.rs @@ -1067,6 +1067,7 @@ NOTE: This error usually indicates an RPC conversion error between the node and cpu_physical_cores: self.system_info.cpu_physical_cores, total_memory: self.system_info.total_memory, fd_limit: self.system_info.fd_limit, + proxy_socket_limit_per_cpu_core: self.system_info.proxy_socket_limit_per_cpu_core, }; Ok(response) diff --git a/utils/src/sysinfo.rs b/utils/src/sysinfo.rs index 4e009d4495..ba6f25110b 100644 --- a/utils/src/sysinfo.rs +++ b/utils/src/sysinfo.rs @@ -2,21 +2,32 @@ use crate::fd_budget; use crate::git; use crate::hex::ToHex; use sha2::{Digest, Sha256}; -use std::fs::File; +use std::fs::{read_to_string, File}; use std::io::Read; +use std::path::PathBuf; +// use std::fs::read_to_string; use std::sync::OnceLock; static SYSTEM_INFO: OnceLock = OnceLock::new(); #[derive(Clone)] pub struct SystemInfo { + /// unique system (machine) identifier pub system_id: Option>, + /// full git commit hash pub git_hash: Option>, + /// short git commit hash pub git_short_hash: Option>, + /// crate (workspace) version pub version: String, + /// number of physical CPU cores pub cpu_physical_cores: u16, + /// total system memory in bytes pub total_memory: u64, + /// file descriptor limit of the current process pub fd_limit: u32, + /// maximum number of sockets per CPU core + pub proxy_socket_limit_per_cpu_core: Option, } // provide hex encoding for system_id, git_hash, and git_short_hash @@ -30,6 +41,7 @@ impl std::fmt::Debug for SystemInfo { .field("cpu_physical_cores", &self.cpu_physical_cores) .field("total_memory", &self.total_memory) .field("fd_limit", &self.fd_limit) + .field("proxy_socket_limit_per_cpu_core", &self.proxy_socket_limit_per_cpu_core) .finish() } } @@ -46,8 +58,18 @@ impl Default for SystemInfo { let git_hash = git::hash(); let git_short_hash = git::short_hash(); let version = git::version(); + let proxy_socket_limit_per_cpu_core = Self::try_proxy_socket_limit_per_cpu_core(); - SystemInfo { system_id, git_hash, git_short_hash, version, cpu_physical_cores, total_memory, fd_limit } + SystemInfo { + system_id, + git_hash, + git_short_hash, + version, + cpu_physical_cores, + total_memory, + fd_limit, + proxy_socket_limit_per_cpu_core, + } }); (*system_info).clone() } @@ -72,6 +94,19 @@ impl SystemInfo { sha256.update(some_id.as_bytes()); Some(sha256.finalize().to_vec()) } + + fn try_proxy_socket_limit_per_cpu_core() -> Option { + let nginx_config_path = PathBuf::from("/etc/nginx/nginx.conf"); + if nginx_config_path.exists() { + read_to_string(nginx_config_path) + .ok() + .and_then(|content| content.lines().find(|line| line.trim().starts_with("worker_connections")).map(String::from)) + .and_then(|line| line.split_whitespace().nth(1).map(|v| v.replace(";", ""))) + .and_then(|value| value.parse::().ok()) + } else { + None + } + } } impl AsRef for SystemInfo { @@ -79,3 +114,14 @@ impl AsRef for SystemInfo { self } } + +// #[cfg(test)] +// mod tests { +// use super::*; + +// #[test] +// fn test_system_info() { +// let system_info = SystemInfo::default(); +// println!("{:#?}", system_info); +// } +// } From 06a874f4ee174d056d0c5c3d11ba1c3be545b8f4 Mon Sep 17 00:00:00 2001 From: starkbamse <139136798+starkbamse@users.noreply.github.com> Date: Thu, 5 Sep 2024 18:51:04 +0200 Subject: [PATCH 3/8] Deprecate zigbuild and glibc in favor of static musl binaries for Linux builds. (#541) * CTNG Config file, Musl build instructions - Crosstools-ng configuration file for quick reproducable builds on musl. - Instructions for how to build RK on musl. * Test * Update ci.yaml * Test crosstools install * Cache ct-ng build * Update ci.yaml * Update ci.yaml * Update ci.yaml * Update ci.yaml * Update ci.yaml * Update ci.yaml * Update ci.yaml * Update ci.yaml * Update ci.yaml * Update ci.yaml * Update ci.yaml * Update ci.yaml * Fix error in command * Update ci.yaml * Update ci.yaml * Update ci.yaml * Update ci.yaml * Update ci.yaml * Update ci.yaml * Update ci.yaml * Update ci.yaml * Update ci.yaml * Update ci.yaml * Comments, naming * Update ci.yaml * Update ci.yaml * Update ci.yaml * Merge new musl build with old CI, Release builds - Merges the old CI script with the new musl build. - Update deploy.yaml to use updated musl toolchain to build musl target for linux. * Move to workspace * Delete musl-build.md * Lock to ctng version 1.26 * Checkout fix * Revert master change * Indentation * Revert "Indentation" This reverts commit 6a7e6c094052f1b5848d1e3e9154f4f0164fad05. * Revert "Revert master change" This reverts commit 1a047e46863ca9383eea169fd2665a333c9d5431. * Update ci.yaml * Force mimalloc * Compress into script * Fix typo * Update build.sh * Replace bloaded config file * Update build.sh * Update build.sh * Source script * Revert vendor * Update defconfig * Update defconfig * Update defconfig * Update build.sh * Update build.sh * Update build.sh * Update build.sh * Update defconfig * Delete defconfig * Create defconfig * Update build.sh * Deprecate config, use default preset * Update build.sh * Add preset hash logic in script * Move preset hash update Move preset hash update after openssl build * Use openssl crate * Update exports, cache config * Remove spaces in export command * Update names Should not trigger cache * Move source preset * CD before preset * Add comment Adds comment and should invalidate cache. --- .github/workflows/ci.yaml | 30 +++++++---- .github/workflows/deploy.yaml | 31 ++++++----- musl-toolchain/build.sh | 96 +++++++++++++++++++++++++++++++++++ musl-toolchain/preset.sh | 4 ++ rpc/wrpc/server/Cargo.toml | 8 ++- 5 files changed, 144 insertions(+), 25 deletions(-) create mode 100755 musl-toolchain/build.sh create mode 100755 musl-toolchain/preset.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 27fe1376a0..693266885c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -353,9 +353,8 @@ jobs: with: name: kaspa-wasm32-sdk-${{ env.SHORT_SHA }}.zip path: wasm/release/kaspa-wasm32-sdk-${{ env.SHORT_SHA }}.zip - build-release: - name: Build Ubuntu Release + name: Build Linux Release runs-on: ubuntu-latest steps: - name: Checkout sources @@ -369,7 +368,7 @@ jobs: - name: Install stable toolchain uses: dtolnay/rust-toolchain@stable - - name: Cache + - name: Cache Cargo Build Outputs uses: actions/cache@v4 with: path: | @@ -379,14 +378,23 @@ jobs: ~/.cargo/git/db/ target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: Cache Toolchain + uses: actions/cache@v4 + with: + path: | + ~/x-tools + key: ${{ runner.os }}-musl-${{ hashFiles('**/musl-toolchain/preset.sh') }} + restore-keys: | + ${{ runner.os }}-musl- - - name: Install zig - if: runner.os == 'Linux' - uses: goto-bus-stop/setup-zig@v2 # needed for cargo-zigbuild - - - name: Build on Linux + + - name: Build RK with musl toolchain if: runner.os == 'Linux' - # We're using musl to make the binaries statically linked and portable run: | - cargo install cargo-zigbuild - cargo --verbose zigbuild --bin kaspad --bin simpa --bin rothschild --release --target x86_64-unknown-linux-gnu.2.27 # Use an older glibc version + # Run build script for musl toolchain + source musl-toolchain/build.sh + # Build for musl + cargo --verbose build --bin kaspad --bin rothschild --bin kaspa-wallet --release --target x86_64-unknown-linux-musl diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 567adb557f..0f9cac899f 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -29,7 +29,7 @@ jobs: - name: Install stable toolchain uses: dtolnay/rust-toolchain@stable - - name: Cache + - name: Cache Cargo Build Outputs uses: actions/cache@v3 with: path: | @@ -40,23 +40,30 @@ jobs: target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Install zig on linux - if: runner.os == 'Linux' - uses: goto-bus-stop/setup-zig@v2 # needed for cargo-zigbuild + - name: Cache Toolchain + uses: actions/cache@v4 + with: + path: | + ~/x-tools + key: ${{ runner.os }}-musl-${{ hashFiles('**/musl-toolchain/preset.sh') }} + restore-keys: | + ${{ runner.os }}-musl- - name: Build on Linux if: runner.os == 'Linux' # We're using musl to make the binaries statically linked and portable run: | - cargo install cargo-zigbuild - cargo --verbose zigbuild --bin kaspad --bin simpa --bin rothschild --bin kaspa-wallet --release --target x86_64-unknown-linux-gnu.2.27 # Use an older glibc version + # Run build script for musl toolchain + source musl-toolchain/build.sh + + # Build for musl + cargo --verbose build --bin kaspad --bin rothschild --bin kaspa-wallet --release --target x86_64-unknown-linux-musl mkdir bin || true - cp target/x86_64-unknown-linux-gnu/release/kaspad bin/ - cp target/x86_64-unknown-linux-gnu/release/simpa bin/ - cp target/x86_64-unknown-linux-gnu/release/rothschild bin/ - cp target/x86_64-unknown-linux-gnu/release/kaspa-wallet bin/ - archive="bin/rusty-kaspa-${{ github.event.release.tag_name }}-linux-gnu-amd64.zip" - asset_name="rusty-kaspa-${{ github.event.release.tag_name }}-linux-gnu-amd64.zip" + cp target/x86_64-unknown-linux-musl/release/kaspad bin/ + cp target/x86_64-unknown-linux-musl/release/rothschild bin/ + cp target/x86_64-unknown-linux-musl/release/kaspa-wallet bin/ + archive="bin/rusty-kaspa-${{ github.event.release.tag_name }}-linux-musl-amd64.zip" + asset_name="rusty-kaspa-${{ github.event.release.tag_name }}-linux-musl-amd64.zip" zip -r "${archive}" ./bin/* echo "archive=${archive}" >> $GITHUB_ENV echo "asset_name=${asset_name}" >> $GITHUB_ENV diff --git a/musl-toolchain/build.sh b/musl-toolchain/build.sh new file mode 100755 index 0000000000..b32314082b --- /dev/null +++ b/musl-toolchain/build.sh @@ -0,0 +1,96 @@ +#!/bin/bash + +PRESET_HASH_FILE="$HOME/x-tools/preset_hash" + +# Calculate the hash of the preset file +CURRENT_PRESET_HASH=$(sha256sum $GITHUB_WORKSPACE/musl-toolchain/preset.sh | awk '{print $1}') + +echo "Current preset hash: $CURRENT_PRESET_HASH" + +# Traverse to working directory +cd $GITHUB_WORKSPACE/musl-toolchain + +# Set the preset +source preset.sh + +# If the toolchain is not installed or the preset has changed or the preset hash file does not exist +if [ ! -d "$HOME/x-tools" ] || [ ! -f "$PRESET_HASH_FILE" ] || [ "$(cat $PRESET_HASH_FILE)" != "$CURRENT_PRESET_HASH" ]; then + # Install dependencies + sudo apt-get update + sudo apt-get install -y autoconf automake libtool libtool-bin unzip help2man python3.10-dev gperf bison flex texinfo gawk libncurses5-dev + + # Clone crosstool-ng + git clone https://github.com/crosstool-ng/crosstool-ng + + # Configure and build crosstool-ng + cd crosstool-ng + # Use version 1.26 + git checkout crosstool-ng-1.26.0 + ./bootstrap + ./configure --prefix=$HOME/ctng + make + make install + # Add crosstool-ng to PATH + export PATH=$HOME/ctng/bin:$PATH + + + + # Load toolchainc configuration + ct-ng $CTNG_PRESET + + # Build the toolchain + ct-ng build > build.log 2>&1 + + # Set status to the exit code of the build + status=$? + + # We store the log in a file because it bloats the screen too much + # on GitHub Actions. We print it only if the build fails. + echo "Build result:" + if [ $status -eq 0 ]; then + echo "Build succeeded" + ls -la $HOME/x-tools + # Store the current hash of preset.sh after successful build + echo "$CURRENT_PRESET_HASH" > "$PRESET_HASH_FILE" + else + echo "Build failed, here's the log:" + cat .config + cat build.log + fi +fi + +# Update toolchain variables: C compiler, C++ compiler, linker, and archiver +export CC=$HOME/x-tools/$CTNG_PRESET/bin/$CTNG_PRESET-gcc +export CXX=$HOME/x-tools/$CTNG_PRESET/bin/$CTNG_PRESET-g++ +export LD=$HOME/x-tools/$CTNG_PRESET/bin/$CTNG_PRESET-ld +export AR=$HOME/x-tools/$CTNG_PRESET/bin/$CTNG_PRESET-ar + +# Exports for cc crate +# https://docs.rs/cc/latest/cc/#external-configuration-via-environment-variables +export RANLIB_x86_64_unknown_linux_musl=$HOME/x-tools/$CTNG_PRESET/bin/$CTNG_PRESET-ranlib +export CC_x86_64_unknown_linux_musl=$CC +export CXX_x86_64_unknown_linux_musl=$CXX +export AR_x86_64_unknown_linux_musl=$AR +export LD_x86_64_unknown_linux_musl=$LD + +# Set environment variables for static linking +export OPENSSL_STATIC=true +export RUSTFLAGS="-C link-arg=-static" + +# We specify the compiler that will invoke linker +export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=$CC + +# Add target +rustup target add x86_64-unknown-linux-musl + +# Install missing dependencies +cargo fetch --target x86_64-unknown-linux-musl + +# Patch missing include in librocksdb-sys-0.16.0+8.10.0. Credit: @supertypo +FILE_PATH=$(find $HOME/.cargo/registry/src/ -path "*/librocksdb-sys-0.16.0+8.10.0/*/offpeak_time_info.h") + +if [ -n "$FILE_PATH" ]; then + sed -i '1i #include ' "$FILE_PATH" +else + echo "No such file for sed modification." +fi \ No newline at end of file diff --git a/musl-toolchain/preset.sh b/musl-toolchain/preset.sh new file mode 100755 index 0000000000..63e98a7685 --- /dev/null +++ b/musl-toolchain/preset.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# Sets the preset that will be used by crosstool-ng +# Available presets can be fetched with: ct-ng list-samples +export CTNG_PRESET="x86_64-multilib-linux-musl" \ No newline at end of file diff --git a/rpc/wrpc/server/Cargo.toml b/rpc/wrpc/server/Cargo.toml index f0f55aed75..3bf285c3fc 100644 --- a/rpc/wrpc/server/Cargo.toml +++ b/rpc/wrpc/server/Cargo.toml @@ -35,8 +35,12 @@ workflow-log.workspace = true workflow-rpc.workspace = true workflow-serializer.workspace = true -[target.x86_64-unknown-linux-gnu.dependencies] -# Adding explicitely the openssl dependency here is needed for a successful build with zigbuild +# Adding explicitely the openssl dependency here is needed for a successful build with zigbuild and musl # as used in the release deployment in GitHub CI # see: https://github.com/rust-cross/cargo-zigbuild/issues/127 + +[target.x86_64-unknown-linux-gnu.dependencies] +openssl = { version = "0.10", features = ["vendored"] } + +[target.x86_64-unknown-linux-musl.dependencies] openssl = { version = "0.10", features = ["vendored"] } From afbcf9e473acfe238b43785cab52f09387307588 Mon Sep 17 00:00:00 2001 From: starkbamse <139136798+starkbamse@users.noreply.github.com> Date: Fri, 6 Sep 2024 05:40:53 +0200 Subject: [PATCH 4/8] Change directory back to repo root & Fix Rust v1.81 lints (#545) * Change directory back to repodir Change directory back to repodir after building toolchain * Clippy * Update crypto/txscript/src/caches.rs Co-authored-by: Maxim <59533214+biryukovmaxim@users.noreply.github.com> * Update crypto/txscript/src/caches.rs * rename `is_none_or` -> `is_none_or_ex` to avoid conflict with future std * remove `use std::mem::size_of` wherever possible (added to std prelude recently) --------- Co-authored-by: Maxim <59533214+biryukovmaxim@users.noreply.github.com> Co-authored-by: Michael Sutton --- .github/workflows/deploy.yaml | 5 ++++- consensus/core/src/utxo/utxo_diff.rs | 2 +- consensus/src/consensus/storage.rs | 2 +- consensus/src/model/stores/acceptance_data.rs | 1 - consensus/src/model/stores/block_transactions.rs | 1 - consensus/src/model/stores/ghostdag.rs | 1 - consensus/src/model/stores/headers.rs | 1 - consensus/src/model/stores/mod.rs | 7 +++---- consensus/src/model/stores/utxo_set.rs | 5 ++--- .../pipeline/body_processor/body_validation_in_context.rs | 2 +- consensus/src/processes/coinbase.rs | 2 +- consensus/src/processes/pruning.rs | 2 +- consensus/src/processes/sync/mod.rs | 2 +- crypto/muhash/fuzz/fuzz_targets/u3072.rs | 1 - crypto/muhash/src/u3072.rs | 4 ++-- crypto/txscript/src/caches.rs | 3 +-- crypto/txscript/src/data_stack.rs | 1 - crypto/txscript/src/opcodes/mod.rs | 2 -- database/src/registry.rs | 4 ++-- indexes/utxoindex/src/stores/indexed_utxos.rs | 4 +--- math/src/uint.rs | 2 +- mining/src/testutils/coinbase_mock.rs | 1 - protocol/flows/src/flowcontext/orphans.rs | 7 ++++--- protocol/p2p/src/convert/net_address.rs | 5 +---- utils/src/mem_size.rs | 2 +- utils/src/option.rs | 5 +++-- 26 files changed, 31 insertions(+), 43 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 0f9cac899f..8f46cb1fe5 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -55,7 +55,10 @@ jobs: run: | # Run build script for musl toolchain source musl-toolchain/build.sh - + + # Go back to the workspace + cd $GITHUB_WORKSPACE + # Build for musl cargo --verbose build --bin kaspad --bin rothschild --bin kaspa-wallet --release --target x86_64-unknown-linux-musl mkdir bin || true diff --git a/consensus/core/src/utxo/utxo_diff.rs b/consensus/core/src/utxo/utxo_diff.rs index 3cd12f3f5b..fb4ffbcbaa 100644 --- a/consensus/core/src/utxo/utxo_diff.rs +++ b/consensus/core/src/utxo/utxo_diff.rs @@ -5,7 +5,7 @@ use super::{ use crate::tx::{TransactionOutpoint, UtxoEntry, VerifiableTransaction}; use kaspa_utils::mem_size::MemSizeEstimator; use serde::{Deserialize, Serialize}; -use std::{collections::hash_map::Entry::Vacant, mem::size_of}; +use std::collections::hash_map::Entry::Vacant; pub trait ImmutableUtxoDiff { fn added(&self) -> &UtxoCollection; diff --git a/consensus/src/consensus/storage.rs b/consensus/src/consensus/storage.rs index d53324fc6f..89a0f5e265 100644 --- a/consensus/src/consensus/storage.rs +++ b/consensus/src/consensus/storage.rs @@ -31,7 +31,7 @@ use kaspa_consensus_core::{blockstatus::BlockStatus, BlockHashSet}; use kaspa_database::registry::DatabaseStorePrefixes; use kaspa_hashes::Hash; use parking_lot::RwLock; -use std::{mem::size_of, ops::DerefMut, sync::Arc}; +use std::{ops::DerefMut, sync::Arc}; pub struct ConsensusStorage { // DB diff --git a/consensus/src/model/stores/acceptance_data.rs b/consensus/src/model/stores/acceptance_data.rs index a66fcdcfec..83f6c8f13b 100644 --- a/consensus/src/model/stores/acceptance_data.rs +++ b/consensus/src/model/stores/acceptance_data.rs @@ -12,7 +12,6 @@ use kaspa_utils::mem_size::MemSizeEstimator; use rocksdb::WriteBatch; use serde::Deserialize; use serde::Serialize; -use std::mem::size_of; use std::sync::Arc; pub trait AcceptanceDataStoreReader { diff --git a/consensus/src/model/stores/block_transactions.rs b/consensus/src/model/stores/block_transactions.rs index 050606d3ce..5042682888 100644 --- a/consensus/src/model/stores/block_transactions.rs +++ b/consensus/src/model/stores/block_transactions.rs @@ -9,7 +9,6 @@ use kaspa_hashes::Hash; use kaspa_utils::mem_size::MemSizeEstimator; use rocksdb::WriteBatch; use serde::{Deserialize, Serialize}; -use std::mem::size_of; use std::sync::Arc; pub trait BlockTransactionsStoreReader { diff --git a/consensus/src/model/stores/ghostdag.rs b/consensus/src/model/stores/ghostdag.rs index 89c4686c5f..bcf860b3a3 100644 --- a/consensus/src/model/stores/ghostdag.rs +++ b/consensus/src/model/stores/ghostdag.rs @@ -14,7 +14,6 @@ use kaspa_utils::mem_size::MemSizeEstimator; use rocksdb::WriteBatch; use serde::{Deserialize, Serialize}; use std::iter::once; -use std::mem::size_of; use std::{cell::RefCell, sync::Arc}; /// Re-export for convenience diff --git a/consensus/src/model/stores/headers.rs b/consensus/src/model/stores/headers.rs index 64e10a90be..85668f6992 100644 --- a/consensus/src/model/stores/headers.rs +++ b/consensus/src/model/stores/headers.rs @@ -1,4 +1,3 @@ -use std::mem::size_of; use std::sync::Arc; use kaspa_consensus_core::{header::Header, BlockHasher, BlockLevel}; diff --git a/consensus/src/model/stores/mod.rs b/consensus/src/model/stores/mod.rs index 8397558863..9fda332960 100644 --- a/consensus/src/model/stores/mod.rs +++ b/consensus/src/model/stores/mod.rs @@ -3,10 +3,6 @@ pub mod block_transactions; pub mod block_window_cache; pub mod children; pub mod daa; -pub mod selected_chain; -use std::{fmt::Display, mem::size_of}; - -pub use kaspa_database; pub mod depth; pub mod ghostdag; pub mod headers; @@ -16,6 +12,7 @@ pub mod pruning; pub mod pruning_utxoset; pub mod reachability; pub mod relations; +pub mod selected_chain; pub mod statuses; pub mod tips; pub mod utxo_diffs; @@ -23,7 +20,9 @@ pub mod utxo_multisets; pub mod utxo_set; pub mod virtual_state; +pub use kaspa_database; pub use kaspa_database::prelude::DB; +use std::fmt::Display; #[derive(PartialEq, Eq, Clone, Copy, Hash)] pub(crate) struct U64Key([u8; size_of::()]); diff --git a/consensus/src/model/stores/utxo_set.rs b/consensus/src/model/stores/utxo_set.rs index fbe64deaf3..03add09482 100644 --- a/consensus/src/model/stores/utxo_set.rs +++ b/consensus/src/model/stores/utxo_set.rs @@ -28,7 +28,7 @@ pub trait UtxoSetStore: UtxoSetStoreReader { fn write_many(&mut self, utxos: &[(TransactionOutpoint, UtxoEntry)]) -> Result<(), StoreError>; } -pub const UTXO_KEY_SIZE: usize = kaspa_hashes::HASH_SIZE + std::mem::size_of::(); +pub const UTXO_KEY_SIZE: usize = kaspa_hashes::HASH_SIZE + size_of::(); #[derive(Eq, Hash, PartialEq, Debug, Copy, Clone)] struct UtxoKey([u8; UTXO_KEY_SIZE]); @@ -81,8 +81,7 @@ impl From for TransactionOutpoint { fn from(k: UtxoKey) -> Self { let transaction_id = Hash::from_slice(&k.0[..kaspa_hashes::HASH_SIZE]); let index = TransactionIndexType::from_le_bytes( - <[u8; std::mem::size_of::()]>::try_from(&k.0[kaspa_hashes::HASH_SIZE..]) - .expect("expecting index size"), + <[u8; size_of::()]>::try_from(&k.0[kaspa_hashes::HASH_SIZE..]).expect("expecting index size"), ); Self::new(transaction_id, index) } diff --git a/consensus/src/pipeline/body_processor/body_validation_in_context.rs b/consensus/src/pipeline/body_processor/body_validation_in_context.rs index aa2f345b36..b03643df87 100644 --- a/consensus/src/pipeline/body_processor/body_validation_in_context.rs +++ b/consensus/src/pipeline/body_processor/body_validation_in_context.rs @@ -37,7 +37,7 @@ impl BlockBodyProcessor { .copied() .filter(|parent| { let status_option = statuses_read_guard.get(*parent).unwrap_option(); - status_option.is_none_or(|s| !s.has_block_body()) + status_option.is_none_or_ex(|s| !s.has_block_body()) }) .collect(); if !missing.is_empty() { diff --git a/consensus/src/processes/coinbase.rs b/consensus/src/processes/coinbase.rs index 4e3c36b797..f79bbed751 100644 --- a/consensus/src/processes/coinbase.rs +++ b/consensus/src/processes/coinbase.rs @@ -5,7 +5,7 @@ use kaspa_consensus_core::{ tx::{ScriptPublicKey, ScriptVec, Transaction, TransactionOutput}, BlockHashMap, BlockHashSet, }; -use std::{convert::TryInto, mem::size_of}; +use std::convert::TryInto; use crate::{constants, model::stores::ghostdag::GhostdagData}; diff --git a/consensus/src/processes/pruning.rs b/consensus/src/processes/pruning.rs index 0fa1f76243..7c534af8ed 100644 --- a/consensus/src/processes/pruning.rs +++ b/consensus/src/processes/pruning.rs @@ -213,7 +213,7 @@ impl< let mut expected_pps_queue = VecDeque::new(); for current in self.reachability_service.backward_chain_iterator(hst, pruning_info.pruning_point, false) { let current_header = self.headers_store.get_header(current).unwrap(); - if expected_pps_queue.back().is_none_or(|&&h| h != current_header.pruning_point) { + if expected_pps_queue.back().is_none_or_ex(|&&h| h != current_header.pruning_point) { expected_pps_queue.push_back(current_header.pruning_point); } } diff --git a/consensus/src/processes/sync/mod.rs b/consensus/src/processes/sync/mod.rs index 7b84801118..8472229682 100644 --- a/consensus/src/processes/sync/mod.rs +++ b/consensus/src/processes/sync/mod.rs @@ -191,7 +191,7 @@ impl< } } - if highest_with_body.is_none_or(|&h| h == high) { + if highest_with_body.is_none_or_ex(|&h| h == high) { return Ok(vec![]); }; diff --git a/crypto/muhash/fuzz/fuzz_targets/u3072.rs b/crypto/muhash/fuzz/fuzz_targets/u3072.rs index 584006628a..115c6f4a63 100644 --- a/crypto/muhash/fuzz/fuzz_targets/u3072.rs +++ b/crypto/muhash/fuzz/fuzz_targets/u3072.rs @@ -4,7 +4,6 @@ use kaspa_muhash::u3072::{self, U3072}; use num_bigint::BigInt; use num_integer::Integer; use num_traits::{One, Signed}; -use std::mem::size_of; fuzz_target!(|data: &[u8]| { if data.len() < muhash::SERIALIZED_MUHASH_SIZE { diff --git a/crypto/muhash/src/u3072.rs b/crypto/muhash/src/u3072.rs index 8d37f83810..82021eb88d 100644 --- a/crypto/muhash/src/u3072.rs +++ b/crypto/muhash/src/u3072.rs @@ -15,8 +15,8 @@ pub(crate) type DoubleLimb = u128; //#[cfg(target_pointer_width = "32")] //pub(crate) type DoubleLimb = u64; -const LIMB_SIZE_BYTES: usize = std::mem::size_of::(); -const LIMB_SIZE: usize = std::mem::size_of::() * 8; +const LIMB_SIZE_BYTES: usize = size_of::(); +const LIMB_SIZE: usize = Limb::BITS as usize; pub const LIMBS: usize = crate::ELEMENT_BYTE_SIZE / LIMB_SIZE_BYTES; pub const PRIME_DIFF: Limb = 1103717; diff --git a/crypto/txscript/src/caches.rs b/crypto/txscript/src/caches.rs index b3911fcf40..11d4682604 100644 --- a/crypto/txscript/src/caches.rs +++ b/crypto/txscript/src/caches.rs @@ -32,9 +32,8 @@ impl Option { - self.map.read().get(key).cloned().map(|data| { + self.map.read().get(key).cloned().inspect(|_data| { self.counters.get_counts.fetch_add(1, Ordering::Relaxed); - data }) } diff --git a/crypto/txscript/src/data_stack.rs b/crypto/txscript/src/data_stack.rs index 74988042ad..5d8ea18ed6 100644 --- a/crypto/txscript/src/data_stack.rs +++ b/crypto/txscript/src/data_stack.rs @@ -1,7 +1,6 @@ use crate::TxScriptError; use core::fmt::Debug; use core::iter; -use core::mem::size_of; const DEFAULT_SCRIPT_NUM_LEN: usize = 4; diff --git a/crypto/txscript/src/opcodes/mod.rs b/crypto/txscript/src/opcodes/mod.rs index 5d6096b7a3..4406bd5b6d 100644 --- a/crypto/txscript/src/opcodes/mod.rs +++ b/crypto/txscript/src/opcodes/mod.rs @@ -1,5 +1,3 @@ -use core::mem::size_of; - #[macro_use] mod macros; diff --git a/database/src/registry.rs b/database/src/registry.rs index 9e1b129d6f..752efb97b3 100644 --- a/database/src/registry.rs +++ b/database/src/registry.rs @@ -95,8 +95,8 @@ mod tests { let prefix = DatabaseStorePrefixes::AcceptanceData; assert_eq!(&[prefix as u8], prefix.as_ref()); assert_eq!( - std::mem::size_of::(), - std::mem::size_of::(), + size_of::(), + size_of::(), "DatabaseStorePrefixes is expected to have the same memory layout of u8" ); } diff --git a/indexes/utxoindex/src/stores/indexed_utxos.rs b/indexes/utxoindex/src/stores/indexed_utxos.rs index a96f5e46b7..c9bce2c717 100644 --- a/indexes/utxoindex/src/stores/indexed_utxos.rs +++ b/indexes/utxoindex/src/stores/indexed_utxos.rs @@ -11,7 +11,6 @@ use kaspa_index_core::indexed_utxos::BalanceByScriptPublicKey; use serde::{Deserialize, Serialize}; use std::collections::HashSet; use std::fmt::Display; -use std::mem::size_of; use std::sync::Arc; pub const VERSION_TYPE_SIZE: usize = size_of::(); // Const since we need to re-use this a few times. @@ -67,8 +66,7 @@ impl From for TransactionOutpoint { fn from(key: TransactionOutpointKey) -> Self { let transaction_id = Hash::from_slice(&key.0[..kaspa_hashes::HASH_SIZE]); let index = TransactionIndexType::from_le_bytes( - <[u8; std::mem::size_of::()]>::try_from(&key.0[kaspa_hashes::HASH_SIZE..]) - .expect("expected index size"), + <[u8; size_of::()]>::try_from(&key.0[kaspa_hashes::HASH_SIZE..]).expect("expected index size"), ); Self::new(transaction_id, index) } diff --git a/math/src/uint.rs b/math/src/uint.rs index deb01496e2..4ecc1fe122 100644 --- a/math/src/uint.rs +++ b/math/src/uint.rs @@ -15,7 +15,7 @@ macro_rules! construct_uint { pub const MIN: Self = Self::ZERO; pub const MAX: Self = $name([u64::MAX; $n_words]); pub const BITS: u32 = $n_words * u64::BITS; - pub const BYTES: usize = $n_words * core::mem::size_of::(); + pub const BYTES: usize = $n_words * size_of::(); pub const LIMBS: usize = $n_words; #[inline] diff --git a/mining/src/testutils/coinbase_mock.rs b/mining/src/testutils/coinbase_mock.rs index 12e0905a8a..8d19c2fcd0 100644 --- a/mining/src/testutils/coinbase_mock.rs +++ b/mining/src/testutils/coinbase_mock.rs @@ -4,7 +4,6 @@ use kaspa_consensus_core::{ subnets::SUBNETWORK_ID_COINBASE, tx::{Transaction, TransactionOutput}, }; -use std::mem::size_of; const LENGTH_OF_BLUE_SCORE: usize = size_of::(); const LENGTH_OF_SUBSIDY: usize = size_of::(); diff --git a/protocol/flows/src/flowcontext/orphans.rs b/protocol/flows/src/flowcontext/orphans.rs index d1122b0e07..f18649e558 100644 --- a/protocol/flows/src/flowcontext/orphans.rs +++ b/protocol/flows/src/flowcontext/orphans.rs @@ -166,7 +166,7 @@ impl OrphanBlocksPool { } } else { let status = consensus.async_get_block_status(current).await; - if status.is_none_or(|s| s.is_header_only()) { + if status.is_none_or_ex(|s| s.is_header_only()) { // Block is not in the orphan pool nor does its body exist consensus-wise, so it is a root roots.push(current); } @@ -193,7 +193,8 @@ impl OrphanBlocksPool { if let Occupied(entry) = self.orphans.entry(orphan_hash) { let mut processable = true; for p in entry.get().block.header.direct_parents().iter().copied() { - if !processing.contains_key(&p) && consensus.async_get_block_status(p).await.is_none_or(|s| s.is_header_only()) { + if !processing.contains_key(&p) && consensus.async_get_block_status(p).await.is_none_or_ex(|s| s.is_header_only()) + { processable = false; break; } @@ -249,7 +250,7 @@ impl OrphanBlocksPool { let mut processable = true; for parent in block.block.header.direct_parents().iter().copied() { if self.orphans.contains_key(&parent) - || consensus.async_get_block_status(parent).await.is_none_or(|status| status.is_header_only()) + || consensus.async_get_block_status(parent).await.is_none_or_ex(|status| status.is_header_only()) { processable = false; break; diff --git a/protocol/p2p/src/convert/net_address.rs b/protocol/p2p/src/convert/net_address.rs index 5a2ffec0e5..c525300ef8 100644 --- a/protocol/p2p/src/convert/net_address.rs +++ b/protocol/p2p/src/convert/net_address.rs @@ -1,7 +1,4 @@ -use std::{ - mem::size_of, - net::{IpAddr, Ipv4Addr, Ipv6Addr}, -}; +use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; use super::error::ConversionError; use crate::pb as protowire; diff --git a/utils/src/mem_size.rs b/utils/src/mem_size.rs index c7963a40c8..449f649bc0 100644 --- a/utils/src/mem_size.rs +++ b/utils/src/mem_size.rs @@ -2,7 +2,7 @@ //! estimate sizes of run-time objects in memory, including deep heap allocations. See //! struct-level docs for more details. -use std::{collections::HashSet, mem::size_of, sync::Arc}; +use std::{collections::HashSet, sync::Arc}; use parking_lot::RwLock; diff --git a/utils/src/option.rs b/utils/src/option.rs index 9ccf96c90a..ff4779dc12 100644 --- a/utils/src/option.rs +++ b/utils/src/option.rs @@ -1,9 +1,10 @@ pub trait OptionExtensions { - fn is_none_or(&self, f: impl FnOnce(&T) -> bool) -> bool; + /// Substitute for unstable [Option::is_non_or] + fn is_none_or_ex(&self, f: impl FnOnce(&T) -> bool) -> bool; } impl OptionExtensions for Option { - fn is_none_or(&self, f: impl FnOnce(&T) -> bool) -> bool { + fn is_none_or_ex(&self, f: impl FnOnce(&T) -> bool) -> bool { match self { Some(v) => f(v), None => true, From 27cef9e06d4fe563017643cbec4843a24e383448 Mon Sep 17 00:00:00 2001 From: aspect Date: Mon, 9 Sep 2024 15:15:40 +0300 Subject: [PATCH 5/8] WIP: Updates for 15-rc3 (#546) * update unit tests to unwrap mass to u64::max * update WASM mass APIs to be more clear with the data they produce * add fingerprint() fn to PublicKey * cleanup * fix recursive mutex in From<&Transaction> for RpcTransaction * update rust-version to 1.81.0 * generator: fix incorrect change output value info triggering a sanity-check assert! --- Cargo.toml | 2 +- consensus/client/src/utxo.rs | 2 +- rpc/core/src/wasm/convert.rs | 2 +- rpc/core/src/wasm/message.rs | 4 +- wallet/core/src/tx/generator/generator.rs | 1 - wallet/core/src/tx/generator/test.rs | 59 +++++++++++++++++++++-- wallet/core/src/wasm/tx/mass.rs | 58 +++++++++++++++++----- wallet/keys/src/publickey.rs | 17 ++++++- 8 files changed, 121 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0fdc4a499f..123041aa0b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,7 +61,7 @@ members = [ ] [workspace.package] -rust-version = "1.80.0" +rust-version = "1.81.0" version = "0.14.5" authors = ["Kaspa developers"] license = "ISC" diff --git a/consensus/client/src/utxo.rs b/consensus/client/src/utxo.rs index 3f519d067f..0a8b3fdb94 100644 --- a/consensus/client/src/utxo.rs +++ b/consensus/client/src/utxo.rs @@ -445,7 +445,7 @@ impl UtxoEntryReference { let outpoint = TransactionOutpoint::simulated(); let script_public_key = kaspa_txscript::pay_to_address_script(address); let block_daa_score = 0; - let is_coinbase = true; + let is_coinbase = false; let utxo_entry = UtxoEntry { address: Some(address.clone()), outpoint, amount, script_public_key, block_daa_score, is_coinbase }; diff --git a/rpc/core/src/wasm/convert.rs b/rpc/core/src/wasm/convert.rs index 96fd8c299d..7bc68171b3 100644 --- a/rpc/core/src/wasm/convert.rs +++ b/rpc/core/src/wasm/convert.rs @@ -67,7 +67,7 @@ cfg_if::cfg_if! { subnetwork_id: inner.subnetwork_id.clone(), gas: inner.gas, payload: inner.payload.clone(), - mass: tx.get_mass(), + mass: inner.mass, verbose_data: None, } } diff --git a/rpc/core/src/wasm/message.rs b/rpc/core/src/wasm/message.rs index fdc01c86ef..6bd35f3267 100644 --- a/rpc/core/src/wasm/message.rs +++ b/rpc/core/src/wasm/message.rs @@ -1454,8 +1454,8 @@ try_from! ( args: ISubmitTransactionRequest, SubmitTransactionRequest, { } else { let tx = Transaction::try_cast_from(&transaction)?; SubmitTransactionRequest { - transaction : tx.as_ref().into(), - allow_orphan, + transaction : tx.as_ref().into(), + allow_orphan, } }; Ok(request) diff --git a/wallet/core/src/tx/generator/generator.rs b/wallet/core/src/tx/generator/generator.rs index 52dafa0f77..398ba1b4dc 100644 --- a/wallet/core/src/tx/generator/generator.rs +++ b/wallet/core/src/tx/generator/generator.rs @@ -705,7 +705,6 @@ impl Generator { Ok((DataKind::NoOp, data)) } else if stage.number_of_transactions > 0 { data.aggregate_mass += self.inner.standard_change_output_compute_mass; - data.change_output_value = Some(data.aggregate_input_value - data.transaction_fees); Ok((DataKind::Edge, data)) } else if data.aggregate_input_value < data.transaction_fees { Err(Error::InsufficientFunds { additional_needed: data.transaction_fees - data.aggregate_input_value, origin: "relay" }) diff --git a/wallet/core/src/tx/generator/test.rs b/wallet/core/src/tx/generator/test.rs index 769e13bdf7..990698b722 100644 --- a/wallet/core/src/tx/generator/test.rs +++ b/wallet/core/src/tx/generator/test.rs @@ -16,7 +16,7 @@ use workflow_log::style; use super::*; -const DISPLAY_LOGS: bool = true; +const DISPLAY_LOGS: bool = false; const DISPLAY_EXPECTED: bool = true; #[derive(Clone, Copy, Debug)] @@ -173,7 +173,7 @@ fn validate(pt: &PendingTransaction) { let compute_mass = calc.calc_compute_mass_for_unsigned_consensus_transaction(&tx, pt.minimum_signatures()); let utxo_entries = pt.utxo_entries().values().cloned().collect::>(); - let storage_mass = calc.calc_storage_mass_for_transaction_parts(&utxo_entries, &tx.outputs).unwrap_or_default(); + let storage_mass = calc.calc_storage_mass_for_transaction_parts(&utxo_entries, &tx.outputs).unwrap_or(u64::MAX); let calculated_mass = calc.combine_mass(compute_mass, storage_mass) + additional_mass; assert_eq!(pt.inner.mass, calculated_mass, "pending transaction mass does not match calculated mass"); @@ -203,7 +203,7 @@ where let compute_mass = calc.calc_compute_mass_for_unsigned_consensus_transaction(&tx, pt.minimum_signatures()); let utxo_entries = pt.utxo_entries().values().cloned().collect::>(); - let storage_mass = calc.calc_storage_mass_for_transaction_parts(&utxo_entries, &tx.outputs).unwrap_or_default(); + let storage_mass = calc.calc_storage_mass_for_transaction_parts(&utxo_entries, &tx.outputs).unwrap_or(u64::MAX); if DISPLAY_LOGS && storage_mass != 0 { println!("calculated storage mass: {} calculated_compute_mass: {}", storage_mass, compute_mass,); } @@ -323,6 +323,21 @@ impl Harness { self.clone() } + pub fn accumulate(self: &Rc, count: usize) -> Rc { + for _n in 0..count { + if DISPLAY_LOGS { + println!( + "{}", + style(format!("accumulate gathering transaction: {} ({})", _n, self.accumulator.borrow().list.len())).magenta() + ); + } + let ptx = self.generator.generate_transaction().unwrap().unwrap(); + ptx.accumulate(&mut self.accumulator.borrow_mut()); + } + // println!("accumulated `{}` transactions", self.accumulator.borrow().list.len()); + self.clone() + } + pub fn validate(self: &Rc) -> Rc { while let Some(pt) = self.generator.generate_transaction().unwrap() { pt.accumulate(&mut self.accumulator.borrow_mut()).validate(); @@ -332,7 +347,16 @@ impl Harness { pub fn finalize(self: Rc) { let pt = self.generator.generate_transaction().unwrap(); - assert!(pt.is_none(), "expected no more transactions"); + if pt.is_some() { + let mut pending = self.generator.generate_transaction().unwrap(); + let mut count = 1; + while pending.is_some() { + count += 1; + pending = self.generator.generate_transaction().unwrap(); + } + + panic!("received extra `{}` unexpected transactions", count); + } let summary = self.generator.summary(); if DISPLAY_LOGS { println!("{:#?}", summary); @@ -644,7 +668,7 @@ fn test_generator_inputs_100_outputs_1_fees_exclude_insufficient_funds() -> Resu } #[test] -fn test_generator_inputs_903_outputs_2_fees_exclude() -> Result<()> { +fn test_generator_inputs_1k_outputs_2_fees_exclude() -> Result<()> { generator(test_network_id(), &[10.0; 1_000], &[], Fees::sender(Kaspa(5.0)), [(output_address, Kaspa(9_000.0))].as_slice()) .unwrap() .harness() @@ -676,3 +700,28 @@ fn test_generator_inputs_903_outputs_2_fees_exclude() -> Result<()> { Ok(()) } + +#[test] +fn test_generator_inputs_32k_outputs_2_fees_exclude() -> Result<()> { + let f = 130.0; + generator( + test_network_id(), + &[f; 32_747], + &[], + Fees::sender(Kaspa(10_000.0)), + [(output_address, Kaspa(f * 32_747.0 - 10_001.0))].as_slice(), + ) + .unwrap() + .harness() + .accumulate(379) + .finalize(); + Ok(()) +} + +#[test] +fn test_generator_inputs_250k_outputs_2_sweep() -> Result<()> { + let f = 130.0; + let generator = make_generator(test_network_id(), &[f; 250_000], &[], Fees::None, change_address, PaymentDestination::Change); + generator.unwrap().harness().accumulate(2875).finalize(); + Ok(()) +} diff --git a/wallet/core/src/wasm/tx/mass.rs b/wallet/core/src/wasm/tx/mass.rs index 30d6a2f795..af04a55b18 100644 --- a/wallet/core/src/wasm/tx/mass.rs +++ b/wallet/core/src/wasm/tx/mass.rs @@ -1,17 +1,33 @@ use crate::imports::NetworkParams; use crate::result::Result; -use crate::tx::mass; +use crate::tx::{mass, MAXIMUM_STANDARD_TRANSACTION_MASS}; use kaspa_consensus_client::*; use kaspa_consensus_core::config::params::Params; use kaspa_consensus_core::network::{NetworkId, NetworkIdT}; use wasm_bindgen::prelude::*; use workflow_wasm::convert::*; +/// `maximumStandardTransactionMass()` returns the maximum transaction +/// size allowed by the network. +/// +/// @category Wallet SDK +/// @see {@link calculateTransactionMass} +/// @see {@link updateTransactionMass} +/// @see {@link calculateTransactionFee} +#[wasm_bindgen(js_name = maximumStandardTransactionMass)] +pub fn maximum_standard_transaction_mass() -> u64 { + MAXIMUM_STANDARD_TRANSACTION_MASS +} + /// `calculateTransactionMass()` returns the mass of the passed transaction. /// If the transaction is invalid, or the mass can not be calculated /// the function throws an error. /// +/// The mass value must not exceed the maximum standard transaction mass +/// that can be obtained using `maximumStandardTransactionMass()`. +/// /// @category Wallet SDK +/// @see {@link maximumStandardTransactionMass} /// #[wasm_bindgen(js_name = calculateTransactionMass)] pub fn calculate_unsigned_transaction_mass(network_id: NetworkIdT, tx: &TransactionT, minimum_signatures: Option) -> Result { @@ -24,39 +40,59 @@ pub fn calculate_unsigned_transaction_mass(network_id: NetworkIdT, tx: &Transact } /// `updateTransactionMass()` updates the mass property of the passed transaction. -/// If the transaction is invalid, or the mass is larger than transaction mass allowed -/// by the network, the function throws an error. +/// If the transaction is invalid, the function throws an error. +/// +/// The function returns `true` if the mass is within the maximum standard transaction mass and +/// the transaction mass is updated. Otherwise, the function returns `false`. /// -/// This is the same as `calculateTransactionMass()` but modifies the supplied +/// This is similar to `calculateTransactionMass()` but modifies the supplied /// `Transaction` object. /// /// @category Wallet SDK +/// @see {@link maximumStandardTransactionMass} +/// @see {@link calculateTransactionMass} +/// @see {@link calculateTransactionFee} /// #[wasm_bindgen(js_name = updateTransactionMass)] -pub fn update_unsigned_transaction_mass(network_id: NetworkIdT, tx: &Transaction, minimum_signatures: Option) -> Result<()> { +pub fn update_unsigned_transaction_mass(network_id: NetworkIdT, tx: &Transaction, minimum_signatures: Option) -> Result { let network_id = NetworkId::try_owned_from(network_id)?; let consensus_params = Params::from(network_id); let network_params = NetworkParams::from(network_id); let mc = mass::MassCalculator::new(&consensus_params, network_params); let mass = mc.calc_overall_mass_for_unsigned_client_transaction(tx, minimum_signatures.unwrap_or(1))?; - tx.set_mass(mass); - Ok(()) + if mass > MAXIMUM_STANDARD_TRANSACTION_MASS { + Ok(false) + } else { + tx.set_mass(mass); + Ok(true) + } } /// `calculateTransactionFee()` returns minimum fees needed for the transaction to be /// accepted by the network. If the transaction is invalid or the mass can not be calculated, -/// the function throws an error. +/// the function throws an error. If the mass exceeds the maximum standard transaction mass, +/// the function returns `undefined`. /// /// @category Wallet SDK +/// @see {@link maximumStandardTransactionMass} +/// @see {@link calculateTransactionMass} +/// @see {@link updateTransactionMass} /// #[wasm_bindgen(js_name = calculateTransactionFee)] -pub fn calculate_unsigned_transaction_fee(network_id: NetworkIdT, tx: &TransactionT, minimum_signatures: Option) -> Result { +pub fn calculate_unsigned_transaction_fee( + network_id: NetworkIdT, + tx: &TransactionT, + minimum_signatures: Option, +) -> Result> { let tx = Transaction::try_cast_from(tx)?; let network_id = NetworkId::try_owned_from(network_id)?; let consensus_params = Params::from(network_id); let network_params = NetworkParams::from(network_id); let mc = mass::MassCalculator::new(&consensus_params, network_params); let mass = mc.calc_overall_mass_for_unsigned_client_transaction(tx.as_ref(), minimum_signatures.unwrap_or(1))?; - let fee = mc.calc_fee_for_mass(mass); - Ok(fee) + if mass > MAXIMUM_STANDARD_TRANSACTION_MASS { + Ok(None) + } else { + Ok(Some(mc.calc_fee_for_mass(mass))) + } } diff --git a/wallet/keys/src/publickey.rs b/wallet/keys/src/publickey.rs index c26903db53..d63eca491c 100644 --- a/wallet/keys/src/publickey.rs +++ b/wallet/keys/src/publickey.rs @@ -17,10 +17,12 @@ //! ``` //! -use kaspa_consensus_core::network::NetworkType; - use crate::imports::*; +use kaspa_consensus_core::network::NetworkType; +use ripemd::{Digest, Ripemd160}; +use sha2::Sha256; + /// Data structure that envelopes a PublicKey. /// Only supports Schnorr-based addresses. /// @category Wallet SDK @@ -69,6 +71,17 @@ impl PublicKey { pub fn to_x_only_public_key(&self) -> XOnlyPublicKey { self.xonly_public_key.into() } + + /// Compute a 4-byte key fingerprint for this public key as a hex string. + /// Default implementation uses `RIPEMD160(SHA256(public_key))`. + pub fn fingerprint(&self) -> Option { + if let Some(public_key) = self.public_key.as_ref() { + let digest = Ripemd160::digest(Sha256::digest(public_key.serialize().as_slice())); + Some(digest[..4].as_ref().to_hex().into()) + } else { + None + } + } } impl PublicKey { From 7271509d7b1d82c695921c2a46d2233febdc1bce Mon Sep 17 00:00:00 2001 From: Elichai Turkel Date: Tue, 10 Sep 2024 00:33:42 +0300 Subject: [PATCH 6/8] Replace openssl with rustls + ring + webpki_roots (#547) * Remove openssl and replace with rustls + ring + webpki_roots * - init calls, - unused imports - Removed init calls - Removed unused imports * Add rustls to network stack --------- Co-authored-by: starkbamse <139136798+starkbamse@users.noreply.github.com> --- Cargo.lock | 333 +++++++++++++++---------------------- Cargo.toml | 37 +++-- rpc/grpc/client/Cargo.toml | 1 + rpc/grpc/server/Cargo.toml | 1 + rpc/wrpc/client/Cargo.toml | 1 + rpc/wrpc/server/Cargo.toml | 11 +- rpc/wrpc/wasm/Cargo.toml | 1 + simpa/Cargo.toml | 2 +- wallet/wasm/Cargo.toml | 2 +- 9 files changed, 162 insertions(+), 227 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d1ebf9cfac..1deb983e79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -538,7 +538,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "rustc-hash", + "rustc-hash 1.1.0", "shlex", "which", ] @@ -558,7 +558,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "rustc-hash", + "rustc-hash 1.1.0", "shlex", "syn 2.0.75", ] @@ -1356,7 +1356,7 @@ dependencies = [ "lazy_static", "mintex", "parking_lot", - "rustc-hash", + "rustc-hash 1.1.0", "serde", "serde_json", "thousands", @@ -1606,21 +1606,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -2106,6 +2091,7 @@ dependencies = [ "tokio", "tokio-rustls 0.26.0", "tower-service", + "webpki-roots 0.26.5", ] [[package]] @@ -2120,22 +2106,6 @@ dependencies = [ "tokio-io-timeout", ] -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper 1.4.1", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", -] - [[package]] name = "hyper-util" version = "0.1.7" @@ -2785,6 +2755,7 @@ dependencies = [ "prost", "rand 0.8.5", "regex", + "rustls 0.23.12", "thiserror", "tokio", "tokio-stream", @@ -2848,6 +2819,7 @@ dependencies = [ "paste", "prost", "rand 0.8.5", + "rustls 0.23.12", "thiserror", "tokio", "tokio-stream", @@ -3634,6 +3606,7 @@ dependencies = [ "paste", "rand 0.8.5", "regex", + "rustls 0.23.12", "serde", "serde-wasm-bindgen", "serde_json", @@ -3701,8 +3674,8 @@ dependencies = [ "kaspa-utils", "log", "num_cpus", - "openssl", "paste", + "rustls 0.23.12", "serde", "thiserror", "tokio", @@ -3730,6 +3703,7 @@ dependencies = [ "kaspa-rpc-macros", "kaspa-wasm-core", "kaspa-wrpc-client", + "ring", "serde", "serde-wasm-bindgen", "serde_json", @@ -4246,23 +4220,6 @@ dependencies = [ "rand 0.8.5", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "ndarray" version = "0.13.1" @@ -4524,60 +4481,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags 2.6.0", - "cfg-if 1.0.0", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.75", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-src" -version = "300.3.1+3.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7259953d42a81bf137fbbd73bd30a8e1914d6dce43c2b90ed575783a22608b91" -dependencies = [ - "cc", -] - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "openssl-src", - "pkg-config", - "vcpkg", -] - [[package]] name = "option-ext" version = "0.2.0" @@ -4926,6 +4829,54 @@ dependencies = [ "prost", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash 2.0.0", + "rustls 0.23.12", + "socket2 0.5.7", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand 0.8.5", + "ring", + "rustc-hash 2.0.0", + "rustls 0.23.12", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fe68c2e9e1a1234e218683dbdf9f9dfcb094113c5ac2b938dfcb9bab4c4140b" +dependencies = [ + "libc", + "once_cell", + "socket2 0.5.7", + "tracing", + "windows-sys 0.59.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -5117,29 +5068,31 @@ dependencies = [ "http-body-util", "hyper 1.4.1", "hyper-rustls", - "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls 0.23.12", "rustls-pemfile 2.1.3", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper 1.0.1", "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls 0.26.0", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots 0.26.5", "windows-registry", ] @@ -5222,6 +5175,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustc_version" version = "0.4.0" @@ -5277,6 +5236,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" dependencies = [ "once_cell", + "ring", "rustls-pki-types", "rustls-webpki 0.102.6", "subtle", @@ -5359,15 +5319,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "schannel" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" -dependencies = [ - "windows-sys 0.52.0", -] - [[package]] name = "scoped-tls" version = "1.0.1" @@ -5410,29 +5361,6 @@ dependencies = [ "cc", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags 2.6.0", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "semver" version = "1.0.23" @@ -5875,9 +5803,9 @@ dependencies = [ [[package]] name = "system-configuration" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658bc6ee10a9b4fcf576e9b0819d95ec16f4d2c02d39fd83ac1c8789785c4a42" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ "bitflags 2.6.0", "core-foundation", @@ -6068,16 +5996,6 @@ dependencies = [ "syn 2.0.75", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.24.1" @@ -6118,10 +6036,12 @@ checksum = "c6989540ced10490aaf14e6bad2e3d33728a2813310a0c71d1574304c49631cd" dependencies = [ "futures-util", "log", - "native-tls", + "rustls 0.23.12", + "rustls-pki-types", "tokio", - "tokio-native-tls", + "tokio-rustls 0.26.0", "tungstenite", + "webpki-roots 0.26.5", ] [[package]] @@ -6211,6 +6131,7 @@ dependencies = [ "tower-layer", "tower-service", "tracing", + "webpki-roots 0.25.4", ] [[package]] @@ -6332,8 +6253,9 @@ dependencies = [ "http 1.1.0", "httparse", "log", - "native-tls", "rand 0.8.5", + "rustls 0.23.12", + "rustls-pki-types", "sha1", "thiserror", "utf-8", @@ -6649,6 +6571,21 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.25.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" + +[[package]] +name = "webpki-roots" +version = "0.26.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bd24728e5af82c6c4ec1b66ac4844bdf8156257fccda846ec58b42cd0cdbe6a" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "which" version = "4.4.2" @@ -6952,9 +6889,9 @@ dependencies = [ [[package]] name = "workflow-chrome" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97134771e915c188b83d7a704b7ab626ef7a5c403deb5f09e89387536a1f3156" +checksum = "1e0c0dfbc178cb7c3a47bd2aabf6902364d2db7e4c4f5b0dad57b75d78c6fe1f" dependencies = [ "cfg-if 1.0.0", "chrome-sys", @@ -6967,9 +6904,9 @@ dependencies = [ [[package]] name = "workflow-core" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff42951d05b777c35c0650fa1d16bef24f37e4aae539d06463bcedb2d8125e90" +checksum = "a1d67bbe225ea90aa6979167f28935275506696ac867661e218893d3a42e1666" dependencies = [ "async-channel 2.3.1", "async-std", @@ -7000,9 +6937,9 @@ dependencies = [ [[package]] name = "workflow-core-macros" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "137266453ee5696254d8cc0cf1a535ad931be18860b657749f1ea79431c95129" +checksum = "65659ed208b0066a9344142218abda353eb6c6cc1fc3ae4808b750c560de004b" dependencies = [ "convert_case 0.6.0", "parse-variants", @@ -7017,9 +6954,9 @@ dependencies = [ [[package]] name = "workflow-dom" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f632b72a510fbd06711ac00edd41800f5ff789af66ef295736a0b74fa288fde" +checksum = "503bba85907753c960ddfd73b4e79bffadf521cc3c992ef2b2a29fd3af09a957" dependencies = [ "futures", "js-sys", @@ -7035,9 +6972,9 @@ dependencies = [ [[package]] name = "workflow-http" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac8974f653aa090c4627738082a3e532c5b70ef75bc5d8bdc00e9df93a84c6a8" +checksum = "a3c654c7395e448001c658309377a44a8c3d7c28c7acb30e9babbaeacb575bb0" dependencies = [ "cfg-if 1.0.0", "reqwest", @@ -7051,9 +6988,9 @@ dependencies = [ [[package]] name = "workflow-log" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8a0f71b5bd0fc4fe6e256cce3c9ba3b888f154533a9c91bec647bac715e9c37" +checksum = "64bf52c539193f219b7a79eb0c7c5f6c222ccf9b95c5e0bd59e924feb762256f" dependencies = [ "cfg-if 1.0.0", "console", @@ -7067,9 +7004,9 @@ dependencies = [ [[package]] name = "workflow-macro-tools" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "058b63fd7d255d04a5da8a4e2aab57bd8c9693dfd09a31c82ef47a65d807ca75" +checksum = "085d3045d5ca780fb589d230030e34fec962b3638d6c69806a72a7d7d1affea4" dependencies = [ "convert_case 0.6.0", "parse-variants", @@ -7080,9 +7017,9 @@ dependencies = [ [[package]] name = "workflow-node" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45c6227ecff04a63c6cd42f8d179526e49a33708b6216abcd803e9a3b3ae94ac" +checksum = "9b85c9add43b5da3bed3d0d6d92eb3a2c5986c0ae65c7c3f5189876c19648154" dependencies = [ "borsh", "futures", @@ -7101,9 +7038,9 @@ dependencies = [ [[package]] name = "workflow-nw" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9014be650ede0fdcc10e5cdeece72f30db7e35846fd4c1e9e7a0dbb2e4a11815" +checksum = "a2dd8c77686e6456be8e92237daaa88ad31546974e04514a09b1a38f812530ef" dependencies = [ "ahash", "async-trait", @@ -7125,9 +7062,9 @@ dependencies = [ [[package]] name = "workflow-panic-hook" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05c8909242a7d2f15d15d4f20f6cdc05932b394c6f34bd122de0a94eeddde493" +checksum = "74c76ca8b459e4f0c949f06ce2d45565a6769748e83ca7064d36671bbd67b4da" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen", @@ -7150,9 +7087,9 @@ dependencies = [ [[package]] name = "workflow-rpc" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e26bdfb04aee86d80206160d817132966a4cca636b3565d597171412c3a570a" +checksum = "ec4235eb167f0bef3bcbdf0c578823a0105ab5303115e3b2afb4d526e2498b08" dependencies = [ "ahash", "async-std", @@ -7180,9 +7117,9 @@ dependencies = [ [[package]] name = "workflow-rpc-macros" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d8bd0c19bab1fc8606fd8a7b89b76bbc1c70b5389a4895c7ab5c81199b31578" +checksum = "f048ca6b1c551f468c3c0c829f958e83dd15b20138b5466bb617ffde500e8cf4" dependencies = [ "parse-variants", "proc-macro-error", @@ -7193,9 +7130,9 @@ dependencies = [ [[package]] name = "workflow-serializer" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23a7e3a8965373eb92d4dde26078a08677c4aebb422096d96f36ad89c33ddadb" +checksum = "64679db6856852a472caff4ce869e3ecebe291fbccc9406e9643eb5951a0904a" dependencies = [ "ahash", "borsh", @@ -7204,9 +7141,9 @@ dependencies = [ [[package]] name = "workflow-store" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "782c42bf9ea4eff8a518c6c65b000f4d10179dedfa19348a26d34f4637571437" +checksum = "d161c4b844eee479f81306f2526266f9608a663e0a679d9fc0572ee15c144e06" dependencies = [ "async-std", "base64 0.22.1", @@ -7232,9 +7169,9 @@ dependencies = [ [[package]] name = "workflow-task" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dbc4593b9c3a635b11952e35e33b273db513ce304af368bfb2e59eca47e77f8" +checksum = "3d1a90743bb4d3f68606cb4e9a78551a53399ebc35ddba981cbb56bf2b31940a" dependencies = [ "futures", "thiserror", @@ -7244,9 +7181,9 @@ dependencies = [ [[package]] name = "workflow-task-macros" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ee242b444bc37cf4d338c3c2994a3302b82ca2fa6a33537037bfed09e1583a0" +checksum = "7ecf6be36b52dc1e16d11b55f717d9ec2fec5804aff7f392af591933ba4af45e" dependencies = [ "convert_case 0.6.0", "parse-variants", @@ -7260,9 +7197,9 @@ dependencies = [ [[package]] name = "workflow-terminal" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f7b181672f3debb02b0c1db672164a8ae827d0ae064a77c008c7beb126341b6" +checksum = "75b64a2ecf68442edf844c3138f0b78e1398cfe4279540f94cc51b4afb885e5b" dependencies = [ "async-std", "async-trait", @@ -7289,9 +7226,9 @@ dependencies = [ [[package]] name = "workflow-terminal-macros" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ac116e1d603e4462496ba2ec4133c43af29e7729493ff0ed8ea91319221cf06" +checksum = "7bf96dca7d1847a74d7566c5620610d1accc854032308489105b80c08ebf525f" dependencies = [ "convert_case 0.6.0", "parse-variants", @@ -7305,9 +7242,9 @@ dependencies = [ [[package]] name = "workflow-wasm" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a878ee79b2a117277ae24d87525686f50006b87f43cf2052401e12c330fddbbc" +checksum = "799e5fbf266e0fffb5c24d6103735eb2b94bb31f93b664b91eaaf63b4f959804" dependencies = [ "cfg-if 1.0.0", "faster-hex", @@ -7326,9 +7263,9 @@ dependencies = [ [[package]] name = "workflow-wasm-macros" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9268b990788e1bf1a307e1bc9d9f498e9ee2cb6d4ba3292d1c7b0b5d3d0d9e46" +checksum = "40237c65ecff78dbfedb13985e33f802a31f6f7de72dff12a6674fcdcf601822" dependencies = [ "js-sys", "proc-macro-error", @@ -7340,9 +7277,9 @@ dependencies = [ [[package]] name = "workflow-websocket" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15d03ec3c5ad42ba1a2bfba7e752be890ecacabf73c6da300ad78a2ffa1e3c5a" +checksum = "515483a047477c91b5142e1090cce0afc21a0139d9c0c06ea42f0d3dbf3a6fcd" dependencies = [ "ahash", "async-channel 2.3.1", diff --git a/Cargo.toml b/Cargo.toml index 123041aa0b..13ce765e21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -250,7 +250,7 @@ thiserror = "1.0.50" tokio = { version = "1.33.0", features = ["sync", "rt-multi-thread"] } tokio-stream = "0.1.14" toml = "0.8.8" -tonic = { version = "0.10.2", features = ["tls", "gzip", "transport"] } +tonic = { version = "0.10.2", features = ["tls-webpki-roots", "gzip", "transport"] } tonic-build = { version = "0.10.2", features = ["prost"] } triggered = "0.1.2" uuid = { version = "1.5.0", features = ["v4", "fast-rng", "serde"] } @@ -274,20 +274,21 @@ indexed_db_futures = "0.5.0" # workflow-perf-monitor = { path = "../../../workflow-perf-monitor-rs" } workflow-perf-monitor = "0.0.2" nw-sys = "0.1.6" +rustls = { version = "0.23", default-features = false, features = ["ring"] } # workflow dependencies -workflow-core = { version = "0.17.0" } -workflow-d3 = { version = "0.17.0" } -workflow-dom = { version = "0.17.0" } -workflow-http = { version = "0.17.0" } -workflow-log = { version = "0.17.0" } -workflow-node = { version = "0.17.0" } -workflow-nw = { version = "0.17.0" } -workflow-rpc = { version = "0.17.0" } -workflow-serializer = { version = "0.17.0" } -workflow-store = { version = "0.17.0" } -workflow-terminal = { version = "0.17.0" } -workflow-wasm = { version = "0.17.0" } +workflow-core = { version = "0.18.0" } +workflow-d3 = { version = "0.18.0" } +workflow-dom = { version = "0.18.0" } +workflow-http = { version = "0.18.0", default-features = false, features = ["rustls-tls-webpki-roots", "http2", "charset", "macos-system-configuration"] } +workflow-log = { version = "0.18.0" } +workflow-node = { version = "0.18.0" } +workflow-nw = { version = "0.18.0" } +workflow-rpc = { version = "0.18.0", default-features = false, features = ["rustls-tls-webpki-roots"] } +workflow-serializer = { version = "0.18.0" } +workflow-store = { version = "0.18.0" } +workflow-terminal = { version = "0.18.0" } +workflow-wasm = { version = "0.18.0" } # if below is enabled, this means that there is an ongoing work # on the workflow-rs crate. This requires that you clone workflow-rs @@ -295,25 +296,27 @@ workflow-wasm = { version = "0.17.0" } # workflow-core = { path = "../workflow-rs/core" } # workflow-d3 = { path = "../workflow-rs/d3" } # workflow-dom = { path = "../workflow-rs/dom" } -# workflow-http = { path = "../workflow-rs/http" } +# # Same features as default but with rustls-tls-webpki-roots instead of native-tls +# workflow-http = { path = "../workflow-rs/http", default-features = false, features = ["rustls-tls-webpki-roots", "http2", "charset", "macos-system-configuration"] } # workflow-log = { path = "../workflow-rs/log" } # workflow-node = { path = "../workflow-rs/node" } # workflow-nw = { path = "../workflow-rs/nw" } -# workflow-rpc = { path = "../workflow-rs/rpc" } +# workflow-rpc = { path = "../workflow-rs/rpc", default-features = false, features = ["rustls-tls-webpki-roots"] } # workflow-serializer = { path = "../workflow-rs/serializer" } # workflow-store = { path = "../workflow-rs/store" } # workflow-terminal = { path = "../workflow-rs/terminal" } # workflow-wasm = { path = "../workflow-rs/wasm" } + # --- # workflow-core = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" } # workflow-d3 = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" } # workflow-dom = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" } -# workflow-http = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" } +# workflow-http = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master", default-features = false, features = ["rustls-tls-webpki-roots", "http2", "charset", "macos-system-configuration"] } # workflow-log = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" } # workflow-node = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" } # workflow-nw = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" } -# workflow-rpc = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" } +# workflow-rpc = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master", default-features = false, features = ["rustls-tls-webpki-roots"] } # workflow-serializer = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" } # workflow-store = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" } # workflow-terminal = { git = "https://github.com/workflow-rs/workflow-rs.git", branch = "master" } diff --git a/rpc/grpc/client/Cargo.toml b/rpc/grpc/client/Cargo.toml index f4be5818cc..eeda4b2f8d 100644 --- a/rpc/grpc/client/Cargo.toml +++ b/rpc/grpc/client/Cargo.toml @@ -41,6 +41,7 @@ tokio-stream.workspace = true tonic = { workspace = true, features = ["gzip"] } triggered.workspace = true futures-util.workspace = true +rustls.workspace = true [features] heap = [] diff --git a/rpc/grpc/server/Cargo.toml b/rpc/grpc/server/Cargo.toml index 9f6ae74b47..452dc7d9ee 100644 --- a/rpc/grpc/server/Cargo.toml +++ b/rpc/grpc/server/Cargo.toml @@ -39,6 +39,7 @@ tokio-stream.workspace = true tonic = { workspace = true, features = ["gzip"] } triggered.workspace = true uuid.workspace = true +rustls.workspace = true [dev-dependencies] kaspa-grpc-client.workspace = true diff --git a/rpc/wrpc/client/Cargo.toml b/rpc/wrpc/client/Cargo.toml index c9dccc65b6..1cc0a21917 100644 --- a/rpc/wrpc/client/Cargo.toml +++ b/rpc/wrpc/client/Cargo.toml @@ -46,3 +46,4 @@ workflow-log.workspace = true workflow-rpc.workspace = true workflow-serializer.workspace = true workflow-wasm.workspace = true +rustls.workspace = true \ No newline at end of file diff --git a/rpc/wrpc/server/Cargo.toml b/rpc/wrpc/server/Cargo.toml index 3bf285c3fc..54137e95be 100644 --- a/rpc/wrpc/server/Cargo.toml +++ b/rpc/wrpc/server/Cargo.toml @@ -34,13 +34,4 @@ workflow-core.workspace = true workflow-log.workspace = true workflow-rpc.workspace = true workflow-serializer.workspace = true - -# Adding explicitely the openssl dependency here is needed for a successful build with zigbuild and musl -# as used in the release deployment in GitHub CI -# see: https://github.com/rust-cross/cargo-zigbuild/issues/127 - -[target.x86_64-unknown-linux-gnu.dependencies] -openssl = { version = "0.10", features = ["vendored"] } - -[target.x86_64-unknown-linux-musl.dependencies] -openssl = { version = "0.10", features = ["vendored"] } +rustls.workspace = true \ No newline at end of file diff --git a/rpc/wrpc/wasm/Cargo.toml b/rpc/wrpc/wasm/Cargo.toml index 9bd639fdb1..54019fdcaa 100644 --- a/rpc/wrpc/wasm/Cargo.toml +++ b/rpc/wrpc/wasm/Cargo.toml @@ -40,6 +40,7 @@ js-sys.workspace = true wasm-bindgen-futures.workspace = true workflow-core.workspace = true futures.workspace = true +ring = { version = "0.17", features = ["wasm32_unknown_unknown_js"] } [lints] workspace = true diff --git a/simpa/Cargo.toml b/simpa/Cargo.toml index 30162ba4f1..815edf6a64 100644 --- a/simpa/Cargo.toml +++ b/simpa/Cargo.toml @@ -11,7 +11,7 @@ license.workspace = true repository.workspace = true [dependencies] -kaspa-alloc.workspace = true # This changes the global allocator for all of the next dependencies so should be kept first +kaspa-alloc.workspace = true # This changes the global allocator for all of the next dependencies so should be kept first kaspa-consensus-core.workspace = true kaspa-consensus-notify.workspace = true kaspa-consensus.workspace = true diff --git a/wallet/wasm/Cargo.toml b/wallet/wasm/Cargo.toml index 976665c52a..b4b3d0f2ca 100644 --- a/wallet/wasm/Cargo.toml +++ b/wallet/wasm/Cargo.toml @@ -23,4 +23,4 @@ wasm-bindgen-futures.workspace = true wasm-bindgen.workspace = true workflow-log.workspace = true workflow-terminal.workspace = true -workflow-wasm.workspace = true +workflow-wasm.workspace = true \ No newline at end of file From 5b9c3cf95718b0adba9baac80c531029c7815249 Mon Sep 17 00:00:00 2001 From: aspect Date: Tue, 10 Sep 2024 00:57:22 +0300 Subject: [PATCH 7/8] Fix CLI not showing incorrect URL on connect + add disconnect() before connect() (#549) * wRPC: update descriptor with URL supplied in connect options * cli: present public node connection warning only once * cli: update messaging * bump version to 0.14.7 --- Cargo.lock | 114 +++++++++++++++++----------------- Cargo.toml | 112 ++++++++++++++++----------------- cli/src/modules/connect.rs | 24 ++++--- rpc/wrpc/client/src/client.rs | 4 ++ 4 files changed, 134 insertions(+), 120 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1deb983e79..622bafd183 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2363,7 +2363,7 @@ dependencies = [ [[package]] name = "kaspa-addresses" -version = "0.14.5" +version = "0.14.7" dependencies = [ "borsh", "criterion", @@ -2380,7 +2380,7 @@ dependencies = [ [[package]] name = "kaspa-addressmanager" -version = "0.14.5" +version = "0.14.7" dependencies = [ "borsh", "igd-next", @@ -2403,14 +2403,14 @@ dependencies = [ [[package]] name = "kaspa-alloc" -version = "0.14.5" +version = "0.14.7" dependencies = [ "mimalloc", ] [[package]] name = "kaspa-bip32" -version = "0.14.5" +version = "0.14.7" dependencies = [ "borsh", "bs58", @@ -2437,7 +2437,7 @@ dependencies = [ [[package]] name = "kaspa-cli" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-trait", "borsh", @@ -2484,7 +2484,7 @@ dependencies = [ [[package]] name = "kaspa-connectionmanager" -version = "0.14.5" +version = "0.14.7" dependencies = [ "duration-string", "futures-util", @@ -2501,7 +2501,7 @@ dependencies = [ [[package]] name = "kaspa-consensus" -version = "0.14.5" +version = "0.14.7" dependencies = [ "arc-swap", "async-channel 2.3.1", @@ -2544,7 +2544,7 @@ dependencies = [ [[package]] name = "kaspa-consensus-client" -version = "0.14.5" +version = "0.14.7" dependencies = [ "ahash", "cfg-if 1.0.0", @@ -2572,7 +2572,7 @@ dependencies = [ [[package]] name = "kaspa-consensus-core" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-trait", "bincode", @@ -2610,7 +2610,7 @@ dependencies = [ [[package]] name = "kaspa-consensus-notify" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-channel 2.3.1", "cfg-if 1.0.0", @@ -2629,7 +2629,7 @@ dependencies = [ [[package]] name = "kaspa-consensus-wasm" -version = "0.14.5" +version = "0.14.7" dependencies = [ "cfg-if 1.0.0", "faster-hex", @@ -2653,7 +2653,7 @@ dependencies = [ [[package]] name = "kaspa-consensusmanager" -version = "0.14.5" +version = "0.14.7" dependencies = [ "duration-string", "futures", @@ -2671,7 +2671,7 @@ dependencies = [ [[package]] name = "kaspa-core" -version = "0.14.5" +version = "0.14.7" dependencies = [ "cfg-if 1.0.0", "ctrlc", @@ -2689,7 +2689,7 @@ dependencies = [ [[package]] name = "kaspa-daemon" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-trait", "borsh", @@ -2711,7 +2711,7 @@ dependencies = [ [[package]] name = "kaspa-database" -version = "0.14.5" +version = "0.14.7" dependencies = [ "bincode", "enum-primitive-derive", @@ -2733,7 +2733,7 @@ dependencies = [ [[package]] name = "kaspa-grpc-client" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-channel 2.3.1", "async-stream", @@ -2765,7 +2765,7 @@ dependencies = [ [[package]] name = "kaspa-grpc-core" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-channel 2.3.1", "async-stream", @@ -2794,7 +2794,7 @@ dependencies = [ [[package]] name = "kaspa-grpc-server" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-channel 2.3.1", "async-stream", @@ -2830,7 +2830,7 @@ dependencies = [ [[package]] name = "kaspa-hashes" -version = "0.14.5" +version = "0.14.7" dependencies = [ "blake2b_simd", "borsh", @@ -2851,7 +2851,7 @@ dependencies = [ [[package]] name = "kaspa-index-core" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-channel 2.3.1", "async-trait", @@ -2870,7 +2870,7 @@ dependencies = [ [[package]] name = "kaspa-index-processor" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-channel 2.3.1", "async-trait", @@ -2898,7 +2898,7 @@ dependencies = [ [[package]] name = "kaspa-math" -version = "0.14.5" +version = "0.14.7" dependencies = [ "borsh", "criterion", @@ -2919,14 +2919,14 @@ dependencies = [ [[package]] name = "kaspa-merkle" -version = "0.14.5" +version = "0.14.7" dependencies = [ "kaspa-hashes", ] [[package]] name = "kaspa-metrics-core" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-trait", "borsh", @@ -2942,7 +2942,7 @@ dependencies = [ [[package]] name = "kaspa-mining" -version = "0.14.5" +version = "0.14.7" dependencies = [ "criterion", "futures-util", @@ -2969,7 +2969,7 @@ dependencies = [ [[package]] name = "kaspa-mining-errors" -version = "0.14.5" +version = "0.14.7" dependencies = [ "kaspa-consensus-core", "thiserror", @@ -2977,7 +2977,7 @@ dependencies = [ [[package]] name = "kaspa-muhash" -version = "0.14.5" +version = "0.14.7" dependencies = [ "criterion", "kaspa-hashes", @@ -2990,7 +2990,7 @@ dependencies = [ [[package]] name = "kaspa-notify" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-channel 2.3.1", "async-trait", @@ -3026,7 +3026,7 @@ dependencies = [ [[package]] name = "kaspa-p2p-flows" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-trait", "chrono", @@ -3057,7 +3057,7 @@ dependencies = [ [[package]] name = "kaspa-p2p-lib" -version = "0.14.5" +version = "0.14.7" dependencies = [ "borsh", "ctrlc", @@ -3088,7 +3088,7 @@ dependencies = [ [[package]] name = "kaspa-perf-monitor" -version = "0.14.5" +version = "0.14.7" dependencies = [ "kaspa-core", "log", @@ -3100,7 +3100,7 @@ dependencies = [ [[package]] name = "kaspa-pow" -version = "0.14.5" +version = "0.14.7" dependencies = [ "criterion", "js-sys", @@ -3116,7 +3116,7 @@ dependencies = [ [[package]] name = "kaspa-rpc-core" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-channel 2.3.1", "async-trait", @@ -3158,7 +3158,7 @@ dependencies = [ [[package]] name = "kaspa-rpc-macros" -version = "0.14.5" +version = "0.14.7" dependencies = [ "convert_case 0.6.0", "proc-macro-error", @@ -3170,7 +3170,7 @@ dependencies = [ [[package]] name = "kaspa-rpc-service" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-trait", "kaspa-addresses", @@ -3199,7 +3199,7 @@ dependencies = [ [[package]] name = "kaspa-testing-integration" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-channel 2.3.1", "async-trait", @@ -3259,7 +3259,7 @@ dependencies = [ [[package]] name = "kaspa-txscript" -version = "0.14.5" +version = "0.14.7" dependencies = [ "blake2b_simd", "borsh", @@ -3291,7 +3291,7 @@ dependencies = [ [[package]] name = "kaspa-txscript-errors" -version = "0.14.5" +version = "0.14.7" dependencies = [ "secp256k1", "thiserror", @@ -3299,7 +3299,7 @@ dependencies = [ [[package]] name = "kaspa-utils" -version = "0.14.5" +version = "0.14.7" dependencies = [ "arc-swap", "async-channel 2.3.1", @@ -3335,7 +3335,7 @@ dependencies = [ [[package]] name = "kaspa-utils-tower" -version = "0.14.5" +version = "0.14.7" dependencies = [ "cfg-if 1.0.0", "futures", @@ -3349,7 +3349,7 @@ dependencies = [ [[package]] name = "kaspa-utxoindex" -version = "0.14.5" +version = "0.14.7" dependencies = [ "futures", "kaspa-consensus", @@ -3370,7 +3370,7 @@ dependencies = [ [[package]] name = "kaspa-wallet" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-std", "async-trait", @@ -3382,7 +3382,7 @@ dependencies = [ [[package]] name = "kaspa-wallet-cli-wasm" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-trait", "js-sys", @@ -3396,7 +3396,7 @@ dependencies = [ [[package]] name = "kaspa-wallet-core" -version = "0.14.5" +version = "0.14.7" dependencies = [ "aes", "ahash", @@ -3477,7 +3477,7 @@ dependencies = [ [[package]] name = "kaspa-wallet-keys" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-trait", "borsh", @@ -3510,7 +3510,7 @@ dependencies = [ [[package]] name = "kaspa-wallet-macros" -version = "0.14.5" +version = "0.14.7" dependencies = [ "convert_case 0.5.0", "proc-macro-error", @@ -3523,7 +3523,7 @@ dependencies = [ [[package]] name = "kaspa-wallet-pskt" -version = "0.14.5" +version = "0.14.7" dependencies = [ "bincode", "derive_builder", @@ -3550,7 +3550,7 @@ dependencies = [ [[package]] name = "kaspa-wasm" -version = "0.14.5" +version = "0.14.7" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -3578,7 +3578,7 @@ dependencies = [ [[package]] name = "kaspa-wasm-core" -version = "0.14.5" +version = "0.14.7" dependencies = [ "faster-hex", "hexplay", @@ -3589,7 +3589,7 @@ dependencies = [ [[package]] name = "kaspa-wrpc-client" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-std", "async-trait", @@ -3625,7 +3625,7 @@ dependencies = [ [[package]] name = "kaspa-wrpc-example-subscriber" -version = "0.14.5" +version = "0.14.7" dependencies = [ "ctrlc", "futures", @@ -3640,7 +3640,7 @@ dependencies = [ [[package]] name = "kaspa-wrpc-proxy" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-trait", "clap 4.5.16", @@ -3659,7 +3659,7 @@ dependencies = [ [[package]] name = "kaspa-wrpc-server" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-trait", "borsh", @@ -3687,7 +3687,7 @@ dependencies = [ [[package]] name = "kaspa-wrpc-wasm" -version = "0.14.5" +version = "0.14.7" dependencies = [ "ahash", "async-std", @@ -3717,7 +3717,7 @@ dependencies = [ [[package]] name = "kaspad" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-channel 2.3.1", "cfg-if 1.0.0", @@ -5141,7 +5141,7 @@ dependencies = [ [[package]] name = "rothschild" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-channel 2.3.1", "clap 4.5.16", @@ -5593,7 +5593,7 @@ dependencies = [ [[package]] name = "simpa" -version = "0.14.5" +version = "0.14.7" dependencies = [ "async-channel 2.3.1", "cfg-if 1.0.0", diff --git a/Cargo.toml b/Cargo.toml index 13ce765e21..f3096a714f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,7 +62,7 @@ members = [ [workspace.package] rust-version = "1.81.0" -version = "0.14.5" +version = "0.14.7" authors = ["Kaspa developers"] license = "ISC" repository = "https://github.com/kaspanet/rusty-kaspa" @@ -79,61 +79,61 @@ include = [ ] [workspace.dependencies] -# kaspa-testing-integration = { version = "0.14.5", path = "testing/integration" } -kaspa-addresses = { version = "0.14.5", path = "crypto/addresses" } -kaspa-addressmanager = { version = "0.14.5", path = "components/addressmanager" } -kaspa-bip32 = { version = "0.14.5", path = "wallet/bip32" } -kaspa-cli = { version = "0.14.5", path = "cli" } -kaspa-connectionmanager = { version = "0.14.5", path = "components/connectionmanager" } -kaspa-consensus = { version = "0.14.5", path = "consensus" } -kaspa-consensus-core = { version = "0.14.5", path = "consensus/core" } -kaspa-consensus-client = { version = "0.14.5", path = "consensus/client" } -kaspa-consensus-notify = { version = "0.14.5", path = "consensus/notify" } -kaspa-consensus-wasm = { version = "0.14.5", path = "consensus/wasm" } -kaspa-consensusmanager = { version = "0.14.5", path = "components/consensusmanager" } -kaspa-core = { version = "0.14.5", path = "core" } -kaspa-daemon = { version = "0.14.5", path = "daemon" } -kaspa-database = { version = "0.14.5", path = "database" } -kaspa-grpc-client = { version = "0.14.5", path = "rpc/grpc/client" } -kaspa-grpc-core = { version = "0.14.5", path = "rpc/grpc/core" } -kaspa-grpc-server = { version = "0.14.5", path = "rpc/grpc/server" } -kaspa-hashes = { version = "0.14.5", path = "crypto/hashes" } -kaspa-index-core = { version = "0.14.5", path = "indexes/core" } -kaspa-index-processor = { version = "0.14.5", path = "indexes/processor" } -kaspa-math = { version = "0.14.5", path = "math" } -kaspa-merkle = { version = "0.14.5", path = "crypto/merkle" } -kaspa-metrics-core = { version = "0.14.5", path = "metrics/core" } -kaspa-mining = { version = "0.14.5", path = "mining" } -kaspa-mining-errors = { version = "0.14.5", path = "mining/errors" } -kaspa-muhash = { version = "0.14.5", path = "crypto/muhash" } -kaspa-notify = { version = "0.14.5", path = "notify" } -kaspa-p2p-flows = { version = "0.14.5", path = "protocol/flows" } -kaspa-p2p-lib = { version = "0.14.5", path = "protocol/p2p" } -kaspa-perf-monitor = { version = "0.14.5", path = "metrics/perf_monitor" } -kaspa-pow = { version = "0.14.5", path = "consensus/pow" } -kaspa-rpc-core = { version = "0.14.5", path = "rpc/core" } -kaspa-rpc-macros = { version = "0.14.5", path = "rpc/macros" } -kaspa-rpc-service = { version = "0.14.5", path = "rpc/service" } -kaspa-txscript = { version = "0.14.5", path = "crypto/txscript" } -kaspa-txscript-errors = { version = "0.14.5", path = "crypto/txscript/errors" } -kaspa-utils = { version = "0.14.5", path = "utils" } -kaspa-utils-tower = { version = "0.14.5", path = "utils/tower" } -kaspa-utxoindex = { version = "0.14.5", path = "indexes/utxoindex" } -kaspa-wallet = { version = "0.14.5", path = "wallet/native" } -kaspa-wallet-cli-wasm = { version = "0.14.5", path = "wallet/wasm" } -kaspa-wallet-keys = { version = "0.14.5", path = "wallet/keys" } -kaspa-wallet-pskt = { version = "0.14.5", path = "wallet/pskt" } -kaspa-wallet-core = { version = "0.14.5", path = "wallet/core" } -kaspa-wallet-macros = { version = "0.14.5", path = "wallet/macros" } -kaspa-wasm = { version = "0.14.5", path = "wasm" } -kaspa-wasm-core = { version = "0.14.5", path = "wasm/core" } -kaspa-wrpc-client = { version = "0.14.5", path = "rpc/wrpc/client" } -kaspa-wrpc-proxy = { version = "0.14.5", path = "rpc/wrpc/proxy" } -kaspa-wrpc-server = { version = "0.14.5", path = "rpc/wrpc/server" } -kaspa-wrpc-wasm = { version = "0.14.5", path = "rpc/wrpc/wasm" } -kaspa-wrpc-example-subscriber = { version = "0.14.5", path = "rpc/wrpc/examples/subscriber" } -kaspad = { version = "0.14.5", path = "kaspad" } -kaspa-alloc = { version = "0.14.5", path = "utils/alloc" } +# kaspa-testing-integration = { version = "0.14.7", path = "testing/integration" } +kaspa-addresses = { version = "0.14.7", path = "crypto/addresses" } +kaspa-addressmanager = { version = "0.14.7", path = "components/addressmanager" } +kaspa-bip32 = { version = "0.14.7", path = "wallet/bip32" } +kaspa-cli = { version = "0.14.7", path = "cli" } +kaspa-connectionmanager = { version = "0.14.7", path = "components/connectionmanager" } +kaspa-consensus = { version = "0.14.7", path = "consensus" } +kaspa-consensus-core = { version = "0.14.7", path = "consensus/core" } +kaspa-consensus-client = { version = "0.14.7", path = "consensus/client" } +kaspa-consensus-notify = { version = "0.14.7", path = "consensus/notify" } +kaspa-consensus-wasm = { version = "0.14.7", path = "consensus/wasm" } +kaspa-consensusmanager = { version = "0.14.7", path = "components/consensusmanager" } +kaspa-core = { version = "0.14.7", path = "core" } +kaspa-daemon = { version = "0.14.7", path = "daemon" } +kaspa-database = { version = "0.14.7", path = "database" } +kaspa-grpc-client = { version = "0.14.7", path = "rpc/grpc/client" } +kaspa-grpc-core = { version = "0.14.7", path = "rpc/grpc/core" } +kaspa-grpc-server = { version = "0.14.7", path = "rpc/grpc/server" } +kaspa-hashes = { version = "0.14.7", path = "crypto/hashes" } +kaspa-index-core = { version = "0.14.7", path = "indexes/core" } +kaspa-index-processor = { version = "0.14.7", path = "indexes/processor" } +kaspa-math = { version = "0.14.7", path = "math" } +kaspa-merkle = { version = "0.14.7", path = "crypto/merkle" } +kaspa-metrics-core = { version = "0.14.7", path = "metrics/core" } +kaspa-mining = { version = "0.14.7", path = "mining" } +kaspa-mining-errors = { version = "0.14.7", path = "mining/errors" } +kaspa-muhash = { version = "0.14.7", path = "crypto/muhash" } +kaspa-notify = { version = "0.14.7", path = "notify" } +kaspa-p2p-flows = { version = "0.14.7", path = "protocol/flows" } +kaspa-p2p-lib = { version = "0.14.7", path = "protocol/p2p" } +kaspa-perf-monitor = { version = "0.14.7", path = "metrics/perf_monitor" } +kaspa-pow = { version = "0.14.7", path = "consensus/pow" } +kaspa-rpc-core = { version = "0.14.7", path = "rpc/core" } +kaspa-rpc-macros = { version = "0.14.7", path = "rpc/macros" } +kaspa-rpc-service = { version = "0.14.7", path = "rpc/service" } +kaspa-txscript = { version = "0.14.7", path = "crypto/txscript" } +kaspa-txscript-errors = { version = "0.14.7", path = "crypto/txscript/errors" } +kaspa-utils = { version = "0.14.7", path = "utils" } +kaspa-utils-tower = { version = "0.14.7", path = "utils/tower" } +kaspa-utxoindex = { version = "0.14.7", path = "indexes/utxoindex" } +kaspa-wallet = { version = "0.14.7", path = "wallet/native" } +kaspa-wallet-cli-wasm = { version = "0.14.7", path = "wallet/wasm" } +kaspa-wallet-keys = { version = "0.14.7", path = "wallet/keys" } +kaspa-wallet-pskt = { version = "0.14.7", path = "wallet/pskt" } +kaspa-wallet-core = { version = "0.14.7", path = "wallet/core" } +kaspa-wallet-macros = { version = "0.14.7", path = "wallet/macros" } +kaspa-wasm = { version = "0.14.7", path = "wasm" } +kaspa-wasm-core = { version = "0.14.7", path = "wasm/core" } +kaspa-wrpc-client = { version = "0.14.7", path = "rpc/wrpc/client" } +kaspa-wrpc-proxy = { version = "0.14.7", path = "rpc/wrpc/proxy" } +kaspa-wrpc-server = { version = "0.14.7", path = "rpc/wrpc/server" } +kaspa-wrpc-wasm = { version = "0.14.7", path = "rpc/wrpc/wasm" } +kaspa-wrpc-example-subscriber = { version = "0.14.7", path = "rpc/wrpc/examples/subscriber" } +kaspad = { version = "0.14.7", path = "kaspad" } +kaspa-alloc = { version = "0.14.7", path = "utils/alloc" } # external aes = "0.8.3" diff --git a/cli/src/modules/connect.rs b/cli/src/modules/connect.rs index 92a3c676ba..024f7e6934 100644 --- a/cli/src/modules/connect.rs +++ b/cli/src/modules/connect.rs @@ -26,13 +26,23 @@ impl Connect { }; if is_public { - tpara!( - ctx, - "Please note that public node infrastructure is community-operated and \ - accessing it may expose your IP address to different node providers. \ - Consider running your own node for better privacy. \ - ", - ); + static WARNING: AtomicBool = AtomicBool::new(false); + if !WARNING.load(Ordering::Relaxed) { + WARNING.store(true, Ordering::Relaxed); + + tprintln!(ctx); + + tpara!( + ctx, + "Please note that public node infrastructure is operated by contributors and \ + accessing it may expose your IP address to different node providers. \ + Consider running your own node for better privacy. \ + ", + ); + tprintln!(ctx); + tpara!(ctx, "Please do not connect to public nodes directly as they are load-balanced."); + tprintln!(ctx); + } } let options = ConnectOptions { diff --git a/rpc/wrpc/client/src/client.rs b/rpc/wrpc/client/src/client.rs index 2bd66b7cc4..71147fd67b 100644 --- a/rpc/wrpc/client/src/client.rs +++ b/rpc/wrpc/client/src/client.rs @@ -422,12 +422,16 @@ impl KaspaRpcClient { /// This method starts background RPC services if they are not running and /// attempts to connect to the RPC endpoint. pub async fn connect(&self, options: Option) -> ConnectResult { + // this has no effect if not currently connected + self.disconnect().await?; + let _guard = self.inner.connect_guard.lock().await; let options = options.unwrap_or_default(); let strategy = options.strategy; self.inner.set_default_url(options.url.as_deref()); + self.inner.rpc_ctl.set_descriptor(options.url.clone()); // 1Gb message and frame size limits (on native and NodeJs platforms) let ws_config = WebSocketConfig { From d1dc5dd34426d7ce5f92ed9408701c8dae6cfe57 Mon Sep 17 00:00:00 2001 From: thesheepcat <68336151+thesheepcat@users.noreply.github.com> Date: Tue, 10 Sep 2024 00:59:36 +0200 Subject: [PATCH 8/8] Simple wRPC client example (#550) * simple client example created * fine-tuning on simple wRPC client example (with comments) * code fixed after Aspect's suggestions * empty lines cleanup --- Cargo.lock | 10 ++ Cargo.toml | 1 + rpc/wrpc/examples/simple_client/Cargo.toml | 18 ++++ rpc/wrpc/examples/simple_client/src/main.rs | 104 ++++++++++++++++++++ 4 files changed, 133 insertions(+) create mode 100644 rpc/wrpc/examples/simple_client/Cargo.toml create mode 100644 rpc/wrpc/examples/simple_client/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 622bafd183..c61450bd9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3685,6 +3685,16 @@ dependencies = [ "workflow-serializer", ] +[[package]] +name = "kaspa-wrpc-simple-client-example" +version = "0.14.5" +dependencies = [ + "futures", + "kaspa-rpc-core", + "kaspa-wrpc-client", + "tokio", +] + [[package]] name = "kaspa-wrpc-wasm" version = "0.14.7" diff --git a/Cargo.toml b/Cargo.toml index f3096a714f..c4d46c6ed8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ members = [ "rpc/wrpc/proxy", "rpc/wrpc/wasm", "rpc/wrpc/examples/subscriber", + "rpc/wrpc/examples/simple_client", "mining", "mining/errors", "protocol/p2p", diff --git a/rpc/wrpc/examples/simple_client/Cargo.toml b/rpc/wrpc/examples/simple_client/Cargo.toml new file mode 100644 index 0000000000..c55774b685 --- /dev/null +++ b/rpc/wrpc/examples/simple_client/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "kaspa-wrpc-simple-client-example" +description = "Kaspa wRPC simple client example" +publish = false +rust-version.workspace = true +version.workspace = true +edition.workspace = true +authors.workspace = true +include.workspace = true +license.workspace = true +repository.workspace = true + +[dependencies] +futures.workspace = true +kaspa-rpc-core.workspace = true +kaspa-wrpc-client.workspace = true +tokio.workspace = true + diff --git a/rpc/wrpc/examples/simple_client/src/main.rs b/rpc/wrpc/examples/simple_client/src/main.rs new file mode 100644 index 0000000000..0d63a24c27 --- /dev/null +++ b/rpc/wrpc/examples/simple_client/src/main.rs @@ -0,0 +1,104 @@ +// Example of simple client to connect with Kaspa node using wRPC connection and collect some node and network basic data + +use kaspa_rpc_core::{api::rpc::RpcApi, GetBlockDagInfoResponse, GetServerInfoResponse}; +use kaspa_wrpc_client::{ + client::{ConnectOptions, ConnectStrategy}, + prelude::NetworkId, + prelude::NetworkType, + result::Result, + KaspaRpcClient, Resolver, WrpcEncoding, +}; +use std::process::ExitCode; +use std::time::Duration; + +#[tokio::main] +async fn main() -> ExitCode { + match check_node_status().await { + Ok(_) => { + println!("Well done! You successfully completed your first client connection to Kaspa node!"); + ExitCode::SUCCESS + } + Err(error) => { + println!("An error occurred: {error}"); + ExitCode::FAILURE + } + } +} + +async fn check_node_status() -> Result<()> { + // Select encoding method to use, depending on node settings + let encoding = WrpcEncoding::Borsh; + + // If you want to connect to your own node, define your node address and wRPC port using let url = Some("ws://0.0.0.0:17110") + // Verify your Kaspa node is runnning with --rpclisten-borsh=0.0.0.0:17110 parameter + // In this example we don't use a specific node but we connect through the resolver, which use a pool of public nodes + let url = None; + let resolver = Some(Resolver::default()); + + // Define the network your Kaspa node is connected to + // You can select NetworkType::Mainnet, NetworkType::Testnet, NetworkType::Devnet, NetworkType::Simnet + let network_type = NetworkType::Mainnet; + let selected_network = Some(NetworkId::new(network_type)); + + // Advanced options + let subscription_context = None; + + // Create new wRPC client with parameters defined above + let client = KaspaRpcClient::new(encoding, url, resolver, selected_network, subscription_context)?; + + // Advanced connection options + let timeout = 5_000; + let options = ConnectOptions { + block_async_connect: true, + connect_timeout: Some(Duration::from_millis(timeout)), + strategy: ConnectStrategy::Fallback, + ..Default::default() + }; + + // Connect to selected Kaspa node + client.connect(Some(options)).await?; + + // Retrieve and show Kaspa node information + let GetServerInfoResponse { is_synced, server_version, network_id, has_utxo_index, .. } = client.get_server_info().await?; + + println!("Node version: {server_version}"); + println!("Network: {network_id}"); + println!("Node is synced: {is_synced}"); + println!("Node is indexing UTXOs: {has_utxo_index}"); + + // Retrieve and show Kaspa network information + let GetBlockDagInfoResponse { + block_count, + header_count, + tip_hashes, + difficulty, + past_median_time, + virtual_parent_hashes, + pruning_point_hash, + virtual_daa_score, + sink, + .. + } = client.get_block_dag_info().await?; + + println!("Block count: {block_count}"); + println!("Header count: {header_count}"); + println!("Tip hashes:"); + for tip_hash in tip_hashes { + println!("{tip_hash}"); + } + println!("Difficulty: {difficulty}"); + println!("Past median time: {past_median_time}"); + println!("Virtual parent hashes:"); + for virtual_parent_hash in virtual_parent_hashes { + println!("{virtual_parent_hash}"); + } + println!("Pruning point hash: {pruning_point_hash}"); + println!("Virtual DAA score: {virtual_daa_score}"); + println!("Sink: {sink}"); + + // Disconnect client from Kaspa node + client.disconnect().await?; + + // Return function result + Ok(()) +}