Skip to content

Commit 291f8f6

Browse files
Merge branch 'master' into master
2 parents 6ebf1b9 + 116dfb0 commit 291f8f6

File tree

21 files changed

+7700
-286
lines changed

21 files changed

+7700
-286
lines changed

Diff for: .github/workflows/ci.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ jobs:
128128

129129
- name: Run cargo doc
130130
run: cargo doc --release --no-deps --workspace
131+
- name: Run kip-10 example
132+
run: cargo run --example kip-10
133+
131134

132135
# test-release:
133136
# name: Test Suite Release
@@ -210,7 +213,7 @@ jobs:
210213
run: cargo fmt --all -- --check
211214

212215
- name: Run cargo clippy
213-
run: cargo clippy --workspace --tests --benches -- -D warnings
216+
run: cargo clippy --workspace --tests --benches --examples -- -D warnings
214217

215218

216219
check-wasm32:

Diff for: consensus/benches/check_scripts.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn benchmark_check_scripts(c: &mut Criterion) {
8484
let cache = Cache::new(inputs_count as u64);
8585
b.iter(|| {
8686
cache.clear();
87-
check_scripts_sequential(black_box(&cache), black_box(&tx.as_verifiable())).unwrap();
87+
check_scripts_sequential(black_box(&cache), black_box(&tx.as_verifiable()), false).unwrap();
8888
})
8989
});
9090

@@ -93,7 +93,7 @@ fn benchmark_check_scripts(c: &mut Criterion) {
9393
let cache = Cache::new(inputs_count as u64);
9494
b.iter(|| {
9595
cache.clear();
96-
check_scripts_par_iter(black_box(&cache), black_box(&tx.as_verifiable())).unwrap();
96+
check_scripts_par_iter(black_box(&cache), black_box(&tx.as_verifiable()), false).unwrap();
9797
})
9898
});
9999

@@ -107,7 +107,8 @@ fn benchmark_check_scripts(c: &mut Criterion) {
107107
let cache = Cache::new(inputs_count as u64);
108108
b.iter(|| {
109109
cache.clear();
110-
check_scripts_par_iter_pool(black_box(&cache), black_box(&tx.as_verifiable()), black_box(&pool)).unwrap();
110+
check_scripts_par_iter_pool(black_box(&cache), black_box(&tx.as_verifiable()), black_box(&pool), false)
111+
.unwrap();
111112
})
112113
});
113114
}

