+ // One or more claim tx should have been broadcast, check it
+ let timeout;
+ let preimage;
+ let feerate_timeout;
+ let feerate_preimage;
+ {
+ let mut node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
+ assert_eq!(node_txn.len(), 7); // 2 * claim tx (broadcasted from ChannelMonitor) * 2 (block-reparsing) + local commitment tx + local HTLC-timeout + HTLC-success (broadcasted from ChannelManager)
+ assert_eq!(node_txn[0], node_txn[5]);
+ assert_eq!(node_txn[1], node_txn[6]);
+ assert_eq!(node_txn[0].input.len(), 1);
+ assert_eq!(node_txn[1].input.len(), 1);
+ check_spends!(node_txn[0], remote_txn[0].clone());
+ check_spends!(node_txn[1], remote_txn[0].clone());
+ check_spends!(node_txn[2], chan.3);
+ check_spends!(node_txn[3], node_txn[2]);
+ check_spends!(node_txn[4], node_txn[2]);
+ if node_txn[0].input[0].witness.last().unwrap().len() == ACCEPTED_HTLC_SCRIPT_WEIGHT {
+ timeout = node_txn[0].txid();
+ let index = node_txn[0].input[0].previous_output.vout;
+ let fee = remote_txn[0].output[index as usize].value - node_txn[0].output[0].value;
+ feerate_timeout = fee * 1000 / node_txn[0].get_weight() as u64;
+
+ preimage = node_txn[1].txid();
+ let index = node_txn[1].input[0].previous_output.vout;
+ let fee = remote_txn[0].output[index as usize].value - node_txn[1].output[0].value;
+ feerate_preimage = fee * 1000 / node_txn[1].get_weight() as u64;
+ } else {
+ timeout = node_txn[1].txid();
+ let index = node_txn[1].input[0].previous_output.vout;
+ let fee = remote_txn[0].output[index as usize].value - node_txn[1].output[0].value;
+ feerate_timeout = fee * 1000 / node_txn[1].get_weight() as u64;
+
+ preimage = node_txn[0].txid();
+ let index = node_txn[0].input[0].previous_output.vout;
+ let fee = remote_txn[0].output[index as usize].value - node_txn[0].output[0].value;
+ feerate_preimage = fee * 1000 / node_txn[0].get_weight() as u64;
+ }
+ node_txn.clear();
+ };
+ assert_ne!(feerate_timeout, 0);
+ assert_ne!(feerate_preimage, 0);
+
+ // After exhaustion of height timer, new bumped claim txn should have been broadcast, check it
+ connect_blocks(&nodes[1].block_notifier, 15, 1, true, header.bitcoin_hash());
+ {
+ let mut node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
+ assert_eq!(node_txn.len(), 2);
+ assert_eq!(node_txn[0].input.len(), 1);
+ assert_eq!(node_txn[1].input.len(), 1);
+ check_spends!(node_txn[0], remote_txn[0].clone());
+ check_spends!(node_txn[1], remote_txn[0].clone());
+ if node_txn[0].input[0].witness.last().unwrap().len() == ACCEPTED_HTLC_SCRIPT_WEIGHT {
+ let index = node_txn[0].input[0].previous_output.vout;
+ let fee = remote_txn[0].output[index as usize].value - node_txn[0].output[0].value;
+ let new_feerate = fee * 1000 / node_txn[0].get_weight() as u64;
+ assert!(new_feerate * 100 > feerate_timeout * 125);
+ assert_ne!(timeout, node_txn[0].txid());
+
+ let index = node_txn[1].input[0].previous_output.vout;
+ let fee = remote_txn[0].output[index as usize].value - node_txn[1].output[0].value;
+ let new_feerate = fee * 1000 / node_txn[1].get_weight() as u64;
+ assert!(new_feerate * 100 > feerate_preimage * 125);
+ assert_ne!(preimage, node_txn[1].txid());
+ } else {
+ let index = node_txn[1].input[0].previous_output.vout;
+ let fee = remote_txn[0].output[index as usize].value - node_txn[1].output[0].value;
+ let new_feerate = fee * 1000 / node_txn[1].get_weight() as u64;
+ assert!(new_feerate * 100 > feerate_timeout * 125);
+ assert_ne!(timeout, node_txn[1].txid());
+
+ let index = node_txn[0].input[0].previous_output.vout;
+ let fee = remote_txn[0].output[index as usize].value - node_txn[0].output[0].value;
+ let new_feerate = fee * 1000 / node_txn[0].get_weight() as u64;
+ assert!(new_feerate * 100 > feerate_preimage * 125);
+ assert_ne!(preimage, node_txn[0].txid());
+ }
+ node_txn.clear();
+ }
+
+ nodes[1].node.get_and_clear_pending_events();
+ nodes[1].node.get_and_clear_pending_msg_events();
+}
+
+#[test]
+fn test_set_outpoints_partial_claiming() {
+ // - remote party claim tx, new bump tx
+ // - disconnect remote claiming tx, new bump
+ // - disconnect tx, see no tx anymore
+ let node_cfgs = create_node_cfgs(2);
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
+ let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
+
+ let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000, InitFeatures::supported(), InitFeatures::supported());
+ let payment_preimage_1 = route_payment(&nodes[1], &vec!(&nodes[0])[..], 3_000_000).0;
+ let payment_preimage_2 = route_payment(&nodes[1], &vec!(&nodes[0])[..], 3_000_000).0;
+
+ // Remote commitment txn with 4 outputs: to_local, to_remote, 2 outgoing HTLC
+ let remote_txn = nodes[1].node.channel_state.lock().unwrap().by_id.get_mut(&chan.2).unwrap().channel_monitor().get_latest_local_commitment_txn();
+ assert_eq!(remote_txn.len(), 3);
+ assert_eq!(remote_txn[0].output.len(), 4);
+ assert_eq!(remote_txn[0].input.len(), 1);
+ assert_eq!(remote_txn[0].input[0].previous_output.txid, chan.3.txid());
+ check_spends!(remote_txn[1], remote_txn[0].clone());
+ check_spends!(remote_txn[2], remote_txn[0].clone());
+
+ // Connect blocks on node A to advance height towards TEST_FINAL_CLTV
+ let prev_header_100 = connect_blocks(&nodes[1].block_notifier, 100, 0, false, Default::default());
+ // Provide node A with both preimage
+ nodes[0].node.claim_funds(payment_preimage_1, 3_000_000);
+ nodes[0].node.claim_funds(payment_preimage_2, 3_000_000);
+ check_added_monitors!(nodes[0], 2);
+ nodes[0].node.get_and_clear_pending_events();
+ nodes[0].node.get_and_clear_pending_msg_events();
+
+ // Connect blocks on node A commitment transaction
+ let header = BlockHeader { version: 0x20000000, prev_blockhash: prev_header_100, merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
+ nodes[0].block_notifier.block_connected(&Block { header, txdata: vec![remote_txn[0].clone()] }, 101);
+ // Verify node A broadcast tx claiming both HTLCs
+ {
+ let mut node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
+ assert_eq!(node_txn.len(), 5);
+ assert_eq!(node_txn[0], node_txn[4]);
+ check_spends!(node_txn[0], remote_txn[0].clone());
+ check_spends!(node_txn[1], chan.3.clone());
+ check_spends!(node_txn[2], node_txn[1]);
+ check_spends!(node_txn[3], node_txn[1]);
+ assert_eq!(node_txn[0].input.len(), 2);
+ node_txn.clear();
+ }
+ nodes[0].node.get_and_clear_pending_msg_events();
+
+ // Connect blocks on node B
+ connect_blocks(&nodes[1].block_notifier, 135, 0, false, Default::default());
+ // Verify node B broadcast 2 HTLC-timeout txn
+ let partial_claim_tx = {
+ let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
+ assert_eq!(node_txn.len(), 3);
+ check_spends!(node_txn[1], node_txn[0].clone());
+ check_spends!(node_txn[2], node_txn[0].clone());
+ assert_eq!(node_txn[1].input.len(), 1);
+ assert_eq!(node_txn[2].input.len(), 1);
+ node_txn[1].clone()
+ };
+ nodes[1].node.get_and_clear_pending_msg_events();
+
+ // Broadcast partial claim on node A, should regenerate a claiming tx with HTLC dropped
+ let header = BlockHeader { version: 0x20000000, prev_blockhash: header.bitcoin_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
+ nodes[0].block_notifier.block_connected(&Block { header, txdata: vec![partial_claim_tx.clone()] }, 102);