Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the smt cache height #6757

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions applications/minotari_node/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ pub async fn configure_and_initialize_node(
app_config.base_node.lmdb_path.as_path(),
app_config.base_node.lmdb.clone(),
app_config.base_node.storage.pruning_interval,
app_config.base_node.storage.pruning_horizon,
rules,
)
.map_err(|e| ExitError::new(ExitCode::DatabaseError, e))?;
Expand Down
2 changes: 2 additions & 0 deletions applications/minotari_node/src/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub async fn run_recovery(node_config: &BaseNodeConfig) -> Result<(), anyhow::Er
&node_config.lmdb_path,
node_config.lmdb.clone(),
node_config.storage.pruning_interval,
node_config.storage.pruning_horizon,
rules.clone(),
)
.map_err(|e| {
Expand All @@ -97,6 +98,7 @@ pub async fn run_recovery(node_config: &BaseNodeConfig) -> Result<(), anyhow::Er
&temp_path,
node_config.lmdb.clone(),
node_config.storage.pruning_interval,
node_config.storage.pruning_horizon,
rules.clone(),
)
.map_err(|e| {
Expand Down
20 changes: 16 additions & 4 deletions base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const LMDB_DB_VALIDATOR_NODES: &str = "validator_nodes";
const LMDB_DB_VALIDATOR_NODES_MAPPING: &str = "validator_nodes_mapping";
const LMDB_DB_TEMPLATE_REGISTRATIONS: &str = "template_registrations";
const LMDB_DB_UTXO_SMT: &str = "utxo_smt";
const SMT_CACHE_PERIOD: u64 = 1000;
const SMT_CACHE_PERIOD: u64 = 500;

/// HeaderHash(32), mmr_pos(8), hash(32)
type KernelKey = CompositeKey<72>;
Expand All @@ -174,6 +174,7 @@ pub fn create_lmdb_database<P: AsRef<Path>>(
path: P,
config: LMDBConfig,
prune_interval: u64,
pruning_horizon: u64,
consensus_manager: ConsensusManager,
) -> Result<LMDBDatabase, ChainStorageError> {
let flags = db::CREATE;
Expand Down Expand Up @@ -218,7 +219,13 @@ pub fn create_lmdb_database<P: AsRef<Path>>(
.build()
.map_err(|err| ChainStorageError::CriticalError(format!("Could not create LMDB store:{}", err)))?;
debug!(target: LOG_TARGET, "LMDB database creation successful");
LMDBDatabase::new(&lmdb_store, file_lock, consensus_manager, prune_interval)
LMDBDatabase::new(
&lmdb_store,
file_lock,
consensus_manager,
prune_interval,
pruning_horizon,
)
}

/// This is a lmdb-based blockchain database for persistent storage of the chain state.
Expand Down Expand Up @@ -291,9 +298,10 @@ impl LMDBDatabase {
file_lock: File,
consensus_manager: ConsensusManager,
prune_interval: u64,
pruning_horizon: u64,
) -> Result<Self, ChainStorageError> {
let env = store.env();
let smt_cache_period = if prune_interval == 0 {
let smt_cache_period = if pruning_horizon == 0 || prune_interval == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a comment here what the thinking is, because it's not clear why the interval / 2

SMT_CACHE_PERIOD
} else {
prune_interval / 2
Expand Down Expand Up @@ -461,6 +469,10 @@ impl LMDBDatabase {
// for security we check that the best block does exist, and we check the previous value
// we dont want to check this if the prev block has never been set, this means a empty hash of 32
// bytes.
debug!(target: LOG_TARGET,
"Setting new best block as height: {}",
height
);
if *height > 0 {
let prev = fetch_best_block(&write_txn, &self.metadata_db)?;
if *expected_prev_best_block != prev {
Expand Down Expand Up @@ -1771,7 +1783,7 @@ impl LMDBDatabase {

match lmdb_replace(txn, &self.utxo_smt, &k.as_u32(), smt, Some(estimated_bytes)) {
Ok(_) => {
trace!(
debug!(
target: LOG_TARGET,
"Inserted ~{} MB with key '{}' into '{}' (size {}) in {:.2?}",
estimated_bytes / BYTES_PER_MB,
Expand Down
4 changes: 2 additions & 2 deletions base_layer/core/src/test_helpers/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl TempDatabase {
let rules = create_consensus_rules();

Self {
db: Some(create_lmdb_database(&temp_path, LMDBConfig::default(), 0, rules).unwrap()),
db: Some(create_lmdb_database(&temp_path, LMDBConfig::default(), 0, 0, rules).unwrap()),
path: temp_path,
delete_on_drop: true,
}
Expand All @@ -177,7 +177,7 @@ impl TempDatabase {
pub fn from_path<P: AsRef<Path>>(temp_path: P) -> Self {
let rules = create_consensus_rules();
Self {
db: Some(create_lmdb_database(&temp_path, LMDBConfig::default(), 0, rules).unwrap()),
db: Some(create_lmdb_database(&temp_path, LMDBConfig::default(), 0, 0, rules).unwrap()),
path: temp_path.as_ref().to_path_buf(),
delete_on_drop: true,
}
Expand Down
Loading