mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
LS queries to nonfinal blocks (#941)
Co-authored-by: SpyCheese <mikle98@yandex.ru>
This commit is contained in:
parent
0feaaf591c
commit
9452c367e4
23 changed files with 809 additions and 150 deletions
|
@ -155,7 +155,9 @@ std::string lite_query_name_by_id(int id) {
|
|||
{lite_api::liteServer_getConfigParams::ID, "getConfigParams"},
|
||||
{lite_api::liteServer_getValidatorStats::ID, "getValidatorStats"},
|
||||
{lite_api::liteServer_getLibraries::ID, "getLibraries"},
|
||||
{lite_api::liteServer_getShardBlockProof::ID, "getShardBlockProof"}};
|
||||
{lite_api::liteServer_getShardBlockProof::ID, "getShardBlockProof"},
|
||||
{lite_api::liteServer_nonfinal_getCandidate::ID, "nonfinal.getCandidate"},
|
||||
{lite_api::liteServer_nonfinal_getValidatorGroups::ID, "nonfinal.getValidatorGroups"}};
|
||||
auto it = names.find(id);
|
||||
if (it == names.end()) {
|
||||
return "unknown";
|
||||
|
|
|
@ -60,6 +60,12 @@ liteServer.lookupBlockResult id:tonNode.blockIdExt mode:# mc_block_id:tonNode.bl
|
|||
|
||||
liteServer.debug.verbosity value:int = liteServer.debug.Verbosity;
|
||||
|
||||
liteServer.nonfinal.candidateId block_id:tonNode.blockIdExt creator:int256 collated_data_hash:int256 = liteServer.nonfinal.CandidateId;
|
||||
liteServer.nonfinal.candidate id:liteServer.nonfinal.candidateId data:bytes collated_data:bytes = liteServer.nonfinal.Candidate;
|
||||
liteServer.nonfinal.candidateInfo id:liteServer.nonfinal.candidateId available:Bool approved_weight:long signed_weight:long total_weight:long = liteServer.nonfinal.CandidateInfo;
|
||||
liteServer.nonfinal.validatorGroupInfo next_block_id:tonNode.blockId cc_seqno:int prev:(vector tonNode.blockIdExt) candidates:(vector liteServer.nonfinal.candidateInfo) = liteServer.nonfinal.ValidatorGroupInfo;
|
||||
liteServer.nonfinal.validatorGroups groups:(vector liteServer.nonfinal.validatorGroupInfo) = liteServer.nonfinal.ValidatorGroups;
|
||||
|
||||
---functions---
|
||||
|
||||
liteServer.getMasterchainInfo = liteServer.MasterchainInfo;
|
||||
|
@ -89,6 +95,9 @@ liteServer.getLibraries library_list:(vector int256) = liteServer.LibraryResult;
|
|||
liteServer.getLibrariesWithProof id:tonNode.blockIdExt mode:# library_list:(vector int256) = liteServer.LibraryResultWithProof;
|
||||
liteServer.getShardBlockProof id:tonNode.blockIdExt = liteServer.ShardBlockProof;
|
||||
|
||||
liteServer.nonfinal.getValidatorGroups mode:# wc:mode.0?int shard:mode.1?long = liteServer.nonfinal.ValidatorGroups;
|
||||
liteServer.nonfinal.getCandidate id:liteServer.nonfinal.candidateId = liteServer.nonfinal.Candidate;
|
||||
|
||||
liteServer.queryPrefix = Object;
|
||||
liteServer.query data:bytes = Object;
|
||||
liteServer.waitMasterchainSeqno seqno:int timeout_ms:int = Object; // query prefix
|
||||
|
|
Binary file not shown.
|
@ -1368,6 +1368,7 @@ td::Status ValidatorEngine::load_global_config() {
|
|||
validator_options_.write().set_max_open_archive_files(max_open_archive_files_);
|
||||
validator_options_.write().set_archive_preload_period(archive_preload_period_);
|
||||
validator_options_.write().set_disable_rocksdb_stats(disable_rocksdb_stats_);
|
||||
validator_options_.write().set_nonfinal_ls_queries_enabled(nonfinal_ls_queries_enabled_);
|
||||
|
||||
std::vector<ton::BlockIdExt> h;
|
||||
for (auto &x : conf.validator_->hardforks_) {
|
||||
|
@ -3820,6 +3821,9 @@ int main(int argc, char *argv[]) {
|
|||
p.add_option('\0', "disable-rocksdb-stats", "disable gathering rocksdb statistics (enabled by default)", [&]() {
|
||||
acts.push_back([&x]() { td::actor::send_closure(x, &ValidatorEngine::set_disable_rocksdb_stats, true); });
|
||||
});
|
||||
p.add_option('\0', "nonfinal-ls", "enable special LS queries to non-finalized blocks", [&]() {
|
||||
acts.push_back([&x]() { td::actor::send_closure(x, &ValidatorEngine::set_nonfinal_ls_queries_enabled); });
|
||||
});
|
||||
auto S = p.run(argc, argv);
|
||||
if (S.is_error()) {
|
||||
LOG(ERROR) << "failed to parse options: " << S.move_as_error();
|
||||
|
|
|
@ -207,6 +207,7 @@ class ValidatorEngine : public td::actor::Actor {
|
|||
size_t max_open_archive_files_ = 0;
|
||||
double archive_preload_period_ = 0.0;
|
||||
bool disable_rocksdb_stats_ = false;
|
||||
bool nonfinal_ls_queries_enabled_ = false;
|
||||
bool read_config_ = false;
|
||||
bool started_keyring_ = false;
|
||||
bool started_ = false;
|
||||
|
@ -276,6 +277,9 @@ class ValidatorEngine : public td::actor::Actor {
|
|||
void set_disable_rocksdb_stats(bool value) {
|
||||
disable_rocksdb_stats_ = value;
|
||||
}
|
||||
void set_nonfinal_ls_queries_enabled() {
|
||||
nonfinal_ls_queries_enabled_ = true;
|
||||
}
|
||||
void start_up() override;
|
||||
ValidatorEngine() {
|
||||
}
|
||||
|
|
|
@ -376,6 +376,15 @@ class ValidatorSessionRoundState : public ValidatorSessionDescription::RootObjec
|
|||
void dump(ValidatorSessionDescription& desc, td::StringBuilder& sb, td::uint32 att) const;
|
||||
void dump_cur_attempt(ValidatorSessionDescription& desc, td::StringBuilder& sb) const;
|
||||
|
||||
void for_each_sent_block(std::function<void(const SessionBlockCandidate*)> foo) const {
|
||||
if (!sent_blocks_) {
|
||||
return;
|
||||
}
|
||||
for (td::uint32 i = 0; i < sent_blocks_->size(); ++i) {
|
||||
foo(sent_blocks_->at(i));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const SentBlock* precommitted_block_;
|
||||
const td::uint32 seqno_;
|
||||
|
@ -516,6 +525,19 @@ class ValidatorSessionState : public ValidatorSessionDescription::RootObject {
|
|||
cur_round_->dump_cur_attempt(desc, sb);
|
||||
}
|
||||
|
||||
void for_each_cur_round_sent_block(std::function<void(const SessionBlockCandidate*)> foo) const {
|
||||
cur_round_->for_each_sent_block(std::move(foo));
|
||||
}
|
||||
|
||||
const SentBlock* get_cur_round_precommitted_block() const {
|
||||
bool found;
|
||||
return cur_round_->get_precommitted_block(found);
|
||||
}
|
||||
|
||||
const CntVector<const SessionBlockCandidateSignature*>* get_cur_round_signatures() const {
|
||||
return cur_round_->get_signatures();
|
||||
}
|
||||
|
||||
static const ValidatorSessionState* make_one(ValidatorSessionDescription& desc, const ValidatorSessionState* state,
|
||||
td::uint32 src_idx, td::uint32 att, bool& made);
|
||||
static const ValidatorSessionState* make_all(ValidatorSessionDescription& desc, const ValidatorSessionState* state,
|
||||
|
|
|
@ -929,6 +929,53 @@ void ValidatorSessionImpl::get_current_stats(td::Promise<ValidatorSessionStats>
|
|||
promise.set_result(std::move(stats));
|
||||
}
|
||||
|
||||
void ValidatorSessionImpl::get_validator_group_info_for_litequery(
|
||||
td::uint32 cur_round,
|
||||
td::Promise<std::vector<tl_object_ptr<lite_api::liteServer_nonfinal_candidateInfo>>> promise) {
|
||||
if (cur_round != cur_round_ || real_state_->cur_round_seqno() != cur_round) {
|
||||
promise.set_value({});
|
||||
return;
|
||||
}
|
||||
std::vector<tl_object_ptr<lite_api::liteServer_nonfinal_candidateInfo>> result;
|
||||
real_state_->for_each_cur_round_sent_block([&](const SessionBlockCandidate *block) {
|
||||
if (block->get_block() == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto candidate = create_tl_object<lite_api::liteServer_nonfinal_candidateInfo>();
|
||||
|
||||
candidate->id_ = create_tl_object<lite_api::liteServer_nonfinal_candidateId>();
|
||||
candidate->id_->block_id_ = create_tl_object<lite_api::tonNode_blockIdExt>();
|
||||
candidate->id_->block_id_->root_hash_ =
|
||||
block->get_block()->get_root_hash(); // other fields will be filled in validator-group.cpp
|
||||
candidate->id_->block_id_->file_hash_ = block->get_block()->get_file_hash();
|
||||
candidate->id_->creator_ =
|
||||
description().get_source_public_key(block->get_block()->get_src_idx()).ed25519_value().raw();
|
||||
candidate->id_->collated_data_hash_ = block->get_block()->get_collated_data_file_hash();
|
||||
|
||||
candidate->total_weight_ = description().get_total_weight();
|
||||
candidate->approved_weight_ = 0;
|
||||
candidate->signed_weight_ = 0;
|
||||
for (td::uint32 i = 0; i < description().get_total_nodes(); ++i) {
|
||||
if (real_state_->check_block_is_approved_by(description(), i, block->get_id())) {
|
||||
candidate->approved_weight_ += description().get_node_weight(i);
|
||||
}
|
||||
}
|
||||
auto precommited = real_state_->get_cur_round_precommitted_block();
|
||||
if (SentBlock::get_block_id(precommited) == SentBlock::get_block_id(block->get_block())) {
|
||||
auto signatures = real_state_->get_cur_round_signatures();
|
||||
if (signatures) {
|
||||
for (td::uint32 i = 0; i < description().get_total_nodes(); ++i) {
|
||||
if (signatures->at(i)) {
|
||||
candidate->signed_weight_ += description().get_node_weight(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result.push_back(std::move(candidate));
|
||||
});
|
||||
promise.set_result(std::move(result));
|
||||
}
|
||||
|
||||
void ValidatorSessionImpl::start_up() {
|
||||
CHECK(!rldp_.empty());
|
||||
cur_round_ = 0;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "catchain/catchain-types.h"
|
||||
|
||||
#include "validator-session-types.h"
|
||||
#include "auto/tl/lite_api.h"
|
||||
|
||||
namespace ton {
|
||||
|
||||
|
@ -92,6 +93,9 @@ class ValidatorSession : public td::actor::Actor {
|
|||
virtual void start() = 0;
|
||||
virtual void destroy() = 0;
|
||||
virtual void get_current_stats(td::Promise<ValidatorSessionStats> promise) = 0;
|
||||
virtual void get_validator_group_info_for_litequery(
|
||||
td::uint32 cur_round,
|
||||
td::Promise<std::vector<tl_object_ptr<lite_api::liteServer_nonfinal_candidateInfo>>> promise) = 0;
|
||||
|
||||
static td::actor::ActorOwn<ValidatorSession> create(
|
||||
catchain::CatChainSessionId session_id, ValidatorSessionOptions opts, PublicKeyHash local_id,
|
||||
|
|
|
@ -175,6 +175,9 @@ class ValidatorSessionImpl : public ValidatorSession {
|
|||
void start() override;
|
||||
void destroy() override;
|
||||
void get_current_stats(td::Promise<ValidatorSessionStats> promise) override;
|
||||
void get_validator_group_info_for_litequery(
|
||||
td::uint32 cur_round,
|
||||
td::Promise<std::vector<tl_object_ptr<lite_api::liteServer_nonfinal_candidateInfo>>> promise) override;
|
||||
|
||||
void process_blocks(std::vector<catchain::CatChainBlock *> blocks);
|
||||
void finished_processing();
|
||||
|
|
|
@ -7,6 +7,7 @@ endif()
|
|||
set(TON_VALIDATOR_SOURCE
|
||||
accept-block.cpp
|
||||
block.cpp
|
||||
candidates-buffer.cpp
|
||||
check-proof.cpp
|
||||
collator.cpp
|
||||
config.cpp
|
||||
|
@ -24,6 +25,7 @@ set(TON_VALIDATOR_SOURCE
|
|||
|
||||
accept-block.hpp
|
||||
block.hpp
|
||||
candidates-buffer.hpp
|
||||
check-proof.hpp
|
||||
collate-query-impl.h
|
||||
collator-impl.h
|
||||
|
|
213
validator/impl/candidates-buffer.cpp
Normal file
213
validator/impl/candidates-buffer.cpp
Normal file
|
@ -0,0 +1,213 @@
|
|||
/*
|
||||
This file is part of TON Blockchain Library.
|
||||
|
||||
TON Blockchain Library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TON Blockchain Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "candidates-buffer.hpp"
|
||||
#include "fabric.h"
|
||||
|
||||
namespace ton::validator {
|
||||
|
||||
void CandidatesBuffer::start_up() {
|
||||
alarm_timestamp() = td::Timestamp::in(60.0);
|
||||
}
|
||||
|
||||
void CandidatesBuffer::alarm() {
|
||||
alarm_timestamp() = td::Timestamp::in(60.0);
|
||||
for (auto it = candidates_.begin(); it != candidates_.end();) {
|
||||
Candidate &entry = it->second;
|
||||
if (entry.ttl_.is_in_past()) {
|
||||
for (auto &p : entry.data_waiters_) {
|
||||
p.set_error(td::Status::Error(ErrorCode::timeout, "timeout"));
|
||||
}
|
||||
for (auto &p : entry.state_waiters_) {
|
||||
p.set_error(td::Status::Error(ErrorCode::timeout, "timeout"));
|
||||
}
|
||||
it = candidates_.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CandidatesBuffer::add_new_candidate(BlockIdExt id, PublicKey source, FileHash collated_data_file_hash) {
|
||||
auto it = candidates_.emplace(id, Candidate{});
|
||||
Candidate &entry = it.first->second;
|
||||
entry.ttl_ = td::Timestamp::in(120.0);
|
||||
if (!it.second) { // not inserted
|
||||
return;
|
||||
}
|
||||
LOG(DEBUG) << "New block candidate " << id.to_str();
|
||||
entry.source_ = source;
|
||||
entry.collated_data_file_hash_ = collated_data_file_hash;
|
||||
}
|
||||
|
||||
void CandidatesBuffer::get_block_data(BlockIdExt id, td::Promise<td::Ref<BlockData>> promise) {
|
||||
auto it = candidates_.find(id);
|
||||
if (it == candidates_.end()) {
|
||||
promise.set_error(td::Status::Error(ErrorCode::notready, "unknown block candidate"));
|
||||
return;
|
||||
}
|
||||
Candidate &entry = it->second;
|
||||
if (entry.data_.not_null()) {
|
||||
promise.set_result(entry.data_);
|
||||
return;
|
||||
}
|
||||
entry.data_waiters_.push_back(std::move(promise));
|
||||
if (entry.data_requested_) {
|
||||
return;
|
||||
}
|
||||
entry.data_requested_ = true;
|
||||
td::actor::send_closure(manager_, &ValidatorManager::get_block_candidate_from_db, entry.source_, id,
|
||||
entry.collated_data_file_hash_, [SelfId = actor_id(this), id](td::Result<BlockCandidate> R) {
|
||||
td::actor::send_closure(SelfId, &CandidatesBuffer::got_block_candidate, id, std::move(R));
|
||||
});
|
||||
}
|
||||
|
||||
void CandidatesBuffer::got_block_candidate(BlockIdExt id, td::Result<BlockCandidate> R) {
|
||||
if (R.is_error()) {
|
||||
finish_get_block_data(id, R.move_as_error());
|
||||
return;
|
||||
}
|
||||
BlockCandidate cand = R.move_as_ok();
|
||||
CHECK(cand.id == id);
|
||||
finish_get_block_data(id, create_block(id, std::move(cand.data)));
|
||||
}
|
||||
|
||||
void CandidatesBuffer::get_block_state(BlockIdExt id, td::Promise<td::Ref<ShardState>> promise) {
|
||||
auto it = candidates_.find(id);
|
||||
if (it == candidates_.end()) {
|
||||
promise.set_error(td::Status::Error(ErrorCode::notready, "unknown block candidate"));
|
||||
return;
|
||||
}
|
||||
Candidate &entry = it->second;
|
||||
if (entry.state_.not_null()) {
|
||||
promise.set_result(entry.state_);
|
||||
return;
|
||||
}
|
||||
entry.state_waiters_.push_back(std::move(promise));
|
||||
if (entry.state_requested_) {
|
||||
return;
|
||||
}
|
||||
entry.state_requested_ = true;
|
||||
get_block_data(id, [SelfId = actor_id(this), id](td::Result<td::Ref<BlockData>> R) {
|
||||
if (R.is_error()) {
|
||||
td::actor::send_closure(SelfId, &CandidatesBuffer::finish_get_block_state, id, R.move_as_error());
|
||||
return;
|
||||
}
|
||||
td::actor::send_closure(SelfId, &CandidatesBuffer::get_block_state_cont, id, R.move_as_ok());
|
||||
});
|
||||
}
|
||||
|
||||
void CandidatesBuffer::get_block_state_cont(BlockIdExt id, td::Ref<BlockData> data) {
|
||||
CHECK(id == data->block_id());
|
||||
std::vector<BlockIdExt> prev;
|
||||
BlockIdExt mc_blkid;
|
||||
bool after_split;
|
||||
auto S = block::unpack_block_prev_blk_ext(data->root_cell(), id, prev, mc_blkid, after_split);
|
||||
if (S.is_error()) {
|
||||
finish_get_block_state(id, std::move(S));
|
||||
return;
|
||||
}
|
||||
get_block_state_cont2(std::move(data), std::move(prev), {});
|
||||
}
|
||||
|
||||
void CandidatesBuffer::get_block_state_cont2(td::Ref<BlockData> block, std::vector<BlockIdExt> prev,
|
||||
std::vector<td::Ref<ShardState>> prev_states) {
|
||||
if (prev_states.size() < prev.size()) {
|
||||
BlockIdExt prev_id = prev[prev_states.size()];
|
||||
td::actor::send_closure(manager_, &ValidatorManager::get_shard_state_from_db_short, prev_id,
|
||||
[SelfId = actor_id(this), block = std::move(block), prev = std::move(prev),
|
||||
prev_states = std::move(prev_states)](td::Result<td::Ref<ShardState>> R) mutable {
|
||||
if (R.is_error()) {
|
||||
td::actor::send_closure(SelfId, &CandidatesBuffer::finish_get_block_state,
|
||||
block->block_id(), R.move_as_error());
|
||||
return;
|
||||
}
|
||||
prev_states.push_back(R.move_as_ok());
|
||||
td::actor::send_closure(SelfId, &CandidatesBuffer::get_block_state_cont2,
|
||||
std::move(block), std::move(prev), std::move(prev_states));
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
BlockIdExt id = block->block_id();
|
||||
td::Ref<ShardState> state;
|
||||
CHECK(prev_states.size() == 1 || prev_states.size() == 2);
|
||||
if (prev_states.size() == 2) { // after merge
|
||||
auto R = prev_states[0]->merge_with(*prev_states[1]);
|
||||
if (R.is_error()) {
|
||||
finish_get_block_state(id, R.move_as_error());
|
||||
return;
|
||||
}
|
||||
state = R.move_as_ok();
|
||||
} else if (id.shard_full() != prev[0].shard_full()) { // after split
|
||||
auto R = prev_states[0]->split();
|
||||
if (R.is_error()) {
|
||||
finish_get_block_state(id, R.move_as_error());
|
||||
return;
|
||||
}
|
||||
auto s = R.move_as_ok();
|
||||
state = is_left_child(id.shard_full()) ? std::move(s.first) : std::move(s.second);
|
||||
} else { // no split/merge
|
||||
state = std::move(prev_states[0]);
|
||||
}
|
||||
|
||||
auto S = state.write().apply_block(id, std::move(block));
|
||||
if (S.is_error()) {
|
||||
finish_get_block_state(id, std::move(S));
|
||||
return;
|
||||
}
|
||||
finish_get_block_state(id, std::move(state));
|
||||
}
|
||||
|
||||
void CandidatesBuffer::finish_get_block_data(BlockIdExt id, td::Result<td::Ref<BlockData>> res) {
|
||||
auto it = candidates_.find(id);
|
||||
if (it == candidates_.end()) {
|
||||
return;
|
||||
}
|
||||
Candidate &entry = it->second;
|
||||
for (auto &p : entry.data_waiters_) {
|
||||
p.set_result(res.clone());
|
||||
}
|
||||
entry.data_waiters_.clear();
|
||||
entry.data_requested_ = false;
|
||||
if (res.is_ok()) {
|
||||
entry.data_ = res.move_as_ok();
|
||||
LOG(DEBUG) << "Loaded block data for " << id.to_str();
|
||||
} else {
|
||||
LOG(DEBUG) << "Failed to load block data for " << id.to_str() << ": " << res.move_as_error();
|
||||
}
|
||||
}
|
||||
|
||||
void CandidatesBuffer::finish_get_block_state(BlockIdExt id, td::Result<td::Ref<ShardState>> res) {
|
||||
auto it = candidates_.find(id);
|
||||
if (it == candidates_.end()) {
|
||||
return;
|
||||
}
|
||||
Candidate &entry = it->second;
|
||||
for (auto &p : entry.state_waiters_) {
|
||||
p.set_result(res.clone());
|
||||
}
|
||||
entry.state_waiters_.clear();
|
||||
entry.state_requested_ = false;
|
||||
if (res.is_ok()) {
|
||||
entry.state_ = res.move_as_ok();
|
||||
LOG(DEBUG) << "Loaded block state for " << id.to_str();
|
||||
} else {
|
||||
LOG(DEBUG) << "Failed to load block state for " << id.to_str() << ": " << res.move_as_error();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ton::validator
|
64
validator/impl/candidates-buffer.hpp
Normal file
64
validator/impl/candidates-buffer.hpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
This file is part of TON Blockchain Library.
|
||||
|
||||
TON Blockchain Library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TON Blockchain Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include "ton/ton-types.h"
|
||||
#include "td/actor/actor.h"
|
||||
#include "interfaces/validator-manager.h"
|
||||
|
||||
namespace ton::validator {
|
||||
|
||||
class CandidatesBuffer : public td::actor::Actor {
|
||||
public:
|
||||
explicit CandidatesBuffer(td::actor::ActorId<ValidatorManager> manager) : manager_(std::move(manager)) {
|
||||
}
|
||||
|
||||
void start_up() override;
|
||||
void alarm() override;
|
||||
|
||||
void add_new_candidate(BlockIdExt id, PublicKey source, FileHash collated_data_file_hash);
|
||||
void get_block_data(BlockIdExt id, td::Promise<td::Ref<BlockData>> promise);
|
||||
void get_block_state(BlockIdExt id, td::Promise<td::Ref<ShardState>> promise);
|
||||
|
||||
private:
|
||||
td::actor::ActorId<ValidatorManager> manager_;
|
||||
|
||||
struct Candidate {
|
||||
PublicKey source_;
|
||||
FileHash collated_data_file_hash_;
|
||||
td::Timestamp ttl_;
|
||||
|
||||
td::Ref<BlockData> data_;
|
||||
std::vector<td::Promise<td::Ref<BlockData>>> data_waiters_;
|
||||
bool data_requested_{false};
|
||||
|
||||
td::Ref<ShardState> state_;
|
||||
std::vector<td::Promise<td::Ref<ShardState>>> state_waiters_;
|
||||
bool state_requested_{false};
|
||||
};
|
||||
std::map<BlockIdExt, Candidate> candidates_;
|
||||
|
||||
void got_block_candidate(BlockIdExt id, td::Result<BlockCandidate> R);
|
||||
|
||||
void get_block_state_cont(BlockIdExt id, td::Ref<BlockData> data);
|
||||
void get_block_state_cont2(td::Ref<BlockData> block, std::vector<BlockIdExt> prev,
|
||||
std::vector<td::Ref<ShardState>> prev_states);
|
||||
|
||||
void finish_get_block_data(BlockIdExt id, td::Result<td::Ref<BlockData>> res);
|
||||
void finish_get_block_state(BlockIdExt id, td::Result<td::Ref<ShardState>> res);
|
||||
};
|
||||
|
||||
} // namespace ton::validator
|
|
@ -275,6 +275,13 @@ void LiteQuery::perform() {
|
|||
[&](lite_api::liteServer_getShardBlockProof& q) {
|
||||
this->perform_getShardBlockProof(create_block_id(q.id_));
|
||||
},
|
||||
[&](lite_api::liteServer_nonfinal_getCandidate& q) {
|
||||
this->perform_nonfinal_getCandidate(q.id_->creator_, create_block_id(q.id_->block_id_),
|
||||
q.id_->collated_data_hash_);
|
||||
},
|
||||
[&](lite_api::liteServer_nonfinal_getValidatorGroups& q) {
|
||||
this->perform_nonfinal_getValidatorGroups(q.mode_, ShardIdFull{q.wc_, (ShardId)q.shard_});
|
||||
},
|
||||
[&](auto& obj) { this->abort_query(td::Status::Error(ErrorCode::protoviolation, "unknown query")); }));
|
||||
}
|
||||
|
||||
|
@ -343,21 +350,15 @@ void LiteQuery::perform_getBlock(BlockIdExt blkid) {
|
|||
fatal_error("invalid BlockIdExt");
|
||||
return;
|
||||
}
|
||||
get_block_handle_checked(blkid, [manager = manager_, Self = actor_id(this), blkid](td::Result<ConstBlockHandle> R) {
|
||||
if (R.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query, R.move_as_error());
|
||||
return;
|
||||
}
|
||||
td::actor::send_closure_later(manager, &ValidatorManager::get_block_data_from_db, R.move_as_ok(),
|
||||
[=](td::Result<Ref<ton::validator::BlockData>> res) {
|
||||
if (res.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
|
||||
} else {
|
||||
td::actor::send_closure_later(Self, &LiteQuery::continue_getBlock, blkid,
|
||||
res.move_as_ok());
|
||||
}
|
||||
});
|
||||
});
|
||||
td::actor::send_closure(manager_, &ValidatorManager::get_block_data_for_litequery, blkid,
|
||||
[Self = actor_id(this), blkid](td::Result<Ref<ton::validator::BlockData>> res) {
|
||||
if (res.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
|
||||
} else {
|
||||
td::actor::send_closure_later(Self, &LiteQuery::continue_getBlock, blkid,
|
||||
res.move_as_ok());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void LiteQuery::continue_getBlock(BlockIdExt blkid, Ref<ton::validator::BlockData> block) {
|
||||
|
@ -375,21 +376,15 @@ void LiteQuery::perform_getBlockHeader(BlockIdExt blkid, int mode) {
|
|||
fatal_error("invalid BlockIdExt");
|
||||
return;
|
||||
}
|
||||
get_block_handle_checked(blkid, [=, manager = manager_, Self = actor_id(this)](td::Result<ConstBlockHandle> R) {
|
||||
if (R.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query, R.move_as_error());
|
||||
return;
|
||||
}
|
||||
td::actor::send_closure_later(manager, &ValidatorManager::get_block_data_from_db, R.move_as_ok(),
|
||||
[=](td::Result<Ref<ton::validator::BlockData>> res) {
|
||||
if (res.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
|
||||
} else {
|
||||
td::actor::send_closure_later(Self, &LiteQuery::continue_getBlockHeader, blkid,
|
||||
mode, res.move_as_ok());
|
||||
}
|
||||
});
|
||||
});
|
||||
td::actor::send_closure(manager_, &ValidatorManager::get_block_data_for_litequery, blkid,
|
||||
[Self = actor_id(this), blkid, mode](td::Result<Ref<ton::validator::BlockData>> res) {
|
||||
if (res.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
|
||||
} else {
|
||||
td::actor::send_closure_later(Self, &LiteQuery::continue_getBlockHeader, blkid, mode,
|
||||
res.move_as_ok());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static bool visit(Ref<vm::Cell> cell);
|
||||
|
@ -495,33 +490,27 @@ void LiteQuery::perform_getState(BlockIdExt blkid) {
|
|||
fatal_error("cannot request total state: possibly too large");
|
||||
return;
|
||||
}
|
||||
get_block_handle_checked(blkid, [=, manager = manager_, Self = actor_id(this)](td::Result<ConstBlockHandle> R) {
|
||||
if (R.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query, R.move_as_error());
|
||||
return;
|
||||
}
|
||||
if (blkid.id.seqno) {
|
||||
td::actor::send_closure_later(manager, &ValidatorManager::get_shard_state_from_db, R.move_as_ok(),
|
||||
[=](td::Result<Ref<ton::validator::ShardState>> res) {
|
||||
if (res.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
|
||||
} else {
|
||||
td::actor::send_closure_later(Self, &LiteQuery::continue_getState, blkid,
|
||||
res.move_as_ok());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
td::actor::send_closure_later(manager, &ValidatorManager::get_zero_state, blkid,
|
||||
[=](td::Result<td::BufferSlice> res) {
|
||||
if (res.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
|
||||
} else {
|
||||
td::actor::send_closure_later(Self, &LiteQuery::continue_getZeroState, blkid,
|
||||
res.move_as_ok());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (blkid.id.seqno) {
|
||||
td::actor::send_closure(manager_, &ValidatorManager::get_block_state_for_litequery, blkid,
|
||||
[Self = actor_id(this), blkid](td::Result<Ref<ShardState>> res) {
|
||||
if (res.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
|
||||
} else {
|
||||
td::actor::send_closure_later(Self, &LiteQuery::continue_getState, blkid,
|
||||
res.move_as_ok());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
td::actor::send_closure_later(manager_, &ValidatorManager::get_zero_state, blkid,
|
||||
[Self = actor_id(this), blkid](td::Result<td::BufferSlice> res) {
|
||||
if (res.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
|
||||
} else {
|
||||
td::actor::send_closure_later(Self, &LiteQuery::continue_getZeroState, blkid,
|
||||
res.move_as_ok());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void LiteQuery::continue_getState(BlockIdExt blkid, Ref<ton::validator::ShardState> state) {
|
||||
|
@ -583,7 +572,7 @@ bool LiteQuery::request_mc_block_data(BlockIdExt blkid) {
|
|||
base_blk_id_ = blkid;
|
||||
++pending_;
|
||||
td::actor::send_closure_later(
|
||||
manager_, &ValidatorManager::get_block_data_from_db_short, blkid,
|
||||
manager_, &ValidatorManager::get_block_data_for_litequery, blkid,
|
||||
[Self = actor_id(this), blkid](td::Result<Ref<BlockData>> res) {
|
||||
if (res.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query,
|
||||
|
@ -641,7 +630,7 @@ bool LiteQuery::request_mc_block_state(BlockIdExt blkid) {
|
|||
base_blk_id_ = blkid;
|
||||
++pending_;
|
||||
td::actor::send_closure_later(
|
||||
manager_, &ValidatorManager::get_shard_state_from_db_short, blkid,
|
||||
manager_, &ValidatorManager::get_block_state_for_litequery, blkid,
|
||||
[Self = actor_id(this), blkid](td::Result<Ref<ShardState>> res) {
|
||||
if (res.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query,
|
||||
|
@ -671,22 +660,16 @@ bool LiteQuery::request_block_state(BlockIdExt blkid) {
|
|||
}
|
||||
blk_id_ = blkid;
|
||||
++pending_;
|
||||
get_block_handle_checked(blkid, [=, manager = manager_, Self = actor_id(this)](td::Result<ConstBlockHandle> R) {
|
||||
if (R.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query, R.move_as_error());
|
||||
return;
|
||||
}
|
||||
td::actor::send_closure_later(
|
||||
manager, &ValidatorManager::get_shard_state_from_db, R.move_as_ok(),
|
||||
[=](td::Result<Ref<ShardState>> res) {
|
||||
if (res.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query,
|
||||
res.move_as_error_prefix("cannot load state for "s + blkid.to_str() + " : "));
|
||||
} else {
|
||||
td::actor::send_closure_later(Self, &LiteQuery::got_block_state, blkid, res.move_as_ok());
|
||||
}
|
||||
});
|
||||
});
|
||||
td::actor::send_closure(manager_, &ValidatorManager::get_block_state_for_litequery, blkid,
|
||||
[Self = actor_id(this), blkid](td::Result<Ref<ShardState>> res) {
|
||||
if (res.is_error()) {
|
||||
td::actor::send_closure(
|
||||
Self, &LiteQuery::abort_query,
|
||||
res.move_as_error_prefix("cannot load state for "s + blkid.to_str() + " : "));
|
||||
} else {
|
||||
td::actor::send_closure_later(Self, &LiteQuery::got_block_state, blkid, res.move_as_ok());
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -699,22 +682,16 @@ bool LiteQuery::request_block_data(BlockIdExt blkid) {
|
|||
}
|
||||
blk_id_ = blkid;
|
||||
++pending_;
|
||||
get_block_handle_checked(blkid, [=, manager = manager_, Self = actor_id(this)](td::Result<ConstBlockHandle> R) {
|
||||
if (R.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query, R.move_as_error());
|
||||
return;
|
||||
}
|
||||
td::actor::send_closure_later(
|
||||
manager, &ValidatorManager::get_block_data_from_db, R.move_as_ok(),
|
||||
[=](td::Result<Ref<BlockData>> res) {
|
||||
if (res.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query,
|
||||
res.move_as_error_prefix("cannot load block "s + blkid.to_str() + " : "));
|
||||
} else {
|
||||
td::actor::send_closure_later(Self, &LiteQuery::got_block_data, blkid, res.move_as_ok());
|
||||
}
|
||||
});
|
||||
});
|
||||
td::actor::send_closure(manager_, &ValidatorManager::get_block_data_for_litequery, blkid,
|
||||
[Self = actor_id(this), blkid](td::Result<Ref<BlockData>> res) {
|
||||
if (res.is_error()) {
|
||||
td::actor::send_closure(
|
||||
Self, &LiteQuery::abort_query,
|
||||
res.move_as_error_prefix("cannot load block "s + blkid.to_str() + " : "));
|
||||
} else {
|
||||
td::actor::send_closure_later(Self, &LiteQuery::got_block_data, blkid, res.move_as_ok());
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1712,7 +1689,7 @@ void LiteQuery::continue_getTransactions(unsigned remaining, bool exact) {
|
|||
LOG(DEBUG) << "sending get_block_by_lt_from_db() query to manager for " << acc_workchain_ << ":" << acc_addr_.to_hex()
|
||||
<< " " << trans_lt_;
|
||||
td::actor::send_closure_later(
|
||||
manager_, &ValidatorManager::get_block_by_lt_from_db_for_litequery, ton::extract_addr_prefix(acc_workchain_, acc_addr_),
|
||||
manager_, &ValidatorManager::get_block_by_lt_for_litequery, ton::extract_addr_prefix(acc_workchain_, acc_addr_),
|
||||
trans_lt_, [Self = actor_id(this), remaining, manager = manager_](td::Result<ConstBlockHandle> res) {
|
||||
if (res.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_getTransactions, res.move_as_error(), ton::BlockIdExt{});
|
||||
|
@ -2088,11 +2065,13 @@ void LiteQuery::perform_lookupBlockWithProof(BlockId blkid, BlockIdExt mc_blkid,
|
|||
});
|
||||
|
||||
if (mode & 2) {
|
||||
td::actor::send_closure_later(manager_, &ValidatorManager::get_block_by_lt_from_db_for_litequery, pfx, lt, std::move(P));
|
||||
td::actor::send_closure_later(manager_, &ValidatorManager::get_block_by_lt_for_litequery, pfx, lt, std::move(P));
|
||||
} else if (mode & 4) {
|
||||
td::actor::send_closure_later(manager_, &ValidatorManager::get_block_by_unix_time_from_db_for_litequery, pfx, utime, std::move(P));
|
||||
td::actor::send_closure_later(manager_, &ValidatorManager::get_block_by_unix_time_for_litequery, pfx, utime,
|
||||
std::move(P));
|
||||
} else {
|
||||
td::actor::send_closure_later(manager_, &ValidatorManager::get_block_by_seqno_from_db_for_litequery, pfx, blkid.seqno, std::move(P));
|
||||
td::actor::send_closure_later(manager_, &ValidatorManager::get_block_by_seqno_for_litequery, pfx, blkid.seqno,
|
||||
std::move(P));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2368,13 +2347,13 @@ void LiteQuery::perform_lookupBlock(BlockId blkid, int mode, LogicalTime lt, Uni
|
|||
|
||||
ton::AccountIdPrefixFull pfx{blkid.workchain, blkid.shard};
|
||||
if (mode & 2) {
|
||||
td::actor::send_closure_later(manager_, &ValidatorManager::get_block_by_lt_from_db_for_litequery, pfx, lt,
|
||||
td::actor::send_closure_later(manager_, &ValidatorManager::get_block_by_lt_for_litequery, pfx, lt,
|
||||
std::move(P));
|
||||
} else if (mode & 4) {
|
||||
td::actor::send_closure_later(manager_, &ValidatorManager::get_block_by_unix_time_from_db_for_litequery, pfx, utime,
|
||||
td::actor::send_closure_later(manager_, &ValidatorManager::get_block_by_unix_time_for_litequery, pfx, utime,
|
||||
std::move(P));
|
||||
} else {
|
||||
td::actor::send_closure_later(manager_, &ValidatorManager::get_block_by_seqno_from_db_for_litequery, pfx,
|
||||
td::actor::send_closure_later(manager_, &ValidatorManager::get_block_by_seqno_for_litequery, pfx,
|
||||
blkid.seqno, std::move(P));
|
||||
}
|
||||
}
|
||||
|
@ -3133,7 +3112,7 @@ void LiteQuery::perform_getShardBlockProof(BlockIdExt blkid) {
|
|||
}
|
||||
AccountIdPrefixFull pfx{masterchainId, shardIdAll};
|
||||
td::actor::send_closure_later(
|
||||
manager, &ValidatorManager::get_block_by_seqno_from_db_for_litequery, pfx, handle->masterchain_ref_block(),
|
||||
manager, &ValidatorManager::get_block_by_seqno_for_litequery, pfx, handle->masterchain_ref_block(),
|
||||
[Self, manager](td::Result<ConstBlockHandle> R) {
|
||||
if (R.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query, R.move_as_error());
|
||||
|
@ -3237,5 +3216,45 @@ void LiteQuery::continue_getShardBlockProof(Ref<BlockData> cur_block,
|
|||
});
|
||||
}
|
||||
|
||||
void LiteQuery::perform_nonfinal_getCandidate(td::Bits256 source, BlockIdExt blkid, td::Bits256 collated_data_hash) {
|
||||
LOG(INFO) << "started a nonfinal.getCandidate liteserver query";
|
||||
td::actor::send_closure_later(
|
||||
manager_, &ValidatorManager::get_block_candidate_for_litequery, PublicKey{pubkeys::Ed25519{source}}, blkid, collated_data_hash,
|
||||
[Self = actor_id(this)](td::Result<BlockCandidate> R) {
|
||||
if (R.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query, R.move_as_error());
|
||||
} else {
|
||||
BlockCandidate cand = R.move_as_ok();
|
||||
td::actor::send_closure_later(
|
||||
Self, &LiteQuery::finish_query,
|
||||
create_serialize_tl_object<lite_api::liteServer_nonfinal_candidate>(
|
||||
create_tl_object<lite_api::liteServer_nonfinal_candidateId>(
|
||||
create_tl_lite_block_id(cand.id), cand.pubkey.as_bits256(), cand.collated_file_hash),
|
||||
std::move(cand.data), std::move(cand.collated_data)),
|
||||
false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void LiteQuery::perform_nonfinal_getValidatorGroups(int mode, ShardIdFull shard) {
|
||||
bool with_shard = mode & 1;
|
||||
LOG(INFO) << "started a nonfinal.getValidatorGroups" << (with_shard ? shard.to_str() : "(all)")
|
||||
<< " liteserver query";
|
||||
td::optional<ShardIdFull> maybe_shard;
|
||||
if (with_shard) {
|
||||
maybe_shard = shard;
|
||||
}
|
||||
td::actor::send_closure(
|
||||
manager_, &ValidatorManager::get_validator_groups_info_for_litequery, maybe_shard,
|
||||
[Self = actor_id(this)](td::Result<tl_object_ptr<lite_api::liteServer_nonfinal_validatorGroups>> R) {
|
||||
if (R.is_error()) {
|
||||
td::actor::send_closure(Self, &LiteQuery::abort_query, R.move_as_error());
|
||||
} else {
|
||||
td::actor::send_closure_later(Self, &LiteQuery::finish_query, serialize_tl_object(R.move_as_ok(), true),
|
||||
false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace validator
|
||||
} // namespace ton
|
||||
|
|
|
@ -168,6 +168,8 @@ class LiteQuery : public td::actor::Actor {
|
|||
void perform_getShardBlockProof(BlockIdExt blkid);
|
||||
void continue_getShardBlockProof(Ref<BlockData> cur_block,
|
||||
std::vector<std::pair<BlockIdExt, td::BufferSlice>> result);
|
||||
void perform_nonfinal_getCandidate(td::Bits256 source, BlockIdExt blkid, td::Bits256 collated_data_hash);
|
||||
void perform_nonfinal_getValidatorGroups(int mode, ShardIdFull shard);
|
||||
|
||||
void load_prevKeyBlock(ton::BlockIdExt blkid, td::Promise<std::pair<BlockIdExt, Ref<BlockQ>>>);
|
||||
void continue_loadPrevKeyBlock(ton::BlockIdExt blkid, td::Result<std::pair<Ref<MasterchainState>, BlockIdExt>> res,
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "liteserver.h"
|
||||
#include "crypto/vm/db/DynamicBagOfCellsDb.h"
|
||||
#include "validator-session/validator-session-types.h"
|
||||
#include "auto/tl/lite_api.h"
|
||||
|
||||
namespace ton {
|
||||
|
||||
|
@ -171,12 +172,19 @@ class ValidatorManager : public ValidatorManagerInterface {
|
|||
virtual void log_validator_session_stats(BlockIdExt block_id, validatorsession::ValidatorSessionStats stats) = 0;
|
||||
|
||||
virtual void get_block_handle_for_litequery(BlockIdExt block_id, td::Promise<ConstBlockHandle> promise) = 0;
|
||||
virtual void get_block_by_lt_from_db_for_litequery(AccountIdPrefixFull account, LogicalTime lt,
|
||||
td::Promise<ConstBlockHandle> promise) = 0;
|
||||
virtual void get_block_by_unix_time_from_db_for_litequery(AccountIdPrefixFull account, UnixTime ts,
|
||||
td::Promise<ConstBlockHandle> promise) = 0;
|
||||
virtual void get_block_by_seqno_from_db_for_litequery(AccountIdPrefixFull account, BlockSeqno seqno,
|
||||
td::Promise<ConstBlockHandle> promise) = 0;
|
||||
virtual void get_block_data_for_litequery(BlockIdExt block_id, td::Promise<td::Ref<BlockData>> promise) = 0;
|
||||
virtual void get_block_state_for_litequery(BlockIdExt block_id, td::Promise<td::Ref<ShardState>> promise) = 0;
|
||||
virtual void get_block_by_lt_for_litequery(AccountIdPrefixFull account, LogicalTime lt,
|
||||
td::Promise<ConstBlockHandle> promise) = 0;
|
||||
virtual void get_block_by_unix_time_for_litequery(AccountIdPrefixFull account, UnixTime ts,
|
||||
td::Promise<ConstBlockHandle> promise) = 0;
|
||||
virtual void get_block_by_seqno_for_litequery(AccountIdPrefixFull account, BlockSeqno seqno,
|
||||
td::Promise<ConstBlockHandle> promise) = 0;
|
||||
virtual void get_block_candidate_for_litequery(PublicKey source, BlockIdExt block_id, FileHash collated_data_hash,
|
||||
td::Promise<BlockCandidate> promise) = 0;
|
||||
virtual void get_validator_groups_info_for_litequery(
|
||||
td::optional<ShardIdFull> shard,
|
||||
td::Promise<tl_object_ptr<lite_api::liteServer_nonfinal_validatorGroups>> promise) = 0;
|
||||
|
||||
virtual void add_lite_query_stats(int lite_query_id) {
|
||||
}
|
||||
|
|
|
@ -387,18 +387,33 @@ class ValidatorManagerImpl : public ValidatorManager {
|
|||
void get_block_handle_for_litequery(BlockIdExt block_id, td::Promise<ConstBlockHandle> promise) override {
|
||||
get_block_handle(block_id, false, promise.wrap([](BlockHandle &&handle) -> ConstBlockHandle { return handle; }));
|
||||
}
|
||||
void get_block_by_lt_from_db_for_litequery(AccountIdPrefixFull account, LogicalTime lt,
|
||||
void get_block_data_for_litequery(BlockIdExt block_id, td::Promise<td::Ref<BlockData>> promise) override {
|
||||
get_block_data_from_db_short(block_id, std::move(promise));
|
||||
}
|
||||
void get_block_state_for_litequery(BlockIdExt block_id, td::Promise<td::Ref<ShardState>> promise) override {
|
||||
get_shard_state_from_db_short(block_id, std::move(promise));
|
||||
}
|
||||
void get_block_by_lt_for_litequery(AccountIdPrefixFull account, LogicalTime lt,
|
||||
td::Promise<ConstBlockHandle> promise) override {
|
||||
get_block_by_lt_from_db(account, lt, std::move(promise));
|
||||
}
|
||||
void get_block_by_unix_time_from_db_for_litequery(AccountIdPrefixFull account, UnixTime ts,
|
||||
void get_block_by_unix_time_for_litequery(AccountIdPrefixFull account, UnixTime ts,
|
||||
td::Promise<ConstBlockHandle> promise) override {
|
||||
get_block_by_unix_time_from_db(account, ts, std::move(promise));
|
||||
}
|
||||
void get_block_by_seqno_from_db_for_litequery(AccountIdPrefixFull account, BlockSeqno seqno,
|
||||
void get_block_by_seqno_for_litequery(AccountIdPrefixFull account, BlockSeqno seqno,
|
||||
td::Promise<ConstBlockHandle> promise) override {
|
||||
get_block_by_seqno_from_db(account, seqno, std::move(promise));
|
||||
}
|
||||
void get_block_candidate_for_litequery(PublicKey source, BlockIdExt block_id, FileHash collated_data_hash,
|
||||
td::Promise<BlockCandidate> promise) override {
|
||||
promise.set_result(td::Status::Error("not implemented"));
|
||||
}
|
||||
void get_validator_groups_info_for_litequery(
|
||||
td::optional<ShardIdFull> shard,
|
||||
td::Promise<tl_object_ptr<lite_api::liteServer_nonfinal_validatorGroups>> promise) override {
|
||||
promise.set_result(td::Status::Error("not implemented"));
|
||||
}
|
||||
|
||||
private:
|
||||
PublicKeyHash local_id_;
|
||||
|
|
|
@ -448,18 +448,33 @@ class ValidatorManagerImpl : public ValidatorManager {
|
|||
void get_block_handle_for_litequery(BlockIdExt block_id, td::Promise<ConstBlockHandle> promise) override {
|
||||
get_block_handle(block_id, false, promise.wrap([](BlockHandle &&handle) -> ConstBlockHandle { return handle; }));
|
||||
}
|
||||
void get_block_by_lt_from_db_for_litequery(AccountIdPrefixFull account, LogicalTime lt,
|
||||
void get_block_data_for_litequery(BlockIdExt block_id, td::Promise<td::Ref<BlockData>> promise) override {
|
||||
get_block_data_from_db_short(block_id, std::move(promise));
|
||||
}
|
||||
void get_block_state_for_litequery(BlockIdExt block_id, td::Promise<td::Ref<ShardState>> promise) override {
|
||||
get_shard_state_from_db_short(block_id, std::move(promise));
|
||||
}
|
||||
void get_block_by_lt_for_litequery(AccountIdPrefixFull account, LogicalTime lt,
|
||||
td::Promise<ConstBlockHandle> promise) override {
|
||||
get_block_by_lt_from_db(account, lt, std::move(promise));
|
||||
}
|
||||
void get_block_by_unix_time_from_db_for_litequery(AccountIdPrefixFull account, UnixTime ts,
|
||||
void get_block_by_unix_time_for_litequery(AccountIdPrefixFull account, UnixTime ts,
|
||||
td::Promise<ConstBlockHandle> promise) override {
|
||||
get_block_by_unix_time_from_db(account, ts, std::move(promise));
|
||||
}
|
||||
void get_block_by_seqno_from_db_for_litequery(AccountIdPrefixFull account, BlockSeqno seqno,
|
||||
void get_block_by_seqno_for_litequery(AccountIdPrefixFull account, BlockSeqno seqno,
|
||||
td::Promise<ConstBlockHandle> promise) override {
|
||||
get_block_by_seqno_from_db(account, seqno, std::move(promise));
|
||||
}
|
||||
void get_block_candidate_for_litequery(PublicKey source, BlockIdExt block_id, FileHash collated_data_hash,
|
||||
td::Promise<BlockCandidate> promise) override {
|
||||
promise.set_result(td::Status::Error("not implemented"));
|
||||
}
|
||||
void get_validator_groups_info_for_litequery(
|
||||
td::optional<ShardIdFull> shard,
|
||||
td::Promise<tl_object_ptr<lite_api::liteServer_nonfinal_validatorGroups>> promise) override {
|
||||
promise.set_result(td::Status::Error("not implemented"));
|
||||
}
|
||||
|
||||
private:
|
||||
td::Ref<ValidatorManagerOptions> opts_;
|
||||
|
|
|
@ -225,13 +225,13 @@ void ValidatorManagerImpl::sync_complete(td::Promise<td::Unit> promise) {
|
|||
|
||||
VLOG(VALIDATOR_WARNING) << "completed sync. Validating " << validator_groups_.size() << " groups";
|
||||
for (auto &v : validator_groups_) {
|
||||
if (!v.second.empty()) {
|
||||
td::actor::send_closure(v.second, &ValidatorGroup::create_session);
|
||||
if (!v.second.actor.empty()) {
|
||||
td::actor::send_closure(v.second.actor, &ValidatorGroup::create_session);
|
||||
}
|
||||
}
|
||||
for (auto &v : next_validator_groups_) {
|
||||
if (!v.second.empty()) {
|
||||
td::actor::send_closure(v.second, &ValidatorGroup::create_session);
|
||||
if (!v.second.actor.empty()) {
|
||||
td::actor::send_closure(v.second.actor, &ValidatorGroup::create_session);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1168,6 +1168,10 @@ void ValidatorManagerImpl::set_next_block(BlockIdExt block_id, BlockIdExt next,
|
|||
}
|
||||
|
||||
void ValidatorManagerImpl::set_block_candidate(BlockIdExt id, BlockCandidate candidate, td::Promise<td::Unit> promise) {
|
||||
if (!candidates_buffer_.empty()) {
|
||||
td::actor::send_closure(candidates_buffer_, &CandidatesBuffer::add_new_candidate, id,
|
||||
PublicKey{pubkeys::Ed25519{candidate.pubkey.as_bits256()}}, candidate.collated_file_hash);
|
||||
}
|
||||
td::actor::send_closure(db_, &Db::store_block_candidate, std::move(candidate), std::move(promise));
|
||||
}
|
||||
|
||||
|
@ -1575,8 +1579,11 @@ void ValidatorManagerImpl::started(ValidatorManagerInitResult R) {
|
|||
td::actor::send_closure(SelfId, &ValidatorManagerImpl::read_gc_list, R.move_as_ok());
|
||||
}
|
||||
});
|
||||
|
||||
td::actor::send_closure(db_, &Db::get_destroyed_validator_sessions, std::move(P));
|
||||
|
||||
if (opts_->nonfinal_ls_queries_enabled()) {
|
||||
candidates_buffer_ = td::actor::create_actor<CandidatesBuffer>("candidates-buffer", actor_id(this));
|
||||
}
|
||||
}
|
||||
|
||||
void ValidatorManagerImpl::read_gc_list(std::vector<ValidatorSessionId> list) {
|
||||
|
@ -1868,8 +1875,8 @@ void ValidatorManagerImpl::update_shards() {
|
|||
|
||||
VLOG(VALIDATOR_DEBUG) << "total shards=" << new_shards.size() << " config shards=" << exp_vec.size();
|
||||
|
||||
std::map<ValidatorSessionId, td::actor::ActorOwn<ValidatorGroup>> new_validator_groups_;
|
||||
std::map<ValidatorSessionId, td::actor::ActorOwn<ValidatorGroup>> new_next_validator_groups_;
|
||||
std::map<ValidatorSessionId, ValidatorGroupEntry> new_validator_groups_;
|
||||
std::map<ValidatorSessionId, ValidatorGroupEntry> new_next_validator_groups_;
|
||||
|
||||
bool force_recover = false;
|
||||
{
|
||||
|
@ -1901,8 +1908,8 @@ void ValidatorManagerImpl::update_shards() {
|
|||
} else {
|
||||
auto it2 = next_validator_groups_.find(legacy_val_group_id);
|
||||
if (it2 != next_validator_groups_.end()) {
|
||||
if (!it2->second.empty()) {
|
||||
td::actor::send_closure(it2->second, &ValidatorGroup::start, prev, last_masterchain_block_id_,
|
||||
if (!it2->second.actor.empty()) {
|
||||
td::actor::send_closure(it2->second.actor, &ValidatorGroup::start, prev, last_masterchain_block_id_,
|
||||
last_masterchain_state_->get_unix_time());
|
||||
}
|
||||
new_validator_groups_.emplace(val_group_id, std::move(it2->second));
|
||||
|
@ -1912,7 +1919,7 @@ void ValidatorManagerImpl::update_shards() {
|
|||
td::actor::send_closure(G, &ValidatorGroup::start, prev, last_masterchain_block_id_,
|
||||
last_masterchain_state_->get_unix_time());
|
||||
}
|
||||
new_validator_groups_.emplace(val_group_id, std::move(G));
|
||||
new_validator_groups_.emplace(val_group_id, ValidatorGroupEntry{std::move(G), shard});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1957,8 +1964,8 @@ void ValidatorManagerImpl::update_shards() {
|
|||
} else {
|
||||
auto it2 = next_validator_groups_.find(val_group_id);
|
||||
if (it2 != next_validator_groups_.end()) {
|
||||
if (!it2->second.empty()) {
|
||||
td::actor::send_closure(it2->second, &ValidatorGroup::start, prev, last_masterchain_block_id_,
|
||||
if (!it2->second.actor.empty()) {
|
||||
td::actor::send_closure(it2->second.actor, &ValidatorGroup::start, prev, last_masterchain_block_id_,
|
||||
last_masterchain_state_->get_unix_time());
|
||||
}
|
||||
new_validator_groups_.emplace(val_group_id, std::move(it2->second));
|
||||
|
@ -1968,7 +1975,7 @@ void ValidatorManagerImpl::update_shards() {
|
|||
td::actor::send_closure(G, &ValidatorGroup::start, prev, last_masterchain_block_id_,
|
||||
last_masterchain_state_->get_unix_time());
|
||||
}
|
||||
new_validator_groups_.emplace(val_group_id, std::move(G));
|
||||
new_validator_groups_.emplace(val_group_id, ValidatorGroupEntry{std::move(G), shard});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1988,23 +1995,24 @@ void ValidatorManagerImpl::update_shards() {
|
|||
//CHECK(!it->second.empty());
|
||||
new_next_validator_groups_.emplace(val_group_id, std::move(it->second));
|
||||
} else {
|
||||
new_next_validator_groups_.emplace(val_group_id,
|
||||
create_validator_group(val_group_id, shard, val_set, opts, started_));
|
||||
new_next_validator_groups_.emplace(
|
||||
val_group_id,
|
||||
ValidatorGroupEntry{create_validator_group(val_group_id, shard, val_set, opts, started_), shard});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<td::actor::ActorId<ValidatorGroup>> gc;
|
||||
for (auto &v : validator_groups_) {
|
||||
if (!v.second.empty()) {
|
||||
if (!v.second.actor.empty()) {
|
||||
gc_list_.push_back(v.first);
|
||||
gc.push_back(v.second.release());
|
||||
gc.push_back(v.second.actor.release());
|
||||
}
|
||||
}
|
||||
for (auto &v : next_validator_groups_) {
|
||||
if (!v.second.empty()) {
|
||||
if (!v.second.actor.empty()) {
|
||||
gc_list_.push_back(v.first);
|
||||
gc.push_back(v.second.release());
|
||||
gc.push_back(v.second.actor.release());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2704,19 +2712,72 @@ void ValidatorManagerImpl::log_validator_session_stats(BlockIdExt block_id,
|
|||
}
|
||||
|
||||
void ValidatorManagerImpl::get_block_handle_for_litequery(BlockIdExt block_id, td::Promise<ConstBlockHandle> promise) {
|
||||
get_block_handle(
|
||||
block_id, false,
|
||||
[SelfId = actor_id(this), block_id, promise = std::move(promise)](td::Result<BlockHandle> R) mutable {
|
||||
if (R.is_ok() && R.ok()->is_applied()) {
|
||||
promise.set_value(R.move_as_ok());
|
||||
} else {
|
||||
td::actor::send_closure(SelfId, &ValidatorManagerImpl::process_block_handle_for_litequery_error, block_id,
|
||||
std::move(R), std::move(promise));
|
||||
}
|
||||
});
|
||||
get_block_handle(block_id, false,
|
||||
[SelfId = actor_id(this), block_id, promise = std::move(promise),
|
||||
allow_not_applied = opts_->nonfinal_ls_queries_enabled()](td::Result<BlockHandle> R) mutable {
|
||||
if (R.is_ok() && (allow_not_applied || R.ok()->is_applied())) {
|
||||
promise.set_value(R.move_as_ok());
|
||||
} else {
|
||||
td::actor::send_closure(SelfId, &ValidatorManagerImpl::process_block_handle_for_litequery_error,
|
||||
block_id, std::move(R), std::move(promise));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void ValidatorManagerImpl::get_block_by_lt_from_db_for_litequery(AccountIdPrefixFull account, LogicalTime lt,
|
||||
void ValidatorManagerImpl::get_block_data_for_litequery(BlockIdExt block_id, td::Promise<td::Ref<BlockData>> promise) {
|
||||
if (candidates_buffer_.empty()) {
|
||||
get_block_handle_for_litequery(
|
||||
block_id, [manager = actor_id(this), promise = std::move(promise)](td::Result<ConstBlockHandle> R) mutable {
|
||||
TRY_RESULT_PROMISE(promise, handle, std::move(R));
|
||||
td::actor::send_closure_later(manager, &ValidatorManager::get_block_data_from_db, std::move(handle),
|
||||
std::move(promise));
|
||||
});
|
||||
} else {
|
||||
td::actor::send_closure(
|
||||
candidates_buffer_, &CandidatesBuffer::get_block_data, block_id,
|
||||
[manager = actor_id(this), promise = std::move(promise), block_id](td::Result<td::Ref<BlockData>> R) mutable {
|
||||
if (R.is_ok()) {
|
||||
promise.set_result(R.move_as_ok());
|
||||
return;
|
||||
}
|
||||
td::actor::send_closure(manager, &ValidatorManagerImpl::get_block_handle_for_litequery, block_id,
|
||||
[manager, promise = std::move(promise)](td::Result<ConstBlockHandle> R) mutable {
|
||||
TRY_RESULT_PROMISE(promise, handle, std::move(R));
|
||||
td::actor::send_closure_later(manager, &ValidatorManager::get_block_data_from_db,
|
||||
std::move(handle), std::move(promise));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ValidatorManagerImpl::get_block_state_for_litequery(BlockIdExt block_id,
|
||||
td::Promise<td::Ref<ShardState>> promise) {
|
||||
if (candidates_buffer_.empty()) {
|
||||
get_block_handle_for_litequery(
|
||||
block_id, [manager = actor_id(this), promise = std::move(promise)](td::Result<ConstBlockHandle> R) mutable {
|
||||
TRY_RESULT_PROMISE(promise, handle, std::move(R));
|
||||
td::actor::send_closure_later(manager, &ValidatorManager::get_shard_state_from_db, std::move(handle),
|
||||
std::move(promise));
|
||||
});
|
||||
} else {
|
||||
td::actor::send_closure(
|
||||
candidates_buffer_, &CandidatesBuffer::get_block_state, block_id,
|
||||
[manager = actor_id(this), promise = std::move(promise), block_id](td::Result<td::Ref<ShardState>> R) mutable {
|
||||
if (R.is_ok()) {
|
||||
promise.set_result(R.move_as_ok());
|
||||
return;
|
||||
}
|
||||
td::actor::send_closure(manager, &ValidatorManagerImpl::get_block_handle_for_litequery,
|
||||
block_id, [manager, promise = std::move(promise)](td::Result<ConstBlockHandle> R) mutable {
|
||||
TRY_RESULT_PROMISE(promise, handle, std::move(R));
|
||||
td::actor::send_closure_later(manager, &ValidatorManager::get_shard_state_from_db, std::move(handle),
|
||||
std::move(promise));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ValidatorManagerImpl::get_block_by_lt_for_litequery(AccountIdPrefixFull account, LogicalTime lt,
|
||||
td::Promise<ConstBlockHandle> promise) {
|
||||
get_block_by_lt_from_db(
|
||||
account, lt, [=, SelfId = actor_id(this), promise = std::move(promise)](td::Result<ConstBlockHandle> R) mutable {
|
||||
|
@ -2729,7 +2790,7 @@ void ValidatorManagerImpl::get_block_by_lt_from_db_for_litequery(AccountIdPrefix
|
|||
});
|
||||
}
|
||||
|
||||
void ValidatorManagerImpl::get_block_by_unix_time_from_db_for_litequery(AccountIdPrefixFull account, UnixTime ts,
|
||||
void ValidatorManagerImpl::get_block_by_unix_time_for_litequery(AccountIdPrefixFull account, UnixTime ts,
|
||||
td::Promise<ConstBlockHandle> promise) {
|
||||
get_block_by_unix_time_from_db(
|
||||
account, ts, [=, SelfId = actor_id(this), promise = std::move(promise)](td::Result<ConstBlockHandle> R) mutable {
|
||||
|
@ -2742,7 +2803,7 @@ void ValidatorManagerImpl::get_block_by_unix_time_from_db_for_litequery(AccountI
|
|||
});
|
||||
}
|
||||
|
||||
void ValidatorManagerImpl::get_block_by_seqno_from_db_for_litequery(AccountIdPrefixFull account, BlockSeqno seqno,
|
||||
void ValidatorManagerImpl::get_block_by_seqno_for_litequery(AccountIdPrefixFull account, BlockSeqno seqno,
|
||||
td::Promise<ConstBlockHandle> promise) {
|
||||
get_block_by_seqno_from_db(
|
||||
account, seqno,
|
||||
|
@ -2840,6 +2901,77 @@ void ValidatorManagerImpl::process_lookup_block_for_litequery_error(AccountIdPre
|
|||
promise.set_error(std::move(err));
|
||||
}
|
||||
|
||||
void ValidatorManagerImpl::get_block_candidate_for_litequery(PublicKey source, BlockIdExt block_id,
|
||||
FileHash collated_data_hash,
|
||||
td::Promise<BlockCandidate> promise) {
|
||||
if (!opts_->nonfinal_ls_queries_enabled()) {
|
||||
promise.set_error(td::Status::Error("query is not allowed"));
|
||||
return;
|
||||
}
|
||||
get_block_candidate_from_db(source, block_id, collated_data_hash, std::move(promise));
|
||||
}
|
||||
|
||||
void ValidatorManagerImpl::get_validator_groups_info_for_litequery(
|
||||
td::optional<ShardIdFull> shard,
|
||||
td::Promise<tl_object_ptr<lite_api::liteServer_nonfinal_validatorGroups>> promise) {
|
||||
if (!opts_->nonfinal_ls_queries_enabled()) {
|
||||
promise.set_error(td::Status::Error("query is not allowed"));
|
||||
return;
|
||||
}
|
||||
class Actor : public td::actor::Actor {
|
||||
public:
|
||||
explicit Actor(std::vector<td::actor::ActorId<ValidatorGroup>> groups,
|
||||
td::Promise<tl_object_ptr<lite_api::liteServer_nonfinal_validatorGroups>> promise)
|
||||
: groups_(std::move(groups)), promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void start_up() override {
|
||||
pending_ = groups_.size();
|
||||
if (pending_ == 0) {
|
||||
promise_.set_result(std::move(result_));
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
for (auto &x : groups_) {
|
||||
td::actor::send_closure(
|
||||
x, &ValidatorGroup::get_validator_group_info_for_litequery,
|
||||
[SelfId = actor_id(this)](td::Result<tl_object_ptr<lite_api::liteServer_nonfinal_validatorGroupInfo>> R) {
|
||||
td::actor::send_closure(SelfId, &Actor::on_result, R.is_ok() ? R.move_as_ok() : nullptr);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void on_result(tl_object_ptr<lite_api::liteServer_nonfinal_validatorGroupInfo> r) {
|
||||
if (r) {
|
||||
result_->groups_.push_back(std::move(r));
|
||||
}
|
||||
--pending_;
|
||||
if (pending_ == 0) {
|
||||
promise_.set_result(std::move(result_));
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<td::actor::ActorId<ValidatorGroup>> groups_;
|
||||
size_t pending_;
|
||||
td::Promise<tl_object_ptr<lite_api::liteServer_nonfinal_validatorGroups>> promise_;
|
||||
tl_object_ptr<lite_api::liteServer_nonfinal_validatorGroups> result_ =
|
||||
create_tl_object<lite_api::liteServer_nonfinal_validatorGroups>();
|
||||
};
|
||||
std::vector<td::actor::ActorId<ValidatorGroup>> groups;
|
||||
for (auto &x : validator_groups_) {
|
||||
if (x.second.actor.empty()) {
|
||||
continue;
|
||||
}
|
||||
if (shard && shard.value() != x.second.shard) {
|
||||
continue;
|
||||
}
|
||||
groups.push_back(x.second.actor.get());
|
||||
}
|
||||
td::actor::create_actor<Actor>("get-validator-groups-info", std::move(groups), std::move(promise)).release();
|
||||
}
|
||||
|
||||
td::actor::ActorOwn<ValidatorManagerInterface> ValidatorManagerFactory::create(
|
||||
td::Ref<ValidatorManagerOptions> opts, std::string db_root, td::actor::ActorId<keyring::Keyring> keyring,
|
||||
td::actor::ActorId<adnl::Adnl> adnl, td::actor::ActorId<rldp::Rldp> rldp,
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "rldp/rldp.h"
|
||||
#include "token-manager.h"
|
||||
#include "queue-size-counter.hpp"
|
||||
#include "impl/candidates-buffer.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
@ -235,8 +236,12 @@ class ValidatorManagerImpl : public ValidatorManager {
|
|||
td::Ref<ValidatorSet> validator_set,
|
||||
validatorsession::ValidatorSessionOptions opts,
|
||||
bool create_catchain);
|
||||
std::map<ValidatorSessionId, td::actor::ActorOwn<ValidatorGroup>> validator_groups_;
|
||||
std::map<ValidatorSessionId, td::actor::ActorOwn<ValidatorGroup>> next_validator_groups_;
|
||||
struct ValidatorGroupEntry {
|
||||
td::actor::ActorOwn<ValidatorGroup> actor;
|
||||
ShardIdFull shard;
|
||||
};
|
||||
std::map<ValidatorSessionId, ValidatorGroupEntry> validator_groups_;
|
||||
std::map<ValidatorSessionId, ValidatorGroupEntry> next_validator_groups_;
|
||||
|
||||
std::set<ValidatorSessionId> check_gc_list_;
|
||||
std::vector<ValidatorSessionId> gc_list_;
|
||||
|
@ -563,17 +568,24 @@ class ValidatorManagerImpl : public ValidatorManager {
|
|||
}
|
||||
|
||||
void get_block_handle_for_litequery(BlockIdExt block_id, td::Promise<ConstBlockHandle> promise) override;
|
||||
void get_block_by_lt_from_db_for_litequery(AccountIdPrefixFull account, LogicalTime lt,
|
||||
void get_block_data_for_litequery(BlockIdExt block_id, td::Promise<td::Ref<BlockData>> promise) override;
|
||||
void get_block_state_for_litequery(BlockIdExt block_id, td::Promise<td::Ref<ShardState>> promise) override;
|
||||
void get_block_by_lt_for_litequery(AccountIdPrefixFull account, LogicalTime lt,
|
||||
td::Promise<ConstBlockHandle> promise) override;
|
||||
void get_block_by_unix_time_from_db_for_litequery(AccountIdPrefixFull account, UnixTime ts,
|
||||
void get_block_by_unix_time_for_litequery(AccountIdPrefixFull account, UnixTime ts,
|
||||
td::Promise<ConstBlockHandle> promise) override;
|
||||
void get_block_by_seqno_from_db_for_litequery(AccountIdPrefixFull account, BlockSeqno seqno,
|
||||
void get_block_by_seqno_for_litequery(AccountIdPrefixFull account, BlockSeqno seqno,
|
||||
td::Promise<ConstBlockHandle> promise) override;
|
||||
void process_block_handle_for_litequery_error(BlockIdExt block_id, td::Result<BlockHandle> r_handle,
|
||||
td::Promise<ConstBlockHandle> promise);
|
||||
void process_lookup_block_for_litequery_error(AccountIdPrefixFull account, int type, td::uint64 value,
|
||||
td::Result<ConstBlockHandle> r_handle,
|
||||
td::Promise<ConstBlockHandle> promise);
|
||||
void get_block_candidate_for_litequery(PublicKey source, BlockIdExt block_id, FileHash collated_data_hash,
|
||||
td::Promise<BlockCandidate> promise) override;
|
||||
void get_validator_groups_info_for_litequery(
|
||||
td::optional<ShardIdFull> shard,
|
||||
td::Promise<tl_object_ptr<lite_api::liteServer_nonfinal_validatorGroups>> promise) override;
|
||||
|
||||
void add_lite_query_stats(int lite_query_id) override {
|
||||
++ls_stats_[lite_query_id];
|
||||
|
@ -648,6 +660,8 @@ class ValidatorManagerImpl : public ValidatorManager {
|
|||
td::Timestamp log_ls_stats_at_;
|
||||
std::map<int, td::uint32> ls_stats_; // lite_api ID -> count, 0 for unknown
|
||||
td::uint32 ls_stats_check_ext_messages_{0};
|
||||
|
||||
td::actor::ActorOwn<CandidatesBuffer> candidates_buffer_;
|
||||
};
|
||||
|
||||
} // namespace validator
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "ton/ton-io.hpp"
|
||||
#include "td/utils/overloaded.h"
|
||||
#include "common/delay.h"
|
||||
#include "ton/lite-tl.hpp"
|
||||
|
||||
namespace ton {
|
||||
|
||||
|
@ -61,7 +62,9 @@ void ValidatorGroup::generated_block_candidate(std::shared_ptr<CachedCollatedBlo
|
|||
cached_collated_block_ = nullptr;
|
||||
}
|
||||
} else {
|
||||
cache->result = R.move_as_ok();
|
||||
auto candidate = R.move_as_ok();
|
||||
add_available_block_candidate(candidate.pubkey.as_bits256(), candidate.id, candidate.collated_file_hash);
|
||||
cache->result = std::move(candidate);
|
||||
for (auto &p : cache->promises) {
|
||||
p.set_value(cache->result.value().clone());
|
||||
}
|
||||
|
@ -108,6 +111,8 @@ void ValidatorGroup::validate_block_candidate(td::uint32 round_id, BlockCandidat
|
|||
[&](UnixTime ts) {
|
||||
td::actor::send_closure(SelfId, &ValidatorGroup::update_approve_cache, block_to_cache_key(block),
|
||||
ts);
|
||||
td::actor::send_closure(SelfId, &ValidatorGroup::add_available_block_candidate, block.pubkey.as_bits256(),
|
||||
block.id, block.collated_file_hash);
|
||||
promise.set_result(ts);
|
||||
},
|
||||
[&](CandidateReject reject) {
|
||||
|
@ -224,6 +229,16 @@ BlockIdExt ValidatorGroup::create_next_block_id(RootHash root_hash, FileHash fil
|
|||
return BlockIdExt{shard_.workchain, shard_.shard, seqno + 1, root_hash, file_hash};
|
||||
}
|
||||
|
||||
BlockId ValidatorGroup::create_next_block_id_simple() const {
|
||||
BlockSeqno seqno = 0;
|
||||
for (auto &p : prev_block_ids_) {
|
||||
if (seqno < p.id.seqno) {
|
||||
seqno = p.id.seqno;
|
||||
}
|
||||
}
|
||||
return BlockId{shard_.workchain, shard_.shard, seqno + 1};
|
||||
}
|
||||
|
||||
std::unique_ptr<validatorsession::ValidatorSession::Callback> ValidatorGroup::make_validator_session_callback() {
|
||||
class Callback : public validatorsession::ValidatorSession::Callback {
|
||||
public:
|
||||
|
@ -377,6 +392,47 @@ void ValidatorGroup::destroy() {
|
|||
stop();
|
||||
}
|
||||
|
||||
void ValidatorGroup::get_validator_group_info_for_litequery(
|
||||
td::Promise<tl_object_ptr<lite_api::liteServer_nonfinal_validatorGroupInfo>> promise) {
|
||||
if (session_.empty()) {
|
||||
promise.set_error(td::Status::Error(ErrorCode::notready, "not started"));
|
||||
return;
|
||||
}
|
||||
td::actor::send_closure(
|
||||
session_, &validatorsession::ValidatorSession::get_validator_group_info_for_litequery, last_known_round_id_,
|
||||
[SelfId = actor_id(this), promise = std::move(promise), round = last_known_round_id_](
|
||||
td::Result<std::vector<tl_object_ptr<lite_api::liteServer_nonfinal_candidateInfo>>> R) mutable {
|
||||
TRY_RESULT_PROMISE(promise, result, std::move(R));
|
||||
td::actor::send_closure(SelfId, &ValidatorGroup::get_validator_group_info_for_litequery_cont, round,
|
||||
std::move(result), std::move(promise));
|
||||
});
|
||||
}
|
||||
|
||||
void ValidatorGroup::get_validator_group_info_for_litequery_cont(
|
||||
td::uint32 expected_round, std::vector<tl_object_ptr<lite_api::liteServer_nonfinal_candidateInfo>> candidates,
|
||||
td::Promise<tl_object_ptr<lite_api::liteServer_nonfinal_validatorGroupInfo>> promise) {
|
||||
if (expected_round != last_known_round_id_) {
|
||||
candidates.clear();
|
||||
}
|
||||
|
||||
BlockId next_block_id = create_next_block_id_simple();
|
||||
for (auto &candidate : candidates) {
|
||||
BlockIdExt id{next_block_id, candidate->id_->block_id_->root_hash_, candidate->id_->block_id_->file_hash_};
|
||||
candidate->id_->block_id_ = create_tl_lite_block_id(id);
|
||||
candidate->available_ =
|
||||
available_block_candidates_.count({candidate->id_->creator_, id, candidate->id_->collated_data_hash_});
|
||||
}
|
||||
|
||||
auto result = create_tl_object<lite_api::liteServer_nonfinal_validatorGroupInfo>();
|
||||
result->next_block_id_ = create_tl_lite_block_id_simple(next_block_id);
|
||||
for (const BlockIdExt& prev : prev_block_ids_) {
|
||||
result->prev_.push_back(create_tl_lite_block_id(prev));
|
||||
}
|
||||
result->cc_seqno_ = validator_set_->get_catchain_seqno();
|
||||
result->candidates_ = std::move(candidates);
|
||||
promise.set_result(std::move(result));
|
||||
}
|
||||
|
||||
} // namespace validator
|
||||
|
||||
} // namespace ton
|
||||
|
|
|
@ -47,6 +47,7 @@ class ValidatorGroup : public td::actor::Actor {
|
|||
void get_approved_candidate(PublicKey source, RootHash root_hash, FileHash file_hash,
|
||||
FileHash collated_data_file_hash, td::Promise<BlockCandidate> promise);
|
||||
BlockIdExt create_next_block_id(RootHash root_hash, FileHash file_hash) const;
|
||||
BlockId create_next_block_id_simple() const;
|
||||
|
||||
void start(std::vector<BlockIdExt> prev, BlockIdExt min_masterchain_block_id, UnixTime min_ts);
|
||||
void create_session();
|
||||
|
@ -58,6 +59,9 @@ class ValidatorGroup : public td::actor::Actor {
|
|||
}
|
||||
}
|
||||
|
||||
void get_validator_group_info_for_litequery(
|
||||
td::Promise<tl_object_ptr<lite_api::liteServer_nonfinal_validatorGroupInfo>> promise);
|
||||
|
||||
ValidatorGroup(ShardIdFull shard, PublicKeyHash local_id, ValidatorSessionId session_id,
|
||||
td::Ref<ValidatorSet> validator_set, validatorsession::ValidatorSessionOptions config,
|
||||
td::actor::ActorId<keyring::Keyring> keyring, td::actor::ActorId<adnl::Adnl> adnl,
|
||||
|
@ -135,6 +139,17 @@ class ValidatorGroup : public td::actor::Actor {
|
|||
static CacheKey block_to_cache_key(const BlockCandidate& block) {
|
||||
return std::make_tuple(block.pubkey.as_bits256(), block.id, sha256_bits256(block.data), block.collated_file_hash);
|
||||
}
|
||||
|
||||
void get_validator_group_info_for_litequery_cont(
|
||||
td::uint32 expected_round,
|
||||
std::vector<tl_object_ptr<lite_api::liteServer_nonfinal_candidateInfo>> candidates,
|
||||
td::Promise<tl_object_ptr<lite_api::liteServer_nonfinal_validatorGroupInfo>> promise);
|
||||
|
||||
std::set<std::tuple<td::Bits256, BlockIdExt, FileHash>> available_block_candidates_; // source, id, collated hash
|
||||
|
||||
void add_available_block_candidate(td::Bits256 source, BlockIdExt id, FileHash collated_data_hash) {
|
||||
available_block_candidates_.emplace(source, id, collated_data_hash);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace validator
|
||||
|
|
|
@ -126,6 +126,9 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
|
|||
bool get_disable_rocksdb_stats() const override {
|
||||
return disable_rocksdb_stats_;
|
||||
}
|
||||
bool nonfinal_ls_queries_enabled() const override {
|
||||
return nonfinal_ls_queries_enabled_;
|
||||
}
|
||||
|
||||
void set_zero_block_id(BlockIdExt block_id) override {
|
||||
zero_block_id_ = block_id;
|
||||
|
@ -191,6 +194,9 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
|
|||
void set_disable_rocksdb_stats(bool value) override {
|
||||
disable_rocksdb_stats_ = value;
|
||||
}
|
||||
void set_nonfinal_ls_queries_enabled(bool value) override {
|
||||
nonfinal_ls_queries_enabled_ = value;
|
||||
}
|
||||
|
||||
ValidatorManagerOptionsImpl *make_copy() const override {
|
||||
return new ValidatorManagerOptionsImpl(*this);
|
||||
|
@ -237,6 +243,7 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
|
|||
size_t max_open_archive_files_ = 0;
|
||||
double archive_preload_period_ = 0.0;
|
||||
bool disable_rocksdb_stats_;
|
||||
bool nonfinal_ls_queries_enabled_ = false;
|
||||
};
|
||||
|
||||
} // namespace validator
|
||||
|
|
|
@ -85,6 +85,7 @@ struct ValidatorManagerOptions : public td::CntObject {
|
|||
virtual size_t get_max_open_archive_files() const = 0;
|
||||
virtual double get_archive_preload_period() const = 0;
|
||||
virtual bool get_disable_rocksdb_stats() const = 0;
|
||||
virtual bool nonfinal_ls_queries_enabled() const = 0;
|
||||
|
||||
virtual void set_zero_block_id(BlockIdExt block_id) = 0;
|
||||
virtual void set_init_block_id(BlockIdExt block_id) = 0;
|
||||
|
@ -108,6 +109,7 @@ struct ValidatorManagerOptions : public td::CntObject {
|
|||
virtual void set_max_open_archive_files(size_t value) = 0;
|
||||
virtual void set_archive_preload_period(double value) = 0;
|
||||
virtual void set_disable_rocksdb_stats(bool value) = 0;
|
||||
virtual void set_nonfinal_ls_queries_enabled(bool value) = 0;
|
||||
|
||||
static td::Ref<ValidatorManagerOptions> create(
|
||||
BlockIdExt zero_block_id, BlockIdExt init_block_id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue