/* 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 . */ #pragma once #include "interfaces/validator-manager.h" #include "rldp/rldp.h" #include namespace ton::validator { class ValidatorManager; class CollatorNode : public td::actor::Actor { public: CollatorNode(adnl::AdnlNodeIdShort local_id, td::Ref opts, td::actor::ActorId manager, td::actor::ActorId adnl, td::actor::ActorId rldp); void start_up() override; void tear_down() override; void add_shard(ShardIdFull shard); void del_shard(ShardIdFull shard); void new_masterchain_block_notification(td::Ref state); void update_validator_group_info(ShardIdFull shard, std::vector prev, CatchainSeqno cc_seqno); void update_options(td::Ref opts) { opts_ = std::move(opts); } private: void receive_query(adnl::AdnlNodeIdShort src, td::BufferSlice data, td::Promise promise); bool can_collate_shard(ShardIdFull shard) const; adnl::AdnlNodeIdShort local_id_; td::Ref opts_; td::actor::ActorId manager_; td::actor::ActorId adnl_; td::actor::ActorId rldp_; std::vector collating_shards_; std::set validator_adnl_ids_; struct CacheEntry { bool started = false; BlockSeqno block_seqno = 0; td::optional result; td::CancellationTokenSource cancellation_token_source; std::vector> promises; void cancel(td::Status reason); }; struct ValidatorGroupInfo { CatchainSeqno cc_seqno{0}; std::vector prev; BlockSeqno next_block_seqno{0}; std::map, std::shared_ptr> cache; void cleanup(); }; struct FutureValidatorGroup { std::vector> pending_blocks; std::vector> promises; }; std::map validator_groups_; std::map, FutureValidatorGroup> future_validator_groups_; td::Ref last_masterchain_state_; td::Result get_future_validator_group(ShardIdFull shard, CatchainSeqno cc_seqno); void generate_block(ShardIdFull shard, CatchainSeqno cc_seqno, std::vector prev_blocks, td::Timestamp timeout, td::Promise promise); void process_result(std::shared_ptr cache_entry, td::Result R); public: static tl_object_ptr serialize_candidate(const BlockCandidate& block, bool compress); static td::Result deserialize_candidate(tl_object_ptr f, int max_decompressed_data_size); }; } // namespace ton::validator