Skip to content

Commit

Permalink
Extend timeout in collator if previous block is too old
Browse files Browse the repository at this point in the history
  • Loading branch information
SpyCheese committed Dec 6, 2023
1 parent 31a71e2 commit 379e37d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tdutils/td/utils/Time.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class Timestamp {
}

friend bool operator==(Timestamp a, Timestamp b);
friend Timestamp &operator+=(Timestamp &a, double b);

private:
double at_{0};
Expand All @@ -122,6 +123,11 @@ inline bool operator<(const Timestamp &a, const Timestamp &b) {
return a.at() < b.at();
}

inline Timestamp &operator+=(Timestamp &a, double b) {
a.at_ += b;
return a;
}

template <class StorerT>
void store(const Timestamp &timestamp, StorerT &storer) {
storer.store_binary(timestamp.at() - Time::now() + Clocks::system());
Expand Down
11 changes: 11 additions & 0 deletions validator/impl/collator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,17 @@ bool Collator::init_utime() {
CHECK(config_);
// consider unixtime and lt from previous block(s) of the same shardchain
prev_now_ = prev_state_utime_;
// Extend collator timeout if previous block is too old
td::Timestamp new_timeout = td::Timestamp::in(std::min(30.0, (td::Clocks::system() - (double)prev_now_) / 2));
if (timeout < new_timeout) {
double add = new_timeout.at() - timeout.at();
timeout = new_timeout;
queue_cleanup_timeout_ += add;
soft_timeout_ += add;
medium_timeout_ += add;
alarm_timestamp() = timeout;
}

auto prev = std::max<td::uint32>(config_->utime, prev_now_);
now_ = std::max<td::uint32>(prev + 1, (unsigned)std::time(nullptr));
if (now_ > now_upper_limit_) {
Expand Down

0 comments on commit 379e37d

Please sign in to comment.