1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

Merge branch 'safe_features' into testnet-update

This commit is contained in:
SpyCheese 2024-09-06 11:48:46 +03:00
commit feff73c4be
41 changed files with 1066 additions and 207 deletions

View file

@ -478,6 +478,14 @@ class ValidatorSessionState : public ValidatorSessionDescription::RootObject {
auto get_ts(td::uint32 src_idx) const {
return att_->at(src_idx);
}
td::uint32 cur_attempt_in_round(const ValidatorSessionDescription& desc) const {
td::uint32 first_attempt = cur_round_->get_first_attempt(desc.get_self_idx());
td::uint32 cur_attempt = desc.get_attempt_seqno(desc.get_ts());
if (cur_attempt < first_attempt || first_attempt == 0) {
return 0;
}
return cur_attempt - first_attempt;
}
const SentBlock* choose_block_to_sign(ValidatorSessionDescription& desc, td::uint32 src_idx, bool& found) const;
const SentBlock* get_committed_block(ValidatorSessionDescription& desc, td::uint32 seqno) const;

View file

@ -814,13 +814,25 @@ 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 > catchain_max_block_delay_) { // default = 0.5
x = catchain_max_block_delay_;
}
x = std::min(x, get_current_max_block_delay()); // default = 0.4
td::actor::send_closure(catchain_, &catchain::CatChain::need_new_block, td::Timestamp::in(x));
}
}
double ValidatorSessionImpl::get_current_max_block_delay() const {
td::uint32 att = real_state_->cur_attempt_in_round(*description_);
td::uint32 att1 = description_->opts().max_round_attempts;
if (att <= att1) {
return catchain_max_block_delay_;
}
td::uint32 att2 = att1 + 4;
if (att >= att2) {
return catchain_max_block_delay_slow_;
}
return catchain_max_block_delay_ +
(catchain_max_block_delay_slow_ - catchain_max_block_delay_) * (double)(att - att1) / (double)(att2 - att1);
}
void ValidatorSessionImpl::on_new_round(td::uint32 round) {
if (round != 0) {
CHECK(cur_round_ < round);

View file

@ -109,7 +109,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;
virtual void set_catchain_max_block_delay(double delay, double delay_slow) = 0;
static td::actor::ActorOwn<ValidatorSession> create(
catchain::CatChainSessionId session_id, ValidatorSessionOptions opts, PublicKeyHash local_id,

View file

@ -91,6 +91,7 @@ class ValidatorSessionImpl : public ValidatorSession {
std::unique_ptr<ValidatorSessionDescription> description_;
double catchain_max_block_delay_ = 0.4;
double catchain_max_block_delay_slow_ = 1.0;
void on_new_round(td::uint32 round);
void on_catchain_started();
@ -150,6 +151,7 @@ class ValidatorSessionImpl : public ValidatorSession {
}
void request_new_block(bool now);
double get_current_max_block_delay() const;
void get_broadcast_p2p(PublicKeyHash node, ValidatorSessionFileHash file_hash,
ValidatorSessionCollatedDataFileHash collated_data_file_hash, PublicKeyHash src,
td::uint32 round, ValidatorSessionRootHash root_hash, td::Promise<td::BufferSlice> promise,
@ -191,8 +193,10 @@ 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 set_catchain_max_block_delay(double delay, double delay_slow) override {
catchain_max_block_delay_ = delay;
catchain_max_block_delay_slow_ = delay_slow;
}
void process_blocks(std::vector<catchain::CatChainBlock *> blocks);