Skip to content

Commit 9a4a3e2

Browse files
committed
Add AttributionData to HTLCUpdateAwaitingACK::ClaimHTLC
Necessary to preserve attribution data when the HTLC is in the holding cell.
1 parent 58955d8 commit 9a4a3e2

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

lightning/src/ln/channel.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ enum HTLCUpdateAwaitingACK {
466466
},
467467
ClaimHTLC {
468468
payment_preimage: PaymentPreimage,
469+
attribution_data: Option<AttributionData>,
469470
htlc_id: u64,
470471
},
471472
FailHTLC {
@@ -6339,6 +6340,7 @@ where
63396340
self.context.holding_cell_htlc_updates.push(HTLCUpdateAwaitingACK::ClaimHTLC {
63406341
payment_preimage: payment_preimage_arg,
63416342
htlc_id: htlc_id_arg,
6343+
attribution_data: None,
63426344
});
63436345
return UpdateFulfillFetch::NewClaim {
63446346
monitor_update,
@@ -12558,7 +12560,7 @@ where
1255812560
Vec::with_capacity(holding_cell_htlc_update_count);
1255912561
let mut holding_cell_blinding_points: Vec<Option<PublicKey>> =
1256012562
Vec::with_capacity(holding_cell_htlc_update_count);
12561-
let mut holding_cell_failure_attribution_data: Vec<Option<&AttributionData>> =
12563+
let mut holding_cell_attribution_data: Vec<Option<&AttributionData>> =
1256212564
Vec::with_capacity(holding_cell_htlc_update_count);
1256312565
// Vec of (htlc_id, failure_code, sha256_of_onion)
1256412566
let mut malformed_htlcs: Vec<(u64, u16, [u8; 32])> = Vec::new();
@@ -12584,19 +12586,25 @@ where
1258412586
holding_cell_skimmed_fees.push(skimmed_fee_msat);
1258512587
holding_cell_blinding_points.push(blinding_point);
1258612588
},
12587-
&HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
12589+
&HTLCUpdateAwaitingACK::ClaimHTLC {
12590+
ref payment_preimage,
12591+
ref htlc_id,
12592+
ref attribution_data,
12593+
} => {
1258812594
1u8.write(writer)?;
1258912595
payment_preimage.write(writer)?;
1259012596
htlc_id.write(writer)?;
12597+
12598+
// Store the attribution data for later writing.
12599+
holding_cell_attribution_data.push(attribution_data.as_ref());
1259112600
},
1259212601
&HTLCUpdateAwaitingACK::FailHTLC { ref htlc_id, ref err_packet } => {
1259312602
2u8.write(writer)?;
1259412603
htlc_id.write(writer)?;
1259512604
err_packet.data.write(writer)?;
1259612605

1259712606
// Store the attribution data for later writing.
12598-
holding_cell_failure_attribution_data
12599-
.push(err_packet.attribution_data.as_ref());
12607+
holding_cell_attribution_data.push(err_packet.attribution_data.as_ref());
1260012608
},
1260112609
&HTLCUpdateAwaitingACK::FailMalformedHTLC {
1260212610
htlc_id,
@@ -12613,7 +12621,7 @@ where
1261312621

1261412622
// Push 'None' attribution data for FailMalformedHTLC, because FailMalformedHTLC uses the same
1261512623
// type 2 and is deserialized as a FailHTLC.
12616-
holding_cell_failure_attribution_data.push(None);
12624+
holding_cell_attribution_data.push(None);
1261712625
},
1261812626
}
1261912627
}
@@ -12817,7 +12825,7 @@ where
1281712825
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
1281812826
(54, self.pending_funding, optional_vec), // Added in 0.2
1281912827
(55, removed_htlc_attribution_data, optional_vec), // Added in 0.2
12820-
(57, holding_cell_failure_attribution_data, optional_vec), // Added in 0.2
12828+
(57, holding_cell_attribution_data, optional_vec), // Added in 0.2
1282112829
(58, self.interactive_tx_signing_session, option), // Added in 0.2
1282212830
(59, self.funding.minimum_depth_override, option), // Added in 0.2
1282312831
(60, self.context.historical_scids, optional_vec), // Added in 0.2
@@ -12991,6 +12999,7 @@ where
1299112999
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
1299213000
payment_preimage: Readable::read(reader)?,
1299313001
htlc_id: Readable::read(reader)?,
13002+
attribution_data: None,
1299413003
},
1299513004
2 => HTLCUpdateAwaitingACK::FailHTLC {
1299613005
htlc_id: Readable::read(reader)?,
@@ -13163,7 +13172,7 @@ where
1316313172
let mut holding_cell_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1316413173

1316513174
let mut removed_htlc_attribution_data: Option<Vec<Option<AttributionData>>> = None;
13166-
let mut holding_cell_failure_attribution_data: Option<Vec<Option<AttributionData>>> = None;
13175+
let mut holding_cell_attribution_data: Option<Vec<Option<AttributionData>>> = None;
1316713176

1316813177
let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
1316913178
let mut monitor_pending_update_adds: Option<Vec<msgs::UpdateAddHTLC>> = None;
@@ -13216,7 +13225,7 @@ where
1321613225
(53, funding_tx_broadcast_safe_event_emitted, option),
1321713226
(54, pending_funding, optional_vec), // Added in 0.2
1321813227
(55, removed_htlc_attribution_data, optional_vec),
13219-
(57, holding_cell_failure_attribution_data, optional_vec),
13228+
(57, holding_cell_attribution_data, optional_vec),
1322013229
(58, interactive_tx_signing_session, option), // Added in 0.2
1322113230
(59, minimum_depth_override, option), // Added in 0.2
1322213231
(60, historical_scids, optional_vec), // Added in 0.2
@@ -13346,18 +13355,17 @@ where
1334613355
}
1334713356
}
1334813357

13349-
if let Some(attribution_data_list) = holding_cell_failure_attribution_data {
13358+
if let Some(attribution_data_list) = holding_cell_attribution_data {
1335013359
let mut holding_cell_failures =
13351-
holding_cell_htlc_updates.iter_mut().filter_map(|upd| {
13352-
if let HTLCUpdateAwaitingACK::FailHTLC {
13360+
holding_cell_htlc_updates.iter_mut().filter_map(|upd| match upd {
13361+
HTLCUpdateAwaitingACK::FailHTLC {
1335313362
err_packet: OnionErrorPacket { ref mut attribution_data, .. },
1335413363
..
13355-
} = upd
13356-
{
13364+
} => Some(attribution_data),
13365+
HTLCUpdateAwaitingACK::ClaimHTLC { attribution_data, .. } => {
1335713366
Some(attribution_data)
13358-
} else {
13359-
None
13360-
}
13367+
},
13368+
_ => None,
1336113369
});
1336213370

1336313371
for attribution_data in attribution_data_list {
@@ -14355,6 +14363,7 @@ mod tests {
1435514363
let dummy_holding_cell_claim_htlc = HTLCUpdateAwaitingACK::ClaimHTLC {
1435614364
payment_preimage: PaymentPreimage([42; 32]),
1435714365
htlc_id: 0,
14366+
attribution_data: None,
1435814367
};
1435914368
let dummy_holding_cell_failed_htlc = |htlc_id| HTLCUpdateAwaitingACK::FailHTLC {
1436014369
htlc_id,

0 commit comments

Comments
 (0)