pending_events
}
}
+
+#[cfg(test)]
+mod tests {
+ use ::{check_added_monitors, get_local_commitment_txn};
+ use ln::features::InitFeatures;
+ use ln::functional_test_utils::*;
+ use util::events::EventsProvider;
+ use util::events::MessageSendEventsProvider;
+ use util::test_utils::{OnRegisterOutput, TxOutReference};
+
+ /// Tests that in-block dependent transactions are processed by `block_connected` when not
+ /// included in `txdata` but returned by [`chain::Filter::register_output`]. For instance,
+ /// a (non-anchor) commitment transaction's HTLC output may be spent in the same block as the
+ /// commitment transaction itself. An Electrum client may filter the commitment transaction but
+ /// needs to return the HTLC transaction so it can be processed.
+ #[test]
+ fn connect_block_checks_dependent_transactions() {
+ let chanmon_cfgs = create_chanmon_cfgs(2);
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
+ let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
+ let channel = create_announced_chan_between_nodes(
+ &nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
+
+ // Send a payment, saving nodes[0]'s revoked commitment and HTLC-Timeout transactions.
+ let (commitment_tx, htlc_tx) = {
+ let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 5_000_000).0;
+ let mut txn = get_local_commitment_txn!(nodes[0], channel.2);
+ claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage, 5_000_000);
+
+ assert_eq!(txn.len(), 2);
+ (txn.remove(0), txn.remove(0))
+ };
+
+ // Set expectations on nodes[1]'s chain source to return dependent transactions.
+ let htlc_output = TxOutReference(commitment_tx.clone(), 0);
+ let to_local_output = TxOutReference(commitment_tx.clone(), 1);
+ let htlc_timeout_output = TxOutReference(htlc_tx.clone(), 0);
+ nodes[1].chain_source
+ .expect(OnRegisterOutput { with: htlc_output, returns: Some((1, htlc_tx)) })
+ .expect(OnRegisterOutput { with: to_local_output, returns: None })
+ .expect(OnRegisterOutput { with: htlc_timeout_output, returns: None });
+
+ // Notify nodes[1] that nodes[0]'s revoked commitment transaction was mined. The chain
+ // source should return the dependent HTLC transaction when the HTLC output is registered.
+ mine_transaction(&nodes[1], &commitment_tx);
+
+ // Clean up so uninteresting assertions don't fail.
+ check_added_monitors!(nodes[1], 1);
+ nodes[1].node.get_and_clear_pending_msg_events();
+ nodes[1].node.get_and_clear_pending_events();
+ }
+}