-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move recently_cemented_cache and recently_confirmed_cache to their ow…
…n files. (#4606)
- Loading branch information
Showing
7 changed files
with
215 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <nano/lib/utility.hpp> | ||
#include <nano/node/recently_cemented_cache.hpp> | ||
|
||
/* | ||
* class recently_cemented | ||
*/ | ||
|
||
nano::recently_cemented_cache::recently_cemented_cache (std::size_t max_size_a) : | ||
max_size{ max_size_a } | ||
{ | ||
} | ||
|
||
void nano::recently_cemented_cache::put (const nano::election_status & status) | ||
{ | ||
nano::lock_guard<nano::mutex> guard{ mutex }; | ||
cemented.push_back (status); | ||
if (cemented.size () > max_size) | ||
{ | ||
cemented.pop_front (); | ||
} | ||
} | ||
|
||
nano::recently_cemented_cache::queue_t nano::recently_cemented_cache::list () const | ||
{ | ||
nano::lock_guard<nano::mutex> guard{ mutex }; | ||
return cemented; | ||
} | ||
|
||
std::size_t nano::recently_cemented_cache::size () const | ||
{ | ||
nano::lock_guard<nano::mutex> guard{ mutex }; | ||
return cemented.size (); | ||
} | ||
|
||
std::unique_ptr<nano::container_info_component> nano::recently_cemented_cache::collect_container_info (const std::string & name) | ||
{ | ||
nano::unique_lock<nano::mutex> lock{ mutex }; | ||
|
||
auto composite = std::make_unique<container_info_composite> (name); | ||
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "cemented", cemented.size (), sizeof (decltype (cemented)::value_type) })); | ||
return composite; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include <nano/lib/locks.hpp> | ||
#include <nano/node/election_status.hpp> | ||
|
||
#include <deque> | ||
|
||
namespace nano | ||
{ | ||
class container_info_component; | ||
} | ||
|
||
namespace nano | ||
{ | ||
/* | ||
* Helper container for storing recently cemented elections (a block from election might be confirmed but not yet cemented by confirmation height processor) | ||
*/ | ||
class recently_cemented_cache final | ||
{ | ||
public: | ||
using queue_t = std::deque<nano::election_status>; | ||
|
||
explicit recently_cemented_cache (std::size_t max_size); | ||
|
||
void put (nano::election_status const &); | ||
queue_t list () const; | ||
std::size_t size () const; | ||
|
||
private: | ||
queue_t cemented; | ||
std::size_t const max_size; | ||
|
||
mutable nano::mutex mutex; | ||
|
||
public: // Container info | ||
std::unique_ptr<container_info_component> collect_container_info (std::string const &); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#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 (); | ||
} | ||
|
||
std::unique_ptr<nano::container_info_component> nano::recently_confirmed_cache::collect_container_info (const std::string & name) | ||
{ | ||
nano::unique_lock<nano::mutex> lock{ mutex }; | ||
|
||
auto composite = std::make_unique<container_info_composite> (name); | ||
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "confirmed", confirmed.size (), sizeof (decltype (confirmed)::value_type) })); | ||
return composite; | ||
} |
Oops, something went wrong.