Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized Rothschild performance on high TPS #371

Merged
merged 10 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions consensus/core/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,21 @@ impl Transaction {
gas: u64,
payload: Vec<u8>,
) -> Self {
let mut tx = Self {
let mut tx = Self::new_non_finalized(version, inputs, outputs, lock_time, subnetwork_id, gas, payload);
tx.finalize();
tx
}

pub fn new_non_finalized(
version: u16,
inputs: Vec<TransactionInput>,
outputs: Vec<TransactionOutput>,
lock_time: u64,
subnetwork_id: SubnetworkId,
gas: u64,
payload: Vec<u8>,
) -> Self {
Self {
version,
inputs,
outputs,
Expand All @@ -154,9 +168,7 @@ impl Transaction {
gas,
payload,
id: Default::default(), // Temp init before the finalize below
coderofstuff marked this conversation as resolved.
Show resolved Hide resolved
};
tx.finalize();
tx
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions rothschild/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@ kaspa-rpc-core.workspace = true
kaspa-addresses.workspace = true
kaspa-txscript.workspace = true
kaspa-utils.workspace = true
async-channel.workspace = true
parking_lot.workspace = true

clap.workspace = true
faster-hex.workspace = true
itertools.workspace = true
log.workspace = true
rayon.workspace = true
secp256k1 = { workspace = true, features = ["global-context", "rand-std"] }
tokio = { workspace = true, features = ["rt", "macros", "rt-multi-thread"] }

[dev-dependencies]
criterion.workspace = true

[[bench]]
name = "bench"
harness = false
47 changes: 47 additions & 0 deletions rothschild/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use criterion::{criterion_group, criterion_main, Criterion};
use rayon::prelude::*;

use kaspa_consensus_core::{
constants::TX_VERSION,
subnets::SUBNETWORK_ID_NATIVE,
tx::{ScriptPublicKey, Transaction, TransactionInput, TransactionOutpoint, TransactionOutput},
Hash,
};

fn constuct_tx() -> Transaction {
let inputs = vec![TransactionInput {
previous_outpoint: TransactionOutpoint { transaction_id: Hash::from_bytes([0xFF; 32]), index: 0 },
signature_script: vec![],
sequence: 0,
sig_op_count: 1,
}];
let outputs = vec![TransactionOutput { value: 10000, script_public_key: ScriptPublicKey::from_vec(0, vec![0xff; 35]) }];
Transaction::new(TX_VERSION, inputs, outputs, 0, SUBNETWORK_ID_NATIVE, 0, vec![])
}

fn construct_txs_serially() {
let _ = (0..10000)
.map(|_| {
constuct_tx();
})
.collect::<Vec<_>>();
}

fn construct_txs_parallel() {
let _ = (0..10000)
.into_par_iter()
.map(|_| {
constuct_tx();
})
.collect::<Vec<_>>();
}

pub fn bench_compare_tx_generation(c: &mut Criterion) {
let mut group = c.benchmark_group("compare txs");
group.bench_function("Transaction::SerialCreation", |b| b.iter(construct_txs_serially));
group.bench_function("Transaction::ParallelCreation", |b| b.iter(construct_txs_parallel));
group.finish();
}

criterion_group!(benches, bench_compare_tx_generation);
criterion_main!(benches);
Loading