]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Make `ChannelManager::issue_channel_close_events` take a `ChannelContext`
authorDuncan Dean <git@dunxen.dev>
Tue, 13 Jun 2023 14:43:43 +0000 (16:43 +0200)
committerDuncan Dean <git@dunxen.dev>
Wed, 14 Jun 2023 14:04:28 +0000 (16:04 +0200)
lightning/src/ln/channel.rs
lightning/src/ln/channelmanager.rs

index a9e7ffab4eb8719c0e6096a0ee98630747242ecb..1e37335a86f6b48a30f8d5582b14d0ab4a6d3d28 100644 (file)
@@ -1786,6 +1786,15 @@ impl<Signer: ChannelSigner> ChannelContext<Signer> {
                }
                res
        }
+
+       /// Returns transaction if there is pending funding transaction that is yet to broadcast
+       pub fn unbroadcasted_funding(&self) -> Option<Transaction> {
+               if self.channel_state & (ChannelState::FundingCreated as u32) != 0 {
+                       self.funding_transaction.clone()
+               } else {
+                       None
+               }
+       }
 }
 
 // Internal utility functions for channels
@@ -3350,15 +3359,6 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
                Ok(self.get_announcement_sigs(node_signer, genesis_block_hash, user_config, best_block.height(), logger))
        }
 
-       /// Returns transaction if there is pending funding transaction that is yet to broadcast
-       pub fn unbroadcasted_funding(&self) -> Option<Transaction> {
-               if self.context.channel_state & (ChannelState::FundingCreated as u32) != 0 {
-                       self.context.funding_transaction.clone()
-               } else {
-                       None
-               }
-       }
-
        pub fn update_add_htlc<F, L: Deref>(&mut self, msg: &msgs::UpdateAddHTLC, mut pending_forward_status: PendingHTLCStatus, create_pending_htlc_status: F, logger: &L) -> Result<(), ChannelError>
        where F: for<'a> Fn(&'a Self, PendingHTLCStatus, u16) -> PendingHTLCStatus, L::Target: Logger {
                // We can't accept HTLCs sent after we've sent a shutdown.
index d427e35cc526cd7078cf6df9ee2cc69c42a34eef..49ebf6fe1440baee1bce020cee3feb2170cacd4c 100644 (file)
@@ -2166,19 +2166,19 @@ where
        }
 
        /// Helper function that issues the channel close events
-       fn issue_channel_close_events(&self, channel: &Channel<<SP::Target as SignerProvider>::Signer>, closure_reason: ClosureReason) {
+       fn issue_channel_close_events(&self, context: &ChannelContext<<SP::Target as SignerProvider>::Signer>, closure_reason: ClosureReason) {
                let mut pending_events_lock = self.pending_events.lock().unwrap();
-               match channel.unbroadcasted_funding() {
+               match context.unbroadcasted_funding() {
                        Some(transaction) => {
                                pending_events_lock.push_back((events::Event::DiscardFunding {
-                                       channel_id: channel.context.channel_id(), transaction
+                                       channel_id: context.channel_id(), transaction
                                }, None));
                        },
                        None => {},
                }
                pending_events_lock.push_back((events::Event::ChannelClosed {
-                       channel_id: channel.context.channel_id(),
-                       user_channel_id: channel.context.get_user_id(),
+                       channel_id: context.channel_id(),
+                       user_channel_id: context.get_user_id(),
                        reason: closure_reason
                }, None));
        }
@@ -2225,7 +2225,7 @@ where
                                                                msg: channel_update
                                                        });
                                                }
-                                               self.issue_channel_close_events(&channel, ClosureReason::HolderForceClosed);
+                                               self.issue_channel_close_events(&channel.context, ClosureReason::HolderForceClosed);
                                        }
                                        break Ok(());
                                },
@@ -2335,9 +2335,9 @@ where
                        let peer_state = &mut *peer_state_lock;
                        if let hash_map::Entry::Occupied(chan) = peer_state.channel_by_id.entry(channel_id.clone()) {
                                if let Some(peer_msg) = peer_msg {
-                                       self.issue_channel_close_events(chan.get(),ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString(peer_msg.to_string()) });
+                                       self.issue_channel_close_events(&chan.get().context, ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString(peer_msg.to_string()) });
                                } else {
-                                       self.issue_channel_close_events(chan.get(),ClosureReason::HolderForceClosed);
+                                       self.issue_channel_close_events(&chan.get().context, ClosureReason::HolderForceClosed);
                                }
                                remove_channel!(self, chan)
                        } else {
@@ -5212,7 +5212,7 @@ where
                                        msg: update
                                });
                        }
-                       self.issue_channel_close_events(&chan, ClosureReason::CooperativeClosure);
+                       self.issue_channel_close_events(&chan.context, ClosureReason::CooperativeClosure);
                }
                Ok(())
        }
@@ -5697,7 +5697,7 @@ where
                                                                        } else {
                                                                                ClosureReason::CommitmentTxConfirmed
                                                                        };
-                                                                       self.issue_channel_close_events(&chan, reason);
+                                                                       self.issue_channel_close_events(&chan.context, reason);
                                                                        pending_msg_events.push(events::MessageSendEvent::HandleError {
                                                                                node_id: chan.context.get_counterparty_node_id(),
                                                                                action: msgs::ErrorAction::SendErrorMessage {
@@ -5822,7 +5822,7 @@ where
                                                                        });
                                                                }
 
-                                                               self.issue_channel_close_events(chan, ClosureReason::CooperativeClosure);
+                                                               self.issue_channel_close_events(&chan.context, ClosureReason::CooperativeClosure);
 
                                                                log_info!(self.logger, "Broadcasting {}", log_tx!(tx));
                                                                self.tx_broadcaster.broadcast_transactions(&[&tx]);
@@ -6540,7 +6540,7 @@ where
                                                        });
                                                }
                                                let reason_message = format!("{}", reason);
-                                               self.issue_channel_close_events(channel, reason);
+                                               self.issue_channel_close_events(&channel.context, reason);
                                                pending_msg_events.push(events::MessageSendEvent::HandleError {
                                                        node_id: channel.context.get_counterparty_node_id(),
                                                        action: msgs::ErrorAction::SendErrorMessage { msg: msgs::ErrorMessage {
@@ -6791,7 +6791,7 @@ where
                                        chan.remove_uncommitted_htlcs_and_mark_paused(&self.logger);
                                        if chan.is_shutdown() {
                                                update_maps_on_chan_removal!(self, chan);
-                                               self.issue_channel_close_events(chan, ClosureReason::DisconnectedPeer);
+                                               self.issue_channel_close_events(&chan.context, ClosureReason::DisconnectedPeer);
                                                return false;
                                        }
                                        true