Skip to content

Commit 645d26a

Browse files
authored
Patch tonlib and validator-engine (#1417)
* Don't enable fast state serializer automatically * Fix checking masterchain proof in tonlib lookupBlock
1 parent 7bc50e6 commit 645d26a

File tree

2 files changed

+21
-29
lines changed

2 files changed

+21
-29
lines changed

tonlib/tonlib/TonlibClient.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5673,6 +5673,26 @@ td::Status TonlibClient::do_request(const tonlib_api::blocks_lookupBlock& reques
56735673
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) {
56745674
try {
56755675
ton::BlockIdExt cur_id = ton::create_block_id(result->mc_block_id_);
5676+
if (!cur_id.is_masterchain_ext()) {
5677+
return td::Status::Error("invalid response: mc block id is not from masterchain");
5678+
}
5679+
if (client_mc_blkid != cur_id) {
5680+
auto state = block::check_extract_state_proof(client_mc_blkid, result->client_mc_state_proof_.as_slice(),
5681+
result->mc_block_proof_.as_slice());
5682+
if (state.is_error()) {
5683+
LOG(WARNING) << "cannot check state proof: " << state.move_as_error().to_string();
5684+
return state.move_as_error();
5685+
}
5686+
auto state_root = state.move_as_ok();
5687+
auto prev_blocks_dict = block::get_prev_blocks_dict(state_root);
5688+
if (!prev_blocks_dict) {
5689+
return td::Status::Error("cannot extract prev blocks dict from state");
5690+
}
5691+
5692+
if (!block::check_old_mc_block_id(*prev_blocks_dict, cur_id)) {
5693+
return td::Status::Error("couldn't check old mc block id");
5694+
}
5695+
}
56765696
try {
56775697
for (auto& link : result->shard_links_) {
56785698
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
56865706
return td::Status::Error("invalid block hash in proof");
56875707
}
56885708
if (cur_id.is_masterchain()) {
5689-
if (client_mc_blkid != cur_id) {
5690-
auto state = block::check_extract_state_proof(client_mc_blkid, result->client_mc_state_proof_.as_slice(),
5691-
result->mc_block_proof_.as_slice());
5692-
if (state.is_error()) {
5693-
LOG(WARNING) << "cannot check state proof: " << state.move_as_error().to_string();
5694-
return state.move_as_error();
5695-
}
5696-
auto state_root = state.move_as_ok();
5697-
auto prev_blocks_dict = block::get_prev_blocks_dict(state_root);
5698-
if (!prev_blocks_dict) {
5699-
return td::Status::Error("cannot extract prev blocks dict from state");
5700-
}
5701-
5702-
if (!block::check_old_mc_block_id(*prev_blocks_dict, cur_id)) {
5703-
return td::Status::Error("couldn't check old mc block id");
5704-
}
5705-
}
57065709
block::gen::Block::Record blk;
57075710
block::gen::BlockExtra::Record extra;
57085711
block::gen::McBlockExtra::Record mc_extra;

validator-engine/validator-engine.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,17 +1503,6 @@ td::Status ValidatorEngine::load_global_config() {
15031503
h.push_back(b);
15041504
}
15051505
validator_options_.write().set_hardforks(std::move(h));
1506-
1507-
auto r_total_mem_stat = td::get_total_mem_stat();
1508-
if (r_total_mem_stat.is_error()) {
1509-
LOG(ERROR) << "Failed to get total RAM size: " << r_total_mem_stat.move_as_error();
1510-
} else {
1511-
td::uint64 total_ram = r_total_mem_stat.ok().total_ram;
1512-
LOG(WARNING) << "Total RAM = " << td::format::as_size(total_ram);
1513-
if (total_ram >= (90ULL << 30)) {
1514-
fast_state_serializer_enabled_ = true;
1515-
}
1516-
}
15171506
validator_options_.write().set_fast_state_serializer_enabled(fast_state_serializer_enabled_);
15181507

15191508
return td::Status::OK();
@@ -4553,7 +4542,7 @@ int main(int argc, char *argv[]) {
45534542
});
45544543
p.add_option(
45554544
'\0', "fast-state-serializer",
4556-
"faster persistent state serializer, but requires more RAM (enabled automatically on machines with >= 90GB RAM)",
4545+
"faster persistent state serializer, but requires more RAM",
45574546
[&]() {
45584547
acts.push_back(
45594548
[&x]() { td::actor::send_closure(x, &ValidatorEngine::set_fast_state_serializer_enabled, true); });

0 commit comments

Comments
 (0)