20using namespace std::chrono_literals;
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 0
s;
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))};
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."
void Add(std::chrono::seconds offset) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Add a new time offset sample.
static constexpr size_t MAX_SIZE
Maximum number of timeoffsets stored.
node::Warnings & m_warnings
bool WarnIfOutOfSync() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Raise warnings if the median time offset exceeds the warnings threshold.
std::chrono::seconds Median() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Compute and return the median of the collected time offset samples.
static constexpr std::chrono::minutes WARN_THRESHOLD
Minimum difference between system and network time for a warning to be raised.
bool Unset(warning_type id) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Unset a warning message.
bool Set(warning_type id, bilingual_str message) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Set a warning message.
#define LogDebug(category,...)
bilingual_str _(ConstevalStringLiteral str)
Translation function.