Skip to content

Commit 7c7f7bc

Browse files
committed
f: add drop attribution data test
1 parent 18f7736 commit 7c7f7bc

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lightning/src/ln/onion_utils.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2810,6 +2810,7 @@ fn process_failure_packet(
28102810

28112811
#[cfg(test)]
28122812
mod tests {
2813+
use core::iter;
28132814
use std::sync::Arc;
28142815

28152816
use crate::io;
@@ -3153,14 +3154,18 @@ mod tests {
31533154

31543155
for mutation_type in failure_mutations
31553156
.chain(attribution_data_mutations.map(MutationType::AttributionData))
3157+
.chain(iter::once(MutationType::DropAttributionData))
31563158
{
3159+
// If the mutation is in the attribution data and not in the failure message itself, the invalid
3160+
// attribution data should be ignored and the failure should still surface.
3161+
let failure_ok = matches!(mutation_type, MutationType::DropAttributionData)
3162+
|| matches!(mutation_type, MutationType::AttributionData(_));
3163+
31573164
let mutation = Mutation { node: mutating_node, mutation_type };
31583165
let decrypted_failure =
31593166
test_attributable_failure_packet_onion_with_mutation(Some(mutation));
31603167

3161-
// If the mutation is in the attribution data and not in the failure message itself, the invalid
3162-
// attribution data should be ignored and the failure should still surface.
3163-
if mutated_index >= FAILURE_MESSAGE_LEN {
3168+
if failure_ok {
31643169
assert_eq!(
31653170
decrypted_failure.onion_error_code,
31663171
Some(LocalHTLCFailureReason::IncorrectPaymentDetails)
@@ -3198,6 +3203,7 @@ mod tests {
31983203
enum MutationType {
31993204
FailureMessage(usize),
32003205
AttributionData(AttributionDataMutationType),
3206+
DropAttributionData,
32013207
}
32023208

32033209
struct Mutation {
@@ -3285,6 +3291,10 @@ mod tests {
32853291
// Mutate hold times.
32863292
packet.attribution_data.as_mut().unwrap().hmacs[*i] ^= 1;
32873293
},
3294+
MutationType::DropAttributionData => {
3295+
// Drop attribution data completely. This simulates a node that does not support the feature.
3296+
packet.attribution_data = None;
3297+
},
32883298
}
32893299
};
32903300

0 commit comments

Comments
 (0)