Add log_trace on bump candidates tracking-buffer insertions
[rust-lightning] / lightning / src / ln / channelmonitor.rs
index dfa56d6f2555cab8c59520a5183d1dc6e5f1f7fe..a53a562b88fa6abe3c943d6ef6c642d09e78a1fb 100644 (file)
@@ -152,7 +152,8 @@ pub struct SimpleManyChannelMonitor<Key> {
        fee_estimator: Arc<FeeEstimator>
 }
 
-impl<Key : Send + cmp::Eq + hash::Hash> ChainListener for SimpleManyChannelMonitor<Key> {
+impl<'a, Key : Send + cmp::Eq + hash::Hash> ChainListener for SimpleManyChannelMonitor<Key> {
+
        fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], _indexes_of_txn_matched: &[u32]) {
                let block_hash = header.bitcoin_hash();
                let mut new_events: Vec<events::Event> = Vec::with_capacity(0);
@@ -1414,6 +1415,7 @@ impl ChannelMonitor {
                                                                let sighash_parts = bip143::SighashComponents::new(&single_htlc_tx);
                                                                let (redeemscript, revocation_key) = sign_input!(sighash_parts, single_htlc_tx.input[0], Some(idx), htlc.amount_msat / 1000);
                                                                assert!(predicted_weight >= single_htlc_tx.get_weight());
+                                                               log_trace!(self, "Outpoint {}:{} is being being claimed, if it doesn't succeed, a bumped claiming txn is going to be broadcast at height {}", single_htlc_tx.input[0].previous_output.txid, single_htlc_tx.input[0].previous_output.vout, height_timer);
                                                                match self.our_claim_txn_waiting_first_conf.entry(single_htlc_tx.input[0].previous_output.clone()) {
                                                                        hash_map::Entry::Occupied(_) => {},
                                                                        hash_map::Entry::Vacant(entry) => { entry.insert((height_timer, TxMaterial::Revoked { script: redeemscript, pubkey: Some(revocation_pubkey), key: revocation_key, is_htlc: true, amount: htlc.amount_msat / 1000 }, used_feerate, htlc.cltv_expiry, height)); }
@@ -1494,6 +1496,7 @@ impl ChannelMonitor {
                        for (input, info) in spend_tx.input.iter_mut().zip(inputs_info.iter()) {
                                let (redeemscript, revocation_key) = sign_input!(sighash_parts, input, info.0, info.1);
                                let height_timer = Self::get_height_timer(height, info.2);
+                               log_trace!(self, "Outpoint {}:{} is being being claimed, if it doesn't succeed, a bumped claiming txn is going to be broadcast at height {}", input.previous_output.txid, input.previous_output.vout, height_timer);
                                match self.our_claim_txn_waiting_first_conf.entry(input.previous_output.clone()) {
                                        hash_map::Entry::Occupied(_) => {},
                                        hash_map::Entry::Vacant(entry) => { entry.insert((height_timer, TxMaterial::Revoked { script: redeemscript, pubkey: if info.0.is_some() { Some(revocation_pubkey) } else { None }, key: revocation_key, is_htlc: if info.0.is_some() { true } else { false }, amount: info.1 }, used_feerate, if !info.0.is_some() { height + info.2 } else { info.2 }, height)); }
@@ -1684,6 +1687,7 @@ impl ChannelMonitor {
                                                                                                outpoint: BitcoinOutPoint { txid: single_htlc_tx.txid(), vout: 0 },
                                                                                                output: single_htlc_tx.output[0].clone(),
                                                                                        });
+                                                                                       log_trace!(self, "Outpoint {}:{} is being being claimed, if it doesn't succeed, a bumped claiming txn is going to be broadcast at height {}", single_htlc_tx.input[0].previous_output.txid, single_htlc_tx.input[0].previous_output.vout, height_timer);
                                                                                        match self.our_claim_txn_waiting_first_conf.entry(single_htlc_tx.input[0].previous_output.clone()) {
                                                                                                hash_map::Entry::Occupied(_) => {},
                                                                                                hash_map::Entry::Vacant(entry) => { entry.insert((height_timer, TxMaterial::RemoteHTLC { script: redeemscript, key: htlc_key, preimage: Some(*payment_preimage), amount: htlc.amount_msat / 1000 }, used_feerate, htlc.cltv_expiry, height)); }
@@ -1722,6 +1726,7 @@ impl ChannelMonitor {
                                                                        let (redeemscript, htlc_key) = sign_input!(sighash_parts, timeout_tx.input[0], htlc.amount_msat / 1000, vec![0]);
                                                                        assert!(predicted_weight >= timeout_tx.get_weight());
                                                                        //TODO: track SpendableOutputDescriptor
+                                                                       log_trace!(self, "Outpoint {}:{} is being being claimed, if it doesn't succeed, a bumped claiming txn is going to be broadcast at height {}", timeout_tx.input[0].previous_output.txid, timeout_tx.input[0].previous_output.vout, height_timer);
                                                                        match self.our_claim_txn_waiting_first_conf.entry(timeout_tx.input[0].previous_output.clone()) {
                                                                                hash_map::Entry::Occupied(_) => {},
                                                                                hash_map::Entry::Vacant(entry) => { entry.insert((height_timer, TxMaterial::RemoteHTLC { script : redeemscript, key: htlc_key, preimage: None, amount: htlc.amount_msat / 1000 }, used_feerate, htlc.cltv_expiry, height)); }
@@ -1757,6 +1762,7 @@ impl ChannelMonitor {
                                        for (input, info) in spend_tx.input.iter_mut().zip(inputs_info.iter()) {
                                                let (redeemscript, htlc_key) = sign_input!(sighash_parts, input, info.1, (info.0).0.to_vec());
                                                let height_timer = Self::get_height_timer(height, info.2);
+                                               log_trace!(self, "Outpoint {}:{} is being being claimed, if it doesn't succeed, a bumped claiming txn is going to be broadcast at height {}", input.previous_output.txid, input.previous_output.vout, height_timer);
                                                match self.our_claim_txn_waiting_first_conf.entry(input.previous_output.clone()) {
                                                        hash_map::Entry::Occupied(_) => {},
                                                        hash_map::Entry::Vacant(entry) => { entry.insert((height_timer, TxMaterial::RemoteHTLC { script: redeemscript, key: htlc_key, preimage: Some(*(info.0)), amount: info.1}, used_feerate, info.2, height)); }
@@ -1874,6 +1880,7 @@ impl ChannelMonitor {
                        let outpoint = BitcoinOutPoint { txid: spend_tx.txid(), vout: 0 };
                        let output = spend_tx.output[0].clone();
                        let height_timer = Self::get_height_timer(height, self.their_to_self_delay.unwrap() as u32); // We can safely unwrap given we are past channel opening
+                       log_trace!(self, "Outpoint {}:{} is being being claimed, if it doesn't succeed, a bumped claiming txn is going to be broadcast at height {}", spend_tx.input[0].previous_output.txid, spend_tx.input[0].previous_output.vout, height_timer);
                        match self.our_claim_txn_waiting_first_conf.entry(spend_tx.input[0].previous_output.clone()) {
                                hash_map::Entry::Occupied(_) => {},
                                hash_map::Entry::Vacant(entry) => { entry.insert((height_timer, TxMaterial::Revoked { script: redeemscript, pubkey: None, key: revocation_key, is_htlc: false, amount: tx.output[0].value }, used_feerate, height + self.our_to_self_delay as u32, height)); }
@@ -2143,14 +2150,14 @@ impl ChannelMonitor {
                                };
                                if funding_txo.is_none() || (prevout.txid == funding_txo.as_ref().unwrap().0.txid && prevout.vout == funding_txo.as_ref().unwrap().0.index as u32) {
                                        if (tx.input[0].sequence >> 8*3) as u8 == 0x80 && (tx.lock_time >> 8*3) as u8 == 0x20 {
-                                               let (remote_txn, new_outputs, mut spendable_output) = self.check_spend_remote_transaction(tx, height, fee_estimator);
+                                               let (remote_txn, new_outputs, mut spendable_output) = self.check_spend_remote_transaction(&tx, height, fee_estimator);
                                                txn = remote_txn;
                                                spendable_outputs.append(&mut spendable_output);
                                                if !new_outputs.1.is_empty() {
                                                        watch_outputs.push(new_outputs);
                                                }
                                                if txn.is_empty() {
-                                                       let (local_txn, mut spendable_output, new_outputs) = self.check_spend_local_transaction(tx, height);
+                                                       let (local_txn, mut spendable_output, new_outputs) = self.check_spend_local_transaction(&tx, height);
                                                        spendable_outputs.append(&mut spendable_output);
                                                        txn = local_txn;
                                                        if !new_outputs.1.is_empty() {
@@ -2159,13 +2166,13 @@ impl ChannelMonitor {
                                                }
                                        }
                                        if !funding_txo.is_none() && txn.is_empty() {
-                                               if let Some(spendable_output) = self.check_spend_closing_transaction(tx) {
+                                               if let Some(spendable_output) = self.check_spend_closing_transaction(&tx) {
                                                        spendable_outputs.push(spendable_output);
                                                }
                                        }
                                } else {
                                        if let Some(&(commitment_number, _)) = self.remote_commitment_txn_on_chain.get(&prevout.txid) {
-                                               let (tx, spendable_output) = self.check_spend_remote_htlc(tx, commitment_number, height, fee_estimator);
+                                               let (tx, spendable_output) = self.check_spend_remote_htlc(&tx, commitment_number, height, fee_estimator);
                                                if let Some(tx) = tx {
                                                        txn.push(tx);
                                                }
@@ -2175,13 +2182,14 @@ impl ChannelMonitor {
                                        }
                                }
                                for tx in txn.iter() {
+                                       log_trace!(self, "Broadcast onchain {}", log_tx!(tx));
                                        broadcaster.broadcast_transaction(tx);
                                }
                        }
                        // While all commitment/HTLC-Success/HTLC-Timeout transactions have one input, HTLCs
                        // can also be resolved in a few other ways which can have more than one output. Thus,
                        // we call is_resolving_htlc_output here outside of the tx.input.len() == 1 check.
-                       let mut updated = self.is_resolving_htlc_output(tx, height);
+                       let mut updated = self.is_resolving_htlc_output(&tx, height);
                        if updated.len() > 0 {
                                htlc_updated.append(&mut updated);
                        }
@@ -2210,6 +2218,7 @@ impl ChannelMonitor {
                let mut pending_claims = Vec::new();
                if let Some(ref cur_local_tx) = self.current_local_signed_commitment_tx {
                        if self.would_broadcast_at_height(height) {
+                               log_trace!(self, "Broadcast onchain {}", log_tx!(cur_local_tx.tx));
                                broadcaster.broadcast_transaction(&cur_local_tx.tx);
                                match self.key_storage {
                                        Storage::Local { ref delayed_payment_base_key, ref latest_per_commitment_point, .. } => {
@@ -2220,6 +2229,7 @@ impl ChannelMonitor {
                                                        watch_outputs.push((cur_local_tx.txid.clone(), new_outputs));
                                                }
                                                for tx in txs {
+                                                       log_trace!(self, "Broadcast onchain {}", log_tx!(tx));
                                                        broadcaster.broadcast_transaction(&tx);
                                                }
                                        },
@@ -2231,6 +2241,7 @@ impl ChannelMonitor {
                                                        watch_outputs.push((cur_local_tx.txid.clone(), new_outputs));
                                                }
                                                for tx in txs {
+                                                       log_trace!(self, "Broadcast onchain {}", log_tx!(tx));
                                                        broadcaster.broadcast_transaction(&tx);
                                                }
                                        }