]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add an `InboundUpdateFees` message
authorMatt Corallo <git@bluematt.me>
Sun, 8 Jan 2023 06:00:47 +0000 (06:00 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 9 Jan 2023 03:45:52 +0000 (03:45 +0000)
lightning-net-tokio/src/lib.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/msgs.rs
lightning/src/ln/peer_handler.rs
lightning/src/ln/wire.rs
lightning/src/util/events.rs
lightning/src/util/test_utils.rs

index 7a7cc4bb0992f7589c6df480aa5cc1ff93b86007..f951b79dc19d63af6e5c13880e4bc42d3c59ff32 100644 (file)
@@ -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);
index 1d1d3283f98f2902a2816018ac768f3912947e65..e499576a3f8c6aa8c89abc1117cce541628b3598 100644 (file)
@@ -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,
index 1478f8b6bfb8272795dcd06d8272db926876a959..6ee272453f8d12b82db9ce49a047ec686fafaa03 100644 (file)
@@ -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<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
                self.channel_id.write(w)?;
index d851d29d46cd80e9d608fb951bc535e0c231649b..94cd18f068003354d5bd9755b36bb501333e7f85 100644 (file)
@@ -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<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                                self.message_handler.chan_handler.handle_closing_signed(&their_node_id, &msg);
                        },
 
+                       wire::Message::InboundFeesUpdate(msg) => {
+                               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<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                                                                log_pubkey!(node_id), msg.contents.short_channel_id);
                                                self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
                                        },
+                                       MessageSendEvent::SendInboundFeesUpdate { ref node_id, ref msg } => {
+                                               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 } => {
index deec15a51369e8c31907af564bb0b67453470b8f..b95bd0ee4d88e30a733b6fd98ae2a8db15270b56 100644 (file)
@@ -73,6 +73,7 @@ pub(crate) enum Message<T> 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<T> Message<T> 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<R: io::Read, T, H: core::ops::Deref>(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::*;
index 375174f6f6afa86c556c6804586adfa52020844a..4b416db2bdccfe2b5593c9eee6bc7b777b81b331 100644 (file)
@@ -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
index 5b101e345e22aa8e889f67a8e700c2155305a21b..f861250a83b478d82708a02bc3b760a70c0dec77 100644 (file)
@@ -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()));
        }