27 m_offsets.pop_front();
29 m_offsets.push_back(offset);
31 Ticks<std::chrono::seconds>(offset), m_offsets.size());
39 if (m_offsets.size() < 5)
return 0s;
41 auto sorted_copy = m_offsets;
42 std::sort(sorted_copy.begin(), sorted_copy.end());
43 return sorted_copy[sorted_copy.size() / 2];
49 auto median{std::max(Median(), std::chrono::seconds(std::numeric_limits<int64_t>::min() + 1))};
50 if (std::chrono::abs(median) <= WARN_THRESHOLD) {
56 "Your computer's date and time appear to be more than %d minutes out of sync with the network, " 57 "this may lead to consensus failure. After you've confirmed your computer's clock, this message " 58 "should no longer appear when you restart your node. Without a restart, it should stop showing " 59 "automatically after you've connected to a sufficient number of new outbound peers, which may " 60 "take some time. You can inspect the `timeoffset` field of the `getpeerinfo` and `getnetworkinfo` " 61 "RPC methods to get more info." 62 ), Ticks<std::chrono::minutes>(WARN_THRESHOLD))};
bool WarnIfOutOfSync() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Raise warnings if the median time offset exceeds the warnings threshold.
void Add(std::chrono::seconds offset) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Add a new time offset sample.
#define LogDebug(category,...)
std::chrono::seconds Median() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Compute and return the median of the collected time offset samples.
static constexpr uint64_t MAX_SIZE
The maximum size of a serialized object in bytes or number of elements (for eg vectors) when the size...
bilingual_str _(ConstevalStringLiteral str)
Translation function.