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

Merge branch 'testnet' into block-generation

This commit is contained in:
SpyCheese 2024-03-26 16:19:34 +03:00
commit 7999a7e2c1
52 changed files with 1466 additions and 282 deletions

View file

@ -19,6 +19,7 @@
#include "validator-session.hpp"
#include "td/utils/Random.h"
#include "td/utils/crypto.h"
#include "candidate-serializer.h"
#include "ton/ton-tl.hpp"
namespace ton {
@ -222,7 +223,9 @@ void ValidatorSessionImpl::process_broadcast(PublicKeyHash src, td::BufferSlice
// Note: src is not necessarily equal to the sender of this message:
// If requested using get_broadcast_p2p, src is the creator of the block, sender possibly is some other node.
auto src_idx = description().get_source_idx(src);
auto R = fetch_tl_object<ton_api::validatorSession_candidate>(data.clone(), true);
auto R =
deserialize_candidate(data, compress_block_candidates_,
description().opts().max_block_size + description().opts().max_collated_data_size + 1024);
if (R.is_error()) {
VLOG(VALIDATOR_SESSION_WARNING) << this << "[node " << src << "][broadcast " << sha256_bits256(data.as_slice())
<< "]: failed to parse: " << R.move_as_error();
@ -344,17 +347,17 @@ void ValidatorSessionImpl::process_query(PublicKeyHash src, td::BufferSlice data
}
CHECK(block);
auto P = td::PromiseCreator::lambda(
[promise = std::move(promise), src = f->id_->src_, round_id](td::Result<BlockCandidate> R) mutable {
if (R.is_error()) {
promise.set_error(R.move_as_error_prefix("failed to get candidate: "));
} else {
auto c = R.move_as_ok();
auto obj = create_tl_object<ton_api::validatorSession_candidate>(
src, round_id, c.id.root_hash, std::move(c.data), std::move(c.collated_data));
promise.set_value(serialize_tl_object(obj, true));
}
});
auto P = td::PromiseCreator::lambda([promise = std::move(promise), src = f->id_->src_, round_id,
compress = compress_block_candidates_](td::Result<BlockCandidate> R) mutable {
if (R.is_error()) {
promise.set_error(R.move_as_error_prefix("failed to get candidate: "));
} else {
auto c = R.move_as_ok();
auto obj = create_tl_object<ton_api::validatorSession_candidate>(src, round_id, c.id.root_hash, std::move(c.data),
std::move(c.collated_data));
promise.set_result(serialize_candidate(obj, compress));
}
});
callback_->get_approved_candidate(description().get_source_public_key(block->get_src_idx()), f->id_->root_hash_,
f->id_->file_hash_, f->id_->collated_data_file_hash_, std::move(P));
@ -432,7 +435,7 @@ void ValidatorSessionImpl::generated_block(td::uint32 round, ValidatorSessionCan
auto b = create_tl_object<ton_api::validatorSession_candidate>(local_id().tl(), round, root_hash, std::move(data),
std::move(collated_data));
auto B = serialize_tl_object(b, true);
auto B = serialize_candidate(b, compress_block_candidates_).move_as_ok();
auto block_id = description().candidate_id(local_idx(), root_hash, file_hash, collated_data_file_hash);
@ -863,7 +866,8 @@ void ValidatorSessionImpl::on_catchain_started() {
if (x) {
auto P = td::PromiseCreator::lambda([SelfId = actor_id(this), round = virtual_state_->cur_round_seqno(),
src = description().get_source_id(x->get_src_idx()),
root_hash = x->get_root_hash()](td::Result<BlockCandidate> R) {
root_hash = x->get_root_hash(),
compress = compress_block_candidates_](td::Result<BlockCandidate> R) {
if (R.is_error()) {
LOG(ERROR) << "failed to get candidate: " << R.move_as_error();
} else {
@ -871,7 +875,7 @@ void ValidatorSessionImpl::on_catchain_started() {
auto broadcast = create_tl_object<ton_api::validatorSession_candidate>(
src.tl(), round, root_hash, std::move(B.data), std::move(B.collated_data));
td::actor::send_closure(SelfId, &ValidatorSessionImpl::process_broadcast, src,
serialize_tl_object(broadcast, true), td::optional<ValidatorSessionCandidateId>(),
serialize_candidate(broadcast, compress).move_as_ok(), td::optional<ValidatorSessionCandidateId>(),
false);
}
});
@ -899,6 +903,7 @@ ValidatorSessionImpl::ValidatorSessionImpl(catchain::CatChainSessionId session_i
, rldp_(rldp)
, overlay_manager_(overlays)
, allow_unsafe_self_blocks_resync_(allow_unsafe_self_blocks_resync) {
compress_block_candidates_ = opts.proto_version >= 3;
description_ = ValidatorSessionDescription::create(std::move(opts), nodes, local_id);
src_round_candidate_.resize(description_->get_total_nodes());
}
@ -930,6 +935,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;