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
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue