From 9fb5f81c9b4673036ac0b5362a92f98b24a61aac Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 9 Jan 2023 00:45:11 +0000 Subject: [PATCH] Send peers an `inbound_fee_update` message when updating fees --- lightning/src/ln/channelmanager.rs | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 7be1fe43f..1e0010ebf 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -2682,6 +2682,9 @@ where for channel_id in channel_ids { let channel = channel_state.by_id.get_mut(channel_id).unwrap(); + let prev_inbound_fees = (channel.config().inbound_forwarding_fee_base_msat, + channel.config().inbound_forwarding_fee_proportional_millionths); + //XXX : do this in the same per_peer_state lock post-#1507 let per_peer_state = self.per_peer_state.read().unwrap(); if let Some(peer_state) = per_peer_state.get(counterparty_node_id) { @@ -2689,6 +2692,7 @@ where continue; } } else { return Err(APIError::APIMisuseError { err: format!("XXX: DROP THIS CODE") }); } + if let Ok(msg) = self.get_channel_update_for_broadcast(channel) { channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate { msg }); } else if let Ok(msg) = self.get_channel_update_for_unicast(channel) { @@ -2697,6 +2701,20 @@ where msg, }); } + let new_inbound_fees = (channel.config().inbound_forwarding_fee_base_msat, + channel.config().inbound_forwarding_fee_proportional_millionths); + if prev_inbound_fees != new_inbound_fees { + log_trace!(self.logger, "Inbound fees have changed, notifying peer"); + let msg = msgs::InboundFeesUpdate { + channel_id: channel.channel_id(), + inbound_forwarding_fee_base_msat: new_inbound_fees.0, + inbound_forwarding_fee_proportional_millionths: new_inbound_fees.1, + }; + channel_state.pending_msg_events.push(events::MessageSendEvent::SendInboundFeesUpdate { + node_id: channel.get_counterparty_node_id(), + msg, + }); + } } } Ok(()) @@ -4809,6 +4827,32 @@ where msg, }); } + let mut chan_config = chan.get().config(); + if chan_config.inbound_forwarding_fee_base_msat != 0 || + chan_config.inbound_forwarding_fee_proportional_millionths != 0 + { + // Similarly, if we expect our counterparty to provide inbound fees, we + // should retransmit our inbound fees update. + // Note that the message is even, so we have to check that our + // counterparty currently supports inbound fees or they will disconnect + // us. If they do not, we reset the config knobs back to zero. + let per_peer_state = self.per_peer_state.read().unwrap(); // XXX: Post-1507 this should go away. + if per_peer_state.get(counterparty_node_id).unwrap().lock().unwrap().latest_features.supports_inbound_fees() { // XXX: The unwrap here too + let msg = msgs::InboundFeesUpdate { + channel_id: chan.get().channel_id(), + inbound_forwarding_fee_base_msat: chan_config.inbound_forwarding_fee_base_msat, + inbound_forwarding_fee_proportional_millionths: chan_config.inbound_forwarding_fee_proportional_millionths, + }; + channel_state.pending_msg_events.push(events::MessageSendEvent::SendInboundFeesUpdate { + node_id: chan.get().get_counterparty_node_id(), + msg, + }); + } else { + chan_config.inbound_forwarding_fee_base_msat = 0; + chan_config.inbound_forwarding_fee_proportional_millionths = 0; + chan.get_mut().update_config(&per_peer_state.get(counterparty_node_id).unwrap().lock().unwrap().latest_features, chan_config); // XXX: Post 1507 this should be cleaner + } + } } let need_lnd_workaround = chan.get_mut().workaround_lnd_bug_4006.take(); htlc_forwards = self.handle_channel_resumption( -- 2.39.5