24
24
25
25
#include < silkworm/infra/concurrency/task.hpp>
26
26
27
+ #include < silkworm/db/chain/local_chain_storage.hpp>
27
28
#include < silkworm/db/data_store.hpp>
28
29
29
30
#include " base_transaction.hpp"
@@ -34,9 +35,27 @@ namespace silkworm::db::kv::api {
34
35
35
36
class LocalTransaction : public BaseTransaction {
36
37
public:
37
- LocalTransaction (DataStoreRef data_store, StateCache* state_cache)
38
- : BaseTransaction(state_cache),
38
+ class Cache {
39
+ public:
40
+ using ChainStorageCache = db::chain::LocalChainStorage::Cache;
41
+ explicit Cache (StateCache* state_cache)
42
+ : state_cache_{state_cache},
43
+ chain_storage_cache_{std::make_shared<ChainStorageCache>()} {}
44
+ StateCache* state_cache () const { return state_cache_; }
45
+ std::shared_ptr<ChainStorageCache> chain_storage_cache () const { return chain_storage_cache_; }
46
+
47
+ private:
48
+ // ! The local state cache built upon incoming state changes
49
+ StateCache* state_cache_;
50
+ std::shared_ptr<ChainStorageCache> chain_storage_cache_;
51
+ };
52
+
53
+ LocalTransaction (
54
+ DataStoreRef data_store,
55
+ std::shared_ptr<Cache> cache)
56
+ : BaseTransaction{cache->state_cache ()},
39
57
data_store_{std::move (data_store)},
58
+ cache_{std::move (cache)},
40
59
tx_{data_store_.chaindata .access_ro ().start_ro_tx ()} {}
41
60
42
61
~LocalTransaction () override = default ;
@@ -105,6 +124,7 @@ class LocalTransaction : public BaseTransaction {
105
124
std::map<std::string, std::shared_ptr<CursorDupSort>> dup_cursors_;
106
125
107
126
DataStoreRef data_store_;
127
+ std::shared_ptr<Cache> cache_;
108
128
uint32_t last_cursor_id_{0 };
109
129
datastore::kvdb::ROTxnManaged tx_;
110
130
uint64_t tx_id_{++next_tx_id_};
0 commit comments