@@ -468,6 +468,7 @@ enum HTLCUpdateAwaitingACK {
468
468
},
469
469
ClaimHTLC {
470
470
payment_preimage: PaymentPreimage,
471
+ attribution_data: Option<AttributionData>,
471
472
htlc_id: u64,
472
473
},
473
474
FailHTLC {
@@ -6271,6 +6272,7 @@ where
6271
6272
self.context.holding_cell_htlc_updates.push(HTLCUpdateAwaitingACK::ClaimHTLC {
6272
6273
payment_preimage: payment_preimage_arg,
6273
6274
htlc_id: htlc_id_arg,
6275
+ attribution_data: None,
6274
6276
});
6275
6277
return UpdateFulfillFetch::NewClaim {
6276
6278
monitor_update,
@@ -12518,7 +12520,7 @@ where
12518
12520
Vec::with_capacity(holding_cell_htlc_update_count);
12519
12521
let mut holding_cell_blinding_points: Vec<Option<PublicKey>> =
12520
12522
Vec::with_capacity(holding_cell_htlc_update_count);
12521
- let mut holding_cell_failure_attribution_data : Vec<Option<&AttributionData>> =
12523
+ let mut holding_cell_attribution_data : Vec<Option<&AttributionData>> =
12522
12524
Vec::with_capacity(holding_cell_htlc_update_count);
12523
12525
// Vec of (htlc_id, failure_code, sha256_of_onion)
12524
12526
let mut malformed_htlcs: Vec<(u64, u16, [u8; 32])> = Vec::new();
@@ -12544,19 +12546,25 @@ where
12544
12546
holding_cell_skimmed_fees.push(skimmed_fee_msat);
12545
12547
holding_cell_blinding_points.push(blinding_point);
12546
12548
},
12547
- &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
12549
+ &HTLCUpdateAwaitingACK::ClaimHTLC {
12550
+ ref payment_preimage,
12551
+ ref htlc_id,
12552
+ ref attribution_data,
12553
+ } => {
12548
12554
1u8.write(writer)?;
12549
12555
payment_preimage.write(writer)?;
12550
12556
htlc_id.write(writer)?;
12557
+
12558
+ // Store the attribution data for later writing.
12559
+ holding_cell_attribution_data.push(attribution_data.as_ref());
12551
12560
},
12552
12561
&HTLCUpdateAwaitingACK::FailHTLC { ref htlc_id, ref err_packet } => {
12553
12562
2u8.write(writer)?;
12554
12563
htlc_id.write(writer)?;
12555
12564
err_packet.data.write(writer)?;
12556
12565
12557
12566
// Store the attribution data for later writing.
12558
- holding_cell_failure_attribution_data
12559
- .push(err_packet.attribution_data.as_ref());
12567
+ holding_cell_attribution_data.push(err_packet.attribution_data.as_ref());
12560
12568
},
12561
12569
&HTLCUpdateAwaitingACK::FailMalformedHTLC {
12562
12570
htlc_id,
@@ -12573,7 +12581,7 @@ where
12573
12581
12574
12582
// Push 'None' attribution data for FailMalformedHTLC, because FailMalformedHTLC uses the same
12575
12583
// type 2 and is deserialized as a FailHTLC.
12576
- holding_cell_failure_attribution_data .push(None);
12584
+ holding_cell_attribution_data .push(None);
12577
12585
},
12578
12586
}
12579
12587
}
@@ -12777,7 +12785,7 @@ where
12777
12785
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
12778
12786
(54, self.pending_funding, optional_vec), // Added in 0.2
12779
12787
(55, removed_htlc_attribution_data, optional_vec), // Added in 0.2
12780
- (57, holding_cell_failure_attribution_data , optional_vec), // Added in 0.2
12788
+ (57, holding_cell_attribution_data , optional_vec), // Added in 0.2
12781
12789
(58, self.interactive_tx_signing_session, option), // Added in 0.2
12782
12790
(59, self.funding.minimum_depth_override, option), // Added in 0.2
12783
12791
(60, self.context.historical_scids, optional_vec), // Added in 0.2
@@ -12951,6 +12959,7 @@ where
12951
12959
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
12952
12960
payment_preimage: Readable::read(reader)?,
12953
12961
htlc_id: Readable::read(reader)?,
12962
+ attribution_data: None,
12954
12963
},
12955
12964
2 => HTLCUpdateAwaitingACK::FailHTLC {
12956
12965
htlc_id: Readable::read(reader)?,
@@ -13123,7 +13132,7 @@ where
13123
13132
let mut holding_cell_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
13124
13133
13125
13134
let mut removed_htlc_attribution_data: Option<Vec<Option<AttributionData>>> = None;
13126
- let mut holding_cell_failure_attribution_data : Option<Vec<Option<AttributionData>>> = None;
13135
+ let mut holding_cell_attribution_data : Option<Vec<Option<AttributionData>>> = None;
13127
13136
13128
13137
let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
13129
13138
let mut monitor_pending_update_adds: Option<Vec<msgs::UpdateAddHTLC>> = None;
@@ -13176,7 +13185,7 @@ where
13176
13185
(53, funding_tx_broadcast_safe_event_emitted, option),
13177
13186
(54, pending_funding, optional_vec), // Added in 0.2
13178
13187
(55, removed_htlc_attribution_data, optional_vec),
13179
- (57, holding_cell_failure_attribution_data , optional_vec),
13188
+ (57, holding_cell_attribution_data , optional_vec),
13180
13189
(58, interactive_tx_signing_session, option), // Added in 0.2
13181
13190
(59, minimum_depth_override, option), // Added in 0.2
13182
13191
(60, historical_scids, optional_vec), // Added in 0.2
@@ -13304,24 +13313,23 @@ where
13304
13313
}
13305
13314
}
13306
13315
13307
- if let Some(attribution_data_list) = holding_cell_failure_attribution_data {
13308
- let mut holding_cell_failures =
13309
- holding_cell_htlc_updates.iter_mut().filter_map(|upd| {
13310
- if let HTLCUpdateAwaitingACK::FailHTLC {
13316
+ if let Some(attribution_data_list) = holding_cell_attribution_data {
13317
+ let mut holding_cell_htlcs =
13318
+ holding_cell_htlc_updates.iter_mut().filter_map(|upd| match upd {
13319
+ HTLCUpdateAwaitingACK::FailHTLC {
13311
13320
err_packet: OnionErrorPacket { ref mut attribution_data, .. },
13312
13321
..
13313
- } = upd
13314
- {
13322
+ } => Some(attribution_data),
13323
+ HTLCUpdateAwaitingACK::ClaimHTLC { attribution_data, .. } => {
13315
13324
Some(attribution_data)
13316
- } else {
13317
- None
13318
- }
13325
+ },
13326
+ _ => None,
13319
13327
});
13320
13328
13321
13329
for attribution_data in attribution_data_list {
13322
- *holding_cell_failures .next().ok_or(DecodeError::InvalidValue)? = attribution_data;
13330
+ *holding_cell_htlcs .next().ok_or(DecodeError::InvalidValue)? = attribution_data;
13323
13331
}
13324
- if holding_cell_failures .next().is_some() {
13332
+ if holding_cell_htlcs .next().is_some() {
13325
13333
return Err(DecodeError::InvalidValue);
13326
13334
}
13327
13335
}
@@ -14315,47 +14323,62 @@ mod tests {
14315
14323
skimmed_fee_msat: None,
14316
14324
blinding_point: None,
14317
14325
};
14318
- let dummy_holding_cell_claim_htlc = HTLCUpdateAwaitingACK::ClaimHTLC {
14326
+ let dummy_holding_cell_claim_htlc = |attribution_data| HTLCUpdateAwaitingACK::ClaimHTLC {
14319
14327
payment_preimage: PaymentPreimage([42; 32]),
14320
14328
htlc_id: 0,
14329
+ attribution_data,
14321
14330
};
14322
- let dummy_holding_cell_failed_htlc = |htlc_id| HTLCUpdateAwaitingACK::FailHTLC {
14323
- htlc_id,
14324
- err_packet: msgs::OnionErrorPacket {
14325
- data: vec![42],
14326
- attribution_data: Some(AttributionData::new()),
14327
- },
14328
- };
14331
+ let dummy_holding_cell_failed_htlc =
14332
+ |htlc_id, attribution_data| HTLCUpdateAwaitingACK::FailHTLC {
14333
+ htlc_id,
14334
+ err_packet: msgs::OnionErrorPacket { data: vec![42], attribution_data },
14335
+ };
14329
14336
let dummy_holding_cell_malformed_htlc =
14330
14337
|htlc_id| HTLCUpdateAwaitingACK::FailMalformedHTLC {
14331
14338
htlc_id,
14332
14339
failure_code: LocalHTLCFailureReason::InvalidOnionBlinding.failure_code(),
14333
14340
sha256_of_onion: [0; 32],
14334
14341
};
14335
14342
let mut holding_cell_htlc_updates = Vec::with_capacity(12);
14336
- for i in 0..12 {
14337
- if i % 5 == 0 {
14338
- holding_cell_htlc_updates.push(dummy_holding_cell_add_htlc.clone());
14339
- } else if i % 5 == 1 {
14340
- holding_cell_htlc_updates.push(dummy_holding_cell_claim_htlc.clone());
14341
- } else if i % 5 == 2 {
14342
- let mut dummy_add = dummy_holding_cell_add_htlc.clone();
14343
- if let HTLCUpdateAwaitingACK::AddHTLC {
14344
- ref mut blinding_point,
14345
- ref mut skimmed_fee_msat,
14346
- ..
14347
- } = &mut dummy_add
14348
- {
14349
- *blinding_point = Some(test_utils::pubkey(42 + i));
14350
- *skimmed_fee_msat = Some(42);
14351
- } else {
14352
- panic!()
14353
- }
14354
- holding_cell_htlc_updates.push(dummy_add);
14355
- } else if i % 5 == 3 {
14356
- holding_cell_htlc_updates.push(dummy_holding_cell_malformed_htlc(i as u64));
14357
- } else {
14358
- holding_cell_htlc_updates.push(dummy_holding_cell_failed_htlc(i as u64));
14343
+ for i in 0..16 {
14344
+ match i % 7 {
14345
+ 0 => {
14346
+ holding_cell_htlc_updates.push(dummy_holding_cell_add_htlc.clone());
14347
+ },
14348
+ 1 => {
14349
+ holding_cell_htlc_updates.push(dummy_holding_cell_claim_htlc(None));
14350
+ },
14351
+ 2 => {
14352
+ holding_cell_htlc_updates
14353
+ .push(dummy_holding_cell_claim_htlc(Some(AttributionData::new())));
14354
+ },
14355
+ 3 => {
14356
+ let mut dummy_add = dummy_holding_cell_add_htlc.clone();
14357
+ if let HTLCUpdateAwaitingACK::AddHTLC {
14358
+ ref mut blinding_point,
14359
+ ref mut skimmed_fee_msat,
14360
+ ..
14361
+ } = &mut dummy_add
14362
+ {
14363
+ *blinding_point = Some(test_utils::pubkey(42 + i));
14364
+ *skimmed_fee_msat = Some(42);
14365
+ } else {
14366
+ panic!()
14367
+ }
14368
+ holding_cell_htlc_updates.push(dummy_add);
14369
+ },
14370
+ 4 => {
14371
+ holding_cell_htlc_updates.push(dummy_holding_cell_malformed_htlc(i as u64));
14372
+ },
14373
+ 5 => {
14374
+ holding_cell_htlc_updates.push(dummy_holding_cell_failed_htlc(i as u64, None));
14375
+ },
14376
+ _ => {
14377
+ holding_cell_htlc_updates.push(dummy_holding_cell_failed_htlc(
14378
+ i as u64,
14379
+ Some(AttributionData::new()),
14380
+ ));
14381
+ },
14359
14382
}
14360
14383
}
14361
14384
chan.context.holding_cell_htlc_updates = holding_cell_htlc_updates.clone();
0 commit comments