@@ -54,7 +54,7 @@ use crate::config::{
5454 PAYMENT_CACHE_WARMUP_COUNT ,
5555} ;
5656use crate :: connection:: ConnectionManager ;
57- use crate :: data_store:: { KeepAllEntries , KeepLeastRecentlyUsed } ;
57+ use crate :: data_store:: { KeepAllEntries , KeepLeastRecentlyUsed , KeepNoEntries } ;
5858use crate :: entropy:: NodeEntropy ;
5959use crate :: event:: EventQueue ;
6060use crate :: fee_estimator:: OnchainFeeEstimator ;
@@ -67,7 +67,11 @@ use crate::io::utils::{
6767} ;
6868use crate :: io:: vss_store:: VssStoreBuilder ;
6969use crate :: io:: {
70- self , PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE , PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE ,
70+ self , CHANNEL_FORWARDING_STATS_PERSISTENCE_SECONDARY_NAMESPACE ,
71+ CHANNEL_PAIR_FORWARDING_STATS_PERSISTENCE_SECONDARY_NAMESPACE ,
72+ FORWARDED_PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE ,
73+ FORWARDED_PAYMENT_PERSISTENCE_PRIMARY_NAMESPACE , PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE ,
74+ PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE ,
7175 PENDING_PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE ,
7276 PENDING_PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE ,
7377} ;
@@ -84,7 +88,8 @@ use crate::probing::{
8488use crate :: runtime:: { Runtime , RuntimeSpawner } ;
8589use crate :: tx_broadcaster:: TransactionBroadcaster ;
8690use crate :: types:: {
87- AsyncPersister , ChainMonitor , ChannelManager , DynStore , DynStoreRef , DynStoreWrapper ,
91+ AsyncPersister , ChainMonitor , ChannelForwardingStatsStore , ChannelManager ,
92+ ChannelPairForwardingStatsStore , DynStore , DynStoreRef , DynStoreWrapper , ForwardedPaymentStore ,
8893 GossipSync , Graph , HRNResolver , KeysManager , MessageRouter , OnionMessenger , PaymentStore ,
8994 PeerManager , PendingPaymentStore ,
9095} ;
@@ -1457,26 +1462,37 @@ fn build_with_store_internal(
14571462
14581463 let kv_store_ref = Arc :: clone ( & kv_store) ;
14591464 let logger_ref = Arc :: clone ( & logger) ;
1460- let ( payment_store_res, node_metris_res, pending_payment_store_res, address_pool_res) = runtime
1461- . block_on ( async move {
1462- tokio:: join!(
1463- read_n_objects(
1464- & * kv_store_ref,
1465- PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE ,
1466- PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE ,
1467- PAYMENT_CACHE_WARMUP_COUNT ,
1468- Arc :: clone( & logger_ref) ,
1469- ) ,
1470- read_node_metrics( & * kv_store_ref, Arc :: clone( & logger_ref) ) ,
1471- read_all_objects(
1472- & * kv_store_ref,
1473- PENDING_PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE ,
1474- PENDING_PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE ,
1475- Arc :: clone( & logger_ref) ,
1476- ) ,
1477- read_address_pool( & * kv_store_ref, & * logger_ref)
1478- )
1479- } ) ;
1465+ let (
1466+ payment_store_res,
1467+ channel_forwarding_stats_res,
1468+ node_metris_res,
1469+ pending_payment_store_res,
1470+ address_pool_res,
1471+ ) = runtime. block_on ( async move {
1472+ tokio:: join!(
1473+ read_n_objects(
1474+ & * kv_store_ref,
1475+ PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE ,
1476+ PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE ,
1477+ PAYMENT_CACHE_WARMUP_COUNT ,
1478+ Arc :: clone( & logger_ref) ,
1479+ ) ,
1480+ read_all_objects(
1481+ & * kv_store_ref,
1482+ FORWARDED_PAYMENT_PERSISTENCE_PRIMARY_NAMESPACE ,
1483+ CHANNEL_FORWARDING_STATS_PERSISTENCE_SECONDARY_NAMESPACE ,
1484+ Arc :: clone( & logger_ref) ,
1485+ ) ,
1486+ read_node_metrics( & * kv_store_ref, Arc :: clone( & logger_ref) ) ,
1487+ read_all_objects(
1488+ & * kv_store_ref,
1489+ PENDING_PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE ,
1490+ PENDING_PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE ,
1491+ Arc :: clone( & logger_ref) ,
1492+ ) ,
1493+ read_address_pool( & * kv_store_ref, & * logger_ref) ,
1494+ )
1495+ } ) ;
14801496
14811497 // Initialize the status fields.
14821498 let node_metrics = match node_metris_res {
@@ -1509,6 +1525,39 @@ fn build_with_store_internal(
15091525 } ,
15101526 } ;
15111527
1528+ let forwarded_payment_store = Arc :: new ( ForwardedPaymentStore :: new (
1529+ Vec :: new ( ) ,
1530+ KeepNoEntries ,
1531+ FORWARDED_PAYMENT_PERSISTENCE_PRIMARY_NAMESPACE . to_string ( ) ,
1532+ FORWARDED_PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE . to_string ( ) ,
1533+ Arc :: clone ( & kv_store) ,
1534+ Arc :: clone ( & logger) ,
1535+ ) ) ;
1536+
1537+ let channel_forwarding_stats_store = match channel_forwarding_stats_res {
1538+ Ok ( stats) => Arc :: new ( ChannelForwardingStatsStore :: new (
1539+ stats,
1540+ KeepAllEntries ,
1541+ FORWARDED_PAYMENT_PERSISTENCE_PRIMARY_NAMESPACE . to_string ( ) ,
1542+ CHANNEL_FORWARDING_STATS_PERSISTENCE_SECONDARY_NAMESPACE . to_string ( ) ,
1543+ Arc :: clone ( & kv_store) ,
1544+ Arc :: clone ( & logger) ,
1545+ ) ) ,
1546+ Err ( e) => {
1547+ log_error ! ( logger, "Failed to read channel forwarding stats from store: {}" , e) ;
1548+ return Err ( BuildError :: ReadFailed ) ;
1549+ } ,
1550+ } ;
1551+
1552+ let channel_pair_forwarding_stats_store = Arc :: new ( ChannelPairForwardingStatsStore :: new (
1553+ Vec :: new ( ) ,
1554+ KeepNoEntries ,
1555+ FORWARDED_PAYMENT_PERSISTENCE_PRIMARY_NAMESPACE . to_string ( ) ,
1556+ CHANNEL_PAIR_FORWARDING_STATS_PERSISTENCE_SECONDARY_NAMESPACE . to_string ( ) ,
1557+ Arc :: clone ( & kv_store) ,
1558+ Arc :: clone ( & logger) ,
1559+ ) ) ;
1560+
15121561 let ( chain_source, chain_tip_opt) = match chain_data_source_config {
15131562 Some ( ChainDataSourceConfig :: Esplora { server_url, headers, sync_config } ) => {
15141563 let sync_config = sync_config. unwrap_or ( EsploraSyncConfig :: default ( ) ) ;
@@ -2359,6 +2408,16 @@ fn build_with_store_internal(
23592408 _leak_checker. 0 . push ( Arc :: downgrade ( & wallet) as Weak < dyn Any + Send + Sync > ) ;
23602409 }
23612410
2411+ // How long detail records are kept before being folded into channel-pair buckets. `Stats` keeps
2412+ // none of its own, and only drains records a previous `Detailed` configuration left behind.
2413+ let forwarded_payment_aggregation_retention_secs = match config. forwarded_payment_tracking_mode
2414+ {
2415+ crate :: config:: ForwardedPaymentTrackingMode :: Detailed => {
2416+ crate :: payment:: forwarding_store:: FORWARDED_PAYMENT_AGGREGATION_BUCKET_SIZE_SECS
2417+ } ,
2418+ crate :: config:: ForwardedPaymentTrackingMode :: Stats => 0 ,
2419+ } ;
2420+
23622421 Ok ( Node {
23632422 runtime,
23642423 stop_sender,
@@ -2386,6 +2445,10 @@ fn build_with_store_internal(
23862445 scorer,
23872446 peer_store,
23882447 payment_store,
2448+ forwarded_payment_store,
2449+ channel_forwarding_stats_store,
2450+ channel_pair_forwarding_stats_store,
2451+ forwarded_payment_aggregation_retention_secs,
23892452 lnurl_auth,
23902453 is_running,
23912454 node_metrics,
0 commit comments