@@ -50,18 +50,20 @@ use crate::config::{
5050 default_user_config, may_announce_channel, AnnounceError , AsyncPaymentsRole ,
5151 BitcoindRestClientConfig , Config , ElectrumSyncConfig , EsploraSyncConfig , HRNResolverConfig ,
5252 TorConfig , DEFAULT_ESPLORA_SERVER_URL , DEFAULT_LOG_FILENAME , DEFAULT_LOG_LEVEL ,
53- DEFAULT_MAX_PROBE_AMOUNT_MSAT , DEFAULT_MIN_PROBE_AMOUNT_MSAT ,
53+ DEFAULT_MAX_PROBE_AMOUNT_MSAT , DEFAULT_MIN_PROBE_AMOUNT_MSAT , PAYMENT_CACHE_CAPACITY ,
54+ PAYMENT_CACHE_WARMUP_COUNT ,
5455} ;
5556use crate :: connection:: ConnectionManager ;
57+ use crate :: data_store:: { KeepAllEntries , KeepLeastRecentlyUsed } ;
5658use crate :: entropy:: NodeEntropy ;
5759use crate :: event:: EventQueue ;
5860use crate :: fee_estimator:: OnchainFeeEstimator ;
5961use crate :: gossip:: GossipSource ;
6062use crate :: io:: sqlite_store:: SqliteStore ;
6163use crate :: io:: utils:: {
6264 open_or_migrate_fs_store, read_all_objects, read_event_queue,
63- read_external_pathfinding_scores_from_cache, read_network_graph , read_node_metrics ,
64- read_output_sweeper, read_peer_info, read_scorer,
65+ read_external_pathfinding_scores_from_cache, read_n_objects , read_network_graph ,
66+ read_node_metrics , read_output_sweeper, read_peer_info, read_scorer,
6567} ;
6668use crate :: io:: vss_store:: VssStoreBuilder ;
6769use crate :: io:: {
@@ -1458,10 +1460,11 @@ fn build_with_store_internal(
14581460 let ( payment_store_res, node_metris_res, pending_payment_store_res, address_pool_res) = runtime
14591461 . block_on ( async move {
14601462 tokio:: join!(
1461- read_all_objects (
1463+ read_n_objects (
14621464 & * kv_store_ref,
14631465 PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE ,
14641466 PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE ,
1467+ PAYMENT_CACHE_WARMUP_COUNT ,
14651468 Arc :: clone( & logger_ref) ,
14661469 ) ,
14671470 read_node_metrics( & * kv_store_ref, Arc :: clone( & logger_ref) ) ,
@@ -1490,7 +1493,11 @@ fn build_with_store_internal(
14901493
14911494 let payment_store = match payment_store_res {
14921495 Ok ( payments) => Arc :: new ( PaymentStore :: new (
1493- payments,
1496+ // The read hands us the newest payments first, while the cache treats the objects it
1497+ // is seeded with as increasingly recently used. Reverse them, so that the newest
1498+ // payment is the last one to be evicted rather than the first.
1499+ payments. into_iter ( ) . rev ( ) . collect ( ) ,
1500+ KeepLeastRecentlyUsed :: new ( PAYMENT_CACHE_CAPACITY ) ,
14941501 PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE . to_string ( ) ,
14951502 PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE . to_string ( ) ,
14961503 Arc :: clone ( & kv_store) ,
@@ -1745,8 +1752,12 @@ fn build_with_store_internal(
17451752 } ;
17461753
17471754 let pending_payment_store = match pending_payment_store_res {
1755+ // NOTE: This store must keep all its entries in memory: the wallet scans it in full on
1756+ // every chain tip change and to resolve replaced transactions. It stays bounded anyway,
1757+ // as entries are removed once a payment is no longer pending.
17481758 Ok ( pending_payments) => Arc :: new ( PendingPaymentStore :: new (
17491759 pending_payments,
1760+ KeepAllEntries ,
17501761 PENDING_PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE . to_string ( ) ,
17511762 PENDING_PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE . to_string ( ) ,
17521763 Arc :: clone ( & kv_store) ,
0 commit comments