From 70fcc69eeb3262dfee19623cbe1d71b6fbe9803e Mon Sep 17 00:00:00 2001 From: Stan Bondi Date: Wed, 18 Sep 2024 17:13:09 +0400 Subject: [PATCH] fix(engine): simplify and improve state store performance (#1143) Description --- Removes unnecessary locks in MemoryStateStore Remove de/encoding from MemoryStateStore Removed unused lmdb implementation and lmdb_zero dep Motivation and Context --- MemoryStateStore now uses a hashmap internally without locks. The engine only requires read access to the provided inputs. Key and value types are always SubstateId and Substate respectively, the generic en/decoding to/from CBOR no longer necessary. How Has This Been Tested? --- Existing tests and manually What process can a PR reviewer use to test or verify this change? --- Execution time should be slightly reduced, exact gain is not deteremined. Breaking Changes --- - [x] None - [ ] Requires data directory to be deleted - [ ] Other - Please specify --- Cargo.lock | 14 -- Cargo.toml | 2 - .../src/transaction_executor.rs | 8 +- .../tari_indexer/src/dry_run/processor.rs | 7 +- .../consensus/block_transaction_executor.rs | 22 +- .../src/dry_run_transaction_processor.rs | 8 +- .../src/support/transaction_executor.rs | 18 +- dan_layer/engine/src/runtime/error.rs | 4 +- dan_layer/engine/src/runtime/state_store.rs | 61 +++-- dan_layer/engine/src/runtime/tracker.rs | 4 +- dan_layer/engine/src/runtime/working_state.rs | 4 +- dan_layer/engine/src/state_store/bootstrap.rs | 21 +- dan_layer/engine/src/state_store/memory.rs | 210 ++++-------------- dan_layer/engine/src/state_store/mod.rs | 66 +----- dan_layer/engine/src/transaction/processor.rs | 6 +- dan_layer/engine/tests/test.rs | 9 +- dan_layer/storage_lmdb/Cargo.toml | 21 -- .../storage_lmdb/src/engine_state_store.rs | 171 -------------- dan_layer/storage_lmdb/src/lib.rs | 23 -- .../src/read_only_state_store.rs | 25 +-- .../src/template_test.rs | 84 +++---- 21 files changed, 168 insertions(+), 620 deletions(-) delete mode 100644 dan_layer/storage_lmdb/Cargo.toml delete mode 100644 dan_layer/storage_lmdb/src/engine_state_store.rs delete mode 100644 dan_layer/storage_lmdb/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 3bf791ae9..c2ffdee88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9191,20 +9191,6 @@ dependencies = [ "ts-rs", ] -[[package]] -name = "tari_dan_storage_lmdb" -version = "0.7.0" -dependencies = [ - "hex", - "lmdb-zero", - "serde", - "tari_bor", - "tari_dan_common_types", - "tari_dan_engine", - "tari_storage", - "tempfile", -] - [[package]] name = "tari_dan_storage_sqlite" version = "0.7.0" diff --git a/Cargo.toml b/Cargo.toml index cc5262886..0ed956e22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,6 @@ members = [ "dan_layer/rpc_state_sync", "dan_layer/state_store_sqlite", "dan_layer/state_tree", - "dan_layer/storage_lmdb", "dan_layer/storage_sqlite", "dan_layer/storage", "dan_layer/tari_bor", @@ -193,7 +192,6 @@ libp2p = { git = "https://github.com/tari-project/rust-libp2p.git", rev = "0dccc libsqlite3-sys = "0.25" liquid = "0.26.4" liquid-core = "0.26.4" -lmdb-zero = "0.4.4" log = "0.4.20" log4rs = "1.3" mime_guess = "2.0.4" diff --git a/applications/tari_dan_app_utilities/src/transaction_executor.rs b/applications/tari_dan_app_utilities/src/transaction_executor.rs index 034320a08..f634ea63d 100644 --- a/applications/tari_dan_app_utilities/src/transaction_executor.rs +++ b/applications/tari_dan_app_utilities/src/transaction_executor.rs @@ -16,7 +16,7 @@ use tari_dan_common_types::{ use tari_dan_engine::{ fees::{FeeModule, FeeTable}, runtime::{AuthParams, RuntimeModule}, - state_store::{memory::MemoryStateStore, StateStoreError}, + state_store::{memory::ReadOnlyMemoryStateStore, StateStoreError}, template::LoadedTemplate, transaction::{TransactionError, TransactionProcessor}, }; @@ -33,7 +33,7 @@ pub trait TransactionExecutor { fn execute( &self, transaction: Transaction, - state_store: MemoryStateStore, + state_store: ReadOnlyMemoryStateStore, virtual_substates: VirtualSubstates, ) -> Result; } @@ -110,7 +110,7 @@ where TTemplateProvider: TemplateProvider