Skip to content

Commit d8ae3d0

Browse files
committed
Add AttributionData to HTLCUpdateAwaitingACK::ClaimHTLC
Necessary to preserve attribution data when the HTLC is in the holding cell.
1 parent 55e9449 commit d8ae3d0

File tree

1 file changed

+73
-50
lines changed

1 file changed

+73
-50
lines changed

lightning/src/ln/channel.rs

Lines changed: 73 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ enum HTLCUpdateAwaitingACK {
468468
},
469469
ClaimHTLC {
470470
payment_preimage: PaymentPreimage,
471+
attribution_data: Option<AttributionData>,
471472
htlc_id: u64,
472473
},
473474
FailHTLC {
@@ -6284,6 +6285,7 @@ where
62846285
self.context.holding_cell_htlc_updates.push(HTLCUpdateAwaitingACK::ClaimHTLC {
62856286
payment_preimage: payment_preimage_arg,
62866287
htlc_id: htlc_id_arg,
6288+
attribution_data: None,
62876289
});
62886290
return UpdateFulfillFetch::NewClaim {
62896291
monitor_update,
@@ -12548,7 +12550,7 @@ where
1254812550
Vec::with_capacity(holding_cell_htlc_update_count);
1254912551
let mut holding_cell_blinding_points: Vec<Option<PublicKey>> =
1255012552
Vec::with_capacity(holding_cell_htlc_update_count);
12551-
let mut holding_cell_failure_attribution_data: Vec<Option<&AttributionData>> =
12553+
let mut holding_cell_attribution_data: Vec<Option<&AttributionData>> =
1255212554
Vec::with_capacity(holding_cell_htlc_update_count);
1255312555
// Vec of (htlc_id, failure_code, sha256_of_onion)
1255412556
let mut malformed_htlcs: Vec<(u64, u16, [u8; 32])> = Vec::new();
@@ -12574,19 +12576,25 @@ where
1257412576
holding_cell_skimmed_fees.push(skimmed_fee_msat);
1257512577
holding_cell_blinding_points.push(blinding_point);
1257612578
},
12577-
&HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
12579+
&HTLCUpdateAwaitingACK::ClaimHTLC {
12580+
ref payment_preimage,
12581+
ref htlc_id,
12582+
ref attribution_data,
12583+
} => {
1257812584
1u8.write(writer)?;
1257912585
payment_preimage.write(writer)?;
1258012586
htlc_id.write(writer)?;
12587+
12588+
// Store the attribution data for later writing.
12589+
holding_cell_attribution_data.push(attribution_data.as_ref());
1258112590
},
1258212591
&HTLCUpdateAwaitingACK::FailHTLC { ref htlc_id, ref err_packet } => {
1258312592
2u8.write(writer)?;
1258412593
htlc_id.write(writer)?;
1258512594
err_packet.data.write(writer)?;
1258612595

1258712596
// Store the attribution data for later writing.
12588-
holding_cell_failure_attribution_data
12589-
.push(err_packet.attribution_data.as_ref());
12597+
holding_cell_attribution_data.push(err_packet.attribution_data.as_ref());
1259012598
},
1259112599
&HTLCUpdateAwaitingACK::FailMalformedHTLC {
1259212600
htlc_id,
@@ -12603,7 +12611,7 @@ where
1260312611

1260412612
// Push 'None' attribution data for FailMalformedHTLC, because FailMalformedHTLC uses the same
1260512613
// type 2 and is deserialized as a FailHTLC.
12606-
holding_cell_failure_attribution_data.push(None);
12614+
holding_cell_attribution_data.push(None);
1260712615
},
1260812616
}
1260912617
}
@@ -12807,7 +12815,7 @@ where
1280712815
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
1280812816
(54, self.pending_funding, optional_vec), // Added in 0.2
1280912817
(55, removed_htlc_attribution_data, optional_vec), // Added in 0.2
12810-
(57, holding_cell_failure_attribution_data, optional_vec), // Added in 0.2
12818+
(57, holding_cell_attribution_data, optional_vec), // Added in 0.2
1281112819
(58, self.interactive_tx_signing_session, option), // Added in 0.2
1281212820
(59, self.funding.minimum_depth_override, option), // Added in 0.2
1281312821
(60, self.context.historical_scids, optional_vec), // Added in 0.2
@@ -12981,6 +12989,7 @@ where
1298112989
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
1298212990
payment_preimage: Readable::read(reader)?,
1298312991
htlc_id: Readable::read(reader)?,
12992+
attribution_data: None,
1298412993
},
1298512994
2 => HTLCUpdateAwaitingACK::FailHTLC {
1298612995
htlc_id: Readable::read(reader)?,
@@ -13153,7 +13162,7 @@ where
1315313162
let mut holding_cell_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1315413163

1315513164
let mut removed_htlc_attribution_data: Option<Vec<Option<AttributionData>>> = None;
13156-
let mut holding_cell_failure_attribution_data: Option<Vec<Option<AttributionData>>> = None;
13165+
let mut holding_cell_attribution_data: Option<Vec<Option<AttributionData>>> = None;
1315713166

1315813167
let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
1315913168
let mut monitor_pending_update_adds: Option<Vec<msgs::UpdateAddHTLC>> = None;
@@ -13206,7 +13215,7 @@ where
1320613215
(53, funding_tx_broadcast_safe_event_emitted, option),
1320713216
(54, pending_funding, optional_vec), // Added in 0.2
1320813217
(55, removed_htlc_attribution_data, optional_vec),
13209-
(57, holding_cell_failure_attribution_data, optional_vec),
13218+
(57, holding_cell_attribution_data, optional_vec),
1321013219
(58, interactive_tx_signing_session, option), // Added in 0.2
1321113220
(59, minimum_depth_override, option), // Added in 0.2
1321213221
(60, historical_scids, optional_vec), // Added in 0.2
@@ -13334,24 +13343,23 @@ where
1333413343
}
1333513344
}
1333613345

