Skip to content

Commit 6bde56e

Browse files
committed
Test that txn pay at least a minimum relay fee in functional tests
This also pays a fee on the transactions we generate in response to SpendableOutputDescriptors in tests. This fixes the known issues in #630, though we should test for standardness in other ways as well.
1 parent 00142df commit 6bde56e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,14 +481,25 @@ pub fn create_announced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: &'a
481481
macro_rules! check_spends {
482482
($tx: expr, $($spends_txn: expr),*) => {
483483
{
484-
$tx.verify(|out_point| {
484+
let get_output = |out_point: &bitcoin::blockdata::transaction::OutPoint| {
485485
$(
486486
if out_point.txid == $spends_txn.txid() {
487487
return $spends_txn.output.get(out_point.vout as usize).cloned()
488488
}
489489
)*
490490
None
491-
}).unwrap();
491+
};
492+
let mut total_value_in = 0;
493+
for input in $tx.input.iter() {
494+
total_value_in += get_output(&input.previous_output).unwrap().value;
495+
}
496+
let mut total_value_out = 0;
497+
for output in $tx.output.iter() {
498+
total_value_out += output.value;
499+
}
500+
let min_fee = $tx.get_weight() as u64 / 4; // One sat per vbyte
501+
assert!(total_value_out + min_fee <= total_value_in); // Must not be equal as there must be a fee!
502+
$tx.verify(get_output).unwrap();
492503
}
493504
}
494505
}

lightning/src/ln/functional_tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4686,6 +4686,7 @@ macro_rules! check_spendable_outputs {
46864686
input: vec![input],
46874687
output: vec![outp],
46884688
};
4689+
spend_tx.output[0].value -= (spend_tx.get_weight() + 2 + 1 + 73 + 35) as u64 / 4;
46894690
let secp_ctx = Secp256k1::new();
46904691
let keys = $keysinterface.derive_channel_keys($chan_value, key_derivation_params.0, key_derivation_params.1);
46914692
let remotepubkey = keys.pubkeys().payment_point;
@@ -4720,6 +4721,7 @@ macro_rules! check_spendable_outputs {
47204721

47214722
let delayed_payment_pubkey = PublicKey::from_secret_key(&secp_ctx, &delayed_payment_key);
47224723
let witness_script = chan_utils::get_revokeable_redeemscript(revocation_pubkey, *to_self_delay, &delayed_payment_pubkey);
4724+
spend_tx.output[0].value -= (spend_tx.get_weight() + 2 + 1 + 73 + 1 + witness_script.len() + 1) as u64 / 4;
47234725
let sighash = Message::from_slice(&bip143::SigHashCache::new(&spend_tx).signature_hash(0, &witness_script, output.value, SigHashType::All)[..]).unwrap();
47244726
let local_delayedsig = secp_ctx.sign(&sighash, &delayed_payment_key);
47254727
spend_tx.input[0].witness.push(local_delayedsig.serialize_der().to_vec());
@@ -4747,6 +4749,7 @@ macro_rules! check_spendable_outputs {
47474749
input: vec![input],
47484750
output: vec![outp.clone()],
47494751
};
4752+
spend_tx.output[0].value -= (spend_tx.get_weight() + 2 + 1 + 73 + 35) as u64 / 4;
47504753
let secret = {
47514754
match ExtendedPrivKey::new_master(Network::Testnet, &$node.node_seed) {
47524755
Ok(master_key) => {

0 commit comments

Comments
 (0)