feat: introduce on-disk cache persistance for major nym-api caches (#6302)

This includes:
- mixnet contract cache
- described nodes cache
- nodes annotations cache (performance)

those changes include taking some code developed for the purposes of #6277
This commit is contained in:
Jędrzej Stuczyński
2026-02-11 15:57:47 +00:00
committed by GitHub
parent 46b9d5374b
commit 4897cb0ce4
29 changed files with 436 additions and 151 deletions
+2 -1
View File
@@ -3,10 +3,11 @@
use nym_api_requests::models::{DescribedNodeTypeV2, NymNodeDataV2, NymNodeDescriptionV2};
use nym_mixnet_contract_common::NodeId;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::net::IpAddr;
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DescribedNodes {
pub(crate) nodes: HashMap<NodeId, NymNodeDescriptionV2>,
pub(crate) addresses_cache: HashMap<IpAddr, NodeId>,
+4 -13
View File
@@ -12,6 +12,7 @@ use crate::support::config::DEFAULT_NODE_DESCRIBE_BATCH_SIZE;
use async_trait::async_trait;
use futures::{stream, StreamExt};
use std::collections::HashMap;
use std::path::PathBuf;
use tracing::{error, info};
pub struct NodeDescriptionProvider {
@@ -90,23 +91,11 @@ impl CacheItemProvider for NodeDescriptionProvider {
}
}
// currently dead code : (
#[allow(dead_code)]
pub(crate) fn new_refresher(
config: &config::DescribeCache,
contract_cache: MixnetContractCache,
) -> CacheRefresher<DescribedNodes, NodeDescribeCacheError> {
CacheRefresher::new(
NodeDescriptionProvider::new(contract_cache, config.debug.allow_illegal_ips)
.with_batch_size(config.debug.batch_size),
config.debug.caching_interval,
)
}
pub(crate) fn new_provider_with_initial_value(
config: &config::DescribeCache,
contract_cache: MixnetContractCache,
initial: SharedCache<DescribedNodes>,
on_disk_file: PathBuf,
) -> CacheRefresher<DescribedNodes, NodeDescribeCacheError> {
CacheRefresher::new_with_initial_value(
Box::new(
@@ -116,4 +105,6 @@ pub(crate) fn new_provider_with_initial_value(
config.debug.caching_interval,
initial,
)
.named("node-self-described-data-refresher")
.with_persistent_cache(on_disk_file)
}