* Move container info classes to separate file * Introduce better `container_info` class * Rename legacy to `container_info_entry` * Conversion * Test * Fixes
66 lines
1.7 KiB
C++
66 lines
1.7 KiB
C++
#include <nano/lib/utility.hpp>
|
|
#include <nano/node/recently_confirmed_cache.hpp>
|
|
|
|
/*
|
|
* class recently_confirmed
|
|
*/
|
|
|
|
nano::recently_confirmed_cache::recently_confirmed_cache (std::size_t max_size_a) :
|
|
max_size{ max_size_a }
|
|
{
|
|
}
|
|
|
|
void nano::recently_confirmed_cache::put (const nano::qualified_root & root, const nano::block_hash & hash)
|
|
{
|
|
nano::lock_guard<nano::mutex> guard{ mutex };
|
|
confirmed.get<tag_sequence> ().emplace_back (root, hash);
|
|
if (confirmed.size () > max_size)
|
|
{
|
|
confirmed.get<tag_sequence> ().pop_front ();
|
|
}
|
|
}
|
|
|
|
void nano::recently_confirmed_cache::erase (const nano::block_hash & hash)
|
|
{
|
|
nano::lock_guard<nano::mutex> guard{ mutex };
|
|
confirmed.get<tag_hash> ().erase (hash);
|
|
}
|
|
|
|
void nano::recently_confirmed_cache::clear ()
|
|
{
|
|
nano::lock_guard<nano::mutex> guard{ mutex };
|
|
confirmed.clear ();
|
|
}
|
|
|
|
bool nano::recently_confirmed_cache::exists (const nano::block_hash & hash) const
|
|
{
|
|
nano::lock_guard<nano::mutex> guard{ mutex };
|
|
return confirmed.get<tag_hash> ().find (hash) != confirmed.get<tag_hash> ().end ();
|
|
}
|
|
|
|
bool nano::recently_confirmed_cache::exists (const nano::qualified_root & root) const
|
|
{
|
|
nano::lock_guard<nano::mutex> guard{ mutex };
|
|
return confirmed.get<tag_root> ().find (root) != confirmed.get<tag_root> ().end ();
|
|
}
|
|
|
|
std::size_t nano::recently_confirmed_cache::size () const
|
|
{
|
|
nano::lock_guard<nano::mutex> guard{ mutex };
|
|
return confirmed.size ();
|
|
}
|
|
|
|
nano::recently_confirmed_cache::entry_t nano::recently_confirmed_cache::back () const
|
|
{
|
|
nano::lock_guard<nano::mutex> guard{ mutex };
|
|
return confirmed.back ();
|
|
}
|
|
|
|
nano::container_info nano::recently_confirmed_cache::container_info () const
|
|
{
|
|
nano::lock_guard<nano::mutex> guard{ mutex };
|
|
|
|
nano::container_info info;
|
|
info.put ("confirmed", confirmed);
|
|
return info;
|
|
}
|