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 entry count massa module cache #4793

Open
wants to merge 6 commits into
base: mainnet_2_3
Choose a base branch
from
Open
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
2 changes: 0 additions & 2 deletions massa-execution-worker/src/active_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@ mod test {
executed_ops_changes: Default::default(),
executed_denunciations_changes: Default::default(),
execution_trail_hash_change: Default::default(),
deferred_call_changes: Default::default(),
};
let state_changes_2 = StateChanges {
ledger_changes: Default::default(),
Expand All @@ -454,7 +453,6 @@ mod test {
executed_ops_changes: Default::default(),
executed_denunciations_changes: Default::default(),
execution_trail_hash_change: Default::default(),
deferred_call_changes: Default::default(),
};

let exec_output_1 = ExecutionOutput {
Expand Down
21 changes: 17 additions & 4 deletions massa-module-cache/src/hd_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use massa_hash::Hash;
use massa_sc_runtime::{CondomLimits, GasCosts, RuntimeModule};
use massa_serialization::{DeserializeError, Deserializer, Serializer};
use rand::RngCore;
use rocksdb::{Direction, IteratorMode, WriteBatch, DB};
use rocksdb::{Direction, IteratorMode, Options, WriteBatch, DB};
use std::path::PathBuf;
use tracing::debug;
use tracing::{debug, warn};

const OPEN_ERROR: &str = "critical: rocksdb open operation failed";
const CRUD_ERROR: &str = "critical: rocksdb crud operation failed";
Expand Down Expand Up @@ -58,9 +58,22 @@ impl HDCache {
/// * path: where to store the db
/// * max_entry_count: maximum number of entries we want to keep in the db
/// * amount_to_remove: how many entries are removed when `entry_count` reaches `max_entry_count`
///
/// Note: entry_count refers to the number of modules stored in the db, which is half the number of (key, value) pairs in the db
pub fn new(path: PathBuf, max_entry_count: usize, snip_amount: usize) -> Self {
let db = DB::open_default(path).expect(OPEN_ERROR);
let entry_count = db.iterator(IteratorMode::Start).count();
let mut db = DB::open_default(path.clone()).expect(OPEN_ERROR);
let mut nb_db_entries = db.iterator(IteratorMode::Start).count();
if nb_db_entries % 2 != 0 {
modship marked this conversation as resolved.
Show resolved Hide resolved
warn!(
"massa-module-cache db incoherence: odd number of entries, clearing the db cache"
);
drop(db);
let opts = Options::default();
DB::destroy(&opts, path.clone()).expect("Failed to destroy the database");
db = DB::open_default(path).expect(OPEN_ERROR);
nb_db_entries = 0;
}
let entry_count = nb_db_entries / 2;

Self {
db,
Expand Down
Loading