Skip to content

Commit a6b97fc

Browse files
committed
Fix crash when a claim tx has some non-witness inputs.
The logger which decides what to refer to an on-chain claim tx was assuming that all inputs would have a witness. While this was fine for the one-input case, it broke the fuzzer which was connecting a consensus-invalid transaction. Further, in the case we have multiple inputs, some may not have a witness, which we shouldn't crash on. This fixes 9df0250.
1 parent f8b06ec commit a6b97fc

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

lightning/src/util/macro_logger.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,29 @@ macro_rules! log_route {
9393
pub(crate) struct DebugTx<'a>(pub &'a Transaction);
9494
impl<'a> std::fmt::Display for DebugTx<'a> {
9595
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 }
96+
if self.0.input.len() >= 1 && self.0.input.iter().any(|i| !i.witness.is_empty()) {
97+
if self.0.input.len() == 1 && self.0.input[0].witness.last().unwrap().len() == 71 &&
98+
(self.0.input[0].sequence >> 8*3) as u8 == 0x80 {
99+
write!(f, "commitment tx")?;
100+
} else if self.0.input.len() == 1 && self.0.input[0].witness.last().unwrap().len() == 71 {
101+
write!(f, "closing tx")?;
102+
} else if self.0.input.len() == 1 && self.0.input[0].witness.last().unwrap().len() == 133 &&
103+
self.0.input[0].witness.len() == 5 {
104+
write!(f, "HTLC-timeout tx")?;
105+
} else if self.0.input.len() == 1 &&
106+
(self.0.input[0].witness.last().unwrap().len() == 138 || self.0.input[0].witness.last().unwrap().len() == 139) &&
107+
self.0.input[0].witness.len() == 5 {
108+
write!(f, "HTLC-success tx")?;
109+
} else {
110+
for inp in &self.0.input {
111+
if !inp.witness.is_empty() {
112+
if inp.witness.last().unwrap().len() == 133 { write!(f, "preimage tx")?; break }
113+
else if inp.witness.last().unwrap().len() == 138 { write!(f, "timeout tx")?; break }
114+
}
115+
}
104116
}
117+
} else {
118+
write!(f, "INVALID TRANSACTION");
105119
}
106120
Ok(())
107121
}

0 commit comments

Comments
 (0)