From: Matt Corallo Date: Sun, 8 Jan 2023 06:00:47 +0000 (+0000) Subject: Add an `InboundUpdateFees` message X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=ef383da27e3bcdc10df464cea5527e31a2dd2ef1;p=rust-lightning Add an `InboundUpdateFees` message --- diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index 7a7cc4bb0..f951b79dc 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -602,6 +602,7 @@ mod tests { fn handle_update_fee(&self, _their_node_id: &PublicKey, _msg: &UpdateFee) {} fn handle_announcement_signatures(&self, _their_node_id: &PublicKey, _msg: &AnnouncementSignatures) {} fn handle_channel_update(&self, _their_node_id: &PublicKey, _msg: &ChannelUpdate) {} + fn handle_inbound_fees_update(&self, _their_node_id: &PublicKey, _msg: &InboundFeesUpdate) {} fn peer_disconnected(&self, their_node_id: &PublicKey, _no_connection_possible: bool) { if *their_node_id == self.expected_pubkey { self.disconnected_flag.store(true, Ordering::SeqCst); diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 1d1d3283f..e499576a3 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -5789,6 +5789,10 @@ where }); } + fn handle_inbound_fees_update(&self, counterparty_node_id: &PublicKey, msg: &msgs::InboundFeesUpdate) { + // TODO + } + fn handle_channel_reestablish(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReestablish) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier); let _ = handle_error!(self, self.internal_channel_reestablish(counterparty_node_id, msg), *counterparty_node_id); @@ -5834,6 +5838,7 @@ where &events::MessageSendEvent::BroadcastChannelAnnouncement { .. } => true, &events::MessageSendEvent::BroadcastChannelUpdate { .. } => true, &events::MessageSendEvent::SendChannelUpdate { ref node_id, .. } => node_id != counterparty_node_id, + &events::MessageSendEvent::SendInboundFeesUpdate { ref node_id, .. } => node_id != counterparty_node_id, &events::MessageSendEvent::HandleError { ref node_id, .. } => node_id != counterparty_node_id, &events::MessageSendEvent::SendChannelRangeQuery { .. } => false, &events::MessageSendEvent::SendShortIdsQuery { .. } => false, diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 1478f8b6b..6ee272453 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -676,6 +676,19 @@ pub struct ChannelUpdate { pub contents: UnsignedChannelUpdate, } +/// A request to the peer to update the inbound fees used when forwarding. Note that the peer may +/// continue to use the previous inbound fees (if they were lower) for some time to ensure HTLCs +/// which were in-flight when the change was done are not interrupted. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct InboundFeesUpdate { + /// The channel being updated + pub channel_id: [u8; 32], + /// The inbound fee to pay, in millionths of the payment amount. + pub inbound_forwarding_fee_proportional_millionths: i32, + /// The inbound fee to pay, as a static amount in millisatoshis. + pub inbound_forwarding_fee_base_msat: i32, +} + /// A query_channel_range message is used to query a peer for channel /// UTXOs in a range of blocks. The recipient of a query makes a best /// effort to reply to the query using one or more reply_channel_range @@ -850,6 +863,9 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider { /// Handle an incoming channel_ready message from the given peer. fn handle_channel_ready(&self, their_node_id: &PublicKey, msg: &ChannelReady); + /// Handle an incoming update_fee message from the given peer. + fn handle_inbound_fees_update(&self, their_node_id: &PublicKey, msg: &InboundFeesUpdate); + // Channl close: /// Handle an incoming shutdown message from the given peer. fn handle_shutdown(&self, their_node_id: &PublicKey, their_features: &InitFeatures, msg: &Shutdown); @@ -1648,6 +1664,12 @@ impl_writeable!(ChannelUpdate, { contents }); +impl_writeable!(InboundFeesUpdate, { + channel_id, + inbound_forwarding_fee_proportional_millionths, + inbound_forwarding_fee_base_msat +}); + impl Writeable for ErrorMessage { fn write(&self, w: &mut W) -> Result<(), io::Error> { self.channel_id.write(w)?; diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index d851d29d4..94cd18f06 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -221,6 +221,9 @@ impl ChannelMessageHandler for ErroringMessageHandler { fn handle_channel_reestablish(&self, their_node_id: &PublicKey, msg: &msgs::ChannelReestablish) { ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); } + fn handle_inbound_fees_update(&self, their_node_id: &PublicKey, msg: &msgs::InboundFeesUpdate) { + ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); + } // msgs::ChannelUpdate does not contain the channel_id field, so we just drop them. fn handle_channel_update(&self, _their_node_id: &PublicKey, _msg: &msgs::ChannelUpdate) {} fn peer_disconnected(&self, _their_node_id: &PublicKey, _no_connection_possible: bool) {} @@ -1363,6 +1366,10 @@ impl { + self.message_handler.chan_handler.handle_inbound_fees_update(&their_node_id, &msg); + }, + // Commitment messages: wire::Message::UpdateAddHTLC(msg) => { self.message_handler.chan_handler.handle_update_add_htlc(&their_node_id, &msg); @@ -1722,6 +1729,12 @@ impl { + log_trace!(self.logger, "Handling SendInboundFeesUpdate event in peer_handler for node {} for channel {}", + log_pubkey!(node_id), log_bytes!(msg.channel_id)); + self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg); + }, + MessageSendEvent::HandleError { ref node_id, ref action } => { match *action { msgs::ErrorAction::DisconnectPeer { ref msg } => { diff --git a/lightning/src/ln/wire.rs b/lightning/src/ln/wire.rs index deec15a51..b95bd0ee4 100644 --- a/lightning/src/ln/wire.rs +++ b/lightning/src/ln/wire.rs @@ -73,6 +73,7 @@ pub(crate) enum Message where T: core::fmt::Debug + Type + TestEq { ChannelAnnouncement(msgs::ChannelAnnouncement), NodeAnnouncement(msgs::NodeAnnouncement), ChannelUpdate(msgs::ChannelUpdate), + InboundFeesUpdate(msgs::InboundFeesUpdate), QueryShortChannelIds(msgs::QueryShortChannelIds), ReplyShortChannelIdsEnd(msgs::ReplyShortChannelIdsEnd), QueryChannelRange(msgs::QueryChannelRange), @@ -114,6 +115,7 @@ impl Message where T: core::fmt::Debug + Type + TestEq { &Message::ChannelAnnouncement(ref msg) => msg.type_id(), &Message::NodeAnnouncement(ref msg) => msg.type_id(), &Message::ChannelUpdate(ref msg) => msg.type_id(), + &Message::InboundFeesUpdate(ref msg) => msg.type_id(), &Message::QueryShortChannelIds(ref msg) => msg.type_id(), &Message::ReplyShortChannelIdsEnd(ref msg) => msg.type_id(), &Message::QueryChannelRange(ref msg) => msg.type_id(), @@ -226,6 +228,9 @@ fn do_read(buffer: &mut R, message_type: u1 msgs::ChannelUpdate::TYPE => { Ok(Message::ChannelUpdate(Readable::read(buffer)?)) }, + msgs::InboundFeesUpdate::TYPE => { + Ok(Message::InboundFeesUpdate(Readable::read(buffer)?)) + }, msgs::QueryShortChannelIds::TYPE => { Ok(Message::QueryShortChannelIds(Readable::read(buffer)?)) }, @@ -421,6 +426,10 @@ impl Encode for msgs::GossipTimestampFilter { const TYPE: u16 = 265; } +impl Encode for msgs::InboundFeesUpdate { + const TYPE: u16 = 34242; +} + #[cfg(test)] mod tests { use super::*; diff --git a/lightning/src/util/events.rs b/lightning/src/util/events.rs index 375174f6f..4b416db2b 100644 --- a/lightning/src/util/events.rs +++ b/lightning/src/util/events.rs @@ -1627,6 +1627,14 @@ pub enum MessageSendEvent { /// The channel_update which should be sent. msg: msgs::ChannelUpdate, }, + /// Used to indicate that an `inbound_fees_update` should be sent to a single peer. + SendInboundFeesUpdate { + /// The node_id of the node which should receive this message + node_id: PublicKey, + /// The inbound_fees_update which should be sent. + msg: msgs::InboundFeesUpdate, + }, + /// Broadcast an error downstream to be handled HandleError { /// The node_id of the node which should receive this message diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 5b101e345..f861250a8 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -384,6 +384,9 @@ impl msgs::ChannelMessageHandler for TestChannelMessageHandler { fn handle_channel_update(&self, _their_node_id: &PublicKey, _msg: &msgs::ChannelUpdate) { // Don't call `received_msg` here as `TestRoutingMessageHandler` generates these sometimes } + fn handle_inbound_fees_update(&self, _their_node_id: &PublicKey, msg: &msgs::InboundFeesUpdate) { + self.received_msg(wire::Message::InboundFeesUpdate(msg.clone())); + } fn handle_announcement_signatures(&self, _their_node_id: &PublicKey, msg: &msgs::AnnouncementSignatures) { self.received_msg(wire::Message::AnnouncementSignatures(msg.clone())); }