Skip to content

Commit 8c74a80

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. Co-authored-by: Valentine Wallace <[email protected]> Co-authored-by: Antoine Riard <[email protected]>
1 parent 2cb5b1a commit 8c74a80

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

lightning/src/ln/channel.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,16 @@ 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 to subtract from incoming HTLC cltv_expiry values.
291+
pub cltv_expiry_delta: u16,
292+
}
293+
284294
// TODO: We should refactor this to be an Inbound/OutboundChannel until initial setup handshaking
285295
// has been completed, and then turn into a Channel to get compiler-time enforcement of things like
286296
// calling channel_id() before we're set up or things like get_outbound_funding_signed on an
@@ -391,6 +401,8 @@ pub(super) struct Channel<Signer: Sign> {
391401
//implied by OUR_MAX_HTLCS: max_accepted_htlcs: u16,
392402
minimum_depth: u32,
393403

404+
counterparty_forwarding_info: Option<CounterpartyForwardingInfo>,
405+
394406
pub(crate) channel_transaction_parameters: ChannelTransactionParameters,
395407

396408
counterparty_cur_commitment_point: Option<PublicKey>,
@@ -577,6 +589,8 @@ impl<Signer: Sign> Channel<Signer> {
577589
counterparty_max_accepted_htlcs: 0,
578590
minimum_depth: 0, // Filled in in accept_channel
579591

592+
counterparty_forwarding_info: None,
593+
580594
channel_transaction_parameters: ChannelTransactionParameters {
581595
holder_pubkeys: pubkeys,
582596
holder_selected_contest_delay: config.own_channel_config.our_to_self_delay,
@@ -813,6 +827,8 @@ impl<Signer: Sign> Channel<Signer> {
813827
counterparty_max_accepted_htlcs: msg.max_accepted_htlcs,
814828
minimum_depth: config.own_channel_config.minimum_depth,
815829

830+
counterparty_forwarding_info: None,
831+
816832
channel_transaction_parameters: ChannelTransactionParameters {
817833
holder_pubkeys: pubkeys,
818834
holder_selected_contest_delay: config.own_channel_config.our_to_self_delay,
@@ -4437,6 +4453,16 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
44374453
self.counterparty_max_accepted_htlcs.write(writer)?;
44384454
self.minimum_depth.write(writer)?;
44394455

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

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

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

@@ -4667,6 +4703,8 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
46674703
counterparty_max_accepted_htlcs,
46684704
minimum_depth,
46694705

4706+
counterparty_forwarding_info,
4707+
46704708
channel_transaction_parameters: channel_parameters,
46714709
counterparty_cur_commitment_point,
46724710

0 commit comments

Comments
 (0)