Skip to content

Commit 1da4e9e

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 152ec42 commit 1da4e9e

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ use crate::ln::inbound_payment;
6868
use crate::ln::interactivetxs::InteractiveTxMessageSend;
6969
use crate::ln::msgs;
7070
use crate::ln::msgs::{
71-
BaseMessageHandler, ChannelMessageHandler, CommitmentUpdate, DecodeError, LightningError,
72-
MessageSendEvent,
71+
accountable_into_bool, BaseMessageHandler, ChannelMessageHandler, CommitmentUpdate,
72+
DecodeError, LightningError, MessageSendEvent,
7373
};
7474
use crate::ln::onion_payment::{
7575
check_incoming_htlc_cltv, create_fwd_pending_htlc_info, create_recv_pending_htlc_info,
@@ -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
@@ -5100,7 +5103,7 @@ where
51005103
let current_height: u32 = self.best_block.read().unwrap().height;
51015104
create_recv_pending_htlc_info(decoded_hop, shared_secret, msg.payment_hash,
51025105
msg.amount_msat, msg.cltv_expiry, None, allow_underpay, msg.skimmed_fee_msat,
5103-
current_height)
5106+
accountable_into_bool(msg.accountable), current_height)
51045107
},
51055108
onion_utils::Hop::Forward { .. } | onion_utils::Hop::BlindedForward { .. } => {
51065109
create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt)
@@ -7222,6 +7225,7 @@ where
72227225
payment_hash,
72237226
outgoing_amt_msat,
72247227
outgoing_cltv_value,
7228+
incoming_accountable,
72257229
..
72267230
},
72277231
} = payment;
@@ -7320,6 +7324,7 @@ where
73207324
Some(phantom_shared_secret),
73217325
false,
73227326
None,
7327+
incoming_accountable,
73237328
current_height,
73247329
);
73257330
match create_res {
@@ -15963,6 +15968,7 @@ impl_writeable_tlv_based!(PendingHTLCInfo, {
1596315968
(8, outgoing_cltv_value, required),
1596415969
(9, incoming_amt_msat, option),
1596515970
(10, skimmed_fee_msat, option),
15971+
(11, incoming_accountable, (default_value, false)),
1596615972
});
1596715973

1596815974
impl Writeable for HTLCFailureMsg {
@@ -19398,7 +19404,7 @@ mod tests {
1939819404
if let Err(crate::ln::channelmanager::InboundHTLCErr { reason, .. }) =
1939919405
create_recv_pending_htlc_info(hop_data, [0; 32], PaymentHash([0; 32]),
1940019406
sender_intended_amt_msat - extra_fee_msat - 1, 42, None, true, Some(extra_fee_msat),
19401-
current_height)
19407+
false, current_height)
1940219408
{
1940319409
assert_eq!(reason, LocalHTLCFailureReason::FinalIncorrectHTLCAmount);
1940419410
} else { panic!(); }
@@ -19421,7 +19427,7 @@ mod tests {
1942119427
let current_height: u32 = node[0].node.best_block.read().unwrap().height;
1942219428
assert!(create_recv_pending_htlc_info(hop_data, [0; 32], PaymentHash([0; 32]),
1942319429
sender_intended_amt_msat - extra_fee_msat, 42, None, true, Some(extra_fee_msat),
19424-
current_height).is_ok());
19430+
false, current_height).is_ok());
1942519431
}
1942619432

1942719433
#[test]
@@ -19446,7 +19452,7 @@ mod tests {
1944619452
custom_tlvs: Vec::new(),
1944719453
},
1944819454
shared_secret: SharedSecret::from_bytes([0; 32]),
19449-
}, [0; 32], PaymentHash([0; 32]), 100, TEST_FINAL_CLTV + 1, None, true, None, current_height);
19455+
}, [0; 32], PaymentHash([0; 32]), 100, TEST_FINAL_CLTV + 1, None, true, None, false, current_height);
1945019456

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

lightning/src/ln/onion_payment.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::ln::channelmanager::{
1515
BlindedFailure, BlindedForward, HTLCFailureMsg, PendingHTLCInfo, PendingHTLCRouting,
1616
CLTV_FAR_FAR_AWAY, MIN_CLTV_EXPIRY_DELTA,
1717
};
18-
use crate::ln::msgs;
18+
use crate::ln::msgs::{self, accountable_into_bool};
1919
use crate::ln::onion_utils;
2020
use crate::ln::onion_utils::{HTLCFailReason, LocalHTLCFailureReason, ONION_DATA_LEN};
2121
use crate::sign::{NodeSigner, Recipient};
@@ -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: accountable_into_bool(msg.accountable),
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+
accountable_into_bool(msg.accountable), cur_height,
524527
)?
525528
}
526529
})

0 commit comments

Comments
 (0)