Recompile time for voting.hpp before and vote headers after Before: [117/117] Linking CXX executable rpc_test ninja 1262.92s user 87.90s system 869% cpu 2:35.28 total After: [16/16] Linking CXX executable nano_node ninja 98.05s user 11.24s system 377% cpu 28.917 total
39 lines
1.1 KiB
C++
39 lines
1.1 KiB
C++
#include <nano/node/vote_spacing.hpp>
|
|
|
|
void nano::vote_spacing::trim ()
|
|
{
|
|
recent.get<tag_time> ().erase (recent.get<tag_time> ().begin (), recent.get<tag_time> ().upper_bound (std::chrono::steady_clock::now () - delay));
|
|
}
|
|
|
|
bool nano::vote_spacing::votable (nano::root const & root_a, nano::block_hash const & hash_a) const
|
|
{
|
|
bool result = true;
|
|
for (auto range = recent.get<tag_root> ().equal_range (root_a); result && range.first != range.second; ++range.first)
|
|
{
|
|
auto & item = *range.first;
|
|
result = hash_a == item.hash || item.time < std::chrono::steady_clock::now () - delay;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
void nano::vote_spacing::flag (nano::root const & root_a, nano::block_hash const & hash_a)
|
|
{
|
|
trim ();
|
|
auto now = std::chrono::steady_clock::now ();
|
|
auto existing = recent.get<tag_root> ().find (root_a);
|
|
if (existing != recent.end ())
|
|
{
|
|
recent.get<tag_root> ().modify (existing, [now] (entry & entry) {
|
|
entry.time = now;
|
|
});
|
|
}
|
|
else
|
|
{
|
|
recent.insert ({ root_a, now, hash_a });
|
|
}
|
|
}
|
|
|
|
std::size_t nano::vote_spacing::size () const
|
|
{
|
|
return recent.size ();
|
|
}
|