Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ pub struct Args {
/// keeping a buffer of blocks from tip to handle reorgs.
#[arg(long, env = "SPACED_ENABLE_PRUNING", default_value = "false")]
enable_pruning: bool,

/// Cache size in bytes for the spacedb database
#[arg(long, env = "SPACED_CACHE_SIZE")]
cache_size: Option<usize>,
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, ValueEnum, Serialize, Deserialize)]
Expand Down Expand Up @@ -226,6 +230,7 @@ impl Args {
&data_dir,
args.block_index || args.block_index_full,
args.index_node_hashes,
args.cache_size,
)?;

let anchors_path = match args.skip_anchors {
Expand Down
5 changes: 3 additions & 2 deletions client/src/store/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,19 @@ impl Chain {
dir: &Path,
block_index: bool,
index_hashes: bool,
cache_size: Option<usize>,
) -> anyhow::Result<Self> {
let proto_db_path = dir.join("root.sdb");
let nums_db_path = dir.join("nums.sdb");
let initial_num_sync = !nums_db_path.exists();

let sp_store = SpStore::open(proto_db_path, index_hashes)?;
let sp_store = SpStore::open(proto_db_path, index_hashes, cache_size)?;
let sp = SpLiveStore {
state: sp_store.begin(&genesis)?,
store: sp_store,
};

let num_store = NumStore::open(nums_db_path, index_hashes)?;
let num_store = NumStore::open(nums_db_path, index_hashes, cache_size)?;
let num = NumLiveStore {
state: num_store.begin(&nums_genesis)?,
store: num_store,
Expand Down
9 changes: 6 additions & 3 deletions client/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use spacedb::tx::{ReadTransaction, WriteTransaction};
use spaces_protocol::bitcoin::OutPoint;
use crate::store::chain::ROOT_ANCHORS_COUNT;

const DEFAULT_CACHE_SIZE: usize = 50 * 1024 * 1024; /* 50MB */

pub mod spaces;
pub mod ptrs;
pub mod chain;
Expand Down Expand Up @@ -47,10 +49,11 @@ impl spaces_protocol::hasher::KeyHasher for Sha256 {
}
}

fn open_db(path_buf: PathBuf, auto_hash_index: bool) -> anyhow::Result<Database<Sha256Hasher>> {
fn open_db(path_buf: PathBuf, auto_hash_index: bool, cache_size: Option<usize>) -> anyhow::Result<Database<Sha256Hasher>> {
let config = Configuration::standard()
.with_auto_hash_index(auto_hash_index)
.with_hash_index_pruning(Some(ROOT_ANCHORS_COUNT as _));

.with_hash_index_pruning(Some(ROOT_ANCHORS_COUNT as _))
.with_cache_size(cache_size.unwrap_or(DEFAULT_CACHE_SIZE));

Ok(Database::open_with_config(path_buf.to_str().unwrap(), config)?)
}
4 changes: 2 additions & 2 deletions client/src/store/ptrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ pub struct Staged {
}

impl NumStore {
pub fn open(path: PathBuf, auto_hash_index: bool) -> Result<Self> {
let db = open_db(path, auto_hash_index)?;
pub fn open(path: PathBuf, auto_hash_index: bool, cache_size: Option<usize>) -> Result<Self> {
let db = open_db(path, auto_hash_index, cache_size)?;
Ok(Self(db))
}

Expand Down
4 changes: 2 additions & 2 deletions client/src/store/spaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ pub struct Staged {
}

impl SpStore {
pub fn open(path: PathBuf, auto_hash_index: bool) -> Result<Self> {
let db = open_db(path, auto_hash_index)?;
pub fn open(path: PathBuf, auto_hash_index: bool, cache_size: Option<usize>) -> Result<Self> {
let db = open_db(path, auto_hash_index, cache_size)?;
Ok(Self(db))
}

Expand Down
Loading