Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feat-transaction-cl…
Browse files Browse the repository at this point in the history
…ient-api-atop-new-quoting
  • Loading branch information
jacderida committed Dec 12, 2024
2 parents e4270aa + 7f28a5a commit bc84302
Show file tree
Hide file tree
Showing 45 changed files with 3,506 additions and 1,067 deletions.
47 changes: 25 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions ant-bootstrap/src/cache_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ use std::{

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CacheData {
pub(crate) peers: std::collections::HashMap<PeerId, BootstrapAddresses>,
#[serde(default = "SystemTime::now")]
last_updated: SystemTime,
#[serde(default = "default_version")]
version: u32,
pub peers: std::collections::HashMap<PeerId, BootstrapAddresses>,
pub last_updated: SystemTime,
pub network_version: String,
}

impl CacheData {
Expand Down Expand Up @@ -128,16 +126,12 @@ impl CacheData {
}
}

fn default_version() -> u32 {
1
}

impl Default for CacheData {
fn default() -> Self {
Self {
peers: std::collections::HashMap::new(),
last_updated: SystemTime::now(),
version: default_version(),
network_version: crate::get_network_version(),
}
}
}
Expand Down Expand Up @@ -181,15 +175,21 @@ impl BootstrapCacheStore {
/// Create a empty CacheStore from the given peers argument.
/// This also modifies the cfg if provided based on the PeersArgs.
/// And also performs some actions based on the PeersArgs.
///
/// `PeersArgs::bootstrap_cache_dir` will take precedence over the path provided inside `config`.
pub fn new_from_peers_args(
peers_arg: &PeersArgs,
cfg: Option<BootstrapCacheConfig>,
config: Option<BootstrapCacheConfig>,
) -> Result<Self> {
let config = if let Some(cfg) = cfg {
let mut config = if let Some(cfg) = config {
cfg
} else {
BootstrapCacheConfig::default_config()?
};
if let Some(bootstrap_cache_path) = peers_arg.get_bootstrap_cache_path()? {
config.cache_file_path = bootstrap_cache_path;
}

let mut store = Self::new(config)?;

// If it is the first node, clear the cache.
Expand Down
9 changes: 6 additions & 3 deletions ant-bootstrap/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// permissions and limitations relating to use of the SAFE Network Software.

use crate::error::{Error, Result};
use ant_protocol::version::{get_key_version_str, get_truncate_version_str};
use std::{
path::{Path, PathBuf},
time::Duration,
Expand Down Expand Up @@ -118,8 +117,12 @@ fn default_cache_path() -> Result<PathBuf> {

std::fs::create_dir_all(&dir)?;

let network_id = format!("{}_{}", get_key_version_str(), get_truncate_version_str());
let path = dir.join(format!("bootstrap_cache_{}.json", network_id));
let path = dir.join(cache_file_name());

Ok(path)
}

/// Returns the name of the cache file
pub fn cache_file_name() -> String {
format!("bootstrap_cache_{}.json", crate::get_network_version())
}
Loading

0 comments on commit bc84302

Please sign in to comment.