mirror of
https://github.com/ton-blockchain/ton
synced 2025-02-13 11:42:18 +00:00
Add --lite-validator flag, rework is_validator checks
This commit is contained in:
parent
7241522de2
commit
5ba2a55716
8 changed files with 50 additions and 58 deletions
|
@ -33,7 +33,7 @@ void OptionParser::set_description(string description) {
|
|||
void OptionParser::add_option(Option::Type type, char short_key, Slice long_key, Slice description,
|
||||
std::function<Status(Slice)> callback) {
|
||||
for (auto &option : options_) {
|
||||
if (option.short_key == short_key || (!long_key.empty() && long_key == option.long_key)) {
|
||||
if ((short_key != '\0' && option.short_key == short_key) || (!long_key.empty() && long_key == option.long_key)) {
|
||||
LOG(ERROR) << "Ignore duplicated option '" << short_key << "' '" << long_key << "'";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1391,21 +1391,14 @@ td::Status ValidatorEngine::load_global_config() {
|
|||
h.push_back(b);
|
||||
}
|
||||
validator_options_.write().set_hardforks(std::move(h));
|
||||
validator_options_.write().set_validator_lite_mode(validator_lite_mode_);
|
||||
|
||||
return td::Status::OK();
|
||||
}
|
||||
|
||||
void ValidatorEngine::init_validator_options() {
|
||||
if (!masterchain_only_) {
|
||||
validator_options_.write().set_shard_check_function(
|
||||
[](ton::ShardIdFull shard, ton::CatchainSeqno cc_seqno,
|
||||
ton::validator::ValidatorManagerOptions::ShardCheckMode mode) -> bool {
|
||||
if (mode == ton::validator::ValidatorManagerOptions::ShardCheckMode::m_monitor) {
|
||||
return true;
|
||||
}
|
||||
CHECK(mode == ton::validator::ValidatorManagerOptions::ShardCheckMode::m_validate);
|
||||
return true;
|
||||
});
|
||||
if (!not_all_shards_) {
|
||||
validator_options_.write().set_shard_check_function([](ton::ShardIdFull shard) -> bool { return true; });
|
||||
} else {
|
||||
std::vector<ton::ShardIdFull> shards = {ton::ShardIdFull(ton::masterchainId)};
|
||||
for (const auto& c : config_.collators) {
|
||||
|
@ -1417,18 +1410,13 @@ void ValidatorEngine::init_validator_options() {
|
|||
std::sort(shards.begin(), shards.end());
|
||||
shards.erase(std::unique(shards.begin(), shards.end()), shards.end());
|
||||
validator_options_.write().set_shard_check_function(
|
||||
[shards = std::move(shards)](ton::ShardIdFull shard, ton::CatchainSeqno cc_seqno,
|
||||
ton::validator::ValidatorManagerOptions::ShardCheckMode mode) -> bool {
|
||||
if (mode == ton::validator::ValidatorManagerOptions::ShardCheckMode::m_monitor) {
|
||||
for (auto s : shards) {
|
||||
if (shard_is_ancestor(shard, s)) {
|
||||
return true;
|
||||
}
|
||||
[shards = std::move(shards)](ton::ShardIdFull shard) -> bool {
|
||||
for (auto s : shards) {
|
||||
if (shard_is_ancestor(shard, s)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
CHECK(mode == ton::validator::ValidatorManagerOptions::ShardCheckMode::m_validate);
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -3704,7 +3692,10 @@ int main(int argc, char *argv[]) {
|
|||
return td::Status::OK();
|
||||
});
|
||||
p.add_option('M', "not-all-shards", "monitor only a necessary set of shards instead of all", [&]() {
|
||||
acts.push_back([&x]() { td::actor::send_closure(x, &ValidatorEngine::set_masterchain_only); });
|
||||
acts.push_back([&x]() { td::actor::send_closure(x, &ValidatorEngine::set_not_all_shards); });
|
||||
});
|
||||
p.add_option('\0', "lite-validator", "lite-mode validator (don't collate blocks, use collator nodes instead)", [&]() {
|
||||
acts.push_back([&x]() { td::actor::send_closure(x, &ValidatorEngine::set_validator_lite_mode); });
|
||||
});
|
||||
td::uint32 threads = 7;
|
||||
p.add_checked_option(
|
||||
|
|
|
@ -214,7 +214,8 @@ class ValidatorEngine : public td::actor::Actor {
|
|||
bool started_ = false;
|
||||
ton::BlockSeqno truncate_seqno_{0};
|
||||
std::string session_logs_file_;
|
||||
bool masterchain_only_ = false;
|
||||
bool not_all_shards_ = false;
|
||||
bool validator_lite_mode_ = false;
|
||||
|
||||
std::set<ton::CatchainSeqno> unsafe_catchains_;
|
||||
std::map<ton::BlockSeqno, std::pair<ton::CatchainSeqno, td::uint32>> unsafe_catchain_rotations_;
|
||||
|
@ -266,9 +267,13 @@ class ValidatorEngine : public td::actor::Actor {
|
|||
void add_key_to_set(ton::PublicKey key) {
|
||||
keys_[key.compute_short_id()] = key;
|
||||
}
|
||||
void set_masterchain_only() {
|
||||
masterchain_only_ = true;
|
||||
void set_not_all_shards() {
|
||||
not_all_shards_ = true;
|
||||
}
|
||||
void set_validator_lite_mode() {
|
||||
validator_lite_mode_ = true;
|
||||
}
|
||||
|
||||
void start_up() override;
|
||||
ValidatorEngine() {
|
||||
}
|
||||
|
|
|
@ -369,7 +369,7 @@ void ValidatorManagerImpl::get_key_block_proof_link(BlockIdExt block_id, td::Pro
|
|||
}
|
||||
|
||||
void ValidatorManagerImpl::new_external_message(td::BufferSlice data) {
|
||||
if (!is_validator()) {
|
||||
if (!is_collator()) {
|
||||
return;
|
||||
}
|
||||
if ((double)ext_messages_.size() > max_mempool_num()) {
|
||||
|
@ -388,7 +388,7 @@ void ValidatorManagerImpl::add_external_message(td::Ref<ExtMessage> msg) {
|
|||
auto id = message->ext_id();
|
||||
auto address = message->address();
|
||||
unsigned long per_address_limit = 256;
|
||||
if(ext_addr_messages_.count(address) < per_address_limit) {
|
||||
if (ext_addr_messages_.count(address) < per_address_limit) {
|
||||
if (ext_messages_hashes_.count(id.hash) == 0) {
|
||||
ext_messages_.emplace(id, std::move(message));
|
||||
ext_messages_hashes_.emplace(id.hash, id);
|
||||
|
@ -401,7 +401,7 @@ void ValidatorManagerImpl::check_external_message(td::BufferSlice data, td::Prom
|
|||
}
|
||||
|
||||
void ValidatorManagerImpl::new_ihr_message(td::BufferSlice data) {
|
||||
if (!is_validator()) {
|
||||
if (!is_collator()) {
|
||||
return;
|
||||
}
|
||||
auto R = create_ihr_message(std::move(data));
|
||||
|
@ -418,7 +418,7 @@ void ValidatorManagerImpl::new_ihr_message(td::BufferSlice data) {
|
|||
}
|
||||
|
||||
void ValidatorManagerImpl::new_shard_block(BlockIdExt block_id, CatchainSeqno cc_seqno, td::BufferSlice data) {
|
||||
if (!is_validator()) {
|
||||
if (!is_collator()) {
|
||||
return;
|
||||
}
|
||||
if (!last_masterchain_block_handle_) {
|
||||
|
@ -2086,7 +2086,7 @@ td::actor::ActorOwn<ValidatorGroup> ValidatorManagerImpl::create_validator_group
|
|||
"validatorgroup", shard, validator_id, session_id, validator_set, last_masterchain_state_->get_collator_set(),
|
||||
opts, keyring_, adnl_, rldp_, overlays_,
|
||||
db_root_, actor_id(this), init_session,
|
||||
opts_->check_unsafe_resync_allowed(validator_set->get_catchain_seqno()), true);
|
||||
opts_->check_unsafe_resync_allowed(validator_set->get_catchain_seqno()), opts_->validator_lite_mode());
|
||||
return G;
|
||||
}
|
||||
}
|
||||
|
@ -2457,14 +2457,14 @@ void ValidatorManagerImpl::get_archive_slice(td::uint64 archive_id, td::uint64 o
|
|||
}
|
||||
|
||||
bool ValidatorManagerImpl::is_validator() {
|
||||
// TODO: change is_vaidator to other condition in some cases
|
||||
return true; // temp_keys_.size() > 0 || permanent_keys_.size() > 0;
|
||||
return temp_keys_.size() > 0 || permanent_keys_.size() > 0;
|
||||
}
|
||||
|
||||
bool ValidatorManagerImpl::is_collator() {
|
||||
return !collator_nodes_.empty() || (!opts_->validator_lite_mode() && is_validator());
|
||||
}
|
||||
|
||||
PublicKeyHash ValidatorManagerImpl::get_validator(ShardIdFull shard, td::Ref<ValidatorSet> val_set) {
|
||||
if (!opts_->need_validate(shard, val_set->get_catchain_seqno())) {
|
||||
return PublicKeyHash::zero();
|
||||
}
|
||||
for (auto &key : temp_keys_) {
|
||||
if (val_set->is_validator(key.bits256_value())) {
|
||||
return key;
|
||||
|
@ -2648,9 +2648,6 @@ void ValidatorManagerImpl::add_collator(adnl::AdnlNodeIdShort id, ShardIdFull sh
|
|||
it = collator_nodes_.emplace(id, std::move(actor)).first;
|
||||
}
|
||||
td::actor::send_closure(it->second, &CollatorNode::add_shard, shard);
|
||||
if (shard.is_masterchain()) {
|
||||
collating_masterchain_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
td::actor::ActorOwn<ValidatorManagerInterface> ValidatorManagerFactory::create(
|
||||
|
|
|
@ -491,6 +491,7 @@ class ValidatorManagerImpl : public ValidatorManager {
|
|||
void read_gc_list(std::vector<ValidatorSessionId> list);
|
||||
|
||||
bool is_validator();
|
||||
bool is_collator();
|
||||
PublicKeyHash get_validator(ShardIdFull shard, td::Ref<ValidatorSet> val_set);
|
||||
|
||||
ValidatorManagerImpl(td::Ref<ValidatorManagerOptions> opts, std::string db_root,
|
||||
|
@ -610,7 +611,6 @@ class ValidatorManagerImpl : public ValidatorManager {
|
|||
std::map<BlockSeqno, WaitList<td::actor::Actor, td::Unit>> shard_client_waiters_;
|
||||
|
||||
std::map<adnl::AdnlNodeIdShort, td::actor::ActorOwn<CollatorNode>> collator_nodes_;
|
||||
bool collating_masterchain_ = false;
|
||||
|
||||
std::set<ShardIdFull> shards_to_monitor_ = {ShardIdFull(masterchainId)};
|
||||
};
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace validator {
|
|||
|
||||
td::Ref<ValidatorManagerOptions> ValidatorManagerOptions::create(
|
||||
BlockIdExt zero_block_id, BlockIdExt init_block_id,
|
||||
std::function<bool(ShardIdFull, CatchainSeqno, ShardCheckMode)> check_shard, bool allow_blockchain_init,
|
||||
std::function<bool(ShardIdFull)> check_shard, bool allow_blockchain_init,
|
||||
double sync_blocks_before, double block_ttl, double state_ttl, double max_mempool_num,
|
||||
double archive_ttl, double key_proof_ttl, bool initial_sync_disabled) {
|
||||
return td::make_ref<ValidatorManagerOptionsImpl>(zero_block_id, init_block_id, std::move(check_shard),
|
||||
|
|
|
@ -33,10 +33,7 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
|
|||
return init_block_id_;
|
||||
}
|
||||
bool need_monitor(ShardIdFull shard) const override {
|
||||
return check_shard_(shard, 0, ShardCheckMode::m_monitor);
|
||||
}
|
||||
bool need_validate(ShardIdFull shard, CatchainSeqno cc_seqno) const override {
|
||||
return check_shard_(shard, cc_seqno, ShardCheckMode::m_validate);
|
||||
return check_shard_(shard);
|
||||
}
|
||||
bool allow_blockchain_init() const override {
|
||||
return allow_blockchain_init_;
|
||||
|
@ -114,6 +111,9 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
|
|||
std::string get_session_logs_file() const override {
|
||||
return session_logs_file_;
|
||||
}
|
||||
bool validator_lite_mode() const override {
|
||||
return validator_lite_mode_;
|
||||
}
|
||||
|
||||
void set_zero_block_id(BlockIdExt block_id) override {
|
||||
zero_block_id_ = block_id;
|
||||
|
@ -121,7 +121,7 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
|
|||
void set_init_block_id(BlockIdExt block_id) override {
|
||||
init_block_id_ = block_id;
|
||||
}
|
||||
void set_shard_check_function(std::function<bool(ShardIdFull, CatchainSeqno, ShardCheckMode)> check_shard) override {
|
||||
void set_shard_check_function(std::function<bool(ShardIdFull)> check_shard) override {
|
||||
check_shard_ = std::move(check_shard);
|
||||
}
|
||||
void set_allow_blockchain_init(bool value) override {
|
||||
|
@ -167,17 +167,18 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
|
|||
void set_session_logs_file(std::string f) override {
|
||||
session_logs_file_ = std::move(f);
|
||||
}
|
||||
void set_validator_lite_mode(bool value) override {
|
||||
validator_lite_mode_ = value;
|
||||
}
|
||||
|
||||
ValidatorManagerOptionsImpl *make_copy() const override {
|
||||
return new ValidatorManagerOptionsImpl(*this);
|
||||
}
|
||||
|
||||
ValidatorManagerOptionsImpl(BlockIdExt zero_block_id, BlockIdExt init_block_id,
|
||||
std::function<bool(ShardIdFull, CatchainSeqno, ShardCheckMode)> check_shard,
|
||||
bool allow_blockchain_init, double sync_blocks_before,
|
||||
double block_ttl, double state_ttl, double max_mempool_num,
|
||||
double archive_ttl, double key_proof_ttl,
|
||||
bool initial_sync_disabled)
|
||||
std::function<bool(ShardIdFull)> check_shard, bool allow_blockchain_init,
|
||||
double sync_blocks_before, double block_ttl, double state_ttl, double max_mempool_num,
|
||||
double archive_ttl, double key_proof_ttl, bool initial_sync_disabled)
|
||||
: zero_block_id_(zero_block_id)
|
||||
, init_block_id_(init_block_id)
|
||||
, check_shard_(std::move(check_shard))
|
||||
|
@ -194,7 +195,7 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
|
|||
private:
|
||||
BlockIdExt zero_block_id_;
|
||||
BlockIdExt init_block_id_;
|
||||
std::function<bool(ShardIdFull, CatchainSeqno, ShardCheckMode)> check_shard_;
|
||||
std::function<bool(ShardIdFull)> check_shard_;
|
||||
bool allow_blockchain_init_;
|
||||
double sync_blocks_before_;
|
||||
double block_ttl_;
|
||||
|
@ -209,6 +210,7 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
|
|||
BlockSeqno truncate_{0};
|
||||
BlockSeqno sync_upto_{0};
|
||||
std::string session_logs_file_;
|
||||
bool validator_lite_mode_ = false;
|
||||
};
|
||||
|
||||
} // namespace validator
|
||||
|
|
|
@ -47,12 +47,9 @@ class DownloadToken {
|
|||
|
||||
struct ValidatorManagerOptions : public td::CntObject {
|
||||
public:
|
||||
enum class ShardCheckMode { m_monitor, m_validate };
|
||||
|
||||
virtual BlockIdExt zero_block_id() const = 0;
|
||||
virtual BlockIdExt init_block_id() const = 0;
|
||||
virtual bool need_monitor(ShardIdFull shard) const = 0;
|
||||
virtual bool need_validate(ShardIdFull shard, CatchainSeqno cc_seqno) const = 0;
|
||||
virtual bool allow_blockchain_init() const = 0;
|
||||
virtual double sync_blocks_before() const = 0;
|
||||
virtual double block_ttl() const = 0;
|
||||
|
@ -75,11 +72,11 @@ struct ValidatorManagerOptions : public td::CntObject {
|
|||
virtual BlockSeqno get_truncate_seqno() const = 0;
|
||||
virtual BlockSeqno sync_upto() const = 0;
|
||||
virtual std::string get_session_logs_file() const = 0;
|
||||
virtual bool validator_lite_mode() const = 0;
|
||||
|
||||
virtual void set_zero_block_id(BlockIdExt block_id) = 0;
|
||||
virtual void set_init_block_id(BlockIdExt block_id) = 0;
|
||||
virtual void set_shard_check_function(
|
||||
std::function<bool(ShardIdFull, CatchainSeqno, ShardCheckMode)> check_shard) = 0;
|
||||
virtual void set_shard_check_function(std::function<bool(ShardIdFull)> check_shard) = 0;
|
||||
virtual void set_allow_blockchain_init(bool value) = 0;
|
||||
virtual void set_sync_blocks_before(double value) = 0;
|
||||
virtual void set_block_ttl(double value) = 0;
|
||||
|
@ -94,11 +91,11 @@ struct ValidatorManagerOptions : public td::CntObject {
|
|||
virtual void truncate_db(BlockSeqno seqno) = 0;
|
||||
virtual void set_sync_upto(BlockSeqno seqno) = 0;
|
||||
virtual void set_session_logs_file(std::string f) = 0;
|
||||
virtual void set_validator_lite_mode(bool value) = 0;
|
||||
|
||||
static td::Ref<ValidatorManagerOptions> create(
|
||||
BlockIdExt zero_block_id, BlockIdExt init_block_id,
|
||||
std::function<bool(ShardIdFull, CatchainSeqno, ShardCheckMode)> check_shard = [](ShardIdFull, CatchainSeqno,
|
||||
ShardCheckMode) { return true; },
|
||||
std::function<bool(ShardIdFull)> check_shard = [](ShardIdFull) { return true; },
|
||||
bool allow_blockchain_init = false, double sync_blocks_before = 86400, double block_ttl = 86400 * 7,
|
||||
double state_ttl = 3600, double archive_ttl = 86400 * 365, double key_proof_ttl = 86400 * 3650,
|
||||
double max_mempool_num = 999999,
|
||||
|
|
Loading…
Reference in a new issue