13337-
if let Some(attribution_data_list) = holding_cell_failure_attribution_data {
13338-
let mut holding_cell_failures =
13339-
holding_cell_htlc_updates.iter_mut().filter_map(|upd| {
13340-
if let HTLCUpdateAwaitingACK::FailHTLC {
13346+
if let Some(attribution_data_list) = holding_cell_attribution_data {
13347+
let mut holding_cell_htlcs =
13348+
holding_cell_htlc_updates.iter_mut().filter_map(|upd| match upd {
13349+
HTLCUpdateAwaitingACK::FailHTLC {
1334113350
err_packet: OnionErrorPacket { ref mut attribution_data, .. },
1334213351
..
13343-
} = upd
13344-
{
13352+
} => Some(attribution_data),
13353+
HTLCUpdateAwaitingACK::ClaimHTLC { attribution_data, .. } => {
1334513354
Some(attribution_data)
13346-
} else {
13347-
None
13348-
}
13355+
},
13356+
_ => None,
1334913357
});
1335013358

1335113359
for attribution_data in attribution_data_list {
13352-
*holding_cell_failures.next().ok_or(DecodeError::InvalidValue)? = attribution_data;
13360+
*holding_cell_htlcs.next().ok_or(DecodeError::InvalidValue)? = attribution_data;
1335313361
}
13354-
if holding_cell_failures.next().is_some() {
13362+
if holding_cell_htlcs.next().is_some() {
1335513363
return Err(DecodeError::InvalidValue);
1335613364
}
1335713365
}
@@ -14345,47 +14353,62 @@ mod tests {
1434514353
skimmed_fee_msat: None,
1434614354
blinding_point: None,
1434714355
};
14348-
let dummy_holding_cell_claim_htlc = HTLCUpdateAwaitingACK::ClaimHTLC {
14356+
let dummy_holding_cell_claim_htlc = |attribution_data| HTLCUpdateAwaitingACK::ClaimHTLC {
1434914357
payment_preimage: PaymentPreimage([42; 32]),
1435014358
htlc_id: 0,
14359+
attribution_data,
1435114360
};
14352-
let dummy_holding_cell_failed_htlc = |htlc_id| HTLCUpdateAwaitingACK::FailHTLC {
14353-
htlc_id,
14354-
err_packet: msgs::OnionErrorPacket {
14355-
data: vec![42],
14356-
attribution_data: Some(AttributionData::new()),
14357-
},
14358-
};
14361+
let dummy_holding_cell_failed_htlc =
14362+
|htlc_id, attribution_data| HTLCUpdateAwaitingACK::FailHTLC {
14363+
htlc_id,
14364+
err_packet: msgs::OnionErrorPacket { data: vec![42], attribution_data },
14365+
};
1435914366
let dummy_holding_cell_malformed_htlc =
1436014367
|htlc_id| HTLCUpdateAwaitingACK::FailMalformedHTLC {
1436114368
htlc_id,
1436214369
failure_code: LocalHTLCFailureReason::InvalidOnionBlinding.failure_code(),
1436314370
sha256_of_onion: [0; 32],
1436414371
};
1436514372
let mut holding_cell_htlc_updates = Vec::with_capacity(12);
14366-
for i in 0..12 {
14367-
if i % 5 == 0 {
14368-
holding_cell_htlc_updates.push(dummy_holding_cell_add_htlc.clone());
14369-
} else if i % 5 == 1 {
14370-
holding_cell_htlc_updates.push(dummy_holding_cell_claim_htlc.clone());
14371-
} else if i % 5 == 2 {
14372-
let mut dummy_add = dummy_holding_cell_add_htlc.clone();
14373-
if let HTLCUpdateAwaitingACK::AddHTLC {
14374-
ref mut blinding_point,
14375-
ref mut skimmed_fee_msat,
14376-
..
14377-
} = &mut dummy_add
14378-
{
14379-
*blinding_point = Some(test_utils::pubkey(42 + i));
14380-
*skimmed_fee_msat = Some(42);
14381-
} else {
14382-
panic!()
14383-
}
14384-
holding_cell_htlc_updates.push(dummy_add);
14385-
} else if i % 5 == 3 {
14386-
holding_cell_htlc_updates.push(dummy_holding_cell_malformed_htlc(i as u64));
14387-
} else {
14388-
holding_cell_htlc_updates.push(dummy_holding_cell_failed_htlc(i as u64));
14373+
for i in 0..16 {
14374+
match i % 7 {
14375+
0 => {
14376+
holding_cell_htlc_updates.push(dummy_holding_cell_add_htlc.clone());
14377+
},
14378+
1 => {
14379+
holding_cell_htlc_updates.push(dummy_holding_cell_claim_htlc(None));
14380+
},
14381+
2 => {
14382+
holding_cell_htlc_updates
14383+
.push(dummy_holding_cell_claim_htlc(Some(AttributionData::new())));
14384+
},
14385+
3 => {
14386+
let mut dummy_add = dummy_holding_cell_add_htlc.clone();
14387+
if let HTLCUpdateAwaitingACK::AddHTLC {
14388+
ref mut blinding_point,
14389+
ref mut skimmed_fee_msat,
14390+
..
14391+
} = &mut dummy_add
14392+
{
14393+
*blinding_point = Some(test_utils::pubkey(42 + i));
14394+
*skimmed_fee_msat = Some(42);
14395+
} else {
14396+
panic!()
14397+
}
14398+
holding_cell_htlc_updates.push(dummy_add);
14399+
},
14400+
4 => {
14401+
holding_cell_htlc_updates.push(dummy_holding_cell_malformed_htlc(i as u64));
14402+
},
14403+
5 => {
14404+
holding_cell_htlc_updates.push(dummy_holding_cell_failed_htlc(i as u64, None));
14405+
},
14406+
_ => {
14407+
holding_cell_htlc_updates.push(dummy_holding_cell_failed_htlc(
14408+
i as u64,
14409+
Some(AttributionData::new()),
14410+
));
14411+
},
1438914412
}
1439014413
}
1439114414
chan.context.holding_cell_htlc_updates = holding_cell_htlc_updates.clone();

0 commit comments

Comments
 (0)