Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ jobs:
- name: Run isolated Simnet native proof-of-work regression
run: cargo nextest run -p kaspa-testing-integration --test phase6_native_pow_relay --features phase6-staging-preview

- name: Record native signed settlement batch evidence
if: github.head_ref == 'test/phase6-native-mixed-settlement-workload-20261129' || github.ref_name == 'test/phase6-native-mixed-settlement-workload-20261129'
run: >-
cargo nextest run --locked -p kaspa-testing-integration --test phase6_native_pow_relay --features phase6-staging-preview
--success-output immediate -E 'test(=phase6_native_signed_batches_settle_and_reopen_across_peers)'

- name: Run 35-year emission candidate regressions
if: github.head_ref == 'design/29b-emission-validation-20261122' || github.ref_name == 'design/29b-emission-validation-20261122'
run: cargo nextest run -p kaspa-consensus --lib --features phase6-staging-preview -E 'test(emission_candidate_)'
Expand Down
166 changes: 104 additions & 62 deletions testing/integration/tests/phase6_native_pow_relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ async fn settled_output(

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn phase6_native_signed_fee_settles_and_reopens_across_peers() {
verify_native_signed_settlements(1, 1).await;
}

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn phase6_native_signed_batches_settle_and_reopen_across_peers() {
verify_native_signed_settlements(4, 2).await;
}

async fn verify_native_signed_settlements(settlement_blocks: usize, spends_per_block: usize) {
kaspa_alloc::init_allocator_with_default_settings();
const MATURITY: u64 = 2;
const WARMUP_INTERVAL: Duration = Duration::from_secs(1);
Expand Down Expand Up @@ -196,59 +205,16 @@ async fn phase6_native_signed_fee_settles_and_reopens_across_peers() {
for client in clients {
wait_for_sink(client, tip).await;
}
// Keep the fixture's native warmup on the same one-second cadence as the
// sustained relay rehearsal. After the last tip, let the preceding block's
// mempool bookkeeping finish and its 500 ms announcement interval elapse
// before submitting the only transaction in this otherwise idle fixture.
// Establish a recent, synchronized sink at the cadence used by the
// sustained native relay rehearsal.
tokio::time::sleep(WARMUP_INTERVAL).await;
}
for client in clients {
assert!(client.get_server_info().await.unwrap().is_synced, "transaction relay requires a recent sink");
}

let (input, entry) = tokio::time::timeout(Duration::from_secs(10), async {
loop {
if let Some(coinbase) = utils::fetch_spendable_utxos(&second_client, miner.clone(), MATURITY).await.into_iter().next() {
return coinbase;
}
tokio::time::sleep(Duration::from_millis(50)).await;
}
})
.await
.expect("fixture did not produce a mature native coinbase");
let fee_amount = fee::calc_for_plain_standard_tx(1, 1);
let output_amount = entry.amount.checked_sub(fee_amount).unwrap();
let signed = signed_spend(input, entry.clone(), &destination, key, fee_amount);
let conflict = signed_spend(input, entry, &destination, key, fee_amount + 1);
assert_ne!(signed.id(), conflict.id());
assert_eq!(second_client.submit_transaction((&signed).into(), false).await.unwrap(), signed.id());
for (node, client) in ["miner", "submitter", "follower"].into_iter().zip(clients) {
let mempool = tokio::time::timeout(Duration::from_secs(15), async {
loop {
if let Ok(tx) = client.get_mempool_entry(signed.id(), false, false).await {
return tx;
}
tokio::time::sleep(Duration::from_millis(50)).await;
}
})
.await
.unwrap_or_else(|_| panic!("{node} did not receive signed spend {}", signed.id()));
assert!(!mempool.is_orphan);
assert_eq!(mempool.fee, fee_amount);
assert_eq!(Transaction::try_from(mempool.transaction).unwrap().id(), signed.id());
}

let template = first_client.get_block_template(miner.clone(), vec![]).await.unwrap().block;
assert_eq!(template.transactions.len(), 2);
let included = Transaction::try_from(template.transactions[1].clone()).unwrap();
assert_eq!(included.id(), signed.id());
assert_eq!(included.inputs[0].signature_script, signed.inputs[0].signature_script);
let source = submit_native_template(&first_client, template).await;
for client in clients {
wait_for_sink(client, source).await;
}

// The child pays the selected parent's subsidy and validated fees.
let batch_fee = fee_amount * u64::try_from(spends_per_block).unwrap();
let params = &SIMNET_PARAMS;
let coinbase = CoinbaseManager::new(
params.coinbase_payload_script_public_key_max_len,
Expand All @@ -262,30 +228,106 @@ async fn phase6_native_signed_fee_settles_and_reopens_across_peers() {
params.dev_fee_accrual_activation,
params.dev_fee_payout_interval,
);
let source = first_client.get_block(source, true).await.unwrap();
let subsidy = coinbase.deserialize_coinbase_payload(&source.transactions[0].payload).unwrap().subsidy;
assert!(subsidy > 0);
let tip = submit_native_block(&first_client, &miner, false).await;
let output = TransactionOutpoint::new(signed.id(), 0);
let expected = settled_output(&first_client, &miner, &destination, input, output).await;
assert_eq!(expected.amount, output_amount);
assert!(!expected.is_coinbase);
for client in clients {
wait_for_sink(client, tip).await;
let child = client.get_block(tip, true).await.unwrap();
assert_eq!(child.transactions[0].outputs.iter().map(|output| output.value).sum::<u64>(), subsidy + fee_amount);
assert_eq!(settled_output(client, &miner, &destination, input, output).await, expected);
let mut settled_outputs = Vec::with_capacity(settlement_blocks * spends_per_block);
let mut tip = first_client.get_block_dag_info().await.unwrap().sink;
let workload_started = tokio::time::Instant::now();
for wave in 1..=settlement_blocks {
let inputs = tokio::time::timeout(Duration::from_secs(10), async {
loop {
let inputs = utils::fetch_spendable_utxos(&second_client, miner.clone(), MATURITY).await;
if inputs.len() >= spends_per_block {
return inputs.into_iter().take(spends_per_block);
}
tokio::time::sleep(Duration::from_millis(50)).await;
}
})
.await
.expect("fixture did not produce enough mature native coinbases");
let mut spends = Vec::with_capacity(spends_per_block);
for (input, entry) in inputs {
assert!(!settled_outputs.iter().any(|(spent, _, _)| *spent == input));
let output_amount = entry.amount.checked_sub(fee_amount).unwrap();
let signed = signed_spend(input, entry.clone(), &destination, key, fee_amount);
let conflict = signed_spend(input, entry, &destination, key, fee_amount + 1);
assert_ne!(signed.id(), conflict.id());
assert_eq!(second_client.submit_transaction((&signed).into(), false).await.unwrap(), signed.id());
spends.push((input, output_amount, signed, conflict));
}

// Leave the chain idle until every signed spend has reached both hops.
// Mining meanwhile could mask a missing idle inventory flush.
for (node, client) in ["miner", "submitter", "follower"].into_iter().zip(clients) {
for (_, _, signed, _) in &spends {
let mempool = tokio::time::timeout(Duration::from_secs(15), async {
loop {
if let Ok(tx) = client.get_mempool_entry(signed.id(), false, false).await {
return tx;
}
tokio::time::sleep(Duration::from_millis(50)).await;
}
})
.await
.unwrap_or_else(|_| panic!("wave {wave}: {node} did not receive signed spend {}", signed.id()));
assert!(!mempool.is_orphan);
assert_eq!(mempool.fee, fee_amount);
assert_eq!(Transaction::try_from(mempool.transaction).unwrap().id(), signed.id());
}
}

let template = first_client.get_block_template(miner.clone(), vec![]).await.unwrap().block;
assert_eq!(template.transactions.len(), spends_per_block + 1);
let included = template.transactions[1..].iter().cloned().map(|tx| Transaction::try_from(tx).unwrap()).collect::<Vec<_>>();
for (_, _, signed, _) in &spends {
let included = included.iter().find(|tx| tx.id() == signed.id()).expect("template omitted a signed spend");
assert_eq!(included.inputs[0].signature_script, signed.inputs[0].signature_script);
}
let source_hash = submit_native_template(&first_client, template).await;
for client in clients {
wait_for_sink(client, source_hash).await;
}

// The child pays the selected parent's subsidy and validated fees.
let source = first_client.get_block(source_hash, true).await.unwrap();
let subsidy = coinbase.deserialize_coinbase_payload(&source.transactions[0].payload).unwrap().subsidy;
assert!(subsidy > 0);
tip = submit_native_block(&first_client, &miner, false).await;
for client in clients {
wait_for_sink(client, tip).await;
let child = client.get_block(tip, true).await.unwrap();
assert_eq!(child.transactions[0].outputs.iter().map(|output| output.value).sum::<u64>(), subsidy + batch_fee);
}
for (input, output_amount, signed, conflict) in spends {
let output = TransactionOutpoint::new(signed.id(), 0);
let expected = settled_output(&first_client, &miner, &destination, input, output).await;
assert_eq!(expected.amount, output_amount);
assert!(!expected.is_coinbase);
for client in clients {
assert_eq!(settled_output(client, &miner, &destination, input, output).await, expected);
}
assert!(third_client.submit_transaction((&conflict).into(), false).await.is_err());
assert!(third_client.get_mempool_entry(conflict.id(), true, false).await.is_err());
settled_outputs.push((input, output, expected));
}
println!("phase6_native_signed_wave wave={wave} spends={spends_per_block} fee={batch_fee} source={source_hash} tip={tip}");
}
assert!(third_client.submit_transaction((&conflict).into(), false).await.is_err());
assert!(third_client.get_mempool_entry(conflict.id(), true, false).await.is_err());
let workload_elapsed = workload_started.elapsed();

third_client.disconnect().await.unwrap();
drop(third_client);
let mut third = third.restart(10);
let third_client = third.start().await;
assert!(third_client.get_connected_peer_info().await.unwrap().peer_info.is_empty());
wait_for_sink(&third_client, tip).await;
assert_eq!(settled_output(&third_client, &miner, &destination, input, output).await, expected);
for (input, output, expected) in &settled_outputs {
assert_eq!(settled_output(&third_client, &miner, &destination, *input, *output).await, *expected);
}
println!(
"phase6_native_signed_summary waves={settlement_blocks} spends={} native_workload_blocks={} total_fees={} elapsed_ms={} offline_reopened_tip={tip}",
settled_outputs.len(),
settlement_blocks * 2,
fee_amount * u64::try_from(settled_outputs.len()).unwrap(),
workload_elapsed.as_millis()
);
first_client.disconnect().await.unwrap();
second_client.disconnect().await.unwrap();
third_client.disconnect().await.unwrap();
Expand Down
Loading