1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-02-12 03:05:48 +00:00

Patch tonlib and validator-engine (#1417)

* Don't enable fast state serializer automatically

* Fix checking masterchain proof in tonlib lookupBlock
This commit is contained in:
SpyCheese 2024-12-05 18:50:12 +03:00 committed by GitHub
parent 7bc50e63d7
commit 645d26a1f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 29 deletions

View file

@ -5673,6 +5673,26 @@ td::Status TonlibClient::do_request(const tonlib_api::blocks_lookupBlock& reques
td::Status check_lookup_block_proof(lite_api_ptr<ton::lite_api::liteServer_lookupBlockResult>& result, int mode, ton::BlockId blkid, ton::BlockIdExt client_mc_blkid, td::uint64 lt, td::uint32 utime) {
try {
ton::BlockIdExt cur_id = ton::create_block_id(result->mc_block_id_);
if (!cur_id.is_masterchain_ext()) {
return td::Status::Error("invalid response: mc block id is not from masterchain");
}
if (client_mc_blkid != cur_id) {
auto state = block::check_extract_state_proof(client_mc_blkid, result->client_mc_state_proof_.as_slice(),
result->mc_block_proof_.as_slice());
if (state.is_error()) {
LOG(WARNING) << "cannot check state proof: " << state.move_as_error().to_string();
return state.move_as_error();
}
auto state_root = state.move_as_ok();
auto prev_blocks_dict = block::get_prev_blocks_dict(state_root);
if (!prev_blocks_dict) {
return td::Status::Error("cannot extract prev blocks dict from state");
}
if (!block::check_old_mc_block_id(*prev_blocks_dict, cur_id)) {
return td::Status::Error("couldn't check old mc block id");
}
}
try {
for (auto& link : result->shard_links_) {
ton::BlockIdExt prev_id = create_block_id(link->id_);
@ -5686,23 +5706,6 @@ td::Status check_lookup_block_proof(lite_api_ptr<ton::lite_api::liteServer_looku
return td::Status::Error("invalid block hash in proof");
}
if (cur_id.is_masterchain()) {
if (client_mc_blkid != cur_id) {
auto state = block::check_extract_state_proof(client_mc_blkid, result->client_mc_state_proof_.as_slice(),
result->mc_block_proof_.as_slice());
if (state.is_error()) {
LOG(WARNING) << "cannot check state proof: " << state.move_as_error().to_string();
return state.move_as_error();
}
auto state_root = state.move_as_ok();
auto prev_blocks_dict = block::get_prev_blocks_dict(state_root);
if (!prev_blocks_dict) {
return td::Status::Error("cannot extract prev blocks dict from state");
}
if (!block::check_old_mc_block_id(*prev_blocks_dict, cur_id)) {
return td::Status::Error("couldn't check old mc block id");
}
}
block::gen::Block::Record blk;
block::gen::BlockExtra::Record extra;
block::gen::McBlockExtra::Record mc_extra;

View file

@ -1503,17 +1503,6 @@ td::Status ValidatorEngine::load_global_config() {
h.push_back(b);
}
validator_options_.write().set_hardforks(std::move(h));
auto r_total_mem_stat = td::get_total_mem_stat();
if (r_total_mem_stat.is_error()) {
LOG(ERROR) << "Failed to get total RAM size: " << r_total_mem_stat.move_as_error();
} else {
td::uint64 total_ram = r_total_mem_stat.ok().total_ram;
LOG(WARNING) << "Total RAM = " << td::format::as_size(total_ram);
if (total_ram >= (90ULL << 30)) {
fast_state_serializer_enabled_ = true;
}
}
validator_options_.write().set_fast_state_serializer_enabled(fast_state_serializer_enabled_);
return td::Status::OK();
@ -4553,7 +4542,7 @@ int main(int argc, char *argv[]) {
});
p.add_option(
'\0', "fast-state-serializer",
"faster persistent state serializer, but requires more RAM (enabled automatically on machines with >= 90GB RAM)",
"faster persistent state serializer, but requires more RAM",
[&]() {
acts.push_back(
[&x]() { td::actor::send_closure(x, &ValidatorEngine::set_fast_state_serializer_enabled, true); });