Skip to content

Commit f507a1c

Browse files
author
Antoine Riard
committed
Add log for every tx broadcast
Added macro log_tx in macro_logger.rs
1 parent 126b514 commit f507a1c

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ impl ChannelManager {
768768
self.fail_htlc_backwards_internal(self.channel_state.lock().unwrap(), htlc_source.0, &htlc_source.1, HTLCFailReason::Reason { failure_code: 0x4000 | 8, data: Vec::new() });
769769
}
770770
for tx in local_txn {
771+
log_trace!(self, "Broadcast onchain {}", log_tx!(tx));
771772
self.tx_broadcaster.broadcast_transaction(&tx);
772773
}
773774
}
@@ -2064,6 +2065,7 @@ impl ChannelManager {
20642065
}
20652066
};
20662067
if let Some(broadcast_tx) = tx {
2068+
log_trace!(self, "Broadcast onchain {}", log_tx!(broadcast_tx));
20672069
self.tx_broadcaster.broadcast_transaction(&broadcast_tx);
20682070
}
20692071
if let Some(chan) = chan_option {

lightning/src/ln/channelmonitor.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,6 +2170,7 @@ impl ChannelMonitor {
21702170
}
21712171
}
21722172
for tx in txn.iter() {
2173+
log_trace!(self, "Broadcast onchain {}", log_tx!(tx));
21732174
broadcaster.broadcast_transaction(tx);
21742175
}
21752176
}
@@ -2205,6 +2206,7 @@ impl ChannelMonitor {
22052206
let mut pending_claims = Vec::new();
22062207
if let Some(ref cur_local_tx) = self.current_local_signed_commitment_tx {
22072208
if self.would_broadcast_at_height(height) {
2209+
log_trace!(self, "Broadcast onchain {}", log_tx!(cur_local_tx.tx));
22082210
broadcaster.broadcast_transaction(&cur_local_tx.tx);
22092211
match self.key_storage {
22102212
Storage::Local { ref delayed_payment_base_key, ref latest_per_commitment_point, .. } => {
@@ -2215,6 +2217,7 @@ impl ChannelMonitor {
22152217
watch_outputs.push((cur_local_tx.txid.clone(), new_outputs));
22162218
}
22172219
for tx in txs {
2220+
log_trace!(self, "Broadcast onchain {}", log_tx!(tx));
22182221
broadcaster.broadcast_transaction(&tx);
22192222
}
22202223
},
@@ -2226,6 +2229,7 @@ impl ChannelMonitor {
22262229
watch_outputs.push((cur_local_tx.txid.clone(), new_outputs));
22272230
}
22282231
for tx in txs {
2232+
log_trace!(self, "Broadcast onchain {}", log_tx!(tx));
22292233
broadcaster.broadcast_transaction(&tx);
22302234
}
22312235
}

lightning/src/util/macro_logger.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use chain::transaction::OutPoint;
22

33
use bitcoin_hashes::sha256d::Hash as Sha256dHash;
4+
use bitcoin::blockdata::transaction::Transaction;
45
use secp256k1::key::PublicKey;
56

67
use ln::router::Route;
@@ -89,6 +90,29 @@ macro_rules! log_route {
8990
}
9091
}
9192

93+
pub(crate) struct DebugTx<'a>(pub &'a Transaction);
94+
impl<'a> std::fmt::Display for DebugTx<'a> {
95+
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
96+
if self.0.input.len() == 1 && self.0.input[0].witness.last().unwrap().len() == 71 && (self.0.input[0].sequence >> 8*3) as u8 == 0x80 { write!(f, "commitment tx")?; }
97+
else if self.0.input.len() == 1 && self.0.input[0].witness.last().unwrap().len() == 71 { write!(f, "closing tx")?; }
98+
else if self.0.input.len() == 1 && self.0.input[0].witness.last().unwrap().len() == 133 && self.0.input[0].witness.len() == 5 { write!(f, "HTLC-timeout tx")?; }
99+
else if self.0.input.len() == 1 && self.0.input[0].witness.last().unwrap().len() == 138 && self.0.input[0].witness.len() == 5 { write!(f, "HTLC-success tx")?; }
100+
else {
101+
for inp in &self.0.input {
102+
if inp.witness.last().unwrap().len() == 133 { write!(f, "preimage tx")?; break }
103+
else if inp.witness.last().unwrap().len() == 138 { write!(f, "timeout tx")?; break }
104+
}
105+
}
106+
Ok(())
107+
}
108+
}
109+
110+
macro_rules! log_tx {
111+
($obj: expr) => {
112+
::util::macro_logger::DebugTx(&$obj)
113+
}
114+
}
115+
92116
macro_rules! log_internal {
93117
($self: ident, $lvl:expr, $($arg:tt)+) => (
94118
&$self.logger.log(&::util::logger::Record::new($lvl, format_args!($($arg)+), module_path!(), file!(), line!()));

0 commit comments

Comments
 (0)