Skip to content

Commit 8cc74a8

Browse files
valentinewallaceAntoine Riard
and
Antoine Riard
committed
Add CounterpartyForwardingInfo field to channel.
This will be filled in in upcoming commits, then exposed in ChannelDetails to allow constructing route hints for invoices. Also update the cltv_expiry_deta comment in msgs::ChannelUpdate Co-authored-by: Valentine Wallace <[email protected]> Co-authored-by: Antoine Riard <[email protected]>
1 parent 2cb5b1a commit 8cc74a8

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

lightning/src/ln/channel.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,17 @@ impl HTLCCandidate {
281281
}
282282
}
283283

284+
/// Information needed for constructing an invoice route hint for this channel.
285+
pub struct CounterpartyForwardingInfo {
286+
/// Base routing fee in millisatoshis.
287+
pub fee_base_msat: u32,
288+
/// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
289+
pub fee_proportional_millionths: u32,
290+
/// The number of blocks we'll add to an outgoing HTLC's cltv_expiry before forwarding.
291+
/// See `msgs::ChannelUpdate`'s `cltv_expiry_delta` for more details.
292+
pub cltv_expiry_delta: u16,
293+
}
294+
284295
// TODO: We should refactor this to be an Inbound/OutboundChannel until initial setup handshaking
285296
// has been completed, and then turn into a Channel to get compiler-time enforcement of things like
286297
// calling channel_id() before we're set up or things like get_outbound_funding_signed on an
@@ -391,6 +402,8 @@ pub(super) struct Channel<Signer: Sign> {
391402
//implied by OUR_MAX_HTLCS: max_accepted_htlcs: u16,
392403
minimum_depth: u32,
393404

405+
counterparty_forwarding_info: Option<CounterpartyForwardingInfo>,
406+
394407
pub(crate) channel_transaction_parameters: ChannelTransactionParameters,
395408

396409
counterparty_cur_commitment_point: Option<PublicKey>,
@@ -577,6 +590,8 @@ impl<Signer: Sign> Channel<Signer> {
577590
counterparty_max_accepted_htlcs: 0,
578591
minimum_depth: 0, // Filled in in accept_channel
579592

593+
counterparty_forwarding_info: None,
594+
580595
channel_transaction_parameters: ChannelTransactionParameters {
581596
holder_pubkeys: pubkeys,
582597
holder_selected_contest_delay: config.own_channel_config.our_to_self_delay,
@@ -813,6 +828,8 @@ impl<Signer: Sign> Channel<Signer> {
813828
counterparty_max_accepted_htlcs: msg.max_accepted_htlcs,
814829
minimum_depth: config.own_channel_config.minimum_depth,
815830

831+
counterparty_forwarding_info: None,
832+
816833
channel_transaction_parameters: ChannelTransactionParameters {
817834
holder_pubkeys: pubkeys,
818835
holder_selected_contest_delay: config.own_channel_config.our_to_self_delay,
@@ -4437,6 +4454,16 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
44374454
self.counterparty_max_accepted_htlcs.write(writer)?;
44384455
self.minimum_depth.write(writer)?;
44394456

4457+
match &self.counterparty_forwarding_info {
4458+
Some(info) => {
4459+
1u8.write(writer)?;
4460+
info.fee_base_msat.write(writer)?;
4461+
info.fee_proportional_millionths.write(writer)?;
4462+
info.cltv_expiry_delta.write(writer)?;
4463+
},
4464+
None => 0u8.write(writer)?
4465+
}
4466+
44404467
self.channel_transaction_parameters.write(writer)?;
44414468
self.counterparty_cur_commitment_point.write(writer)?;
44424469

@@ -4597,6 +4624,16 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
45974624
let counterparty_max_accepted_htlcs = Readable::read(reader)?;
45984625
let minimum_depth = Readable::read(reader)?;
45994626

4627+
let counterparty_forwarding_info = match <u8 as Readable>::read(reader)? {
4628+
0 => None,
4629+
1 => Some(CounterpartyForwardingInfo {
4630+
fee_base_msat: Readable::read(reader)?,
4631+
fee_proportional_millionths: Readable::read(reader)?,
4632+
cltv_expiry_delta: Readable::read(reader)?,
4633+
}),
4634+
_ => return Err(DecodeError::InvalidValue),
4635+
};
4636+
46004637
let channel_parameters = Readable::read(reader)?;
46014638
let counterparty_cur_commitment_point = Readable::read(reader)?;
46024639

@@ -4667,6 +4704,8 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
46674704
counterparty_max_accepted_htlcs,
46684705
minimum_depth,
46694706

4707+
counterparty_forwarding_info,
4708+
46704709
channel_transaction_parameters: channel_parameters,
46714710
counterparty_cur_commitment_point,
46724711

lightning/src/ln/msgs.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,12 @@ pub struct UnsignedChannelUpdate {
543543
pub timestamp: u32,
544544
/// Channel flags
545545
pub flags: u8,
546-
/// The number of blocks to subtract from incoming HTLC cltv_expiry values
546+
/// The number of blocks such that if:
547+
/// `htlc.cltv_expiry - current_block_height <= cltv_expiry_delta`
548+
/// then we need to fail the HTLC backwards. When forwarding an HTLC, cltv_expiry_delta is used to
549+
/// calculate the outgoing HTLC's cltv_expiry value -- so, if an incoming HTLC comes in with a
550+
/// cltv_expiry of 100000, and the node we're forwarding to has a cltv_expiry_delta value of 10,
551+
/// then we'll set the outgoing HTLC's cltv_expiry value to 100010.
547552
pub cltv_expiry_delta: u16,
548553
/// The minimum HTLC size incoming to sender, in milli-satoshi
549554
pub htlc_minimum_msat: u64,

0 commit comments

Comments
 (0)