Skip to content

Commit 27ee115

Browse files
author
Antoine Riard
committed
Assert on correct registeration of outputs index
We remove test_no_failure_dust_htlc_local_commitment from our test framework as this test deliberately throwing junk transaction in our monitoring parsing code is hitting new assertions. This test was added in #333, but it sounds as an oversight as the correctness intention of this test (i.e verifying lack of dust HTLCs canceling back in case of junk commitment transaction) doesn't currently break.
1 parent 613ac6e commit 27ee115

File tree

2 files changed

+25
-54
lines changed

2 files changed

+25
-54
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,20 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
17721772
let idx_and_scripts = txouts.iter().map(|o| (o.0, o.1.script_pubkey.clone())).collect();
17731773
self.outputs_to_watch.insert(txid.clone(), idx_and_scripts).is_none()
17741774
});
1775+
#[cfg(test)]
1776+
{
1777+
// If we see a transaction for which we registered outputs previously,
1778+
// make sure the registered scriptpubkey at the expected index match
1779+
// the actual transaction output one. We failed this case before #653.
1780+
for tx in &txn_matched {
1781+
if let Some(outputs) = self.get_outputs_to_watch().get(&tx.txid()) {
1782+
for idx_and_script in outputs.iter() {
1783+
assert!((idx_and_script.0 as usize) < tx.output.len());
1784+
assert_eq!(tx.output[idx_and_script.0 as usize].script_pubkey, idx_and_script.1);
1785+
}
1786+
}
1787+
}
1788+
}
17751789
watch_outputs
17761790
}
17771791

@@ -1821,6 +1835,17 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
18211835
if let Some(outputs) = self.get_outputs_to_watch().get(&input.previous_output.txid) {
18221836
for (idx, _script_pubkey) in outputs.iter() {
18231837
if *idx == input.previous_output.vout {
1838+
#[cfg(test)]
1839+
{
1840+
// If the expected script is a known type, check that the witness
1841+
// appears to be spending the correct type (ie that the match would
1842+
// actually succeed in BIP 158/159-style filters).
1843+
if _script_pubkey.is_v0_p2wsh() {
1844+
assert_eq!(&bitcoin::Address::p2wsh(&Script::from(input.witness.last().unwrap().clone()), bitcoin::Network::Bitcoin).script_pubkey(), _script_pubkey);
1845+
} else if _script_pubkey.is_v0_p2wpkh() {
1846+
assert_eq!(&bitcoin::Address::p2wpkh(&bitcoin::PublicKey::from_slice(&input.witness.last().unwrap()).unwrap(), bitcoin::Network::Bitcoin).unwrap().script_pubkey(), _script_pubkey);
1847+
} else { panic!(); }
1848+
}
18241849
return true;
18251850
}
18261851
}

lightning/src/ln/functional_tests.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7157,60 +7157,6 @@ fn test_failure_delay_dust_htlc_local_commitment() {
71577157
do_test_failure_delay_dust_htlc_local_commitment(false);
71587158
}
71597159

7160-
#[test]
7161-
fn test_no_failure_dust_htlc_local_commitment() {
7162-
// Transaction filters for failing back dust htlc based on local commitment txn infos has been
7163-
// prone to error, we test here that a dummy transaction don't fail them.
7164-
7165-
let chanmon_cfgs = create_chanmon_cfgs(2);
7166-
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
7167-
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
7168-
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
7169-
let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
7170-
7171-
// Rebalance a bit
7172-
send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000, 8_000_000);
7173-
7174-
let as_dust_limit = nodes[0].node.channel_state.lock().unwrap().by_id.get(&chan.2).unwrap().holder_dust_limit_satoshis;
7175-
let bs_dust_limit = nodes[1].node.channel_state.lock().unwrap().by_id.get(&chan.2).unwrap().holder_dust_limit_satoshis;
7176-
7177-
// We route 2 dust-HTLCs between A and B
7178-
let (preimage_1, _) = route_payment(&nodes[0], &[&nodes[1]], bs_dust_limit*1000);
7179-
let (preimage_2, _) = route_payment(&nodes[1], &[&nodes[0]], as_dust_limit*1000);
7180-
7181-
// Build a dummy invalid transaction trying to spend a commitment tx
7182-
let input = TxIn {
7183-
previous_output: BitcoinOutPoint { txid: chan.3.txid(), vout: 0 },
7184-
script_sig: Script::new(),
7185-
sequence: 0,
7186-
witness: Vec::new(),
7187-
};
7188-
7189-
let outp = TxOut {
7190-
script_pubkey: Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script(),
7191-
value: 10000,
7192-
};
7193-
7194-
let dummy_tx = Transaction {
7195-
version: 2,
7196-
lock_time: 0,
7197-
input: vec![input],
7198-
output: vec![outp]
7199-
};
7200-
7201-
let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
7202-
nodes[0].chain_monitor.chain_monitor.block_connected(&header, &[(0, &dummy_tx)], 1);
7203-
assert_eq!(nodes[0].node.get_and_clear_pending_events().len(), 0);
7204-
assert_eq!(nodes[0].node.get_and_clear_pending_msg_events().len(), 0);
7205-
// We broadcast a few more block to check everything is all right
7206-
connect_blocks(&nodes[0], 20, 1, true, header.block_hash());
7207-
assert_eq!(nodes[0].node.get_and_clear_pending_events().len(), 0);
7208-
assert_eq!(nodes[0].node.get_and_clear_pending_msg_events().len(), 0);
7209-
7210-
claim_payment(&nodes[0], &vec!(&nodes[1])[..], preimage_1, bs_dust_limit*1000);
7211-
claim_payment(&nodes[1], &vec!(&nodes[0])[..], preimage_2, as_dust_limit*1000);
7212-
}
7213-
72147160
fn do_test_sweep_outbound_htlc_failure_update(revoked: bool, local: bool) {
72157161
// Outbound HTLC-failure updates must be cancelled if we get a reorg before we reach ANTI_REORG_DELAY.
72167162
// Broadcast of revoked remote commitment tx, trigger failure-update of dust/non-dust HTLCs

0 commit comments

Comments
 (0)