Skip to content

Commit a2aabf6

Browse files
committed
Fix claim_htlc_outputs_single_tx for fixed monitoring
1 parent f3ff7e1 commit a2aabf6

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

src/ln/channelmanager.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3584,44 +3584,46 @@ mod tests {
35843584

35853585
nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 200);
35863586
let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
3587-
assert_eq!(node_txn.len(), 10); // ChannelManager : 2, ChannelMontitor: 8 (2 revocation htlc tx, 1 local commitment tx + 1 htlc timeout tx) * 2 (block-rescan)
3587+
assert_eq!(node_txn.len(), 12); // ChannelManager : 2, ChannelMontitor: 8 (1 standard revoked output, 2 revocation htlc tx, 1 local commitment tx + 1 htlc timeout tx) * 2 (block-rescan)
35883588

3589-
assert_eq!(node_txn[0], node_txn[6]);
3590-
assert_eq!(node_txn[1], node_txn[7]);
3591-
assert_eq!(node_txn[2], node_txn[8]);
3592-
assert_eq!(node_txn[3], node_txn[9]);
3593-
assert_eq!(node_txn[2], node_txn[4]); //local commitment tx + htlc timeout tx broadcated by ChannelManger
3594-
assert_eq!(node_txn[3], node_txn[5]);
3589+
assert_eq!(node_txn[0], node_txn[7]);
3590+
assert_eq!(node_txn[1], node_txn[8]);
3591+
assert_eq!(node_txn[2], node_txn[9]);
3592+
assert_eq!(node_txn[3], node_txn[10]);
3593+
assert_eq!(node_txn[4], node_txn[11]);
3594+
assert_eq!(node_txn[3], node_txn[5]); //local commitment tx + htlc timeout tx broadcated by ChannelManger
3595+
assert_eq!(node_txn[4], node_txn[6]);
35953596

35963597
assert_eq!(node_txn[0].input.len(), 1);
35973598
assert_eq!(node_txn[1].input.len(), 1);
3599+
assert_eq!(node_txn[2].input.len(), 1);
35983600

35993601
let mut revoked_tx_map = HashMap::new();
36003602
revoked_tx_map.insert(revoked_local_txn[0].txid(), revoked_local_txn[0].clone());
36013603
node_txn[0].verify(&revoked_tx_map).unwrap();
36023604
node_txn[1].verify(&revoked_tx_map).unwrap();
3605+
node_txn[2].verify(&revoked_tx_map).unwrap();
36033606

3604-
let witness_script_1 = node_txn[0].clone().input[0].witness.pop().unwrap();
3605-
let witness_script_2 = node_txn[1].clone().input[0].witness.pop().unwrap();
3606-
if witness_script_1.len() > 133 {
3607-
assert_eq!(witness_script_1.len(), 138);
3608-
assert_eq!(witness_script_2.len(), 133);
3609-
} else {
3610-
assert_eq!(witness_script_1.len(), 133);
3611-
assert_eq!(witness_script_2.len(), 138);
3612-
}
3607+
let mut witness_lens = BTreeSet::new();
3608+
witness_lens.insert(node_txn[0].input[0].witness.clone().pop().unwrap().len());
3609+
witness_lens.insert(node_txn[1].input[0].witness.clone().pop().unwrap().len());
3610+
witness_lens.insert(node_txn[2].input[0].witness.clone().pop().unwrap().len());
3611+
assert_eq!(witness_lens.len(), 3);
3612+
assert_eq!(*witness_lens.iter().skip(0).next().unwrap(), 77); // revoked to_local
3613+
assert_eq!(*witness_lens.iter().skip(1).next().unwrap(), 133); // revoked offered HTLC
3614+
assert_eq!(*witness_lens.iter().skip(2).next().unwrap(), 138); // revoked received HTLC
36133615

36143616
let mut funding_tx_map = HashMap::new();
36153617
funding_tx_map.insert(chan_1.3.txid(), chan_1.3.clone());
3616-
node_txn[2].verify(&funding_tx_map).unwrap();
3617-
assert_eq!(node_txn[2].input.len(), 1);
3618-
3618+
node_txn[3].verify(&funding_tx_map).unwrap();
36193619
assert_eq!(node_txn[3].input.len(), 1);
3620-
let witness_script = node_txn[3].clone().input[0].witness.pop().unwrap();
3620+
3621+
assert_eq!(node_txn[4].input.len(), 1);
3622+
let witness_script = node_txn[4].input[0].witness.clone().pop().unwrap();
36213623
assert_eq!(witness_script.len(), 133); //Spending an offered htlc output
3622-
assert_eq!(node_txn[3].input[0].previous_output.txid, node_txn[2].txid());
3623-
assert_ne!(node_txn[3].input[0].previous_output.txid, node_txn[0].input[0].previous_output.txid);
3624-
assert_ne!(node_txn[3].input[0].previous_output.txid, node_txn[1].input[0].previous_output.txid);
3624+
assert_eq!(node_txn[4].input[0].previous_output.txid, node_txn[3].txid());
3625+
assert_ne!(node_txn[4].input[0].previous_output.txid, node_txn[0].input[0].previous_output.txid);
3626+
assert_ne!(node_txn[4].input[0].previous_output.txid, node_txn[1].input[0].previous_output.txid);
36253627
}
36263628
get_announce_close_broadcast_events(&nodes, 0, 1);
36273629
assert_eq!(nodes[0].node.list_channels().len(), 0);

0 commit comments

Comments
 (0)