From 39d90ede88cdfa5c553953b31e5ef60321b0dbf6 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Tue, 17 Dec 2024 15:52:40 +0100 Subject: [PATCH 1/4] Update entry_count value --- massa-module-cache/src/hd_cache.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/massa-module-cache/src/hd_cache.rs b/massa-module-cache/src/hd_cache.rs index b5a8ed91ff0..23516bb287e 100644 --- a/massa-module-cache/src/hd_cache.rs +++ b/massa-module-cache/src/hd_cache.rs @@ -60,7 +60,11 @@ impl HDCache { /// * amount_to_remove: how many entries are removed when `entry_count` reaches `max_entry_count` 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 nb_db_entries = db.iterator(IteratorMode::Start).count(); + if nb_db_entries % 2 != 0 { + panic!("massa-module-cache db incoherence: odd number of entries"); + } + let entry_count = nb_db_entries / 2; Self { db, From 1629e6a38fdb97d77dd5d126f38addbbf9953a75 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Tue, 17 Dec 2024 16:07:44 +0100 Subject: [PATCH 2/4] Reset db instead of panic --- massa-module-cache/src/hd_cache.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/massa-module-cache/src/hd_cache.rs b/massa-module-cache/src/hd_cache.rs index 23516bb287e..5a238a3509b 100644 --- a/massa-module-cache/src/hd_cache.rs +++ b/massa-module-cache/src/hd_cache.rs @@ -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"; @@ -58,11 +58,20 @@ 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 nb_db_entries = 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 { - panic!("massa-module-cache db incoherence: odd number of entries"); + 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; From deef41ec23e3a28dff269ffb2a054b93d178b4a5 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Tue, 17 Dec 2024 15:53:00 +0100 Subject: [PATCH 3/4] Fix deferred_call_changes in active history + fmt --- massa-execution-worker/src/active_history.rs | 2 -- massa-module-cache/src/hd_cache.rs | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/massa-execution-worker/src/active_history.rs b/massa-execution-worker/src/active_history.rs index 08aeeb923ad..3841a98dd1a 100644 --- a/massa-execution-worker/src/active_history.rs +++ b/massa-execution-worker/src/active_history.rs @@ -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(), @@ -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 { diff --git a/massa-module-cache/src/hd_cache.rs b/massa-module-cache/src/hd_cache.rs index 5a238a3509b..201d7c89022 100644 --- a/massa-module-cache/src/hd_cache.rs +++ b/massa-module-cache/src/hd_cache.rs @@ -58,7 +58,7 @@ 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 mut db = DB::open_default(path.clone()).expect(OPEN_ERROR); From 2f5a060537e4f0c870c060eaf4afa00d93f8b967 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Thu, 19 Dec 2024 09:14:04 +0100 Subject: [PATCH 4/4] Always reset DB cache on new ModuleCache --- massa-module-cache/src/hd_cache.rs | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/massa-module-cache/src/hd_cache.rs b/massa-module-cache/src/hd_cache.rs index 201d7c89022..2284f01a616 100644 --- a/massa-module-cache/src/hd_cache.rs +++ b/massa-module-cache/src/hd_cache.rs @@ -7,7 +7,7 @@ use massa_serialization::{DeserializeError, Deserializer, Serializer}; use rand::RngCore; use rocksdb::{Direction, IteratorMode, Options, WriteBatch, DB}; use std::path::PathBuf; -use tracing::{debug, warn}; +use tracing::debug; const OPEN_ERROR: &str = "critical: rocksdb open operation failed"; const CRUD_ERROR: &str = "critical: rocksdb crud operation failed"; @@ -58,22 +58,11 @@ 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 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 { - 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; + // Reset the DB if it already exists + DB::destroy(&Options::default(), path.clone()).expect("Failed to destroy the database"); + let db = DB::open_default(path).expect(OPEN_ERROR); + let entry_count = 0; Self { db,