]> git.bitcoin.ninja Git - rust-lightning/commitdiff
-f address lastest Matt's comments
authorAntoine Riard <dev@ariard.me>
Mon, 20 Sep 2021 23:51:46 +0000 (19:51 -0400)
committerAntoine Riard <dev@ariard.me>
Mon, 20 Sep 2021 23:51:46 +0000 (19:51 -0400)
lightning/src/ln/channelmanager.rs
lightning/src/util/events.rs

index 1e6a865e2d2a9faa9dc3708578c5b47c36bb1cf8..6ab97c2420e0fd1bab7da472de68ff4d27ff684a 100644 (file)
@@ -242,7 +242,7 @@ type ShutdownResult = (Option<(OutPoint, ChannelMonitorUpdate)>, Vec<(HTLCSource
 
 struct MsgHandleErrInternal {
        err: msgs::LightningError,
-       chan_id: Option<[u8; 32]>,
+       chan_id: Option<[u8; 32]>, // If Some a channel of ours has been closed
        shutdown_finish: Option<(ShutdownResult, Option<msgs::ChannelUpdate>)>,
 }
 impl MsgHandleErrInternal {
@@ -1372,6 +1372,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
                                                                msg: channel_update
                                                        });
                                                }
+                                               if let Ok(mut pending_events_lock) = self.pending_events.lock() {
+                                                       pending_events_lock.push(events::Event::ChannelClosed {
+                                                               channel_id: *channel_id,
+                                                               reason: ClosureReason::HolderForceClosed
+                                                       });
+                                               }
                                        }
                                        break Ok(());
                                },
@@ -4093,6 +4099,13 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
                                                                });
                                                        }
 
+                                                       if let Ok(mut pending_events_lock) = self.pending_events.lock() {
+                                                               pending_events_lock.push(events::Event::ChannelClosed {
+                                                                       channel_id: *channel_id,
+                                                                       reason: ClosureReason::HolderForceClosed
+                                                               });
+                                                       }
+
                                                        log_info!(self.logger, "Broadcasting {}", log_tx!(tx));
                                                        self.tx_broadcaster.broadcast_transaction(&tx);
                                                        false
@@ -5316,6 +5329,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
                let mut funding_txo_set = HashSet::with_capacity(cmp::min(channel_count as usize, 128));
                let mut by_id = HashMap::with_capacity(cmp::min(channel_count as usize, 128));
                let mut short_to_id = HashMap::with_capacity(cmp::min(channel_count as usize, 128));
+               let mut channel_closures = Vec::new();
                for _ in 0..channel_count {
                        let mut channel: Channel<Signer> = Channel::read(reader, &args.keys_manager)?;
                        let funding_txo = channel.get_funding_txo().ok_or(DecodeError::InvalidValue)?;
@@ -5346,6 +5360,10 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
                                        let (_, mut new_failed_htlcs) = channel.force_shutdown(true);
                                        failed_htlcs.append(&mut new_failed_htlcs);
                                        monitor.broadcast_latest_holder_commitment_txn(&args.tx_broadcaster, &args.logger);
+                                       channel_closures.push(events::Event::ChannelClosed {
+                                               channel_id: channel.channel_id(),
+                                               reason: ClosureReason::OutdatedChanMan
+                                       });
                                } else {
                                        if let Some(short_channel_id) = channel.get_short_channel_id() {
                                                short_to_id.insert(short_channel_id, channel.channel_id());
@@ -5453,6 +5471,10 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
                let mut secp_ctx = Secp256k1::new();
                secp_ctx.seeded_randomize(&args.keys_manager.get_secure_random_bytes());
 
+               if !channel_closures.is_empty() {
+                       pending_events_read.append(&mut channel_closures);
+               }
+
                let channel_manager = ChannelManager {
                        genesis_hash,
                        fee_estimator: args.fee_estimator,
index 5a91758d87fd04600526aa8459536c2c3661ed31..691d30a846efb251b5ef75344d143d0de517c94b 100644 (file)
@@ -73,12 +73,15 @@ pub enum PaymentPurpose {
 /// The reason which the channel was closed. See individual variants more details.
 pub enum ClosureReason {
        /// Closure generated from receiving a peer error message.
+       ///
+       /// Our counterparty may have broadcasted their latest commitment state, and we have
+       /// as well
        CounterpartyForceClosed {
                /// The error which the peer sent us.
                ///
                /// The string should be sanitized before it is used (e.g emitted to logs
-               /// or printed to stdout). Otherwise, a well crafted error message may trigger
-               /// a security in the terminal emulator or the logging subsystem.
+               /// or printed to stdout). Otherwise, a well crafted error message may exploit
+               /// a security vulnerability in the terminal emulator or the logging subsystem.
                peer_msg: String,
        },
        /// Closure generated from [`ChannelManager::force_close_channel`], called by the user.
@@ -96,9 +99,11 @@ pub enum ClosureReason {
                err: String,
        },
        /// The `PeerManager` informed us that we've disconnected from the peer and that it is
-       /// unlikely we'll be able to connect to the peer, most likely because we have incompatible
-       /// features and the peer, or we, require features which we, or the peer, do not support.
+       /// unlikely we'll be able to connect to the peer.
        DisconnectedPeer,
+       /// Closure generated from [`ChannelManager::read`] if the ChannelMonitor is newer than
+       /// the ChannelManager deserialized.
+       OutdatedChanMan
 }
 
 impl_writeable_tlv_based_enum_upgradable!(ClosureReason,
@@ -108,6 +113,7 @@ impl_writeable_tlv_based_enum_upgradable!(ClosureReason,
        (4, CooperativeClosure) => {},
        (8, ProcessingError) => { (1, err, required) },
        (10, DisconnectedPeer) => {},
+       (12, OutdatedChanMan) => {},
 );
 
 /// An Event which you should probably take some action in response to.