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

Dynamic trie pruning #1556

Merged
merged 89 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
ac86a61
Add trie pruner interface
Harrm Feb 10, 2023
2afa9db
Trie pruner in progress
Harrm Feb 13, 2023
6ad0e6f
Working on pruner
Harrm Feb 14, 2023
2cbe715
Writing reference counter
Harrm Feb 15, 2023
c710ccc
Basic reference counting pruner implementation
Harrm Feb 20, 2023
6e9ee39
Merge branch 'master' of github.com:soramitsu/kagome into feature/dyn…
Harrm Feb 20, 2023
4c7e91f
Optimizing pruning
Harrm Feb 21, 2023
de173d1
Working on pruner
Harrm Mar 1, 2023
efc68cd
Add basic tests
Harrm Mar 2, 2023
41073a2
Working on pruner tests
Harrm Mar 3, 2023
c902fa7
Working on pruner persistency
Harrm Mar 10, 2023
5d400ca
Merge with master
Harrm Mar 10, 2023
46c4a25
bt
iceseer Mar 10, 2023
66d28e5
Fixing pruning bug
Harrm Mar 12, 2023
afec52b
Merge branch 'master' of github.com:soramitsu/kagome into feature/dyn…
Harrm Mar 12, 2023
5fd1de8
Working version of pruner
Harrm Mar 21, 2023
3562319
Remove logs from stream engine
Harrm Mar 22, 2023
8fa0506
Fix restoreState
Harrm Mar 28, 2023
7f10dd1
Merge with master
Harrm Apr 3, 2023
19e805e
Update CLI flag and add comments
Harrm Apr 3, 2023
c2e2955
Merge with master and improve encoding caching
Harrm Apr 4, 2023
8823daa
Fixing cache
Harrm Apr 5, 2023
22986f5
Fix tests
Harrm Apr 6, 2023
8ac8cea
Fix for older compilers
Harrm Apr 6, 2023
b4eee20
Merge branch 'master' into feature/dynamic-trie-pruning
Harrm Apr 6, 2023
1a9b125
Add asserts to AddConfig
Harrm Apr 6, 2023
99630f9
Fix for TSAN
Harrm Apr 7, 2023
17680e5
Add comment about broken cache
Harrm Apr 7, 2023
e8fff09
Change line breaks O.o
Harrm Apr 7, 2023
f63d3ec
Fix logging levels
Harrm Apr 7, 2023
d3b3f40
Merge branch 'master' into feature/dynamic-trie-pruning
Harrm Apr 7, 2023
a0a5df5
Fix log in block trie
Harrm Apr 7, 2023
c629954
Merge branch 'feature/dynamic-trie-pruning' of github.com:soramitsu/k…
Harrm Apr 7, 2023
9c4a686
Fix offchain CLI flag name Newer -> Never
Harrm Apr 13, 2023
1b4e8e9
Ignore blocks without state during restoreState
Harrm Apr 17, 2023
77510ce
Working on reviews
Harrm Apr 20, 2023
cb483ee
Test in progress
Harrm Apr 26, 2023
af244f5
Working on test for fast sync scenario
Harrm Apr 27, 2023
deaffcf
Merge branch 'feature/dynamic-trie-pruning' of github.com:soramitsu/k…
Harrm Apr 27, 2023
4104e9b
Fast sync pruner test
Harrm Apr 28, 2023
1043488
Working on pruner tests
Harrm May 3, 2023
44c23a8
Fixes from review
Harrm May 14, 2023
126dd4a
Merge with master
Harrm May 17, 2023
75f6e82
Fixes from review
Harrm May 17, 2023
8ff73d4
Merge branch 'master' into feature/dynamic-trie-pruning
Harrm May 17, 2023
1be5019
Merge branch 'master' into feature/dynamic-trie-pruning
Harrm May 22, 2023
1fbf9cf
Fixes from reviews
Harrm May 22, 2023
1bd0261
Merge branch 'feature/dynamic-trie-pruning' of github.com:soramitsu/k…
Harrm May 22, 2023
d40cde3
Fixes from review
Harrm May 23, 2023
f797c89
Fixes from review
Harrm May 26, 2023
82c79b0
Merge with master
Harrm May 26, 2023
63086c0
Fix test
Harrm May 29, 2023
deb1fce
Fix test
Harrm May 29, 2023
50d0aa6
Merge branch 'master' into feature/dynamic-trie-pruning
Harrm May 29, 2023
6cdd1df
Merge branch 'master' into feature/dynamic-trie-pruning
Harrm May 29, 2023
d14c792
Merge branch 'master' into feature/dynamic-trie-pruning
Harrm May 30, 2023
bc57c83
Fixes from review
Harrm May 31, 2023
8e5fb4a
Merge branch 'feature/dynamic-trie-pruning' of github.com:soramitsu/k…
Harrm May 31, 2023
f563473
Merge branch 'master' into feature/dynamic-trie-pruning
Harrm May 31, 2023
7c308d2
Fix build issues
Harrm Jun 1, 2023
a003753
Merge branch 'master' into feature/dynamic-trie-pruning
Harrm Jun 1, 2023
b424c05
Fixes from review
Harrm Jun 6, 2023
88bd3b0
Fix for absent rocksdb spaces
Harrm Jun 7, 2023
3d78821
Fixes from review
Harrm Jun 8, 2023
a176795
Fixes from review
Harrm Jun 8, 2023
3c10f43
Fix rocksdb bug
Harrm Jun 8, 2023
c552e91
Fix child tries pruning bug
Harrm Jun 8, 2023
848439f
Fix child tries pruning bug
Harrm Jun 8, 2023
dbdabd1
Fix trie mock for pruner tests
Harrm Jun 9, 2023
037382f
Fix child tries pruning properly
Harrm Jun 9, 2023
33a9a6f
Dyld patch
Harrm Jun 13, 2023
66e3114
Merge remote-tracking branch 'origin/feature/dynamic-trie-pruning' in…
Harrm Jun 14, 2023
cd25715
Fixing value retrieval bug
Harrm Jun 14, 2023
e7785d0
Fix a couple of bugs
Harrm Jun 15, 2023
450aa87
Merge branch 'master' into feature/dynamic-trie-pruning
Harrm Jun 16, 2023
4a3d466
Fix tests
Harrm Jun 19, 2023
31711eb
Merge branch 'master' into feature/dynamic-trie-pruning
Harrm Jun 19, 2023
8cee9d1
Enable dyld patch for debug builds only; Add a comment to trie serial…
Harrm Jun 19, 2023
f5d6e1f
Fix naming in bufferorview
Harrm Jun 19, 2023
18e28cd
Fixes from review
Harrm Jun 21, 2023
1814bef
Install app_config
Harrm Jun 21, 2023
2dcf376
install telemetry/ headers
Harrm Jun 21, 2023
38c7069
Merge branch 'master' into feature/dynamic-trie-pruning
Harrm Jun 22, 2023
76db46f
Fixes from review
Harrm Jun 23, 2023
b98d14a
Fix pruner basic test
Harrm Jun 25, 2023
d32bf72
Merge branch 'master' into feature/dynamic-trie-pruning
Harrm Jun 26, 2023
358cc28
Merge branch 'master' into feature/dynamic-trie-pruning
Harrm Jun 30, 2023
436d57b
Prune parent trie with its child tries in a single batch
Harrm Jul 4, 2023
3f4055e
Fix map management
Harrm Jul 4, 2023
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
4 changes: 2 additions & 2 deletions cmake/Hunter/hunter-gate-url.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
HunterGate(
URL "https://github.com/soramitsu/soramitsu-hunter/archive/refs/tags/v0.23.257-soramitsu49.zip"
SHA1 "a03391d0018024284a360d9e05594d7fa4e42851"
URL "https://github.com/soramitsu/soramitsu-hunter/archive/refs/tags/v0.23.257-soramitsu51.zip"
SHA1 "1839ed95f13509c4767216ee17b9793798e08a6f"
LOCAL
)
3 changes: 2 additions & 1 deletion core/api/service/child_state/impl/child_state_api_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ namespace kagome::api {
storage_->getEphemeralBatchAt(child_root_hash));
auto res = child_storage_trie_reader->tryGet(key);
return common::map_result_optional(
std::move(res), [](common::BufferOrView &&r) { return r.into(); });
std::move(res),
[](common::BufferOrView &&r) { return r.into_buffer(); });
}