Diff for: consensus/client/src/signing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pub fn calc_schnorr_signature_hash(
178178
let utxo = cctx::UtxoEntry::from(utxo.as_ref());
179179

180180
let hash_type = SIG_HASH_ALL;
181-
let mut reused_values = SigHashReusedValues::new();
181+
let reused_values = SigHashReusedValuesUnsync::new();
182182

183183
// let input = verifiable_tx.populated_input(input_index);
184184
// let tx = verifiable_tx.tx();

Diff for: consensus/core/src/config/params.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ pub struct Params {
110110
/// DAA score from which storage mass calculation and transaction mass field are activated as a consensus rule
111111
pub storage_mass_activation: ForkActivation,
112112

113+
/// DAA score from which tx engine:
114+
/// 1. Supports 8-byte integer arithmetic operations (previously limited to 4 bytes)
115+
/// 2. Supports transaction introspection opcodes:
116+
/// - OpTxInputCount (0xb3): Get number of inputs
117+
/// - OpTxOutputCount (0xb4): Get number of outputs
118+
/// - OpTxInputIndex (0xb9): Get current input index
119+
/// - OpTxInputAmount (0xbe): Get input amount
120+
/// - OpTxInputSpk (0xbf): Get input script public key
121+
/// - OpTxOutputAmount (0xc2): Get output amount
122+
/// - OpTxOutputSpk (0xc3): Get output script public key
123+
pub kip10_activation: ForkActivation,
124+
113125
/// DAA score after which the pre-deflationary period switches to the deflationary period
114126
pub deflationary_phase_daa_score: u64,
115127

@@ -380,6 +392,7 @@ pub const MAINNET_PARAMS: Params = Params {
380392

381393
storage_mass_parameter: STORAGE_MASS_PARAMETER,
382394
storage_mass_activation: ForkActivation::never(),
395+
kip10_activation: ForkActivation::never(),
383396

384397
// deflationary_phase_daa_score is the DAA score after which the pre-deflationary period
385398
// switches to the deflationary period. This number is calculated as follows:
@@ -443,7 +456,7 @@ pub const TESTNET_PARAMS: Params = Params {
443456

444457
storage_mass_parameter: STORAGE_MASS_PARAMETER,
445458
storage_mass_activation: ForkActivation::never(),
446-
459+
kip10_activation: ForkActivation::never(),
447460
// deflationary_phase_daa_score is the DAA score after which the pre-deflationary period
448461
// switches to the deflationary period. This number is calculated as follows:
449462
// We define a year as 365.25 days
@@ -513,6 +526,7 @@ pub const TESTNET11_PARAMS: Params = Params {
513526

514527
storage_mass_parameter: STORAGE_MASS_PARAMETER,
515528
storage_mass_activation: ForkActivation::always(),
529+
kip10_activation: ForkActivation::never(),
516530

517531
skip_proof_of_work: false,
518532
max_block_level: 250,
@@ -566,6 +580,7 @@ pub const SIMNET_PARAMS: Params = Params {
566580

567581
storage_mass_parameter: STORAGE_MASS_PARAMETER,
568582
storage_mass_activation: ForkActivation::always(),
583+
kip10_activation: ForkActivation::never(),
569584

570585
skip_proof_of_work: true, // For simnet only, PoW can be simulated by default
571586
max_block_level: 250,
@@ -612,6 +627,7 @@ pub const DEVNET_PARAMS: Params = Params {
612627

613628
storage_mass_parameter: STORAGE_MASS_PARAMETER,
614629
storage_mass_activation: ForkActivation::never(),
630+
kip10_activation: ForkActivation::never(),
615631

616632
// deflationary_phase_daa_score is the DAA score after which the pre-deflationary period
617633
// switches to the deflationary period. This number is calculated as follows:

Diff for: consensus/core/src/tx.rs

+14
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ pub trait VerifiableTransaction {
293293
fn id(&self) -> TransactionId {
294294
self.tx().id()
295295
}
296+
297+
fn utxo(&self, index: usize) -> Option<&UtxoEntry>;
296298
}
297299

298300
/// A custom iterator written only so that `populated_inputs` has a known return type and can de defined on the trait level
@@ -342,6 +344,10 @@ impl<'a> VerifiableTransaction for PopulatedTransaction<'a> {
342344
fn populated_input(&self, index: usize) -> (&TransactionInput, &UtxoEntry) {
343345
(&self.tx.inputs[index], &self.entries[index])
344346
}
347+
348+
fn utxo(&self, index: usize) -> Option<&UtxoEntry> {
349+
self.entries.get(index)
350+
}
345351
}
346352

347353
/// Represents a validated transaction with populated UTXO entry data and a calculated fee
@@ -370,6 +376,10 @@ impl<'a> VerifiableTransaction for ValidatedTransaction<'a> {
370376
fn populated_input(&self, index: usize) -> (&TransactionInput, &UtxoEntry) {
371377
(&self.tx.inputs[index], &self.entries[index])
372378
}
379+
380+
fn utxo(&self, index: usize) -> Option<&UtxoEntry> {
381+
self.entries.get(index)
382+
}
373383
}
374384

375385
impl AsRef<Transaction> for Transaction {
@@ -507,6 +517,10 @@ impl<T: AsRef<Transaction>> VerifiableTransaction for MutableTransactionVerifiab
507517
self.inner.entries[index].as_ref().expect("expected to be called only following full UTXO population"),
508518
)
509519
}
520+
521+
fn utxo(&self, index: usize) -> Option<&UtxoEntry> {
522+
self.inner.entries.get(index).and_then(Option::as_ref)
523+
}
510524
}
511525

512526
/// Specialized impl for `T=Arc<Transaction>`

Diff for: consensus/src/consensus/services.rs

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ impl ConsensusServices {
146146
tx_script_cache_counters,
147147
mass_calculator.clone(),
148148
params.storage_mass_activation,
149+
params.kip10_activation,
149150
);
150151

151152
let pruning_point_manager = PruningPointManager::new(

Diff for: consensus/src/consensus/test_consensus.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ use kaspa_hashes::Hash;
1313
use kaspa_notify::subscription::context::SubscriptionContext;
1414
use parking_lot::RwLock;
1515

16-
use kaspa_database::create_temp_db;
17-
use kaspa_database::prelude::ConnBuilder;
18-
use std::future::Future;
19-
use std::{sync::Arc, thread::JoinHandle};
20-
16+
use super::services::{DbDagTraversalManager, DbGhostdagManager, DbWindowManager};
17+
use super::Consensus;
2118
use crate::pipeline::virtual_processor::test_block_builder::TestBlockBuilder;
2219
use crate::processes::window::WindowManager;
2320
use crate::{
@@ -35,9 +32,10 @@ use crate::{
3532
pipeline::{body_processor::BlockBodyProcessor, virtual_processor::VirtualStateProcessor, ProcessingCounters},
3633
test_helpers::header_from_precomputed_hash,
3734
};
38-
39-
use super::services::{DbDagTraversalManager, DbGhostdagManager, DbWindowManager};
40-
use super::Consensus;
35+
use kaspa_database::create_temp_db;
36+
use kaspa_database::prelude::ConnBuilder;
37+
use std::future::Future;
38+
use std::{sync::Arc, thread::JoinHandle};
4139

4240
pub struct TestConsensus {
4341
params: Params,
@@ -138,6 +136,12 @@ impl TestConsensus {
138136
self.validate_and_insert_block(self.build_block_with_parents(hash, parents).to_immutable()).virtual_state_task
139137
}
140138

139+
/// Adds a valid block with the given transactions and parents to the consensus.
140+
///
141+
/// # Panics
142+
///
143+
/// Panics if block builder validation rules are violated.
144+
/// See `kaspa_consensus_core::errors::block::RuleError` for the complete list of possible validation rules.
141145
pub fn add_utxo_valid_block_with_parents(
142146
&self,
143147
hash: Hash,
@@ -149,6 +153,12 @@ impl TestConsensus {
149153
.virtual_state_task
150154
}
151155

156+
/// Builds a valid block with the given transactions, parents, and miner data.
157+
///
158+
/// # Panics
159+
///
160+
/// Panics if block builder validation rules are violated.
161+
/// See `kaspa_consensus_core::errors::block::RuleError` for the complete list of possible validation rules.
152162
pub fn build_utxo_valid_block_with_parents(
153163
&self,
154164
hash: Hash,

Diff for: consensus/src/processes/transaction_validator/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ pub struct TransactionValidator {
2828

2929
/// Storage mass hardfork DAA score
3030
storage_mass_activation: ForkActivation,
31+
/// KIP-10 hardfork DAA score
32+
kip10_activation: ForkActivation,
3133
}
3234

3335
impl TransactionValidator {
36+
#[allow(clippy::too_many_arguments)]
3437
pub fn new(
3538
max_tx_inputs: usize,
3639
max_tx_outputs: usize,
@@ -42,6 +45,7 @@ impl TransactionValidator {
4245
counters: Arc<TxScriptCacheCounters>,
4346
mass_calculator: MassCalculator,
4447
storage_mass_activation: ForkActivation,
48+
kip10_activation: ForkActivation,
4549
) -> Self {
4650
Self {
4751
max_tx_inputs,
@@ -54,6 +58,7 @@ impl TransactionValidator {
5458
sig_cache: Cache::with_counters(10_000, counters),
5559
mass_calculator,
5660
storage_mass_activation,
61+
kip10_activation,
5762
}
5863
}
5964

@@ -78,6 +83,7 @@ impl TransactionValidator {
7883
sig_cache: Cache::with_counters(10_000, counters),
7984
mass_calculator: MassCalculator::new(0, 0, 0, 0),
8085
storage_mass_activation: ForkActivation::never(),
86+
kip10_activation: ForkActivation::never(),
8187
}
8288
}
8389
}

0 commit comments

Comments
 (0)