mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Add option --catchain-max-block-delay (#990)
Co-authored-by: SpyCheese <mikle98@yandex.ru>
This commit is contained in:
parent
c7fd75ce56
commit
816dd9cf2d
10 changed files with 43 additions and 5 deletions
|
@ -1372,6 +1372,9 @@ td::Status ValidatorEngine::load_global_config() {
|
|||
if (celldb_cache_size_) {
|
||||
validator_options_.write().set_celldb_cache_size(celldb_cache_size_.value());
|
||||
}
|
||||
if (catchain_max_block_delay_) {
|
||||
validator_options_.write().set_catchain_max_block_delay(catchain_max_block_delay_.value());
|
||||
}
|
||||
|
||||
std::vector<ton::BlockIdExt> h;
|
||||
for (auto &x : conf.validator_->hardforks_) {
|
||||
|
@ -3981,6 +3984,16 @@ int main(int argc, char *argv[]) {
|
|||
acts.push_back([&x, v]() { td::actor::send_closure(x, &ValidatorEngine::set_celldb_cache_size, v); });
|
||||
return td::Status::OK();
|
||||
});
|
||||
p.add_checked_option(
|
||||
'\0', "catchain-max-block-delay", "delay before creating a new catchain block, in seconds (default: 0.5)",
|
||||
[&](td::Slice s) -> td::Status {
|
||||
auto v = td::to_double(s);
|
||||
if (v < 0) {
|
||||
return td::Status::Error("catchain-max-block-delay should be non-negative");
|
||||
}
|
||||
acts.push_back([&x, v]() { td::actor::send_closure(x, &ValidatorEngine::set_catchain_max_block_delay, v); });
|
||||
return td::Status::OK();
|
||||
});
|
||||
auto S = p.run(argc, argv);
|
||||
if (S.is_error()) {
|
||||
LOG(ERROR) << "failed to parse options: " << S.move_as_error();
|
||||
|
|
|
@ -210,6 +210,7 @@ class ValidatorEngine : public td::actor::Actor {
|
|||
bool disable_rocksdb_stats_ = false;
|
||||
bool nonfinal_ls_queries_enabled_ = false;
|
||||
td::optional<td::uint64> celldb_cache_size_;
|
||||
td::optional<double> catchain_max_block_delay_;
|
||||
bool read_config_ = false;
|
||||
bool started_keyring_ = false;
|
||||
bool started_ = false;
|
||||
|
@ -285,6 +286,9 @@ class ValidatorEngine : public td::actor::Actor {
|
|||
void set_celldb_cache_size(td::uint64 value) {
|
||||
celldb_cache_size_ = value;
|
||||
}
|
||||
void set_catchain_max_block_delay(double value) {
|
||||
catchain_max_block_delay_ = value;
|
||||
}
|
||||
void start_up() override;
|
||||
ValidatorEngine() {
|
||||
}
|
||||
|
|
|
@ -807,8 +807,8 @@ void ValidatorSessionImpl::request_new_block(bool now) {
|
|||
} else {
|
||||
double lambda = 10.0 / description().get_total_nodes();
|
||||
double x = -1 / lambda * log(td::Random::fast(1, 999) * 0.001);
|
||||
if (x > 0.5) {
|
||||
x = 0.5;
|
||||
if (x > catchain_max_block_delay_) { // default = 0.5
|
||||
x = catchain_max_block_delay_;
|
||||
}
|
||||
td::actor::send_closure(catchain_, &catchain::CatChain::need_new_block, td::Timestamp::in(x));
|
||||
}
|
||||
|
|
|
@ -108,6 +108,7 @@ class ValidatorSession : public td::actor::Actor {
|
|||
virtual void get_validator_group_info_for_litequery(
|
||||
td::uint32 cur_round,
|
||||
td::Promise<std::vector<tl_object_ptr<lite_api::liteServer_nonfinal_candidateInfo>>> promise) = 0;
|
||||
virtual void set_catchain_max_block_delay(double value) = 0;
|
||||
|
||||
static td::actor::ActorOwn<ValidatorSession> create(
|
||||
catchain::CatChainSessionId session_id, ValidatorSessionOptions opts, PublicKeyHash local_id,
|
||||
|
|
|
@ -90,6 +90,8 @@ class ValidatorSessionImpl : public ValidatorSession {
|
|||
td::actor::ActorOwn<catchain::CatChain> catchain_;
|
||||
std::unique_ptr<ValidatorSessionDescription> description_;
|
||||
|
||||
double catchain_max_block_delay_ = 0.5;
|
||||
|
||||
void on_new_round(td::uint32 round);
|
||||
void on_catchain_started();
|
||||
void check_vote_for_slot(td::uint32 att);
|
||||
|
@ -188,6 +190,9 @@ class ValidatorSessionImpl : public ValidatorSession {
|
|||
void get_validator_group_info_for_litequery(
|
||||
td::uint32 cur_round,
|
||||
td::Promise<std::vector<tl_object_ptr<lite_api::liteServer_nonfinal_candidateInfo>>> promise) override;
|
||||
void set_catchain_max_block_delay(double value) override {
|
||||
catchain_max_block_delay_ = value;
|
||||
}
|
||||
|
||||
void process_blocks(std::vector<catchain::CatChainBlock *> blocks);
|
||||
void finished_processing();
|
||||
|
|
|
@ -2135,7 +2135,7 @@ td::actor::ActorOwn<ValidatorGroup> ValidatorManagerImpl::create_validator_group
|
|||
auto G = td::actor::create_actor<ValidatorGroup>(
|
||||
"validatorgroup", shard, validator_id, session_id, validator_set, opts, keyring_, adnl_, rldp_, overlays_,
|
||||
db_root_, actor_id(this), init_session,
|
||||
opts_->check_unsafe_resync_allowed(validator_set->get_catchain_seqno()));
|
||||
opts_->check_unsafe_resync_allowed(validator_set->get_catchain_seqno()), opts_);
|
||||
return G;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -348,6 +348,10 @@ void ValidatorGroup::create_session() {
|
|||
<< ".",
|
||||
allow_unsafe_self_blocks_resync_);
|
||||
}
|
||||
if (opts_->get_catchain_max_block_delay()) {
|
||||
td::actor::send_closure(session_, &validatorsession::ValidatorSession::set_catchain_max_block_delay,
|
||||
opts_->get_catchain_max_block_delay().value());
|
||||
}
|
||||
if (started_) {
|
||||
td::actor::send_closure(session_, &validatorsession::ValidatorSession::start);
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ class ValidatorGroup : public td::actor::Actor {
|
|||
td::actor::ActorId<keyring::Keyring> keyring, td::actor::ActorId<adnl::Adnl> adnl,
|
||||
td::actor::ActorId<rldp::Rldp> rldp, td::actor::ActorId<overlay::Overlays> overlays,
|
||||
std::string db_root, td::actor::ActorId<ValidatorManager> validator_manager, bool create_session,
|
||||
bool allow_unsafe_self_blocks_resync)
|
||||
bool allow_unsafe_self_blocks_resync, td::Ref<ValidatorManagerOptions> opts)
|
||||
: shard_(shard)
|
||||
, local_id_(std::move(local_id))
|
||||
, session_id_(session_id)
|
||||
|
@ -82,7 +82,8 @@ class ValidatorGroup : public td::actor::Actor {
|
|||
, db_root_(std::move(db_root))
|
||||
, manager_(validator_manager)
|
||||
, init_(create_session)
|
||||
, allow_unsafe_self_blocks_resync_(allow_unsafe_self_blocks_resync) {
|
||||
, allow_unsafe_self_blocks_resync_(allow_unsafe_self_blocks_resync)
|
||||
, opts_(std::move(opts)) {
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -123,6 +124,7 @@ class ValidatorGroup : public td::actor::Actor {
|
|||
bool init_ = false;
|
||||
bool started_ = false;
|
||||
bool allow_unsafe_self_blocks_resync_;
|
||||
td::Ref<ValidatorManagerOptions> opts_;
|
||||
td::uint32 last_known_round_id_ = 0;
|
||||
|
||||
struct CachedCollatedBlock {
|
||||
|
|
|
@ -132,6 +132,9 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
|
|||
td::optional<td::uint64> get_celldb_cache_size() const override {
|
||||
return celldb_cache_size_;
|
||||
}
|
||||
td::optional<double> get_catchain_max_block_delay() const override {
|
||||
return catchain_max_block_delay_;
|
||||
}
|
||||
|
||||
void set_zero_block_id(BlockIdExt block_id) override {
|
||||
zero_block_id_ = block_id;
|
||||
|
@ -203,6 +206,9 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
|
|||
void set_celldb_cache_size(td::uint64 value) override {
|
||||
celldb_cache_size_ = value;
|
||||
}
|
||||
void set_catchain_max_block_delay(double value) override {
|
||||
catchain_max_block_delay_ = value;
|
||||
}
|
||||
|
||||
ValidatorManagerOptionsImpl *make_copy() const override {
|
||||
return new ValidatorManagerOptionsImpl(*this);
|
||||
|
@ -251,6 +257,7 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
|
|||
bool disable_rocksdb_stats_;
|
||||
bool nonfinal_ls_queries_enabled_ = false;
|
||||
td::optional<td::uint64> celldb_cache_size_;
|
||||
td::optional<double> catchain_max_block_delay_;
|
||||
};
|
||||
|
||||
} // namespace validator
|
||||
|
|
|
@ -87,6 +87,7 @@ struct ValidatorManagerOptions : public td::CntObject {
|
|||
virtual bool get_disable_rocksdb_stats() const = 0;
|
||||
virtual bool nonfinal_ls_queries_enabled() const = 0;
|
||||
virtual td::optional<td::uint64> get_celldb_cache_size() const = 0;
|
||||
virtual td::optional<double> get_catchain_max_block_delay() const = 0;
|
||||
|
||||
virtual void set_zero_block_id(BlockIdExt block_id) = 0;
|
||||
virtual void set_init_block_id(BlockIdExt block_id) = 0;
|
||||
|
@ -112,6 +113,7 @@ struct ValidatorManagerOptions : public td::CntObject {
|
|||
virtual void set_disable_rocksdb_stats(bool value) = 0;
|
||||
virtual void set_nonfinal_ls_queries_enabled(bool value) = 0;
|
||||
virtual void set_celldb_cache_size(td::uint64 value) = 0;
|
||||
virtual void set_catchain_max_block_delay(double value) = 0;
|
||||
|
||||
static td::Ref<ValidatorManagerOptions> create(
|
||||
BlockIdExt zero_block_id, BlockIdExt init_block_id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue