Skip to content

Commit a8b7978

Browse files
committed
Drop single-use macro from check_spend_holder_transaction
The wait_threshold_conf!() macro in check_spend_holder_transaction was only used once, making it a good candidate for inlining at the callsite. Further, it incorrectly always logged that we were failing HTLCs from the "latest" commitment transaction, when it is sometimes actually failing HTLCs from the previous commitment transaction.
1 parent 8c82665 commit a8b7978

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

lightning/src/chain/channelmonitor.rs

+22-25
Original file line numberDiff line numberDiff line change
@@ -1779,27 +1779,6 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
17791779
let mut claim_requests = Vec::new();
17801780
let mut watch_outputs = Vec::new();
17811781

1782-
macro_rules! wait_threshold_conf {
1783-
($source: expr, $commitment_tx: expr, $payment_hash: expr) => {
1784-
self.onchain_events_awaiting_threshold_conf.retain(|ref entry| {
1785-
if entry.height != height { return true; }
1786-
match entry.event {
1787-
OnchainEvent::HTLCUpdate { source: ref update_source, .. } => {
1788-
*update_source != $source
1789-
},
1790-
_ => true,
1791-
}
1792-
});
1793-
let entry = OnchainEventEntry {
1794-
txid: commitment_txid,
1795-
height,
1796-
event: OnchainEvent::HTLCUpdate { source: $source, payment_hash: $payment_hash },
1797-
};
1798-
log_trace!(logger, "Failing HTLC with payment_hash {} from {} holder commitment tx due to broadcast of transaction, waiting confirmation (at height{})", log_bytes!($payment_hash.0), $commitment_tx, entry.confirmation_threshold());
1799-
self.onchain_events_awaiting_threshold_conf.push(entry);
1800-
}
1801-
}
1802-
18031782
macro_rules! append_onchain_update {
18041783
($updates: expr, $to_watch: expr) => {
18051784
claim_requests = $updates.0;
@@ -1828,21 +1807,39 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
18281807
}
18291808

18301809
macro_rules! fail_dust_htlcs_after_threshold_conf {
1831-
($holder_tx: expr) => {
1810+
($holder_tx: expr, $commitment_tx: expr) => {
18321811
for &(ref htlc, _, ref source) in &$holder_tx.htlc_outputs {
18331812
if htlc.transaction_output_index.is_none() {
18341813
if let &Some(ref source) = source {
1835-
wait_threshold_conf!(source.clone(), "lastest", htlc.payment_hash.clone());
1814+
self.onchain_events_awaiting_threshold_conf.retain(|ref entry| {
1815+
if entry.height != height { return true; }
1816+
match entry.event {
1817+
OnchainEvent::HTLCUpdate { source: ref update_source, .. } => {
1818+
update_source != source
1819+
},
1820+
_ => true,
1821+
}
1822+
});
1823+
let entry = OnchainEventEntry {
1824+
txid: commitment_txid,
1825+
height,
1826+
event: OnchainEvent::HTLCUpdate {
1827+
source: source.clone(), payment_hash: htlc.payment_hash,
1828+
},
1829+
};
1830+
log_trace!(logger, "Failing HTLC with payment_hash {} from {} holder commitment tx due to broadcast of transaction, waiting confirmation (at height{})",
1831+
log_bytes!(htlc.payment_hash.0), $commitment_tx, entry.confirmation_threshold());
1832+
self.onchain_events_awaiting_threshold_conf.push(entry);
18361833
}
18371834
}
18381835
}
18391836
}
18401837
}
18411838

18421839
if is_holder_tx {
1843-
fail_dust_htlcs_after_threshold_conf!(self.current_holder_commitment_tx);
1840+
fail_dust_htlcs_after_threshold_conf!(self.current_holder_commitment_tx, "latest");
18441841
if let &Some(ref holder_tx) = &self.prev_holder_signed_commitment_tx {
1845-
fail_dust_htlcs_after_threshold_conf!(holder_tx);
1842+
fail_dust_htlcs_after_threshold_conf!(holder_tx, "previous");
18461843
}
18471844
}
18481845

0 commit comments

Comments
 (0)