Skip to content

Commit 40a593a

Browse files
committed
ln: add incoming_accountable to PendingHTLCInfo
1 parent 961c0dc commit 40a593a

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: Option<bool>,
430433
}
431434

432435
#[derive(Clone, Debug)] // See FundedChannel::revoke_and_ack for why, tl;dr: Rust bug
@@ -5077,7 +5080,7 @@ where
50775080
let current_height: u32 = self.best_block.read().unwrap().height;
50785081
create_recv_pending_htlc_info(decoded_hop, shared_secret, msg.payment_hash,
50795082
msg.amount_msat, msg.cltv_expiry, None, allow_underpay, msg.skimmed_fee_msat,
5080-
current_height)
5083+
accountable_into_bool(msg.accountable), current_height)
50815084
},
50825085
onion_utils::Hop::Forward { .. } | onion_utils::Hop::BlindedForward { .. } => {
50835086
create_fwd_pending_htlc_info(msg, decoded_hop, shared_secret, next_packet_pubkey_opt)
@@ -7189,6 +7192,7 @@ where
71897192
payment_hash,
71907193
outgoing_amt_msat,
71917194
outgoing_cltv_value,
7195+
incoming_accountable,
71927196
..
71937197
},
71947198
} = payment;
@@ -7287,6 +7291,7 @@ where
72877291
Some(phantom_shared_secret),
72887292
false,
72897293
None,
7294+
incoming_accountable,
72907295
current_height,
72917296
);
72927297
match create_res {
@@ -15883,6 +15888,7 @@ impl_writeable_tlv_based!(PendingHTLCInfo, {
1588315888
(8, outgoing_cltv_value, required),
1588415889
(9, incoming_amt_msat, option),
1588515890
(10, skimmed_fee_msat, option),
15891+
(11, incoming_accountable, option),
1588615892
});
1588715893

1588815894
impl Writeable for HTLCFailureMsg {
@@ -19317,7 +19323,7 @@ mod tests {
1931719323
if let Err(crate::ln::channelmanager::InboundHTLCErr { reason, .. }) =
1931819324
create_recv_pending_htlc_info(hop_data, [0; 32], PaymentHash([0; 32]),
1931919325
sender_intended_amt_msat - extra_fee_msat - 1, 42, None, true, Some(extra_fee_msat),
19320-
current_height)
19326+
None, current_height)
1932119327
{
1932219328
assert_eq!(reason, LocalHTLCFailureReason::FinalIncorrectHTLCAmount);
1932319329
} else { panic!(); }
@@ -19340,7 +19346,7 @@ mod tests {
1934019346
let current_height: u32 = node[0].node.best_block.read().unwrap().height;
1934119347
assert!(create_recv_pending_htlc_info(hop_data, [0; 32], PaymentHash([0; 32]),
1934219348
sender_intended_amt_msat - extra_fee_msat, 42, None, true, Some(extra_fee_msat),
19343-
current_height).is_ok());
19349+
None, current_height).is_ok());
1934419350
}
1934519351

1934619352
#[test]
@@ -19365,7 +19371,7 @@ mod tests {
1936519371
custom_tlvs: Vec::new(),
1936619372
},
1936719373
shared_secret: SharedSecret::from_bytes([0; 32]),
19368-
}, [0; 32], PaymentHash([0; 32]), 100, TEST_FINAL_CLTV + 1, None, true, None, current_height);
19374+
}, [0; 32], PaymentHash([0; 32]), 100, TEST_FINAL_CLTV + 1, None, true, None, None, current_height);
1936919375

1937019376
// Should not return an error as this condition:
1937119377
// 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};
@@ -241,14 +241,15 @@ pub(super) fn create_fwd_pending_htlc_info(
241241
outgoing_amt_msat: amt_to_forward,
242242
outgoing_cltv_value,
243243
skimmed_fee_msat: None,
244+
incoming_accountable: accountable_into_bool(msg.accountable),
244245
})
245246
}
246247

247248
#[rustfmt::skip]
248249
pub(super) fn create_recv_pending_htlc_info(
249250
hop_data: onion_utils::Hop, shared_secret: [u8; 32], payment_hash: PaymentHash,
250251
amt_msat: u64, cltv_expiry: u32, phantom_shared_secret: Option<[u8; 32]>, allow_underpay: bool,
251-
counterparty_skimmed_fee_msat: Option<u64>, current_height: u32
252+
counterparty_skimmed_fee_msat: Option<u64>, incoming_accountable: Option<bool>, current_height: u32
252253
) -> Result<PendingHTLCInfo, InboundHTLCErr> {
253254
let (
254255
payment_data, keysend_preimage, custom_tlvs, onion_amt_msat, onion_cltv_expiry,
@@ -419,6 +420,7 @@ pub(super) fn create_recv_pending_htlc_info(
419420
outgoing_amt_msat: onion_amt_msat,
420421
outgoing_cltv_value: onion_cltv_expiry,
421422
skimmed_fee_msat: counterparty_skimmed_fee_msat,
423+
incoming_accountable,
422424
})
423425
}
424426

@@ -483,7 +485,8 @@ where
483485
let shared_secret = hop.shared_secret().secret_bytes();
484486
create_recv_pending_htlc_info(
485487
hop, shared_secret, msg.payment_hash, msg.amount_msat, msg.cltv_expiry,
486-
None, allow_skimmed_fees, msg.skimmed_fee_msat, cur_height,
488+
None, allow_skimmed_fees, msg.skimmed_fee_msat,
489+
accountable_into_bool(msg.accountable), cur_height,
487490
)?
488491
}
489492
})

0 commit comments

Comments
 (0)