Merge pull request #3039 from valentinewallace/2024-04-invoice-amt-msats-overflow
[rust-lightning] / lightning / src / chain / chainmonitor.rs
index 06052dc84de52dd3d7257e55ec0aa4bed5ccc9e2..257f1d0f30bc1db9840b0e2f2da55aa686beef08 100644 (file)
@@ -31,11 +31,10 @@ use crate::chain::{ChannelMonitorUpdateStatus, Filter, WatchedOutput};
 use crate::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
 use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, Balance, MonitorEvent, TransactionOutputs, WithChannelMonitor};
 use crate::chain::transaction::{OutPoint, TransactionData};
-use crate::ln::ChannelId;
+use crate::ln::types::ChannelId;
 use crate::sign::ecdsa::WriteableEcdsaChannelSigner;
 use crate::events;
 use crate::events::{Event, EventHandler};
-use crate::util::atomic_counter::AtomicCounter;
 use crate::util::logger::{Logger, WithContext};
 use crate::util::errors::APIError;
 use crate::util::wakers::{Future, Notifier};
@@ -221,10 +220,6 @@ pub struct ChainMonitor<ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T:
         P::Target: Persist<ChannelSigner>,
 {
        monitors: RwLock<HashMap<OutPoint, MonitorHolder<ChannelSigner>>>,
-       /// When we generate a monitor update for a chain-event monitor persistence, we need a
-       /// unique ID, which we calculate by simply getting the next value from this counter. Note that
-       /// the ID is never persisted so it's ok that they reset on restart.
-       sync_persistence_id: AtomicCounter,
        chain_source: Option<C>,
        broadcaster: T,
        logger: L,
@@ -236,6 +231,8 @@ pub struct ChainMonitor<ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T:
        /// The best block height seen, used as a proxy for the passage of time.
        highest_chain_height: AtomicUsize,
 
+       /// A [`Notifier`] used to wake up the background processor in case we have any [`Event`]s for
+       /// it to give to users (or [`MonitorEvent`]s for `ChannelManager` to process).
        event_notifier: Notifier,
 }
 
@@ -353,7 +350,6 @@ where C::Target: chain::Filter,
        pub fn new(chain_source: Option<C>, broadcaster: T, logger: L, feeest: F, persister: P) -> Self {
                Self {
                        monitors: RwLock::new(new_hash_map()),
-                       sync_persistence_id: AtomicCounter::new(),
                        chain_source,
                        broadcaster,
                        logger,
@@ -642,6 +638,8 @@ where
                        monitor.block_connected(
                                header, txdata, height, &*self.broadcaster, &*self.fee_estimator, &self.logger)
                });
+               // Assume we may have some new events and wake the event processor
+               self.event_notifier.notify();
        }
 
        fn block_disconnected(&self, header: &Header, height: u32) {
@@ -669,6 +667,8 @@ where
                        monitor.transactions_confirmed(
                                header, txdata, height, &*self.broadcaster, &*self.fee_estimator, &self.logger)
                });
+               // Assume we may have some new events and wake the event processor
+               self.event_notifier.notify();
        }
 
        fn transaction_unconfirmed(&self, txid: &Txid) {
@@ -689,6 +689,8 @@ where
                                header, height, &*self.broadcaster, &*self.fee_estimator, &self.logger
                        )
                });
+               // Assume we may have some new events and wake the event processor
+               self.event_notifier.notify();
        }
 
        fn get_relevant_txids(&self) -> Vec<(Txid, u32, Option<BlockHash>)> {