@@ -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 {
@@ -6289,6 +6290,7 @@ where
6289
6290
self.context.holding_cell_htlc_updates.push(HTLCUpdateAwaitingACK::ClaimHTLC {
6290
6291
payment_preimage: payment_preimage_arg,
6291
6292
htlc_id: htlc_id_arg,
6293
+ attribution_data: None,
6292
6294
});
6293
6295
return UpdateFulfillFetch::NewClaim {
6294
6296
monitor_update,
@@ -12543,7 +12545,7 @@ where
12543
12545
Vec::with_capacity(holding_cell_htlc_update_count);
12544
12546
let mut holding_cell_blinding_points: Vec<Option<PublicKey>> =
12545
12547
Vec::with_capacity(holding_cell_htlc_update_count);
12546
- let mut holding_cell_failure_attribution_data : Vec<Option<&AttributionData>> =
12548
+ let mut holding_cell_attribution_data : Vec<Option<&AttributionData>> =
12547
12549
Vec::with_capacity(holding_cell_htlc_update_count);
12548
12550
// Vec of (htlc_id, failure_code, sha256_of_onion)
12549
12551
let mut malformed_htlcs: Vec<(u64, u16, [u8; 32])> = Vec::new();
@@ -12569,19 +12571,25 @@ where
12569
12571
holding_cell_skimmed_fees.push(skimmed_fee_msat);
12570
12572
holding_cell_blinding_points.push(blinding_point);
12571
12573
},
12572
- &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
12574
+ &HTLCUpdateAwaitingACK::ClaimHTLC {
12575
+ ref payment_preimage,
12576
+ ref htlc_id,
12577
+ ref attribution_data,
12578
+ } => {
12573
12579
1u8.write(writer)?;
12574
12580
payment_preimage.write(writer)?;
12575
12581
htlc_id.write(writer)?;
12582
+
12583
+ // Store the attribution data for later writing.
12584
+ holding_cell_attribution_data.push(attribution_data.as_ref());
12576
12585
},
12577
12586
&HTLCUpdateAwaitingACK::FailHTLC { ref htlc_id, ref err_packet } => {
12578
12587
2u8.write(writer)?;
12579
12588
htlc_id.write(writer)?;
12580
12589
err_packet.data.write(writer)?;
12581
12590
12582
12591
// Store the attribution data for later writing.
12583
- holding_cell_failure_attribution_data
12584
- .push(err_packet.attribution_data.as_ref());
12592
+ holding_cell_attribution_data.push(err_packet.attribution_data.as_ref());
12585
12593
},
12586
12594
&HTLCUpdateAwaitingACK::FailMalformedHTLC {
12587
12595
htlc_id,
@@ -12598,7 +12606,7 @@ where
12598
12606
12599
12607
// Push 'None' attribution data for FailMalformedHTLC, because FailMalformedHTLC uses the same
12600
12608
// type 2 and is deserialized as a FailHTLC.
12601
- holding_cell_failure_attribution_data .push(None);
12609
+ holding_cell_attribution_data .push(None);
12602
12610
},
12603
12611
}
12604
12612
}
@@ -12802,7 +12810,7 @@ where
12802
12810
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
12803
12811
(54, self.pending_funding, optional_vec), // Added in 0.2
12804
12812
(55, removed_htlc_attribution_data, optional_vec), // Added in 0.2
12805
- (57, holding_cell_failure_attribution_data , optional_vec), // Added in 0.2
12813
+ (57, holding_cell_attribution_data , optional_vec), // Added in 0.2
12806
12814
(58, self.interactive_tx_signing_session, option), // Added in 0.2
12807
12815
(59, self.funding.minimum_depth_override, option), // Added in 0.2
12808
12816
(60, self.context.historical_scids, optional_vec), // Added in 0.2
@@ -12976,6 +12984,7 @@ where
12976
12984
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
12977
12985
payment_preimage: Readable::read(reader)?,
12978
12986
htlc_id: Readable::read(reader)?,
12987
+ attribution_data: None,
12979
12988
},
12980
12989
2 => HTLCUpdateAwaitingACK::FailHTLC {
12981
12990
htlc_id: Readable::read(reader)?,
@@ -13148,7 +13157,7 @@ where
13148
13157
let mut holding_cell_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
13149
13158
13150
13159
let mut removed_htlc_attribution_data: Option<Vec<Option<AttributionData>>> = None;
13151
- let mut holding_cell_failure_attribution_data : Option<Vec<Option<AttributionData>>> = None;
13160
+ let mut holding_cell_attribution_data : Option<Vec<Option<AttributionData>>> = None;
13152
13161
13153
13162
let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
13154
13163
let mut monitor_pending_update_adds: Option<Vec<msgs::UpdateAddHTLC>> = None;
@@ -13201,7 +13210,7 @@ where
13201
13210
(53, funding_tx_broadcast_safe_event_emitted, option),
13202
13211
(54, pending_funding, optional_vec), // Added in 0.2
13203
13212
(55, removed_htlc_attribution_data, optional_vec),
13204
- (57, holding_cell_failure_attribution_data , optional_vec),
13213
+ (57, holding_cell_attribution_data , optional_vec),
13205
13214
(58, interactive_tx_signing_session, option), // Added in 0.2
13206
13215
(59, minimum_depth_override, option), // Added in 0.2
13207
13216
(60, historical_scids, optional_vec), // Added in 0.2
@@ -13329,24 +13338,23 @@ where
13329
13338
}
13330
13339
}
13331
13340
13332
- if let Some(attribution_data_list) = holding_cell_failure_attribution_data {
13333
- let mut holding_cell_failures =
13334
- holding_cell_htlc_updates.iter_mut().filter_map(|upd| {
13335
- if let HTLCUpdateAwaitingACK::FailHTLC {
13341
+ if let Some(attribution_data_list) = holding_cell_attribution_data {
13342
+ let mut holding_cell_htlcs =
13343
+ holding_cell_htlc_updates.iter_mut().filter_map(|upd| match upd {
13344
+ HTLCUpdateAwaitingACK::FailHTLC {
13336
13345
err_packet: OnionErrorPacket { ref mut attribution_data, .. },
13337
13346
..
13338
- } = upd
13339
- {
13347
+ } => Some(attribution_data),
13348
+ HTLCUpdateAwaitingACK::ClaimHTLC { attribution_data, .. } => {
13340
13349
Some(attribution_data)
13341
- } else {
13342
- None
13343
- }
13350
+ },
13351
+ _ => None,
13344
13352
});
13345
13353
13346
13354
for attribution_data in attribution_data_list {
13347
- *holding_cell_failures .next().ok_or(DecodeError::InvalidValue)? = attribution_data;
13355
+ *holding_cell_htlcs .next().ok_or(DecodeError::InvalidValue)? = attribution_data;
13348
13356
}
13349
- if holding_cell_failures .next().is_some() {
13357
+ if holding_cell_htlcs .next().is_some() {
13350
13358
return Err(DecodeError::InvalidValue);
13351
13359
}
13352
13360
}
@@ -14340,47 +14348,62 @@ mod tests {
14340
14348
skimmed_fee_msat: None,
14341
14349
blinding_point: None,
14342
14350
};
14343
- let dummy_holding_cell_claim_htlc = HTLCUpdateAwaitingACK::ClaimHTLC {
14351
+ let dummy_holding_cell_claim_htlc = |attribution_data| HTLCUpdateAwaitingACK::ClaimHTLC {
14344
14352
payment_preimage: PaymentPreimage([42; 32]),
14345
14353
htlc_id: 0,
14354
+ attribution_data,
14346
14355
};
14347
- let dummy_holding_cell_failed_htlc = |htlc_id| HTLCUpdateAwaitingACK::FailHTLC {
14348
- htlc_id,
14349
- err_packet: msgs::OnionErrorPacket {
14350
- data: vec![42],
14351
- attribution_data: Some(AttributionData::new()),
14352
- },
14353
- };
14356
+ let dummy_holding_cell_failed_htlc =
14357
+ |htlc_id, attribution_data| HTLCUpdateAwaitingACK::FailHTLC {
14358
+ htlc_id,
14359
+ err_packet: msgs::OnionErrorPacket { data: vec![42], attribution_data },
14360
+ };
14354
14361
let dummy_holding_cell_malformed_htlc =
14355
14362
|htlc_id| HTLCUpdateAwaitingACK::FailMalformedHTLC {
14356
14363
htlc_id,
14357
14364
failure_code: LocalHTLCFailureReason::InvalidOnionBlinding.failure_code(),
14358
14365
sha256_of_onion: [0; 32],
14359
14366
};
14360
14367
let mut holding_cell_htlc_updates = Vec::with_capacity(12);
14361
- for i in 0..12 {
14362
- if i % 5 == 0 {
14363
- holding_cell_htlc_updates.push(dummy_holding_cell_add_htlc.clone());
14364
- } else if i % 5 == 1 {
14365
- holding_cell_htlc_updates.push(dummy_holding_cell_claim_htlc.clone());
14366
- } else if i % 5 == 2 {
14367
- let mut dummy_add = dummy_holding_cell_add_htlc.clone();
14368
- if let HTLCUpdateAwaitingACK::AddHTLC {
14369
- ref mut blinding_point,
14370
- ref mut skimmed_fee_msat,
14371
- ..
14372
- } = &mut dummy_add
14373
- {
14374
- *blinding_point = Some(test_utils::pubkey(42 + i));
14375
- *skimmed_fee_msat = Some(42);
14376
- } else {
14377
- panic!()
14378
- }
14379
- holding_cell_htlc_updates.push(dummy_add);
14380
- } else if i % 5 == 3 {
14381
- holding_cell_htlc_updates.push(dummy_holding_cell_malformed_htlc(i as u64));
14382
- } else {
14383
- holding_cell_htlc_updates.push(dummy_holding_cell_failed_htlc(i as u64));
14368
+ for i in 0..16 {
14369
+ match i % 7 {
14370
+ 0 => {
14371
+ holding_cell_htlc_updates.push(dummy_holding_cell_add_htlc.clone());
14372
+ },
14373
+ 1 => {
14374
+ holding_cell_htlc_updates.push(dummy_holding_cell_claim_htlc(None));
14375
+ },
14376
+ 2 => {
14377
+ holding_cell_htlc_updates
14378
+ .push(dummy_holding_cell_claim_htlc(Some(AttributionData::new())));
14379
+ },
14380
+ 3 => {
14381
+ let mut dummy_add = dummy_holding_cell_add_htlc.clone();
14382
+ if let HTLCUpdateAwaitingACK::AddHTLC {
14383
+ ref mut blinding_point,
14384
+ ref mut skimmed_fee_msat,
14385
+ ..
14386
+ } = &mut dummy_add
14387
+ {
14388
+ *blinding_point = Some(test_utils::pubkey(42 + i));
14389
+ *skimmed_fee_msat = Some(42);
14390
+ } else {
14391
+ panic!()
14392
+ }
14393
+ holding_cell_htlc_updates.push(dummy_add);
14394
+ },
14395
+ 4 => {
14396
+ holding_cell_htlc_updates.push(dummy_holding_cell_malformed_htlc(i as u64));
14397
+ },
14398
+ 5 => {
14399
+ holding_cell_htlc_updates.push(dummy_holding_cell_failed_htlc(i as u64, None));
14400
+ },
14401
+ _ => {
14402
+ holding_cell_htlc_updates.push(dummy_holding_cell_failed_htlc(
14403
+ i as u64,
14404
+ Some(AttributionData::new()),
14405
+ ));
14406
+ },
14384
14407
}
14385
14408
}
14386
14409
chan.context.holding_cell_htlc_updates = holding_cell_htlc_updates.clone();
0 commit comments