Skip to content

Commit be7d3d1

Browse files
authored
Merge pull request #401 from ariard/2019-11-log-tx-broadcast
Add log for every tx broadcast
2 parents 01ae452 + 9df0250 commit be7d3d1

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
@@ -772,6 +772,7 @@ impl<'a> ChannelManager<'a> {
772772
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() });
773773
}
774774
for tx in local_txn {
775+
log_trace!(self, "Broadcast onchain {}", log_tx!(tx));
775776
self.tx_broadcaster.broadcast_transaction(&tx);
776777
}
777778
}
@@ -2077,6 +2078,7 @@ impl<'a> ChannelManager<'a> {
20772078
}
20782079
};
20792080
if let Some(broadcast_tx) = tx {
2081+
log_trace!(self, "Broadcast onchain {}", log_tx!(broadcast_tx));
20802082
self.tx_broadcaster.broadcast_transaction(&broadcast_tx);
20812083
}
20822084
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
@@ -2176,6 +2176,7 @@ impl ChannelMonitor {
21762176
}
21772177
}
21782178
for tx in txn.iter() {
2179+
log_trace!(self, "Broadcast onchain {}", log_tx!(tx));
21792180
broadcaster.broadcast_transaction(tx);
21802181
}
21812182
}
@@ -2211,6 +2212,7 @@ impl ChannelMonitor {
22112212
let mut pending_claims = Vec::new();
22122213
if let Some(ref cur_local_tx) = self.current_local_signed_commitment_tx {
22132214
if self.would_broadcast_at_height(height) {
2215+
log_trace!(self, "Broadcast onchain {}", log_tx!(cur_local_tx.tx));
22142216
broadcaster.broadcast_transaction(&cur_local_tx.tx);
22152217
match self.key_storage {
22162218
Storage::Local { ref delayed_payment_base_key, ref latest_per_commitment_point, .. } => {
@@ -2221,6 +2223,7 @@ impl ChannelMonitor {
22212223
watch_outputs.push((cur_local_tx.txid.clone(), new_outputs));
22222224
}
22232225
for tx in txs {
2226+
log_trace!(self, "Broadcast onchain {}", log_tx!(tx));
22242227
broadcaster.broadcast_transaction(&tx);
22252228
}
22262229
},
@@ -2232,6 +2235,7 @@ impl ChannelMonitor {
22322235
watch_outputs.push((cur_local_tx.txid.clone(), new_outputs));
22332236
}
22342237
for tx in txs {
2238+
log_trace!(self, "Broadcast onchain {}", log_tx!(tx));
22352239
broadcaster.broadcast_transaction(&tx);
22362240
}
22372241
}

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.last().unwrap().len() == 139) && 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)