From dd7546ea09b1dafc3ce7ebedb574a2fd3c2c1f14 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 17 Sep 2020 12:14:05 -0400 Subject: [PATCH] Demo double-spend-creation --- lightning/src/chain/chaininterface.rs | 5 +++-- lightning/src/ln/functional_tests.rs | 13 ++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lightning/src/chain/chaininterface.rs b/lightning/src/chain/chaininterface.rs index 295c337e2..bbef5ec72 100644 --- a/lightning/src/chain/chaininterface.rs +++ b/lightning/src/chain/chaininterface.rs @@ -380,9 +380,10 @@ impl ChainWatchInterface for ChainWatchInterfaceUtil { { let watched = self.watched.lock().unwrap(); for (index, transaction) in block.txdata.iter().enumerate() { - if self.does_match_tx_unguarded(transaction, &watched) { + // Note, while some clients filter, we can't rely on all clients filtering! + //if self.does_match_tx_unguarded(transaction, &watched) { matched_index.push(index); - } + //} } } matched_index diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index a94003c48..6703b1e2e 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -5037,9 +5037,16 @@ fn test_static_spendable_outputs_justice_tx_revoked_htlc_timeout_tx() { check_added_monitors!(nodes[1], 1); let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap(); - assert_eq!(node_txn.len(), 4); // ChannelMonitor: justice tx on revoked commitment, justice tx on revoked HTLC-timeout, adjusted justice tx, ChannelManager: local commitment tx - assert_eq!(node_txn[0].input.len(), 2); - check_spends!(node_txn[0], revoked_local_txn[0]); + assert_eq!(node_txn.len(), 3); // ChannelMonitor: justice tx on revoked commitment, justice tx on revoked HTLC-timeout, adjusted justice tx, ChannelManager: local commitment tx + + // node_txn[0] fully spends revoked_local_txn[0]. + assert_eq!(node_txn[0].input.len(), 3); + assert_eq!(revoked_local_txn[0].output.len(), 2); + // node_txn[0] tries to spend both revoked_local_txn[0] and revoked_htlc_txn[0], but + // revoked_htlc_txn[0] spends revoked_local_txn[0] (ie this is a double-spend)! + check_spends!(node_txn[0], revoked_local_txn[0], revoked_htlc_txn[0]); + check_spends!(revoked_htlc_txn[0], revoked_local_txn[0]); + check_spends!(node_txn[1], chan_1.3); assert_eq!(node_txn[2].input.len(), 1); check_spends!(node_txn[2], revoked_htlc_txn[0]); -- 2.39.5