Skip to content

Commit

Permalink
Merge branch 'master' into sigma
Browse files Browse the repository at this point in the history
  • Loading branch information
biryukovmaxim committed Jan 23, 2025
2 parents f5ee61f + b6b344e commit 170055a
Show file tree
Hide file tree
Showing 42 changed files with 644 additions and 178 deletions.
183 changes: 86 additions & 97 deletions Cargo.lock

Large diffs are not rendered by default.

116 changes: 58 additions & 58 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ members = [

[workspace.package]
rust-version = "1.82.0"
version = "0.15.4"
version = "0.16.0"
authors = ["Kaspa developers"]
license = "ISC"
repository = "https://github.com/kaspanet/rusty-kaspa"
Expand All @@ -80,61 +80,61 @@ include = [
]

[workspace.dependencies]
# kaspa-testing-integration = { version = "0.15.4", path = "testing/integration" }
kaspa-addresses = { version = "0.15.4", path = "crypto/addresses" }
kaspa-addressmanager = { version = "0.15.4", path = "components/addressmanager" }
kaspa-bip32 = { version = "0.15.4", path = "wallet/bip32" }
kaspa-cli = { version = "0.15.4", path = "cli" }
kaspa-connectionmanager = { version = "0.15.4", path = "components/connectionmanager" }
kaspa-consensus = { version = "0.15.4", path = "consensus" }
kaspa-consensus-core = { version = "0.15.4", path = "consensus/core" }
kaspa-consensus-client = { version = "0.15.4", path = "consensus/client" }
kaspa-consensus-notify = { version = "0.15.4", path = "consensus/notify" }
kaspa-consensus-wasm = { version = "0.15.4", path = "consensus/wasm" }
kaspa-consensusmanager = { version = "0.15.4", path = "components/consensusmanager" }
kaspa-core = { version = "0.15.4", path = "core" }
kaspa-daemon = { version = "0.15.4", path = "daemon" }
kaspa-database = { version = "0.15.4", path = "database" }
kaspa-grpc-client = { version = "0.15.4", path = "rpc/grpc/client" }
kaspa-grpc-core = { version = "0.15.4", path = "rpc/grpc/core" }
kaspa-grpc-server = { version = "0.15.4", path = "rpc/grpc/server" }
kaspa-hashes = { version = "0.15.4", path = "crypto/hashes" }
kaspa-index-core = { version = "0.15.4", path = "indexes/core" }
kaspa-index-processor = { version = "0.15.4", path = "indexes/processor" }
kaspa-math = { version = "0.15.4", path = "math" }
kaspa-merkle = { version = "0.15.4", path = "crypto/merkle" }
kaspa-metrics-core = { version = "0.15.4", path = "metrics/core" }
kaspa-mining = { version = "0.15.4", path = "mining" }
kaspa-mining-errors = { version = "0.15.4", path = "mining/errors" }
kaspa-muhash = { version = "0.15.4", path = "crypto/muhash" }
kaspa-notify = { version = "0.15.4", path = "notify" }
kaspa-p2p-flows = { version = "0.15.4", path = "protocol/flows" }
kaspa-p2p-lib = { version = "0.15.4", path = "protocol/p2p" }
kaspa-perf-monitor = { version = "0.15.4", path = "metrics/perf_monitor" }
kaspa-pow = { version = "0.15.4", path = "consensus/pow" }
kaspa-rpc-core = { version = "0.15.4", path = "rpc/core" }
kaspa-rpc-macros = { version = "0.15.4", path = "rpc/macros" }
kaspa-rpc-service = { version = "0.15.4", path = "rpc/service" }
kaspa-txscript = { version = "0.15.4", path = "crypto/txscript" }
kaspa-txscript-errors = { version = "0.15.4", path = "crypto/txscript/errors" }
kaspa-utils = { version = "0.15.4", path = "utils" }
kaspa-utils-tower = { version = "0.15.4", path = "utils/tower" }
kaspa-utxoindex = { version = "0.15.4", path = "indexes/utxoindex" }
kaspa-wallet = { version = "0.15.4", path = "wallet/native" }
kaspa-wallet-cli-wasm = { version = "0.15.4", path = "wallet/wasm" }
kaspa-wallet-keys = { version = "0.15.4", path = "wallet/keys" }
kaspa-wallet-pskt = { version = "0.15.4", path = "wallet/pskt" }
kaspa-wallet-core = { version = "0.15.4", path = "wallet/core" }
kaspa-wallet-macros = { version = "0.15.4", path = "wallet/macros" }
kaspa-wasm = { version = "0.15.4", path = "wasm" }
kaspa-wasm-core = { version = "0.15.4", path = "wasm/core" }
kaspa-wrpc-client = { version = "0.15.4", path = "rpc/wrpc/client" }
kaspa-wrpc-proxy = { version = "0.15.4", path = "rpc/wrpc/proxy" }
kaspa-wrpc-server = { version = "0.15.4", path = "rpc/wrpc/server" }
kaspa-wrpc-wasm = { version = "0.15.4", path = "rpc/wrpc/wasm" }
kaspa-wrpc-example-subscriber = { version = "0.15.4", path = "rpc/wrpc/examples/subscriber" }
kaspad = { version = "0.15.4", path = "kaspad" }
kaspa-alloc = { version = "0.15.4", path = "utils/alloc" }
# kaspa-testing-integration = { version = "0.16.0", path = "testing/integration" }
kaspa-addresses = { version = "0.16.0", path = "crypto/addresses" }
kaspa-addressmanager = { version = "0.16.0", path = "components/addressmanager" }
kaspa-bip32 = { version = "0.16.0", path = "wallet/bip32" }
kaspa-cli = { version = "0.16.0", path = "cli" }
kaspa-connectionmanager = { version = "0.16.0", path = "components/connectionmanager" }
kaspa-consensus = { version = "0.16.0", path = "consensus" }
kaspa-consensus-core = { version = "0.16.0", path = "consensus/core" }
kaspa-consensus-client = { version = "0.16.0", path = "consensus/client" }
kaspa-consensus-notify = { version = "0.16.0", path = "consensus/notify" }
kaspa-consensus-wasm = { version = "0.16.0", path = "consensus/wasm" }
kaspa-consensusmanager = { version = "0.16.0", path = "components/consensusmanager" }
kaspa-core = { version = "0.16.0", path = "core" }
kaspa-daemon = { version = "0.16.0", path = "daemon" }
kaspa-database = { version = "0.16.0", path = "database" }
kaspa-grpc-client = { version = "0.16.0", path = "rpc/grpc/client" }
kaspa-grpc-core = { version = "0.16.0", path = "rpc/grpc/core" }
kaspa-grpc-server = { version = "0.16.0", path = "rpc/grpc/server" }
kaspa-hashes = { version = "0.16.0", path = "crypto/hashes" }
kaspa-index-core = { version = "0.16.0", path = "indexes/core" }
kaspa-index-processor = { version = "0.16.0", path = "indexes/processor" }
kaspa-math = { version = "0.16.0", path = "math" }
kaspa-merkle = { version = "0.16.0", path = "crypto/merkle" }
kaspa-metrics-core = { version = "0.16.0", path = "metrics/core" }
kaspa-mining = { version = "0.16.0", path = "mining" }
kaspa-mining-errors = { version = "0.16.0", path = "mining/errors" }
kaspa-muhash = { version = "0.16.0", path = "crypto/muhash" }
kaspa-notify = { version = "0.16.0", path = "notify" }
kaspa-p2p-flows = { version = "0.16.0", path = "protocol/flows" }
kaspa-p2p-lib = { version = "0.16.0", path = "protocol/p2p" }
kaspa-perf-monitor = { version = "0.16.0", path = "metrics/perf_monitor" }
kaspa-pow = { version = "0.16.0", path = "consensus/pow" }
kaspa-rpc-core = { version = "0.16.0", path = "rpc/core" }
kaspa-rpc-macros = { version = "0.16.0", path = "rpc/macros" }
kaspa-rpc-service = { version = "0.16.0", path = "rpc/service" }
kaspa-txscript = { version = "0.16.0", path = "crypto/txscript" }
kaspa-txscript-errors = { version = "0.16.0", path = "crypto/txscript/errors" }
kaspa-utils = { version = "0.16.0", path = "utils" }
kaspa-utils-tower = { version = "0.16.0", path = "utils/tower" }
kaspa-utxoindex = { version = "0.16.0", path = "indexes/utxoindex" }
kaspa-wallet = { version = "0.16.0", path = "wallet/native" }
kaspa-wallet-cli-wasm = { version = "0.16.0", path = "wallet/wasm" }
kaspa-wallet-keys = { version = "0.16.0", path = "wallet/keys" }
kaspa-wallet-pskt = { version = "0.16.0", path = "wallet/pskt" }
kaspa-wallet-core = { version = "0.16.0", path = "wallet/core" }
kaspa-wallet-macros = { version = "0.16.0", path = "wallet/macros" }
kaspa-wasm = { version = "0.16.0", path = "wasm" }
kaspa-wasm-core = { version = "0.16.0", path = "wasm/core" }
kaspa-wrpc-client = { version = "0.16.0", path = "rpc/wrpc/client" }
kaspa-wrpc-proxy = { version = "0.16.0", path = "rpc/wrpc/proxy" }
kaspa-wrpc-server = { version = "0.16.0", path = "rpc/wrpc/server" }
kaspa-wrpc-wasm = { version = "0.16.0", path = "rpc/wrpc/wasm" }
kaspa-wrpc-example-subscriber = { version = "0.16.0", path = "rpc/wrpc/examples/subscriber" }
kaspad = { version = "0.16.0", path = "kaspad" }
kaspa-alloc = { version = "0.16.0", path = "utils/alloc" }

# external
aes = "0.8.3"
Expand Down Expand Up @@ -256,9 +256,9 @@ tonic = { version = "0.12.3", features = ["tls-webpki-roots", "gzip", "transport
tonic-build = { version = "0.12.3", features = ["prost"] }
triggered = "0.1.2"
uuid = { version = "1.5.0", features = ["v4", "fast-rng", "serde"] }
wasm-bindgen = { version = "0.2.93", features = ["serde-serialize"] }
wasm-bindgen = { version = "0.2.100", features = ["serde-serialize"] }
wasm-bindgen-futures = "0.4.43"
wasm-bindgen-test = "0.3.43"
wasm-bindgen-test = "0.3.50"
web-sys = "0.3.70"
xxhash-rust = { version = "0.8.7", features = ["xxh3"] }
zeroize = { version = "1.6.0", default-features = false, features = ["alloc"] }
Expand Down
2 changes: 1 addition & 1 deletion cli/src/modules/guide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ impl Guide {

let mut paras = Vec::<String>::new();
let mut para = String::new();
let regex = Regex::new(r"\s+").unwrap();
for line in lines {
if line.trim().is_empty() {
if !para.is_empty() {
let regex = Regex::new(r"\s+").unwrap();
let text = regex.replace_all(para.trim(), " ");
paras.push(text.to_string());
para.clear();
Expand Down
15 changes: 15 additions & 0 deletions cli/src/modules/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,21 @@ impl Rpc {
let result = rpc.get_current_block_color_call(None, GetCurrentBlockColorRequest { hash }).await?;
self.println(&ctx, result);
}
RpcApiOps::GetUtxoReturnAddress => {
if argv.is_empty() || argv.len() != 2 {
return Err(Error::custom("Please specify a txid and a accepting_block_daa_score"));
}

let txid = argv.remove(0);
let txid = RpcHash::from_hex(txid.as_str())?;

let accepting_block_daa_score = argv.remove(0).parse::<u64>()?;

let result =
rpc.get_utxo_return_address_call(None, GetUtxoReturnAddressRequest { txid, accepting_block_daa_score }).await?;

self.println(&ctx, result);
}
_ => {
tprintln!(ctx, "rpc method exists but is not supported by the cli: '{op_str}'\r\n");
return Ok(());
Expand Down
2 changes: 1 addition & 1 deletion components/addressmanager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ mod address_store_with_cache {
let target_uniform_dist = Uniform::new(1.0, num_of_buckets as f64).unwrap();
let uniform_cdf = |x: f64| target_uniform_dist.cdf(&x);
for _ in 0..num_of_trials {
// The weight sampled expected uniform distibution
// The weight sampled expected uniform distribution
let prioritized_address_distribution = am
.lock()
.iterate_prioritized_random_addresses(HashSet::new())
Expand Down
1 change: 1 addition & 0 deletions components/consensusmanager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ duration-string.workspace = true
futures-util.workspace = true
futures.workspace = true
itertools.workspace = true
kaspa-addresses.workspace=true
kaspa-consensus-core.workspace = true
kaspa-consensus-notify.workspace = true
kaspa-core.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion components/consensusmanager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl StagingConsensus {
// Drop `prev` so that deletion below succeeds
drop(prev);
// Staging was committed and is now the active consensus so we can delete
// any pervious, now inactive, consensus entries
// any previous, now inactive, consensus entries
self.manager.delete_inactive_consensus_entries();
}

Expand Down
11 changes: 10 additions & 1 deletion components/consensusmanager/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use kaspa_consensus_core::{
header::Header,
pruning::{PruningPointProof, PruningPointTrustedData, PruningPointsList},
trusted::{ExternalGhostdagData, TrustedBlock},
tx::{MutableTransaction, Transaction, TransactionOutpoint, UtxoEntry},
tx::{MutableTransaction, SignableTransaction, Transaction, TransactionOutpoint, UtxoEntry},
utxo::utxo_inquirer::UtxoInquirerError,
BlockHashSet, BlueWorkType, ChainPath, Hash,
};
use kaspa_utils::sync::rwlock::*;
Expand Down Expand Up @@ -313,6 +314,14 @@ impl ConsensusSessionOwned {
self.clone().spawn_blocking(|c| c.get_chain_block_samples()).await
}

pub async fn async_get_populated_transaction(
&self,
txid: Hash,
accepting_block_daa_score: u64,
) -> Result<SignableTransaction, UtxoInquirerError> {
self.clone().spawn_blocking(move |c| c.get_populated_transaction(txid, accepting_block_daa_score)).await
}

/// Returns the antipast of block `hash` from the POV of `context`, i.e. `antipast(hash) ∩ past(context)`.
/// Since this might be an expensive operation for deep blocks, we allow the caller to specify a limit
/// `max_traversal_allowed` on the maximum amount of blocks to traverse for obtaining the answer
Expand Down
1 change: 1 addition & 0 deletions consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ faster-hex.workspace = true
futures-util.workspace = true
indexmap.workspace = true
itertools.workspace = true
kaspa-addresses.workspace = true
kaspa-consensus-core.workspace = true
kaspa-consensus-notify.workspace = true
kaspa-consensusmanager.workspace = true
Expand Down
9 changes: 8 additions & 1 deletion consensus/core/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use crate::{
header::Header,
pruning::{PruningPointProof, PruningPointTrustedData, PruningPointsList, PruningProofMetadata},
trusted::{ExternalGhostdagData, TrustedBlock},
tx::{MutableTransaction, Transaction, TransactionOutpoint, UtxoEntry},
tx::{MutableTransaction, SignableTransaction, Transaction, TransactionOutpoint, UtxoEntry},
utxo::utxo_inquirer::UtxoInquirerError,
BlockHashSet, BlueWorkType, ChainPath,
};
use kaspa_hashes::Hash;
Expand Down Expand Up @@ -170,6 +171,12 @@ pub trait ConsensusApi: Send + Sync {
unimplemented!()
}

/// Returns the fully populated transaction with the given txid which was accepted at the provided accepting_block_daa_score.
/// The argument `accepting_block_daa_score` is expected to be the DAA score of the accepting chain block of `txid`.
fn get_populated_transaction(&self, txid: Hash, accepting_block_daa_score: u64) -> Result<SignableTransaction, UtxoInquirerError> {
unimplemented!()
}

fn get_virtual_parents(&self) -> BlockHashSet {
unimplemented!()
}
Expand Down
8 changes: 8 additions & 0 deletions consensus/core/src/tx/script_public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,9 @@ impl TryCastFromJs for ScriptPublicKey {
#[cfg(test)]
mod tests {
use super::*;
#[cfg(target_arch = "wasm32")]
use js_sys::Object;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::__rt::IntoJsResult;

#[test]
Expand Down Expand Up @@ -438,10 +440,14 @@ mod tests {
assert_eq!(spk, spk2);
}

#[cfg(target_arch = "wasm32")]
use wasm_bindgen::convert::IntoWasmAbi;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test;
#[cfg(target_arch = "wasm32")]
use workflow_wasm::serde::{from_value, to_value};

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen_test]
pub fn test_wasm_serde_constructor() {
let version = 0xc0de;
Expand All @@ -459,6 +465,7 @@ mod tests {
assert_eq!(JsValue::from_str("string"), spk_js.js_typeof());
}

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen_test]
pub fn test_wasm_serde_js_spk_object() {
let version = 0xc0de;
Expand All @@ -478,6 +485,7 @@ mod tests {
assert_eq!(spk, actual);
}

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen_test]
pub fn test_wasm_serde_spk_object() {
let version = 0xc0de;
Expand Down
1 change: 1 addition & 0 deletions consensus/core/src/utxo/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod utxo_collection;
pub mod utxo_diff;
pub mod utxo_error;
pub mod utxo_inquirer;
pub mod utxo_view;
38 changes: 38 additions & 0 deletions consensus/core/src/utxo/utxo_inquirer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use kaspa_hashes::Hash;
use thiserror::Error;

#[derive(Error, Debug, Clone)]
pub enum UtxoInquirerError {
#[error("Transaction is already pruned")]
AlreadyPruned,
#[error("Transaction return address is coinbase")]
TxFromCoinbase,
#[error("Transaction not found at given accepting daa score")]
NoTxAtScore,
#[error("Transaction was found but not standard")]
NonStandard,
#[error("Did not find compact header for block hash {0} ")]
MissingCompactHeaderForBlockHash(Hash),
#[error("Did not find containing_acceptance for tx {0} ")]
MissingContainingAcceptanceForTx(Hash),
#[error("Did not find block {0} at block tx store")]
MissingBlockFromBlockTxStore(Hash),
#[error("Did not find index {0} in transactions of block {1}")]
MissingTransactionIndexOfBlock(usize, Hash),
#[error("Expected {0} to match {1} when checking block_transaction_store using array index of transaction")]
UnexpectedTransactionMismatch(Hash, Hash),
#[error("Did not find a utxo diff for chain block {0} ")]
MissingUtxoDiffForChainBlock(Hash),
#[error("Transaction {0} acceptance data must also be in the same block in this case")]
MissingOtherTransactionAcceptanceData(Hash),
#[error("Did not find index for hash {0}")]
MissingIndexForHash(Hash),
#[error("Did not find tip data")]
MissingTipData,
#[error("Did not find a hash at index {0} ")]
MissingHashAtIndex(u64),
#[error("Did not find acceptance data for chain block {0}")]
MissingAcceptanceDataForChainBlock(Hash),
#[error("Utxo entry is not filled")]
UnfilledUtxoEntry,
}
9 changes: 8 additions & 1 deletion consensus/src/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ use kaspa_consensus_core::{
network::NetworkType,
pruning::{PruningPointProof, PruningPointTrustedData, PruningPointsList, PruningProofMetadata},
trusted::{ExternalGhostdagData, TrustedBlock},
tx::{MutableTransaction, Transaction, TransactionOutpoint, UtxoEntry},
tx::{MutableTransaction, SignableTransaction, Transaction, TransactionOutpoint, UtxoEntry},
utxo::utxo_inquirer::UtxoInquirerError,
BlockHashSet, BlueWorkType, ChainPath, HashMapCustomHasher,
};
use kaspa_consensus_notify::root::ConsensusNotificationRoot;
Expand Down Expand Up @@ -687,6 +688,12 @@ impl ConsensusApi for Consensus {
sample_headers
}

fn get_populated_transaction(&self, txid: Hash, accepting_block_daa_score: u64) -> Result<SignableTransaction, UtxoInquirerError> {
// We need consistency between the pruning_point_store, utxo_diffs_store, block_transactions_store, selected chain and headers store reads
let _guard = self.pruning_lock.blocking_read();
self.virtual_processor.get_populated_transaction(txid, accepting_block_daa_score, self.get_source())
}

fn get_virtual_parents(&self) -> BlockHashSet {
self.lkg_virtual_state.load().parents.iter().copied().collect()
}
Expand Down
1 change: 1 addition & 0 deletions consensus/src/pipeline/virtual_processor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod errors;
mod processor;
mod utxo_inquirer;
mod utxo_validation;
pub use processor::*;
pub mod test_block_builder;
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/pipeline/virtual_processor/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub struct VirtualStateProcessor {
pub(super) block_window_cache_for_past_median_time: Arc<BlockWindowCacheStore>,

// Pruning lock
pruning_lock: SessionLock,
pub(super) pruning_lock: SessionLock,

// Notifier
notification_root: Arc<ConsensusNotificationRoot>,
Expand Down
Loading

0 comments on commit 170055a

Please sign in to comment.