Skip to content

Commit 58955d8

Browse files
committed
Add AttributionData to InboundHTLCRemovalReason::Fulfill
Need to store AttributionData as part of the inbound HTLC removal reason so that it can be used in the upstream UpdateFulfillHTLC message.
1 parent ca0a08f commit 58955d8

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

lightning/src/ln/channel.rs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ enum FeeUpdateState {
138138
enum InboundHTLCRemovalReason {
139139
FailRelay(msgs::OnionErrorPacket),
140140
FailMalformed(([u8; 32], u16)),
141-
Fulfill(PaymentPreimage),
141+
Fulfill(PaymentPreimage, Option<AttributionData>),
142142
}
143143

144144
/// Represents the resolution status of an inbound HTLC.
@@ -234,7 +234,7 @@ impl From<&InboundHTLCState> for Option<InboundHTLCStateDetails> {
234234
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
235235
InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailMalformed(_)) =>
236236
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
237-
InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) =>
237+
InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_, _)) =>
238238
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFulfill),
239239
}
240240
}
@@ -266,7 +266,7 @@ impl InboundHTLCState {
266266

267267
fn preimage(&self) -> Option<PaymentPreimage> {
268268
match self {
269-
InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(preimage)) => {
269+
InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(preimage, _)) => {
270270
Some(*preimage)
271271
},
272272
_ => None,
@@ -6258,7 +6258,7 @@ where
62586258
match htlc.state {
62596259
InboundHTLCState::Committed => {},
62606260
InboundHTLCState::LocalRemoved(ref reason) => {
6261-
if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
6261+
if let &InboundHTLCRemovalReason::Fulfill(_, _) = reason {
62626262
} else {
62636263
log_warn!(logger, "Have preimage and want to fulfill HTLC with payment hash {} we already failed against channel {}", &htlc.payment_hash, &self.context.channel_id());
62646264
debug_assert!(
@@ -6369,6 +6369,7 @@ where
63696369
);
63706370
htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(
63716371
payment_preimage_arg.clone(),
6372+
None,
63726373
));
63736374
}
63746375

@@ -7507,7 +7508,7 @@ where
75077508
pending_inbound_htlcs.retain(|htlc| {
75087509
if let &InboundHTLCState::LocalRemoved(ref reason) = &htlc.state {
75097510
log_trace!(logger, " ...removing inbound LocalRemoved {}", &htlc.payment_hash);
7510-
if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
7511+
if let &InboundHTLCRemovalReason::Fulfill(_, _) = reason {
75117512
value_to_self_msat_diff += htlc.amount_msat as i64;
75127513
}
75137514
*expecting_peer_commitment_signed = true;
@@ -8377,12 +8378,15 @@ where
83778378
failure_code: failure_code.clone(),
83788379
});
83798380
},
8380-
&InboundHTLCRemovalReason::Fulfill(ref payment_preimage) => {
8381+
&InboundHTLCRemovalReason::Fulfill(
8382+
ref payment_preimage,
8383+
ref attribution_data,
8384+
) => {
83818385
update_fulfill_htlcs.push(msgs::UpdateFulfillHTLC {
83828386
channel_id: self.context.channel_id(),
83838387
htlc_id: htlc.htlc_id,
83848388
payment_preimage: payment_preimage.clone(),
8385-
attribution_data: None,
8389+
attribution_data: attribution_data.clone(),
83868390
});
83878391
},
83888392
}
@@ -12454,7 +12458,7 @@ where
1245412458
dropped_inbound_htlcs += 1;
1245512459
}
1245612460
}
12457-
let mut removed_htlc_failure_attribution_data: Vec<&Option<AttributionData>> = Vec::new();
12461+
let mut removed_htlc_attribution_data: Vec<&Option<AttributionData>> = Vec::new();
1245812462
(self.context.pending_inbound_htlcs.len() as u64 - dropped_inbound_htlcs).write(writer)?;
1245912463
for htlc in self.context.pending_inbound_htlcs.iter() {
1246012464
if let &InboundHTLCState::RemoteAnnounced(_) = &htlc.state {
@@ -12486,15 +12490,16 @@ where
1248612490
}) => {
1248712491
0u8.write(writer)?;
1248812492
data.write(writer)?;
12489-
removed_htlc_failure_attribution_data.push(&attribution_data);
12493+
removed_htlc_attribution_data.push(&attribution_data);
1249012494
},
1249112495
InboundHTLCRemovalReason::FailMalformed((hash, code)) => {
1249212496
1u8.write(writer)?;
1249312497
(hash, code).write(writer)?;
1249412498
},
12495-
InboundHTLCRemovalReason::Fulfill(preimage) => {
12499+
InboundHTLCRemovalReason::Fulfill(preimage, attribution_data) => {
1249612500
2u8.write(writer)?;
1249712501
preimage.write(writer)?;
12502+
removed_htlc_attribution_data.push(&attribution_data);
1249812503
},
1249912504
}
1250012505
},
@@ -12811,7 +12816,7 @@ where
1281112816
(51, is_manual_broadcast, option), // Added in 0.0.124
1281212817
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
1281312818
(54, self.pending_funding, optional_vec), // Added in 0.2
12814-
(55, removed_htlc_failure_attribution_data, optional_vec), // Added in 0.2
12819+
(55, removed_htlc_attribution_data, optional_vec), // Added in 0.2
1281512820
(57, holding_cell_failure_attribution_data, optional_vec), // Added in 0.2
1281612821
(58, self.interactive_tx_signing_session, option), // Added in 0.2
1281712822
(59, self.funding.minimum_depth_override, option), // Added in 0.2
@@ -12907,7 +12912,7 @@ where
1290712912
attribution_data: None,
1290812913
}),
1290912914
1 => InboundHTLCRemovalReason::FailMalformed(Readable::read(reader)?),
12910-
2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?),
12915+
2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?, None),
1291112916
_ => return Err(DecodeError::InvalidValue),
1291212917
};
1291312918
InboundHTLCState::LocalRemoved(reason)
@@ -13157,7 +13162,7 @@ where
1315713162
let mut pending_outbound_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1315813163
let mut holding_cell_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1315913164

