Skip to content

Commit

Permalink
Add option --catchain-max-block-delay (ton-blockchain#990)
Browse files Browse the repository at this point in the history
Co-authored-by: SpyCheese <[email protected]>
  • Loading branch information
EmelyanenkoK and SpyCheese authored May 13, 2024
1 parent c7fd75c commit 816dd9c
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 5 deletions.
13 changes: 13 additions & 0 deletions validator-engine/validator-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions validator-engine/validator-engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
}
Expand Down
4 changes: 2 additions & 2 deletions validator-session/validator-session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
1 change: 1 addition & 0 deletions validator-session/validator-session.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions validator-session/validator-session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion validator/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
4 changes: 4 additions & 0 deletions validator/validator-group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions validator/validator-group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions validator/validator-options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions validator/validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit 816dd9c

Please sign in to comment.