2024-02-21 15:38:02 +00:00
|
|
|
/*
|
|
|
|
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 "full-node.h"
|
|
|
|
|
|
|
|
namespace ton::validator::fullnode {
|
|
|
|
|
2024-07-13 12:40:26 +00:00
|
|
|
class FullNodeFastSyncOverlay : public td::actor::Actor {
|
2024-02-21 15:38:02 +00:00
|
|
|
public:
|
2024-05-13 13:38:48 +00:00
|
|
|
void process_broadcast(PublicKeyHash src, ton_api::tonNode_blockBroadcast& query);
|
|
|
|
void process_broadcast(PublicKeyHash src, ton_api::tonNode_blockBroadcastCompressed& query);
|
|
|
|
void process_block_broadcast(PublicKeyHash src, ton_api::tonNode_Broadcast& query);
|
2024-03-26 13:22:52 +00:00
|
|
|
|
2024-05-13 13:38:48 +00:00
|
|
|
void process_broadcast(PublicKeyHash src, ton_api::tonNode_newShardBlockBroadcast& query);
|
2024-05-30 08:21:39 +00:00
|
|
|
|
2024-07-13 12:40:26 +00:00
|
|
|
void process_broadcast(PublicKeyHash src, ton_api::tonNode_newBlockCandidateBroadcast& query);
|
|
|
|
void process_broadcast(PublicKeyHash src, ton_api::tonNode_newBlockCandidateBroadcastCompressed& query);
|
|
|
|
void process_block_candidate_broadcast(PublicKeyHash src, ton_api::tonNode_Broadcast& query);
|
2024-05-30 08:21:39 +00:00
|
|
|
|
2024-02-21 15:38:02 +00:00
|
|
|
template <class T>
|
2024-05-13 13:38:48 +00:00
|
|
|
void process_broadcast(PublicKeyHash, T&) {
|
2024-02-21 15:38:02 +00:00
|
|
|
VLOG(FULL_NODE_WARNING) << "dropping unknown broadcast";
|
|
|
|
}
|
|
|
|
void receive_broadcast(PublicKeyHash src, td::BufferSlice query);
|
|
|
|
|
|
|
|
void send_shard_block_info(BlockIdExt block_id, CatchainSeqno cc_seqno, td::BufferSlice data);
|
|
|
|
void send_broadcast(BlockBroadcast broadcast);
|
2024-05-30 08:21:39 +00:00
|
|
|
void send_block_candidate(BlockIdExt block_id, CatchainSeqno cc_seqno, td::uint32 validator_set_hash,
|
|
|
|
td::BufferSlice data);
|
2024-02-21 15:38:02 +00:00
|
|
|
|
|
|
|
void start_up() override;
|
|
|
|
void tear_down() override;
|
|
|
|
|
2024-07-13 12:40:26 +00:00
|
|
|
void set_validators(std::vector<PublicKeyHash> root_public_keys,
|
|
|
|
std::vector<adnl::AdnlNodeIdShort> current_validators_adnl);
|
|
|
|
void set_member_certificate(overlay::OverlayMemberCertificate member_certificate);
|
2024-07-18 09:43:55 +00:00
|
|
|
void set_receive_broadcasts(bool value);
|
2024-07-13 12:40:26 +00:00
|
|
|
|
|
|
|
FullNodeFastSyncOverlay(adnl::AdnlNodeIdShort local_id, ShardIdFull shard, FileHash zero_state_file_hash,
|
|
|
|
std::vector<PublicKeyHash> root_public_keys,
|
|
|
|
std::vector<adnl::AdnlNodeIdShort> current_validators_adnl,
|
2024-07-18 09:43:55 +00:00
|
|
|
overlay::OverlayMemberCertificate member_certificate, bool receive_broadcasts,
|
2024-07-13 12:40:26 +00:00
|
|
|
td::actor::ActorId<keyring::Keyring> keyring, td::actor::ActorId<adnl::Adnl> adnl,
|
|
|
|
td::actor::ActorId<overlay::Overlays> overlays,
|
|
|
|
td::actor::ActorId<ValidatorManagerInterface> validator_manager,
|
|
|
|
td::actor::ActorId<FullNode> full_node)
|
2024-02-21 15:38:02 +00:00
|
|
|
: local_id_(local_id)
|
|
|
|
, shard_(shard)
|
2024-07-13 12:40:26 +00:00
|
|
|
, root_public_keys_(std::move(root_public_keys))
|
|
|
|
, current_validators_adnl_(std::move(current_validators_adnl))
|
|
|
|
, member_certificate_(std::move(member_certificate))
|
2024-07-18 09:43:55 +00:00
|
|
|
, receive_broadcasts_(receive_broadcasts)
|
2024-02-21 15:38:02 +00:00
|
|
|
, zero_state_file_hash_(zero_state_file_hash)
|
|
|
|
, keyring_(keyring)
|
|
|
|
, adnl_(adnl)
|
|
|
|
, overlays_(overlays)
|
2024-05-13 13:38:48 +00:00
|
|
|
, validator_manager_(validator_manager)
|
|
|
|
, full_node_(full_node) {
|
2024-02-21 15:38:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
adnl::AdnlNodeIdShort local_id_;
|
|
|
|
ShardIdFull shard_;
|
2024-07-13 12:40:26 +00:00
|
|
|
std::vector<PublicKeyHash> root_public_keys_;
|
|
|
|
std::vector<adnl::AdnlNodeIdShort> current_validators_adnl_;
|
|
|
|
overlay::OverlayMemberCertificate member_certificate_;
|
2024-07-18 09:43:55 +00:00
|
|
|
bool receive_broadcasts_;
|
2024-02-21 15:38:02 +00:00
|
|
|
FileHash zero_state_file_hash_;
|
|
|
|
|
|
|
|
td::actor::ActorId<keyring::Keyring> keyring_;
|
|
|
|
td::actor::ActorId<adnl::Adnl> adnl_;
|
|
|
|
td::actor::ActorId<overlay::Overlays> overlays_;
|
|
|
|
td::actor::ActorId<ValidatorManagerInterface> validator_manager_;
|
2024-05-13 13:38:48 +00:00
|
|
|
td::actor::ActorId<FullNode> full_node_;
|
2024-02-21 15:38:02 +00:00
|
|
|
|
|
|
|
bool inited_ = false;
|
|
|
|
overlay::OverlayIdFull overlay_id_full_;
|
|
|
|
overlay::OverlayIdShort overlay_id_;
|
|
|
|
UnixTime created_at_ = (UnixTime)td::Clocks::system();
|
|
|
|
|
|
|
|
void try_init();
|
|
|
|
void init();
|
|
|
|
void get_stats_extra(td::Promise<std::string> promise);
|
|
|
|
};
|
|
|
|
|
2024-07-13 12:40:26 +00:00
|
|
|
class FullNodeFastSyncOverlays {
|
2024-02-21 15:38:02 +00:00
|
|
|
public:
|
2024-07-13 12:40:26 +00:00
|
|
|
td::actor::ActorId<FullNodeFastSyncOverlay> choose_overlay(ShardIdFull shard);
|
2024-02-21 15:38:02 +00:00
|
|
|
void update_overlays(td::Ref<MasterchainState> state, std::set<adnl::AdnlNodeIdShort> my_adnl_ids,
|
2024-07-13 12:40:26 +00:00
|
|
|
std::set<ShardIdFull> monitoring_shards, const FileHash& zero_state_file_hash,
|
|
|
|
const td::actor::ActorId<keyring::Keyring>& keyring, const td::actor::ActorId<adnl::Adnl>& adnl,
|
2024-02-21 15:38:02 +00:00
|
|
|
const td::actor::ActorId<overlay::Overlays>& overlays,
|
2024-05-13 13:38:48 +00:00
|
|
|
const td::actor::ActorId<ValidatorManagerInterface>& validator_manager,
|
|
|
|
const td::actor::ActorId<FullNode>& full_node);
|
2024-07-13 12:40:26 +00:00
|
|
|
void add_member_certificate(adnl::AdnlNodeIdShort local_id, overlay::OverlayMemberCertificate member_certificate);
|
2024-02-21 15:38:02 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct Overlays {
|
2024-07-13 12:40:26 +00:00
|
|
|
std::map<ShardIdFull, td::actor::ActorOwn<FullNodeFastSyncOverlay>> overlays_;
|
|
|
|
overlay::OverlayMemberCertificate current_certificate_;
|
|
|
|
bool is_validator_{false};
|
2024-02-21 15:38:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::map<adnl::AdnlNodeIdShort, Overlays> id_to_overlays_; // local_id -> overlays
|
2024-07-13 12:40:26 +00:00
|
|
|
std::map<adnl::AdnlNodeIdShort, std::vector<overlay::OverlayMemberCertificate>> member_certificates_;
|
|
|
|
|
|
|
|
td::optional<BlockSeqno> last_key_block_seqno_;
|
|
|
|
std::vector<PublicKeyHash> root_public_keys_;
|
|
|
|
std::vector<adnl::AdnlNodeIdShort> current_validators_adnl_;
|
2024-02-21 15:38:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ton::validator::fullnode
|