Skip to content

Commit 667c5f0

Browse files
committed
Debug assert that forwarded-claimed HTLCs are claimed backwards
1 parent 9018b0c commit 667c5f0

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ use crate::sync::{Mutex, LockTestExt};
6969
/// much smaller than a full [`ChannelMonitor`]. However, for large single commitment transaction
7070
/// updates (e.g. ones during which there are hundreds of HTLCs pending on the commitment
7171
/// transaction), a single update may reach upwards of 1 MiB in serialized size.
72-
#[derive(Clone, PartialEq, Eq)]
72+
#[derive(Clone, Debug, PartialEq, Eq)]
7373
#[must_use]
7474
pub struct ChannelMonitorUpdate {
7575
pub(crate) updates: Vec<ChannelMonitorUpdateStep>,
@@ -490,7 +490,7 @@ impl_writeable_tlv_based_enum_upgradable!(OnchainEvent,
490490

491491
);
492492

493-
#[derive(Clone, PartialEq, Eq)]
493+
#[derive(Clone, Debug, PartialEq, Eq)]
494494
pub(crate) enum ChannelMonitorUpdateStep {
495495
LatestHolderCommitmentTXInfo {
496496
commitment_tx: HolderCommitmentTransaction,

lightning/src/ln/chan_utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ pub fn derive_public_revocation_key<T: secp256k1::Verification>(secp_ctx: &Secp2
437437
/// channel basepoints via the new function, or they were obtained via
438438
/// CommitmentTransaction.trust().keys() because we trusted the source of the
439439
/// pre-calculated keys.
440-
#[derive(PartialEq, Eq, Clone)]
440+
#[derive(PartialEq, Eq, Clone, Debug)]
441441
pub struct TxCreationKeys {
442442
/// The broadcaster's per-commitment public key which was used to derive the other keys.
443443
pub per_commitment_point: PublicKey,
@@ -949,7 +949,7 @@ impl<'a> DirectedChannelTransactionParameters<'a> {
949949
/// Information needed to build and sign a holder's commitment transaction.
950950
///
951951
/// The transaction is only signed once we are ready to broadcast.
952-
#[derive(Clone)]
952+
#[derive(Clone, Debug)]
953953
pub struct HolderCommitmentTransaction {
954954
inner: CommitmentTransaction,
955955
/// Our counterparty's signature for the transaction
@@ -1052,7 +1052,7 @@ impl HolderCommitmentTransaction {
10521052
}
10531053

10541054
/// A pre-built Bitcoin commitment transaction and its txid.
1055-
#[derive(Clone)]
1055+
#[derive(Clone, Debug)]
10561056
pub struct BuiltCommitmentTransaction {
10571057
/// The commitment transaction
10581058
pub transaction: Transaction,
@@ -1215,7 +1215,7 @@ impl<'a> TrustedClosingTransaction<'a> {
12151215
///
12161216
/// This class can be used inside a signer implementation to generate a signature given the relevant
12171217
/// secret key.
1218-
#[derive(Clone)]
1218+
#[derive(Clone, Debug)]
12191219
pub struct CommitmentTransaction {
12201220
commitment_number: u64,
12211221
to_broadcaster_value_sat: u64,

lightning/src/ln/channelmanager.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pub(super) enum HTLCForwardInfo {
165165
}
166166

167167
/// Tracks the inbound corresponding to an outbound HTLC
168-
#[derive(Clone, Hash, PartialEq, Eq)]
168+
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
169169
pub(crate) struct HTLCPreviousHopData {
170170
// Note that this may be an outbound SCID alias for the associated channel.
171171
short_channel_id: u64,
@@ -245,7 +245,7 @@ impl Readable for InterceptId {
245245
}
246246
}
247247

248-
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
248+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
249249
/// Uniquely describes an HTLC by its source. Just the guaranteed-unique subset of [`HTLCSource`].
250250
pub(crate) enum SentHTLCId {
251251
PreviousHopData { short_channel_id: u64, htlc_id: u64 },
@@ -276,7 +276,7 @@ impl_writeable_tlv_based_enum!(SentHTLCId,
276276

277277
/// Tracks the inbound corresponding to an outbound HTLC
278278
#[allow(clippy::derive_hash_xor_eq)] // Our Hash is faithful to the data, we just don't have SecretKey::hash
279-
#[derive(Clone, PartialEq, Eq)]
279+
#[derive(Clone, Debug, PartialEq, Eq)]
280280
pub(crate) enum HTLCSource {
281281
PreviousHopData(HTLCPreviousHopData),
282282
OutboundRoute {
@@ -7884,6 +7884,18 @@ where
78847884
false
78857885
} else { true }
78867886
});
7887+
#[cfg(debug_assertions)] {
7888+
if let Some(preimage) = preimage_opt {
7889+
if let Some((node_id, chan_id)) = short_to_chan_info.get(&prev_hop_data.short_channel_id) {
7890+
let chan = peer_channels.get_mut(node_id).unwrap().get_mut(chan_id).unwrap();
7891+
if let UpdateFulfillCommitFetch::DuplicateClaim {} =
7892+
chan.get_update_fulfill_htlc_and_commit(prev_hop_data.htlc_id, preimage, &args.logger) {
7893+
} else {
7894+
panic!("Forwarded HTLCs which were previously claimed absolutely must have been claimed backwards");
7895+
}
7896+
}
7897+
}
7898+
}
78877899
},
78887900
HTLCSource::OutboundRoute { payment_id, session_priv, path, .. } => {
78897901
if let Some(preimage) = preimage_opt {

0 commit comments

Comments
 (0)