Skip to content

Commit 53bcbb1

Browse files
committed
Switch to the new highly-parallel ChannelMonitor reader
Upstream LDK added the ability to read `ChannelMonitor`s from storage in parallel, which we switch to here.
1 parent 2e844be commit 53bcbb1

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/builder.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use crate::connection::ConnectionManager;
5151
use crate::entropy::NodeEntropy;
5252
use crate::event::EventQueue;
5353
use crate::fee_estimator::OnchainFeeEstimator;
54-
use crate::gossip::GossipSource;
54+
use crate::gossip::{GossipSource, RuntimeSpawner};
5555
use crate::io::sqlite_store::SqliteStore;
5656
use crate::io::utils::{
5757
read_event_queue, read_external_pathfinding_scores_from_cache, read_network_graph,
@@ -72,8 +72,9 @@ use crate::peer_store::PeerStore;
7272
use crate::runtime::Runtime;
7373
use crate::tx_broadcaster::TransactionBroadcaster;
7474
use crate::types::{
75-
ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph, KeysManager,
76-
MessageRouter, OnionMessenger, PaymentStore, PeerManager, Persister, SyncAndAsyncKVStore,
75+
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph,
76+
KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager, Persister,
77+
SyncAndAsyncKVStore,
7778
};
7879
use crate::wallet::persist::KVStoreWalletPersister;
7980
use crate::wallet::Wallet;
@@ -1261,8 +1262,9 @@ fn build_with_store_internal(
12611262
));
12621263

12631264
let peer_storage_key = keys_manager.get_peer_storage_key();
1264-
let persister = Arc::new(Persister::new(
1265+
let monitor_reader = Arc::new(AsyncPersister::new(
12651266
Arc::clone(&kv_store),
1267+
RuntimeSpawner::new(Arc::clone(&runtime)),
12661268
Arc::clone(&logger),
12671269
PERSISTER_MAX_PENDING_UPDATES,
12681270
Arc::clone(&keys_manager),
@@ -1272,7 +1274,9 @@ fn build_with_store_internal(
12721274
));
12731275

12741276
// Read ChannelMonitor state from store
1275-
let channel_monitors = match persister.read_all_channel_monitors_with_updates() {
1277+
let monitor_read_result =
1278+
runtime.block_on(monitor_reader.read_all_channel_monitors_with_updates_parallel());
1279+
let channel_monitors = match monitor_read_result {
12761280
Ok(monitors) => monitors,
12771281
Err(e) => {
12781282
if e.kind() == lightning::io::ErrorKind::NotFound {
@@ -1284,6 +1288,16 @@ fn build_with_store_internal(
12841288
},
12851289
};
12861290

1291+
let persister = Arc::new(Persister::new(
1292+
Arc::clone(&kv_store),
1293+
Arc::clone(&logger),
1294+
PERSISTER_MAX_PENDING_UPDATES,
1295+
Arc::clone(&keys_manager),
1296+
Arc::clone(&keys_manager),
1297+
Arc::clone(&tx_broadcaster),
1298+
Arc::clone(&fee_estimator),
1299+
));
1300+
12871301
// Initialize the ChainMonitor
12881302
let chain_monitor: Arc<ChainMonitor> = Arc::new(chainmonitor::ChainMonitor::new(
12891303
Some(Arc::clone(&chain_source)),

src/types.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ use lightning::routing::gossip;
2323
use lightning::routing::router::DefaultRouter;
2424
use lightning::routing::scoring::{CombinedScorer, ProbabilisticScoringFeeParameters};
2525
use lightning::sign::InMemorySigner;
26-
use lightning::util::persist::{KVStore, KVStoreSync, MonitorUpdatingPersister};
26+
use lightning::util::persist::{
27+
KVStore, KVStoreSync, MonitorUpdatingPersister, MonitorUpdatingPersisterAsync,
28+
};
2729
use lightning::util::ser::{Readable, Writeable, Writer};
2830
use lightning::util::sweep::OutputSweeper;
2931
use lightning_block_sync::gossip::GossipVerifier;
@@ -185,6 +187,16 @@ impl<T: SyncAndAsyncKVStore + Send + Sync> DynStoreTrait for DynStoreWrapper<T>
185187
}
186188
}
187189

190+
pub(crate) type AsyncPersister = MonitorUpdatingPersisterAsync<
191+
Arc<DynStore>,
192+
RuntimeSpawner,
193+
Arc<Logger>,
194+
Arc<KeysManager>,
195+
Arc<KeysManager>,
196+
Arc<Broadcaster>,
197+
Arc<OnchainFeeEstimator>,
198+
>;
199+
188200
pub type Persister = MonitorUpdatingPersister<
189201
Arc<DynStore>,
190202
Arc<Logger>,

0 commit comments

Comments
 (0)