1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

celldb in-memory mode, stats for actors, perf counters, minor fix in rldp2 (#1164)

* getactorstats query for validator-engine-console

* celldb in-memory mode (--celldb-in-memory option)

* rldp2: bugfix - do not estimate speed while nothing is sent

* add simple ed25519 benchmark

* fix compilation errors of different platforms and move to c++20

* fix some warnings

* turn on TON_USE_ABSEIL for glibc 2.27 nix build

---------

Co-authored-by: birydrad <>
This commit is contained in:
birydrad 2024-09-23 16:34:37 +02:00 committed by GitHub
parent 5f51d3d04f
commit 72020c04c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
100 changed files with 3407 additions and 359 deletions

View file

@ -22,6 +22,7 @@
#include "ton/ton-io.hpp"
#include "common/delay.h"
#include "td/utils/filesystem.h"
#include "td/utils/HashSet.h"
namespace ton {
@ -227,17 +228,17 @@ void AsyncStateSerializer::got_masterchain_handle(BlockHandle handle) {
class CachedCellDbReader : public vm::CellDbReader {
public:
CachedCellDbReader(std::shared_ptr<vm::CellDbReader> parent,
std::shared_ptr<std::map<td::Bits256, td::Ref<vm::Cell>>> cache)
std::shared_ptr<vm::CellHashSet> cache)
: parent_(std::move(parent)), cache_(std::move(cache)) {
}
td::Result<td::Ref<vm::DataCell>> load_cell(td::Slice hash) override {
++total_reqs_;
DCHECK(hash.size() == 32);
if (cache_) {
auto it = cache_->find(td::Bits256{(const unsigned char*)hash.data()});
auto it = cache_->find(hash);
if (it != cache_->end()) {
++cached_reqs_;
TRY_RESULT(loaded_cell, it->second->load_cell());
TRY_RESULT(loaded_cell, (*it)->load_cell());
return loaded_cell.data_cell;
}
}
@ -248,7 +249,7 @@ class CachedCellDbReader : public vm::CellDbReader {
}
private:
std::shared_ptr<vm::CellDbReader> parent_;
std::shared_ptr<std::map<td::Bits256, td::Ref<vm::Cell>>> cache_;
std::shared_ptr<vm::CellHashSet> cache_;
td::uint64 total_reqs_ = 0;
td::uint64 cached_reqs_ = 0;
@ -272,10 +273,9 @@ void AsyncStateSerializer::PreviousStateCache::prepare_cache(ShardIdFull shard)
td::Timer timer;
LOG(WARNING) << "Preloading previous persistent state for shard " << shard.to_str() << " ("
<< cur_shards.size() << " files)";
std::map<td::Bits256, td::Ref<vm::Cell>> cells;
vm::CellHashSet cells;
std::function<void(td::Ref<vm::Cell>)> dfs = [&](td::Ref<vm::Cell> cell) {
td::Bits256 hash = cell->get_hash().bits();
if (!cells.emplace(hash, cell).second) {
if (!cells.insert(cell).second) {
return;
}
bool is_special;
@ -303,7 +303,7 @@ void AsyncStateSerializer::PreviousStateCache::prepare_cache(ShardIdFull shard)
dfs(r_root.move_as_ok());
}
LOG(WARNING) << "Preloaded previous state: " << cells.size() << " cells in " << timer.elapsed() << "s";
cache = std::make_shared<std::map<td::Bits256, td::Ref<vm::Cell>>>(std::move(cells));
cache = std::make_shared<vm::CellHashSet>(std::move(cells));
}
void AsyncStateSerializer::got_masterchain_state(td::Ref<MasterchainState> state,
@ -322,15 +322,18 @@ void AsyncStateSerializer::got_masterchain_state(td::Ref<MasterchainState> state
shards_.push_back(v->top_block_id());
}
auto write_data = [shard = state->get_shard(), hash = state->root_cell()->get_hash(), cell_db_reader,
auto write_data = [shard = state->get_shard(), root = state->root_cell(), cell_db_reader,
previous_state_cache = previous_state_cache_,
fast_serializer_enabled = opts_->get_fast_state_serializer_enabled(),
cancellation_token = cancellation_token_source_.get_cancellation_token()](td::FileFd& fd) mutable {
if (!cell_db_reader) {
return vm::std_boc_serialize_to_file(root, fd, 31, std::move(cancellation_token));
}
if (fast_serializer_enabled) {
previous_state_cache->prepare_cache(shard);
}
auto new_cell_db_reader = std::make_shared<CachedCellDbReader>(cell_db_reader, previous_state_cache->cache);
auto res = vm::std_boc_serialize_to_file_large(new_cell_db_reader, hash, fd, 31, std::move(cancellation_token));
auto res = vm::std_boc_serialize_to_file_large(new_cell_db_reader, root->get_hash(), fd, 31, std::move(cancellation_token));
new_cell_db_reader->print_stats();
return res;
};
@ -384,15 +387,18 @@ void AsyncStateSerializer::got_shard_state(BlockHandle handle, td::Ref<ShardStat
return;
}
LOG(ERROR) << "serializing shard state " << handle->id().id.to_str();
auto write_data = [shard = state->get_shard(), hash = state->root_cell()->get_hash(), cell_db_reader,
auto write_data = [shard = state->get_shard(), root = state->root_cell(), cell_db_reader,
previous_state_cache = previous_state_cache_,
fast_serializer_enabled = opts_->get_fast_state_serializer_enabled(),
cancellation_token = cancellation_token_source_.get_cancellation_token()](td::FileFd& fd) mutable {
if (!cell_db_reader) {
return vm::std_boc_serialize_to_file(root, fd, 31, std::move(cancellation_token));
}
if (fast_serializer_enabled) {
previous_state_cache->prepare_cache(shard);
}
auto new_cell_db_reader = std::make_shared<CachedCellDbReader>(cell_db_reader, previous_state_cache->cache);
auto res = vm::std_boc_serialize_to_file_large(new_cell_db_reader, hash, fd, 31, std::move(cancellation_token));
auto res = vm::std_boc_serialize_to_file_large(new_cell_db_reader, root->get_hash(), fd, 31, std::move(cancellation_token));
new_cell_db_reader->print_stats();
return res;
};