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

Send only first block candidate optimistically (#1260)

* Broadcast only the first block candidate

* Fix sending block broadcast

---------

Co-authored-by: SpyCheese <mikle98@yandex.ru>
This commit is contained in:
EmelyanenkoK 2024-10-09 13:53:46 +03:00 committed by GitHub
parent 8364a2425f
commit 1da94e62ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 164 additions and 82 deletions

View file

@ -178,6 +178,12 @@ struct EndValidatorGroupStats {
std::vector<Node> nodes;
};
struct BlockSourceInfo {
td::uint32 round, first_block_round;
PublicKey source;
td::int32 source_priority;
};
} // namespace validatorsession
} // namespace ton

View file

@ -553,7 +553,9 @@ void ValidatorSessionImpl::check_generate_slot() {
LOG(WARNING) << print_id << ": failed to generate block candidate: " << R.move_as_error();
}
});
callback_->on_generate_slot(cur_round_, std::move(P));
callback_->on_generate_slot(
BlockSourceInfo{cur_round_, first_block_round_, description().get_source_public_key(local_idx()), priority},
std::move(P));
} else {
alarm_timestamp().relax(t);
}
@ -631,8 +633,10 @@ void ValidatorSessionImpl::try_approve_block(const SentBlock *block) {
});
pending_approve_.insert(block_id);
callback_->on_candidate(cur_round_, description().get_source_public_key(block->get_src_idx()), B->root_hash_,
B->data_.clone(), B->collated_data_.clone(), std::move(P));
callback_->on_candidate(
BlockSourceInfo{cur_round_, first_block_round_, description().get_source_public_key(block->get_src_idx()),
description().get_node_priority(block->get_src_idx(), cur_round_)},
B->root_hash_, B->data_.clone(), B->collated_data_.clone(), std::move(P));
} else if (T.is_in_past()) {
if (!active_requests_.count(block_id)) {
auto v = virtual_state_->get_block_approvers(description(), block_id);
@ -905,15 +909,19 @@ void ValidatorSessionImpl::on_new_round(td::uint32 round) {
stats.rounds.pop_back();
}
BlockSourceInfo source_info{cur_round_, first_block_round_,
description().get_source_public_key(block->get_src_idx()),
description().get_node_priority(block->get_src_idx(), cur_round_)};
if (it == blocks_.end()) {
callback_->on_block_committed(cur_round_, description().get_source_public_key(block->get_src_idx()),
block->get_root_hash(), block->get_file_hash(), td::BufferSlice(),
std::move(export_sigs), std::move(export_approve_sigs), std::move(stats));
callback_->on_block_committed(std::move(source_info), block->get_root_hash(), block->get_file_hash(),
td::BufferSlice(), std::move(export_sigs), std::move(export_approve_sigs),
std::move(stats));
} else {
callback_->on_block_committed(cur_round_, description().get_source_public_key(block->get_src_idx()),
block->get_root_hash(), block->get_file_hash(), it->second->data_.clone(),
std::move(export_sigs), std::move(export_approve_sigs), std::move(stats));
callback_->on_block_committed(std::move(source_info), block->get_root_hash(), block->get_file_hash(),
it->second->data_.clone(), std::move(export_sigs), std::move(export_approve_sigs),
std::move(stats));
}
first_block_round_ = cur_round_ + 1;
}
cur_round_++;
if (have_block) {

View file

@ -85,11 +85,10 @@ class ValidatorSession : public td::actor::Actor {
class Callback {
public:
virtual void on_candidate(td::uint32 round, PublicKey source, ValidatorSessionRootHash root_hash,
td::BufferSlice data, td::BufferSlice collated_data,
td::Promise<CandidateDecision> promise) = 0;
virtual void on_generate_slot(td::uint32 round, td::Promise<GeneratedCandidate> promise) = 0;
virtual void on_block_committed(td::uint32 round, PublicKey source, ValidatorSessionRootHash root_hash,
virtual void on_candidate(BlockSourceInfo source_info, ValidatorSessionRootHash root_hash, td::BufferSlice data,
td::BufferSlice collated_data, td::Promise<CandidateDecision> promise) = 0;
virtual void on_generate_slot(BlockSourceInfo source_info, td::Promise<GeneratedCandidate> promise) = 0;
virtual void on_block_committed(BlockSourceInfo source_info, ValidatorSessionRootHash root_hash,
ValidatorSessionFileHash file_hash, td::BufferSlice data,
std::vector<std::pair<PublicKeyHash, td::BufferSlice>> signatures,
std::vector<std::pair<PublicKeyHash, td::BufferSlice>> approve_signatures,

View file

@ -53,7 +53,7 @@ class ValidatorSessionImpl : public ValidatorSession {
const ValidatorSessionState *real_state_ = nullptr;
const ValidatorSessionState *virtual_state_ = nullptr;
td::uint32 cur_round_ = 0;
td::uint32 cur_round_ = 0, first_block_round_ = 0;
td::Timestamp round_started_at_ = td::Timestamp::never();
td::Timestamp round_debug_at_ = td::Timestamp::never();
std::set<ValidatorSessionCandidateId> pending_approve_;