mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Add candidates cache (#1000)
* Broadcast shardchain block candidates in private overlays, generate proof links from candidates * Disable shardchain block broadcasts in private overlays * Send block candidate broadcasts to custom overlays, allow non-validators to receive candidates --------- Co-authored-by: SpyCheese <mikle98@yandex.ru>
This commit is contained in:
parent
7a74888d2f
commit
539d5dd2de
26 changed files with 382 additions and 20 deletions
|
@ -17,6 +17,7 @@
|
|||
#include "full-node-private-overlay.hpp"
|
||||
#include "ton/ton-tl.hpp"
|
||||
#include "common/delay.h"
|
||||
#include "common/checksum.h"
|
||||
#include "full-node-serializer.hpp"
|
||||
|
||||
namespace ton::validator::fullnode {
|
||||
|
@ -49,6 +50,22 @@ void FullNodePrivateBlockOverlay::process_broadcast(PublicKeyHash src, ton_api::
|
|||
query.block_->cc_seqno_, std::move(query.block_->data_));
|
||||
}
|
||||
|
||||
void FullNodePrivateBlockOverlay::process_broadcast(PublicKeyHash src,
|
||||
ton_api::tonNode_newBlockCandidateBroadcast &query) {
|
||||
if (query.data_.size() > FullNode::max_block_size()) {
|
||||
VLOG(FULL_NODE_WARNING) << "received block candidate with too big size from " << src;
|
||||
return;
|
||||
}
|
||||
BlockIdExt block_id = create_block_id(query.id_);
|
||||
if (td::sha256_bits256(query.data_.as_slice()) != block_id.file_hash) {
|
||||
VLOG(FULL_NODE_WARNING) << "received block candidate with incorrect file hash from " << src;
|
||||
return;
|
||||
}
|
||||
VLOG(FULL_NODE_DEBUG) << "Received newBlockCandidate in private overlay from " << src << ": " << block_id.to_str();
|
||||
td::actor::send_closure(full_node_, &FullNode::process_block_candidate_broadcast, block_id, query.catchain_seqno_,
|
||||
query.validator_set_hash_, std::move(query.data_));
|
||||
}
|
||||
|
||||
void FullNodePrivateBlockOverlay::receive_broadcast(PublicKeyHash src, td::BufferSlice broadcast) {
|
||||
if (adnl::AdnlNodeIdShort{src} == local_id_) {
|
||||
return;
|
||||
|
@ -77,6 +94,19 @@ void FullNodePrivateBlockOverlay::send_shard_block_info(BlockIdExt block_id, Cat
|
|||
}
|
||||
}
|
||||
|
||||
void FullNodePrivateBlockOverlay::send_block_candidate(BlockIdExt block_id, CatchainSeqno cc_seqno,
|
||||
td::uint32 validator_set_hash, td::BufferSlice data) {
|
||||
if (!inited_) {
|
||||
return;
|
||||
}
|
||||
VLOG(FULL_NODE_DEBUG) << "Sending newBlockCandidate in private overlay: " << block_id.to_str();
|
||||
auto B = create_serialize_tl_object<ton_api::tonNode_newBlockCandidateBroadcast>(
|
||||
create_tl_block_id(block_id), cc_seqno, validator_set_hash,
|
||||
create_tl_object<ton_api::tonNode_blockSignature>(Bits256::zero(), td::BufferSlice()), std::move(data));
|
||||
td::actor::send_closure(overlays_, &overlay::Overlays::send_broadcast_fec_ex, local_id_, overlay_id_,
|
||||
local_id_.pubkey_hash(), overlay::Overlays::BroadcastFlagAnySender(), std::move(B));
|
||||
}
|
||||
|
||||
void FullNodePrivateBlockOverlay::send_broadcast(BlockBroadcast broadcast) {
|
||||
if (!inited_) {
|
||||
return;
|
||||
|
@ -199,6 +229,28 @@ void FullNodeCustomOverlay::process_broadcast(PublicKeyHash src, ton_api::tonNod
|
|||
std::move(query.message_->data_), it->second);
|
||||
}
|
||||
|
||||
void FullNodeCustomOverlay::process_broadcast(PublicKeyHash src, ton_api::tonNode_newBlockCandidateBroadcast &query) {
|
||||
if (!block_senders_.count(adnl::AdnlNodeIdShort(src))) {
|
||||
VLOG(FULL_NODE_DEBUG) << "Dropping block candidate broadcast in private overlay \"" << name_
|
||||
<< "\" from unauthorized sender " << src;
|
||||
return;
|
||||
}
|
||||
if (query.data_.size() > FullNode::max_block_size()) {
|
||||
VLOG(FULL_NODE_WARNING) << "received block candidate with too big size from " << src;
|
||||
return;
|
||||
}
|
||||
BlockIdExt block_id = create_block_id(query.id_);
|
||||
if (td::sha256_bits256(query.data_.as_slice()) != block_id.file_hash) {
|
||||
VLOG(FULL_NODE_WARNING) << "received block candidate with incorrect file hash from " << src;
|
||||
return;
|
||||
}
|
||||
// ignore cc_seqno and validator_hash for now
|
||||
VLOG(FULL_NODE_DEBUG) << "Received newBlockCandidate in custom overlay \"" << name_ << "\" from " << src << ": "
|
||||
<< block_id.to_str();
|
||||
td::actor::send_closure(full_node_, &FullNode::process_block_candidate_broadcast, block_id, query.catchain_seqno_,
|
||||
query.validator_set_hash_, std::move(query.data_));
|
||||
}
|
||||
|
||||
void FullNodeCustomOverlay::receive_broadcast(PublicKeyHash src, td::BufferSlice broadcast) {
|
||||
if (adnl::AdnlNodeIdShort{src} == local_id_) {
|
||||
return;
|
||||
|
@ -241,6 +293,19 @@ void FullNodeCustomOverlay::send_broadcast(BlockBroadcast broadcast) {
|
|||
local_id_.pubkey_hash(), overlay::Overlays::BroadcastFlagAnySender(), B.move_as_ok());
|
||||
}
|
||||
|
||||
void FullNodeCustomOverlay::send_block_candidate(BlockIdExt block_id, CatchainSeqno cc_seqno,
|
||||
td::uint32 validator_set_hash, td::BufferSlice data) {
|
||||
if (!inited_) {
|
||||
return;
|
||||
}
|
||||
VLOG(FULL_NODE_DEBUG) << "Sending newBlockCandidate in custom overlay \"" << name_ << "\": " << block_id.to_str();
|
||||
auto B = create_serialize_tl_object<ton_api::tonNode_newBlockCandidateBroadcast>(
|
||||
create_tl_block_id(block_id), cc_seqno, validator_set_hash,
|
||||
create_tl_object<ton_api::tonNode_blockSignature>(Bits256::zero(), td::BufferSlice()), std::move(data));
|
||||
td::actor::send_closure(overlays_, &overlay::Overlays::send_broadcast_fec_ex, local_id_, overlay_id_,
|
||||
local_id_.pubkey_hash(), overlay::Overlays::BroadcastFlagAnySender(), std::move(B));
|
||||
}
|
||||
|
||||
void FullNodeCustomOverlay::start_up() {
|
||||
std::sort(nodes_.begin(), nodes_.end());
|
||||
nodes_.erase(std::unique(nodes_.begin(), nodes_.end()), nodes_.end());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue