18 return "Batch was not created or already was destructed.";
20 return "Unknown error";
24 using storage::trie::TopperTrieBatch;
25 using storage::trie::TopperTrieBatchImpl;
26 using storage::trie::TrieSerializer;
27 using storage::trie::TrieStorage;
30 std::shared_ptr<TrieStorage> trie_storage,
31 std::shared_ptr<TrieSerializer> trie_serializer)
32 : trie_storage_{std::move(trie_storage)},
41 "Setting storage provider to ephemeral batch with root {}",
43 OUTCOME_TRY(batch,
trie_storage_->getEphemeralBatchAt(state_root));
45 return outcome::success();
51 "Setting storage provider to new persistent batch with root {}",
53 OUTCOME_TRY(batch,
trie_storage_->getPersistentBatchAt(state_root));
56 return outcome::success();
59 std::shared_ptr<TrieStorageProviderImpl::Batch>
64 std::optional<std::shared_ptr<TrieStorageProviderImpl::PersistentBatch>>
75 outcome::result<std::shared_ptr<TrieStorageProvider::PersistentBatch>>
79 "Creating new persistent batch for child storage {}",
82 auto child_root_hash =
87 OUTCOME_TRY(child_batch,
92 "Fetching persistent batch for child storage {}",
101 outcome::result<storage::trie::RootHash>
107 std::dynamic_pointer_cast<storage::trie::EphemeralTrieBatch>(
111 OUTCOME_TRY(root, ephemeral->hash());
112 SL_TRACE(
logger_,
"Force commit ephemeral batch, root: {}", root);
113 return std::move(root);
121 "Start storage transaction, depth {}",
124 std::make_shared<TopperTrieBatchImpl>(std::move(current_batch_));
125 return outcome::success();
135 "Rollback storage transaction, depth {}",
138 return outcome::success();
146 auto commitee_batch =
148 BOOST_ASSERT(commitee_batch !=
nullptr);
149 OUTCOME_TRY(commitee_batch->writeBack());
153 "Commit storage transaction, depth {}",
156 return outcome::success();
Class represents arbitrary (including empty) byte buffer.
outcome::result< void > commitTransaction() override
Commit and finish last started transaction.
std::shared_ptr< PersistentBatch > persistent_batch_
outcome::result< void > startTransaction() override
Start nested transaction.
outcome::result< std::shared_ptr< PersistentBatch > > getChildBatchAt(const common::Buffer &root_path) override
Get (or create new) Child Batch with given root hash.
outcome::result< void > setToPersistentAt(const common::Hash256 &state_root) override
outcome::result< void > setToEphemeralAt(const common::Hash256 &state_root) override
std::shared_ptr< storage::trie::TrieSerializer > trie_serializer_
gsl::span< const uint8_t > make_span(const rocksdb::Slice &s)
bool isCurrentlyPersistent() const override
std::string toHex() const
encode bytearray as hex
static outcome::result< Blob< size_ > > fromSpan(const gsl::span< const uint8_t > &span)
std::shared_ptr< storage::trie::TrieStorage > trie_storage_
void clearChildBatches() noexceptoverride
std::string toHex() const noexcept
std::unordered_map< common::Buffer, std::shared_ptr< PersistentBatch > > child_batches_
std::stack< std::shared_ptr< Batch > > stack_of_batches_
std::shared_ptr< Batch > getCurrentBatch() const override
outcome::result< void > rollbackTransaction() override
Rollback and finish last started transaction.
std::optional< std::shared_ptr< PersistentBatch > > tryGetPersistentBatch() const override
std::shared_ptr< Batch > current_batch_
OUTCOME_CPP_DEFINE_CATEGORY(kagome::runtime, TrieStorageProviderImpl::Error, e)
Logger createLogger(const std::string &tag)
TrieStorageProviderImpl(std::shared_ptr< storage::trie::TrieStorage > trie_storage, std::shared_ptr< storage::trie::TrieSerializer > trie_serializer)
outcome::result< storage::trie::RootHash > forceCommit() override
storage::trie::PersistentTrieBatch PersistentBatch