|
26 | 26 | use bitcoin::block::Header; |
27 | 27 | use bitcoin::hash_types::{BlockHash, Txid}; |
28 | 28 |
|
| 29 | +use bitcoin::secp256k1::PublicKey; |
| 30 | + |
29 | 31 | use crate::chain; |
30 | 32 | use crate::chain::chaininterface::{BroadcasterInterface, FeeEstimator}; |
31 | 33 | #[cfg(peer_storage)] |
@@ -57,7 +59,8 @@ use crate::util::persist::{KVStore, MonitorName, MonitorUpdatingPersisterAsync}; |
57 | 59 | #[cfg(peer_storage)] |
58 | 60 | use crate::util::ser::{VecWriter, Writeable}; |
59 | 61 | use crate::util::wakers::{Future, Notifier}; |
60 | | -use bitcoin::secp256k1::PublicKey; |
| 62 | + |
| 63 | +use alloc::sync::Arc; |
61 | 64 | #[cfg(peer_storage)] |
62 | 65 | use core::iter::Cycle; |
63 | 66 | use core::ops::Deref; |
@@ -267,6 +270,7 @@ pub struct AsyncPersister< |
267 | 270 | FE::Target: FeeEstimator, |
268 | 271 | { |
269 | 272 | persister: MonitorUpdatingPersisterAsync<K, S, L, ES, SP, BI, FE>, |
| 273 | + event_notifier: Arc<Notifier>, |
270 | 274 | } |
271 | 275 |
|
272 | 276 | impl< |
@@ -314,15 +318,17 @@ where |
314 | 318 | &self, monitor_name: MonitorName, |
315 | 319 | monitor: &ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>, |
316 | 320 | ) -> ChannelMonitorUpdateStatus { |
317 | | - self.persister.spawn_async_persist_new_channel(monitor_name, monitor); |
| 321 | + let notifier = Arc::clone(&self.event_notifier); |
| 322 | + self.persister.spawn_async_persist_new_channel(monitor_name, monitor, notifier); |
318 | 323 | ChannelMonitorUpdateStatus::InProgress |
319 | 324 | } |
320 | 325 |
|
321 | 326 | fn update_persisted_channel( |
322 | 327 | &self, monitor_name: MonitorName, monitor_update: Option<&ChannelMonitorUpdate>, |
323 | 328 | monitor: &ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>, |
324 | 329 | ) -> ChannelMonitorUpdateStatus { |
325 | | - self.persister.spawn_async_update_persisted_channel(monitor_name, monitor_update, monitor); |
| 330 | + let notifier = Arc::clone(&self.event_notifier); |
| 331 | + self.persister.spawn_async_update_channel(monitor_name, monitor_update, monitor, notifier); |
326 | 332 | ChannelMonitorUpdateStatus::InProgress |
327 | 333 | } |
328 | 334 |
|
@@ -382,7 +388,7 @@ pub struct ChainMonitor< |
382 | 388 |
|
383 | 389 | /// A [`Notifier`] used to wake up the background processor in case we have any [`Event`]s for |
384 | 390 | /// it to give to users (or [`MonitorEvent`]s for `ChannelManager` to process). |
385 | | - event_notifier: Notifier, |
| 391 | + event_notifier: Arc<Notifier>, |
386 | 392 |
|
387 | 393 | /// Messages to send to the peer. This is currently used to distribute PeerStorage to channel partners. |
388 | 394 | pending_send_only_events: Mutex<Vec<MessageSendEvent>>, |
@@ -430,17 +436,18 @@ impl< |
430 | 436 | persister: MonitorUpdatingPersisterAsync<K, S, L, ES, SP, T, F>, _entropy_source: ES, |
431 | 437 | _our_peerstorage_encryption_key: PeerStorageKey, |
432 | 438 | ) -> Self { |
| 439 | + let event_notifier = Arc::new(Notifier::new()); |
433 | 440 | Self { |
434 | 441 | monitors: RwLock::new(new_hash_map()), |
435 | 442 | chain_source, |
436 | 443 | broadcaster, |
437 | 444 | logger, |
438 | 445 | fee_estimator: feeest, |
439 | | - persister: AsyncPersister { persister }, |
440 | 446 | _entropy_source, |
441 | 447 | pending_monitor_events: Mutex::new(Vec::new()), |
442 | 448 | highest_chain_height: AtomicUsize::new(0), |
443 | | - event_notifier: Notifier::new(), |
| 449 | + event_notifier: Arc::clone(&event_notifier), |
| 450 | + persister: AsyncPersister { persister, event_notifier }, |
444 | 451 | pending_send_only_events: Mutex::new(Vec::new()), |
445 | 452 | #[cfg(peer_storage)] |
446 | 453 | our_peerstorage_encryption_key: _our_peerstorage_encryption_key, |
@@ -656,7 +663,7 @@ where |
656 | 663 | _entropy_source, |
657 | 664 | pending_monitor_events: Mutex::new(Vec::new()), |
658 | 665 | highest_chain_height: AtomicUsize::new(0), |
659 | | - event_notifier: Notifier::new(), |
| 666 | + event_notifier: Arc::new(Notifier::new()), |
660 | 667 | pending_send_only_events: Mutex::new(Vec::new()), |
661 | 668 | #[cfg(peer_storage)] |
662 | 669 | our_peerstorage_encryption_key: _our_peerstorage_encryption_key, |
|
0 commit comments