outcome::result<std::optional<primitives::BlockHash>>
Expand Down
4 changes: 2 additions & 2 deletions core/api/service/state/impl/state_api_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace kagome::api {
OUTCOME_TRY(trie_reader, storage_->getEphemeralBatchAt(header.state_root));
auto res = trie_reader->tryGet(key);
return common::map_result_optional(
std::move(res), [](common::BufferOrView &&r) { return r.into(); });
std::move(res), [](common::BufferOrView &&r) { return r.into_buffer(); });
}

outcome::result<std::vector<StateApiImpl::StorageChangeSet>>
Expand Down Expand Up @@ -164,7 +164,7 @@ namespace kagome::api {
OUTCOME_TRY(opt_get, batch->tryGet(key));
auto opt_value = common::map_optional(
std::move(opt_get),
[](common::BufferOrView &&r) { return r.into(); });
[](common::BufferOrView &&r) { return r.into_buffer(); });
auto it = last_values.find(key);
if (it == last_values.end() || it->second != opt_value) {
change.changes.push_back(StorageChangeSet::Change{key, opt_value});
Expand Down
1 change: 1 addition & 0 deletions core/application/impl/app_configuration_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ namespace kagome::application {
offchain_worker_mode_{def_offchain_worker_mode},
enable_offchain_indexing_{def_enable_offchain_indexing},
recovery_state_{def_block_to_recover},
db_cache_size_{def_db_cache_size},
state_pruning_depth_{} {
SL_INFO(logger_, "Soramitsu Kagome started. Version: {} ", buildVersion());
}
Expand Down
2 changes: 1 addition & 1 deletion core/authority_discovery/query/query_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace kagome::authority_discovery {
auto authority = queue_.back();
queue_.pop_back();

common::Buffer hash = crypto::sha256(authority);
common::Buffer hash {crypto::sha256(authority)};
Harrm marked this conversation as resolved.
Show resolved Hide resolved
scheduler_->schedule([=, wp = weak_from_this()] {
if (auto self = wp.lock()) {
std::ignore = kademlia_->getValue(
Expand Down
43 changes: 12 additions & 31 deletions core/blockchain/impl/block_tree_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,7 @@ namespace kagome::blockchain {
node->has_justification = true;

OUTCOME_TRY(pruneNoLock(p, node));
OUTCOME_TRY(pruneTrie(
p, last_finalized_block_info.number, node->getBlockInfo().number));
OUTCOME_TRY(pruneTrie(p, node->getBlockInfo().number));

p.tree_->updateTreeRoot(node);

Expand Down Expand Up @@ -1420,55 +1419,37 @@ namespace kagome::blockchain {

outcome::result<void> BlockTreeImpl::pruneTrie(
const BlockTreeData &block_tree_data,
primitives::BlockNumber old_finalized,
primitives::BlockNumber new_finalized) {
// pruning is disabled
if (!block_tree_data.state_pruner_->getPruningDepth().has_value()) {
return outcome::success();
}
auto *root_node = &block_tree_data.tree_->getRoot();
BOOST_ASSERT(root_node->depth == old_finalized);
auto last_pruned = block_tree_data.state_pruner_->getLastPrunedBlock();

BOOST_ASSERT(!last_pruned.has_value()
|| last_pruned.value().number <= root_node->depth);
auto next_pruned_number = last_pruned ? last_pruned->number + 1 : 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we prune genesis?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't see a reason to treat it differently.


OUTCOME_TRY(hash_opt, getBlockHash(next_pruned_number));
BOOST_ASSERT(hash_opt.has_value());
primitives::BlockHash hash = std::move(*hash_opt);
auto last_to_prune =
new_finalized
- block_tree_data.state_pruner_->getPruningDepth().value_or(0);
for (auto n = next_pruned_number;
n < std::min(old_finalized, last_to_prune);
n++) {
auto pruning_depth =
block_tree_data.state_pruner_->getPruningDepth().value_or(0);
if (new_finalized < pruning_depth) {
return outcome::success();
}

auto last_to_prune = new_finalized - pruning_depth;
for (auto n = next_pruned_number; n < last_to_prune; n++) {
OUTCOME_TRY(next_hash_opt, getBlockHash(n + 1));
BOOST_ASSERT(next_hash_opt.has_value());
auto &next_hash = *next_hash_opt;
OUTCOME_TRY(header, getBlockHeader(hash));
OUTCOME_TRY(block_tree_data.state_pruner_->pruneFinalized(header));
hash = std::move(next_hash);
}
BOOST_ASSERT(
block_tree_data.state_pruner_->getLastPrunedBlock().has_value()
&& block_tree_data.state_pruner_->getLastPrunedBlock().value().number
== root_node->depth);

auto *current_node = root_node;
for (auto n = block_tree_data.state_pruner_->getLastPrunedBlock()->number;
n < last_to_prune;
n++) {
BOOST_ASSERT(current_node->children.size() == 1);
auto next_node = current_node->children[0].get();
OUTCOME_TRY(
header_opt,
block_tree_data.storage_->getBlockHeader(current_node->block_hash));
if (!header_opt.has_value()) {
return BlockTreeError::HEADER_NOT_FOUND;
}
auto &header = header_opt.value();
OUTCOME_TRY(block_tree_data.state_pruner_->pruneFinalized(header));
current_node = next_node;
}

return outcome::success();
}

Expand Down
1 change: 0 additions & 1 deletion core/blockchain/impl/block_tree_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ namespace kagome::blockchain {
const BlockTreeData &p, const primitives::BlockHash &block_hash) const;

outcome::result<void> pruneTrie(const BlockTreeData &block_tree_data,
primitives::BlockNumber old_finalized,
primitives::BlockNumber new_finalized);

outcome::result<void> reorganizeNoLock(BlockTreeData &p);
Expand Down
2 changes: 1 addition & 1 deletion core/common/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace kagome::common {
SLBuffer(const BufferView &s) : Base(s.begin(), s.end()) {}

template <size_t N>
SLBuffer(const std::array<typename Base::value_type, N> &other)
explicit SLBuffer(const std::array<typename Base::value_type, N> &other)
Harrm marked this conversation as resolved.
Show resolved Hide resolved
: Base(other.begin(), other.end()) {}

SLBuffer(const uint8_t *begin, const uint8_t *end) : Base(begin, end){};
Expand Down
9 changes: 5 additions & 4 deletions core/common/buffer_or_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace kagome::common {
/// Moved owned buffer or readonly view.
class BufferOrView {
using Span = gsl::span<const uint8_t>;

template <typename T>
using AsSpan = std::enable_if_t<std::is_convertible_v<T, Span>>;

Expand All @@ -41,7 +42,7 @@ namespace kagome::common {
BufferOrView &operator=(BufferOrView &&) = default;

/// Is buffer owned.
bool owned() const {
bool is_owned() const {
if (variant.which() == 2) {
throw std::logic_error{"Tried to use moved BufferOrView"};
}
Expand All @@ -50,7 +51,7 @@ namespace kagome::common {

/// Get view.
BufferView view() const {
if (!owned()) {
if (!is_owned()) {
return boost::get<BufferView>(variant);
}
return BufferView{boost::get<Buffer>(variant)};
Expand All @@ -68,15 +69,15 @@ namespace kagome::common {

/// Get mutable buffer reference. Copy once if view.
Buffer &mut() {
if (!owned()) {
if (!is_owned()) {
auto view = boost::get<BufferView>(variant);
variant = Buffer{view};
}
return boost::get<Buffer>(variant);
}

/// Move buffer away. Copy once if view.
Buffer into() {
Buffer into_buffer() {
auto buffer = std::move(mut());
variant = Moved{};
return buffer;
Expand Down
2 changes: 1 addition & 1 deletion core/common/size_limited_containers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace kagome::common {

SizeLimitedContainer() = default;

SizeLimitedContainer(size_t size)
explicit SizeLimitedContainer(size_t size)
: Base([&] {
if constexpr (size_check_is_enabled) {
if (unlikely(size > max_size())) {
Expand Down
22 changes: 9 additions & 13 deletions core/consensus/babe/impl/babe_config_repository_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,25 +842,21 @@ namespace kagome::consensus::babe {

void BabeConfigRepositoryImpl::readFromState(
const primitives::BlockInfo &block) {
auto check_res = [this, &block](const auto &res, const auto &msg) {
if (!res) {
logger_->error("readFromState {}, error: {}", block, msg);
return false;
}
return true;
};
auto hash1_opt_res = block_tree_->getBlockHash(1);
if (!check_res(hash1_opt_res, hash1_opt_res.error())) {
if (!hash1_opt_res) {
logger_->error(
"readFromState {}, error: {}", block, hash1_opt_res.error());
return;
}
if (!check_res(hash1_opt_res.value().has_value(),
"Block #1 not present in the storage")) {
if (!hash1_opt_res.value().has_value()) {
logger_->error(
"readFromState {}, error: \"Block #1 not present in the storage\"",
block);
return;
}

auto header1_res = block_tree_->getBlockHeader(*hash1_opt_res.value());
if (!check_res(header1_res,
header1_res.error())) {
if (!header1_res) {
logger_->error("readFromState {}, error: {}", block, header1_res.error());
return;
}

Expand Down
3 changes: 1 addition & 2 deletions core/consensus/babe/impl/babe_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1088,8 +1088,7 @@ namespace kagome::consensus::babe {
return common::Buffer{scale::encode(ext).value()};
}));
return ext_root_res.has_value()
and (ext_root_res.value()
== common::Buffer(block.header.extrinsics_root));
and (ext_root_res.value() == block.header.extrinsics_root);
}(),
"Extrinsics root does not match extrinsics in the block");

Expand Down
6 changes: 3 additions & 3 deletions core/host_api/impl/storage_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,12 @@ namespace kagome::host_api {
auto res = memory.storeBuffer(storage::trie::kEmptyRootHash);
return runtime::PtrSize(res).ptr;
}
storage::trie::PolkadotTrieImpl trie;
auto trie = storage::trie::PolkadotTrieImpl::createEmpty();
for (auto &&p : pv) {
auto &&key = p.first;
common::BufferView value = p.second;
// already scale-encoded
auto put_res = trie.put(key, value);
auto put_res = trie->put(key, value);
if (not put_res) {
logger_->error(
"Insertion of value {} with key {} into the trie failed due to "
Expand All @@ -370,7 +370,7 @@ namespace kagome::host_api {
}
}
const auto &enc =
codec.encodeNode(*trie.getRoot(), storage::trie::StateVersion::V0, {});
codec.encodeNode(*trie->getRoot(), storage::trie::StateVersion::V0, {});
if (!enc) {
logger_->error("failed to encode trie root: {}", enc.error());
throw std::runtime_error(enc.error().message());
Expand Down
15 changes: 8 additions & 7 deletions core/injector/calculate_genesis_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ namespace kagome::injector {
const runtime::ModuleFactory &module_factory,
storage::trie::TrieSerializer &trie_serializer) {
auto trie_from = [](const application::GenesisRawData &kv) {
storage::trie::PolkadotTrieImpl trie;
auto trie = storage::trie::PolkadotTrieImpl::createEmpty();
for (auto &[k, v] : kv) {
trie.put(k, common::BufferView{v}).value();
trie->put(k, common::BufferView{v}).value();
}
return trie;
};
auto top_trie = trie_from(chain_spec.getGenesisTopSection());
OUTCOME_TRY(code, top_trie.get(storage::kRuntimeCodeKey));
OUTCOME_TRY(code, top_trie->get(storage::kRuntimeCodeKey));
OUTCOME_TRY(env,
runtime::RuntimeEnvironment::fromCode(module_factory, code));
runtime::CoreImpl core_api{
Expand All @@ -35,18 +35,19 @@ namespace kagome::injector {
};
OUTCOME_TRY(runtime_version, core_api.version(env));
auto version = storage::trie::StateVersion{runtime_version.state_version};
std::vector<storage::trie::PolkadotTrieImpl> child_tries;
std::vector<std::shared_ptr<storage::trie::PolkadotTrie>> child_tries;
for (auto &[child, kv] : chain_spec.getGenesisChildrenDefaultSection()) {
child_tries.emplace_back(trie_from(kv));
OUTCOME_TRY(root, trie_serializer.storeTrie(child_tries.back(), version));
OUTCOME_TRY(root, trie_serializer.storeTrie(*child_tries.back(), version));

common::Buffer child2;
child2 += storage::kChildStorageDefaultPrefix;
child2 += child;
top_trie.put(child2, common::BufferView{root}).value();
top_trie->put(child2, common::BufferView{root}).value();
}

OUTCOME_TRY(trie_hash, trie_serializer.storeTrie(top_trie, version));
OUTCOME_TRY(code_, top_trie->get(storage::kRuntimeCodeKey));
Harrm marked this conversation as resolved.
Show resolved Hide resolved
OUTCOME_TRY(trie_hash, trie_serializer.storeTrie(*top_trie, version));

return trie_hash;
}
Expand Down
22 changes: 8 additions & 14 deletions core/network/impl/state_sync_request_flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace kagome::network {
const primitives::BlockHeader &block)
: state_pruner_{state_pruner}, block_info_{block_info}, block_{block} {
BOOST_ASSERT(state_pruner_ != nullptr);
roots_.insert({std::nullopt, Root{storage::trie::PolkadotTrieImpl{}, {}}});
roots_.insert({std::nullopt, Root{storage::trie::PolkadotTrieImpl::createEmpty(), {}}});
}

bool StateSyncRequestFlow::complete() const {
Expand Down Expand Up @@ -74,7 +74,7 @@ namespace kagome::network {
OUTCOME_TRY(hash, RootHash::fromSpan(value));
roots_[hash].children.emplace_back(key);
} else {
root.trie.put(key, common::BufferView{value}).value();
root.trie->put(key, common::BufferView{value}).value();
}
}
if (entry.complete) {
Expand All @@ -90,7 +90,7 @@ namespace kagome::network {
storage::trie::TrieSerializer &trie_serializer) {
assert(complete());
auto &top = roots_[std::nullopt];
OUTCOME_TRY(code, top.trie.get(storage::kRuntimeCodeKey));
OUTCOME_TRY(code, top.trie->get(storage::kRuntimeCodeKey));
OUTCOME_TRY(env,
runtime::RuntimeEnvironment::fromCode(module_factory, code));
OUTCOME_TRY(runtime_version, core_api.version(env));
Expand All @@ -101,27 +101,21 @@ namespace kagome::network {
if (not expected) {
continue;
}
OUTCOME_TRY(actual, trie_serializer.storeTrie(root.trie, version));
OUTCOME_TRY(state_pruner_->addNewState(root.trie, version));
OUTCOME_TRY(actual, trie_serializer.storeTrie(*root.trie, version));
OUTCOME_TRY(state_pruner_->addNewState(*root.trie, version));
if (actual != expected) {
return Error::HASH_MISMATCH;
}
for (auto &child : root.children) {
child_hashes.emplace_back(child, actual);
top.trie.put(child, common::BufferView{actual}).value();
top.trie->put(child, common::BufferView{actual}).value();
}
}
OUTCOME_TRY(actual, trie_serializer.storeTrie(top.trie, version));
OUTCOME_TRY(state_pruner_->addNewState(top.trie, version));
OUTCOME_TRY(actual, trie_serializer.storeTrie(*top.trie, version));
OUTCOME_TRY(state_pruner_->addNewState(*top.trie, version));
if (actual != block_.state_root) {
return Error::HASH_MISMATCH;
}
for (auto &[child_key, child_hash] : child_hashes) {
using Parent = storage::trie_pruner::TriePruner::Parent;
using Child = storage::trie_pruner::TriePruner::Child;
OUTCOME_TRY(state_pruner_->markAsChild(
Parent{actual}, child_key, Child{child_hash}));
}
return outcome::success();
}
} // namespace kagome::network
3 changes: 2 additions & 1 deletion core/network/impl/state_sync_request_flow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ namespace kagome::network {
class StateSyncRequestFlow {
using RootHash = storage::trie::RootHash;
struct Root {
storage::trie::PolkadotTrieImpl trie;
std::shared_ptr<storage::trie::PolkadotTrie> trie =
storage::trie::PolkadotTrieImpl::createEmpty();
Harrm marked this conversation as resolved.
Show resolved Hide resolved
std::vector<common::Buffer> children;
};

Expand Down
2 changes: 1 addition & 1 deletion core/offchain/impl/offchain_local_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ namespace kagome::offchain {

auto iKey = internalKey(key);
OUTCOME_TRY(value, storage_->get(iKey));
return value.into();
return value.into_buffer();
}
} // namespace kagome::offchain
2 changes: 1 addition & 1 deletion core/offchain/impl/offchain_persistent_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace kagome::offchain {
const common::BufferView &key) {
auto iKey = internalKey(key);
OUTCOME_TRY(value, storage_->get(iKey));
return value.into();
return value.into_buffer();
}

} // namespace kagome::offchain
Loading