Skip to content

Commit 413aa95

Browse files
committed
ln: add incoming_accountable to PendingHTLCInfo
Persist as a bool so that we don't need to use Option<bool> when we will just inevitably unwrap_or(false) the field. This means that we won't be able to distinguish between an incoming htlc that has no TLV set, and one that has the TLV set with a false value in it. We accept this loss of information for the sake of simplicity in the codebase.
1 parent 46aa1cf commit 413aa95

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ pub struct PendingHTLCInfo {
427427
/// This is used to allow LSPs to take fees as a part of payments, without the sender having to
428428
/// shoulder them.
429429
pub skimmed_fee_msat: Option<u64>,
430+
/// An experimental field indicating whether our node's reputation would be held accountable
431+
/// for the timely resolution of the received HTLC.
432+
pub incoming_accountable: bool,
430433
}
431434

432435
#[derive(Clone, Debug)] // See FundedChannel::revoke_and_ack for why, tl;dr: Rust bug
@@ -5249,7 +5252,7 @@ where
52495252
let current_height: u32 = self.best_block.read().unwrap().height;
52505253
create_recv_pending_htlc_info(decoded_hop, shared_secret, msg.payment_hash,
52515254
msg.amount_msat, msg.cltv_expiry, None, allow_underpay, msg.skimmed_fee_msat,
5252-
current_height)
5255+
msg.accountable.unwrap_or(false), current_height)
52535256
},
52545257
onion_utils::Hop::Forward { .. } | onion_utils::Hop::BlindedForward { .. } => {
52555258
create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt)
@@ -7375,6 +7378,7 @@ where
73757378
payment_hash,
73767379
outgoing_amt_msat,
73777380
outgoing_cltv_value,
7381+
incoming_accountable,
73787382
..
73797383
},
73807384
} = payment;
@@ -7473,6 +7477,7 @@ where
74737477
Some(phantom_shared_secret),
74747478
false,
74757479
None,
7480+
incoming_accountable,
74767481
current_height,
74777482
);
74787483
match create_res {
@@ -16248,6 +16253,7 @@ impl_writeable_tlv_based!(PendingHTLCInfo, {
1624816253
(8, outgoing_cltv_value, required),
1624916254
(9, incoming_amt_msat, option),
1625016255
(10, skimmed_fee_msat, option),
16256+
(11, incoming_accountable, (default_value, false)),
1625116257
});
1625216258

1625316259
impl Writeable for HTLCFailureMsg {
@@ -19837,7 +19843,7 @@ mod tests {
1983719843
if let Err(crate::ln::channelmanager::InboundHTLCErr { reason, .. }) =
1983819844
create_recv_pending_htlc_info(hop_data, [0; 32], PaymentHash([0; 32]),
1983919845
sender_intended_amt_msat - extra_fee_msat - 1, 42, None, true, Some(extra_fee_msat),
19840-
current_height)
19846+
false, current_height)
1984119847
{
1984219848
assert_eq!(reason, LocalHTLCFailureReason::FinalIncorrectHTLCAmount);
1984319849
} else { panic!(); }
@@ -19860,7 +19866,7 @@ mod tests {
1986019866
let current_height: u32 = node[0].node.best_block.read().unwrap().height;
1986119867
assert!(create_recv_pending_htlc_info(hop_data, [0; 32], PaymentHash([0; 32]),
1986219868
sender_intended_amt_msat - extra_fee_msat, 42, None, true, Some(extra_fee_msat),
19863-
current_height).is_ok());
19869+
false, current_height).is_ok());
1986419870
}
1986519871

1986619872
#[test]
@@ -19885,7 +19891,7 @@ mod tests {
1988519891
custom_tlvs: Vec::new(),
1988619892
},
1988719893
shared_secret: SharedSecret::from_bytes([0; 32]),
19888-
}, [0; 32], PaymentHash([0; 32]), 100, TEST_FINAL_CLTV + 1, None, true, None, current_height);
19894+
}, [0; 32], PaymentHash([0; 32]), 100, TEST_FINAL_CLTV + 1, None, true, None, false, current_height);
1988919895

1989019896
// Should not return an error as this condition:
1989119897
// https://github.com/lightning/bolts/blob/4dcc377209509b13cf89a4b91fde7d478f5b46d8/04-onion-routing.md?plain=1#L334

lightning/src/ln/onion_payment.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,15 @@ pub(super) fn create_fwd_pending_htlc_info(
267267
outgoing_amt_msat: amt_to_forward,
268268
outgoing_cltv_value,
269269
skimmed_fee_msat: None,
270+
incoming_accountable: msg.accountable.unwrap_or(false),
270271
})
271272
}
272273

273274
#[rustfmt::skip]
274275
pub(super) fn create_recv_pending_htlc_info(
275276
hop_data: onion_utils::Hop, shared_secret: [u8; 32], payment_hash: PaymentHash,
276277
amt_msat: u64, cltv_expiry: u32, phantom_shared_secret: Option<[u8; 32]>, allow_underpay: bool,
277-
counterparty_skimmed_fee_msat: Option<u64>, current_height: u32
278+
counterparty_skimmed_fee_msat: Option<u64>, incoming_accountable: bool, current_height: u32
278279
) -> Result<PendingHTLCInfo, InboundHTLCErr> {
279280
let (
280281
payment_data, keysend_preimage, custom_tlvs, onion_amt_msat, onion_cltv_expiry,
@@ -456,6 +457,7 @@ pub(super) fn create_recv_pending_htlc_info(
456457
outgoing_amt_msat: onion_amt_msat,
457458
outgoing_cltv_value: onion_cltv_expiry,
458459
skimmed_fee_msat: counterparty_skimmed_fee_msat,
460+
incoming_accountable,
459461
})
460462
}
461463

@@ -520,7 +522,8 @@ where
520522
let shared_secret = hop.shared_secret().secret_bytes();
521523
create_recv_pending_htlc_info(
522524
hop, shared_secret, msg.payment_hash, msg.amount_msat, msg.cltv_expiry,
523-
None, allow_skimmed_fees, msg.skimmed_fee_msat, cur_height,
525+
None, allow_skimmed_fees, msg.skimmed_fee_msat,
526+
msg.accountable.unwrap_or(false), cur_height,
524527
)?
525528
}
526529
})

0 commit comments

Comments
 (0)