Skip to content

Commit 3219926

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 b43a7e3 commit 3219926

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,14 +505,26 @@ pub fn create_announced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: &'a
505505
macro_rules! check_spends {
506506
($tx: expr, $($spends_txn: expr),*) => {
507507
{
508-
$tx.verify(|out_point| {
508+
let get_output = |out_point: &bitcoin::blockdata::transaction::OutPoint| {
509509
$(
510510
if out_point.txid == $spends_txn.txid() {
511511
return $spends_txn.output.get(out_point.vout as usize).cloned()
512512
}
513513
)*
514514
None
515-
}).unwrap();
515+
};
516+
let mut total_value_in = 0;
517+
for input in $tx.input.iter() {
518+
total_value_in += get_output(&input.previous_output).unwrap().value;
519+
}
520+
let mut total_value_out = 0;
521+
for output in $tx.output.iter() {
522+
total_value_out += output.value;
523+
}
524+
let min_fee = ($tx.get_weight() as u64 + 3) / 4; // One sat per vbyte (ie per weight/4, rounded up)
525+
// Input amount - output amount = fee, so check that out + min_fee is smaller than input
526+
assert!(total_value_out + min_fee <= total_value_in);
527+
$tx.verify(get_output).unwrap();
516528
}
517529
}
518530
}

lightning/src/ln/functional_tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4708,6 +4708,7 @@ macro_rules! check_spendable_outputs {
47084708
input: vec![input],
47094709
output: vec![outp],
47104710
};
4711+
spend_tx.output[0].value -= (spend_tx.get_weight() + 2 + 1 + 73 + 35 + 3) as u64 / 4; // (Max weight + 3 (to round up)) / 4
47114712
let secp_ctx = Secp256k1::new();
47124713
let keys = $keysinterface.derive_channel_keys($chan_value, key_derivation_params.0, key_derivation_params.1);
47134714
let remotepubkey = keys.pubkeys().payment_point;
@@ -4742,6 +4743,7 @@ macro_rules! check_spendable_outputs {
47424743

47434744
let delayed_payment_pubkey = PublicKey::from_secret_key(&secp_ctx, &delayed_payment_key);
47444745
let witness_script = chan_utils::get_revokeable_redeemscript(revocation_pubkey, *to_self_delay, &delayed_payment_pubkey);
4746+
spend_tx.output[0].value -= (spend_tx.get_weight() + 2 + 1 + 73 + 1 + witness_script.len() + 1 + 3) as u64 / 4; // (Max weight + 3 (to round up)) / 4
47454747
let sighash = Message::from_slice(&bip143::SigHashCache::new(&spend_tx).signature_hash(0, &witness_script, output.value, SigHashType::All)[..]).unwrap();
47464748
let local_delayedsig = secp_ctx.sign(&sighash, &delayed_payment_key);
47474749
spend_tx.input[0].witness.push(local_delayedsig.serialize_der().to_vec());
@@ -4769,6 +4771,7 @@ macro_rules! check_spendable_outputs {
47694771
input: vec![input],
47704772
output: vec![outp.clone()],
47714773
};
4774+
spend_tx.output[0].value -= (spend_tx.get_weight() + 2 + 1 + 73 + 35 + 3) as u64 / 4; // (Max weight + 3 (to round up)) / 4
47724775
let secret = {
47734776
match ExtendedPrivKey::new_master(Network::Testnet, &$node.node_seed) {
47744777
Ok(master_key) => {

0 commit comments

Comments
 (0)