13160-
let mut removed_htlc_failure_attribution_data: Option<Vec<Option<AttributionData>>> = None;
13165+
let mut removed_htlc_attribution_data: Option<Vec<Option<AttributionData>>> = None;
1316113166
let mut holding_cell_failure_attribution_data: Option<Vec<Option<AttributionData>>> = None;
1316213167

1316313168
let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
@@ -13210,7 +13215,7 @@ where
1321013215
(51, is_manual_broadcast, option),
1321113216
(53, funding_tx_broadcast_safe_event_emitted, option),
1321213217
(54, pending_funding, optional_vec), // Added in 0.2
13213-
(55, removed_htlc_failure_attribution_data, optional_vec),
13218+
(55, removed_htlc_attribution_data, optional_vec),
1321413219
(57, holding_cell_failure_attribution_data, optional_vec),
1321513220
(58, interactive_tx_signing_session, option), // Added in 0.2
1321613221
(59, minimum_depth_override, option), // Added in 0.2
@@ -13314,14 +13319,19 @@ where
1331413319
}
1331513320
}
1331613321

13317-
if let Some(attribution_data_list) = removed_htlc_failure_attribution_data {
13322+
if let Some(attribution_data_list) = removed_htlc_attribution_data {
1331813323
let mut removed_htlc_relay_failures =
1331913324
pending_inbound_htlcs.iter_mut().filter_map(|status| {
13320-
if let InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailRelay(
13321-
ref mut packet,
13322-
)) = &mut status.state
13323-
{
13324-
Some(&mut packet.attribution_data)
13325+
if let InboundHTLCState::LocalRemoved(reason) = &mut status.state {
13326+
match reason {
13327+
InboundHTLCRemovalReason::FailRelay(ref mut packet) => {
13328+
Some(&mut packet.attribution_data)
13329+
},
13330+
InboundHTLCRemovalReason::Fulfill(_, ref mut attribution_data) => {
13331+
Some(attribution_data)
13332+
},
13333+
_ => None,
13334+
}
1332513335
} else {
1332613336
None
1332713337
}

0 commit comments

Comments
 (0)