Skip to content

Commit 44cc756

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 d5e6721 commit 44cc756

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;
@@ -8379,12 +8380,15 @@ where
83798380
failure_code: failure_code.clone(),
83808381
});
83818382
},
8382-
&InboundHTLCRemovalReason::Fulfill(ref payment_preimage) => {
8383+
&InboundHTLCRemovalReason::Fulfill(
8384+
ref payment_preimage,
8385+
ref attribution_data,
8386+
) => {
83838387
update_fulfill_htlcs.push(msgs::UpdateFulfillHTLC {
83848388
channel_id: self.context.channel_id(),
83858389
htlc_id: htlc.htlc_id,
83868390
payment_preimage: payment_preimage.clone(),
8387-
attribution_data: None,
8391+
attribution_data: attribution_data.clone(),
83888392
});
83898393
},
83908394
}
@@ -12456,7 +12460,7 @@ where
1245612460
dropped_inbound_htlcs += 1;
1245712461
}
1245812462
}
12459-
let mut removed_htlc_failure_attribution_data: Vec<&Option<AttributionData>> = Vec::new();
12463+
let mut removed_htlc_attribution_data: Vec<&Option<AttributionData>> = Vec::new();
1246012464
(self.context.pending_inbound_htlcs.len() as u64 - dropped_inbound_htlcs).write(writer)?;
1246112465
for htlc in self.context.pending_inbound_htlcs.iter() {
1246212466
if let &InboundHTLCState::RemoteAnnounced(_) = &htlc.state {
@@ -12488,15 +12492,16 @@ where
1248812492
}) => {
1248912493
0u8.write(writer)?;
1249012494
data.write(writer)?;
12491-
removed_htlc_failure_attribution_data.push(&attribution_data);
12495+
removed_htlc_attribution_data.push(&attribution_data);
1249212496
},
1249312497
InboundHTLCRemovalReason::FailMalformed((hash, code)) => {
1249412498
1u8.write(writer)?;
1249512499
(hash, code).write(writer)?;
1249612500
},
12497-
InboundHTLCRemovalReason::Fulfill(preimage) => {
12501+
InboundHTLCRemovalReason::Fulfill(preimage, attribution_data) => {
1249812502
2u8.write(writer)?;
1249912503
preimage.write(writer)?;
12504+
removed_htlc_attribution_data.push(&attribution_data);
1250012505
},
1250112506
}
1250212507
},
@@ -12816,7 +12821,7 @@ where
1281612821
(51, is_manual_broadcast, option), // Added in 0.0.124
1281712822
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
1281812823
(54, self.pending_funding, optional_vec), // Added in 0.2
12819-
(55, removed_htlc_failure_attribution_data, optional_vec), // Added in 0.2
12824+
(55, removed_htlc_attribution_data, optional_vec), // Added in 0.2
1282012825
(57, holding_cell_failure_attribution_data, optional_vec), // Added in 0.2
1282112826
(58, self.interactive_tx_signing_session, option), // Added in 0.2
1282212827
(59, self.funding.minimum_depth_override, option), // Added in 0.2
@@ -12913,7 +12918,7 @@ where
1291312918
attribution_data: None,
1291412919
}),
1291512920
1 => InboundHTLCRemovalReason::FailMalformed(Readable::read(reader)?),
12916-
2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?),
12921+
2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?, None),
1291712922
_ => return Err(DecodeError::InvalidValue),
1291812923
};
1291912924
InboundHTLCState::LocalRemoved(reason)
@@ -13164,7 +13169,7 @@ where
1316413169
let mut pending_outbound_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1316513170
let mut holding_cell_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1316613171

13167-
let mut removed_htlc_failure_attribution_data: Option<Vec<Option<AttributionData>>> = None;
13172+
let mut removed_htlc_attribution_data: Option<Vec<Option<AttributionData>>> = None;
1316813173
let mut holding_cell_failure_attribution_data: Option<Vec<Option<AttributionData>>> = None;
1316913174

1317013175
let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
@@ -13217,7 +13222,7 @@ where
1321713222
(51, is_manual_broadcast, option),
1321813223
(53, funding_tx_broadcast_safe_event_emitted, option),
1321913224
(54, pending_funding, optional_vec), // Added in 0.2
13220-
(55, removed_htlc_failure_attribution_data, optional_vec),
13225+
(55, removed_htlc_attribution_data, optional_vec),
1322113226
(57, holding_cell_failure_attribution_data, optional_vec),
1322213227
(58, interactive_tx_signing_session, option), // Added in 0.2
1322313228
(59, minimum_depth_override, option), // Added in 0.2
@@ -13325,14 +13330,19 @@ where
1332513330
}
1332613331
}
1332713332

13328-
if let Some(attribution_data_list) = removed_htlc_failure_attribution_data {
13333+
if let Some(attribution_data_list) = removed_htlc_attribution_data {
1332913334
let mut removed_htlc_relay_failures =
1333013335
pending_inbound_htlcs.iter_mut().filter_map(|status| {
13331-
if let InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailRelay(
13332-
ref mut packet,
13333-
)) = &mut status.state
13334-
{
13335-
Some(&mut packet.attribution_data)
13336+
if let InboundHTLCState::LocalRemoved(reason) = &mut status.state {
13337+
match reason {
13338+
InboundHTLCRemovalReason::FailRelay(ref mut packet) => {
13339+
Some(&mut packet.attribution_data)
13340+
},
13341+
InboundHTLCRemovalReason::Fulfill(_, ref mut attribution_data) => {
13342+
Some(attribution_data)
13343+
},
13344+
_ => None,
13345+
}
1333613346
} else {
1333713347
None
1333813348
}

0 commit comments

Comments
 (0)