Moves out peer methods from the block store class (#3318)
* Moves out peer methods from the block store class
This commit is contained in:
parent
cb4906c2be
commit
b172d4d62f
19 changed files with 141 additions and 94 deletions
|
@ -1077,57 +1077,57 @@ TEST (block_store, peers)
|
|||
auto transaction (store->tx_begin_write ());
|
||||
|
||||
// Confirm that the store is empty
|
||||
ASSERT_FALSE (store->peer_exists (transaction, endpoint));
|
||||
ASSERT_EQ (store->peer_count (transaction), 0);
|
||||
ASSERT_FALSE (store->peer.exists (transaction, endpoint));
|
||||
ASSERT_EQ (store->peer.count (transaction), 0);
|
||||
|
||||
// Add one
|
||||
store->peer_put (transaction, endpoint);
|
||||
ASSERT_TRUE (store->peer_exists (transaction, endpoint));
|
||||
store->peer.put (transaction, endpoint);
|
||||
ASSERT_TRUE (store->peer.exists (transaction, endpoint));
|
||||
}
|
||||
|
||||
// Confirm that it can be found
|
||||
{
|
||||
auto transaction (store->tx_begin_read ());
|
||||
ASSERT_EQ (store->peer_count (transaction), 1);
|
||||
ASSERT_EQ (store->peer.count (transaction), 1);
|
||||
}
|
||||
|
||||
// Add another one and check that it (and the existing one) can be found
|
||||
nano::endpoint_key endpoint1 (boost::asio::ip::address_v6::any ().to_bytes (), 101);
|
||||
{
|
||||
auto transaction (store->tx_begin_write ());
|
||||
store->peer_put (transaction, endpoint1);
|
||||
ASSERT_TRUE (store->peer_exists (transaction, endpoint1)); // Check new peer is here
|
||||
ASSERT_TRUE (store->peer_exists (transaction, endpoint)); // Check first peer is still here
|
||||
store->peer.put (transaction, endpoint1);
|
||||
ASSERT_TRUE (store->peer.exists (transaction, endpoint1)); // Check new peer is here
|
||||
ASSERT_TRUE (store->peer.exists (transaction, endpoint)); // Check first peer is still here
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction (store->tx_begin_read ());
|
||||
ASSERT_EQ (store->peer_count (transaction), 2);
|
||||
ASSERT_EQ (store->peer.count (transaction), 2);
|
||||
}
|
||||
|
||||
// Delete the first one
|
||||
{
|
||||
auto transaction (store->tx_begin_write ());
|
||||
store->peer_del (transaction, endpoint1);
|
||||
ASSERT_FALSE (store->peer_exists (transaction, endpoint1)); // Confirm it no longer exists
|
||||
ASSERT_TRUE (store->peer_exists (transaction, endpoint)); // Check first peer is still here
|
||||
store->peer.del (transaction, endpoint1);
|
||||
ASSERT_FALSE (store->peer.exists (transaction, endpoint1)); // Confirm it no longer exists
|
||||
ASSERT_TRUE (store->peer.exists (transaction, endpoint)); // Check first peer is still here
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction (store->tx_begin_read ());
|
||||
ASSERT_EQ (store->peer_count (transaction), 1);
|
||||
ASSERT_EQ (store->peer.count (transaction), 1);
|
||||
}
|
||||
|
||||
// Delete original one
|
||||
{
|
||||
auto transaction (store->tx_begin_write ());
|
||||
store->peer_del (transaction, endpoint);
|
||||
ASSERT_FALSE (store->peer_exists (transaction, endpoint));
|
||||
store->peer.del (transaction, endpoint);
|
||||
ASSERT_FALSE (store->peer.exists (transaction, endpoint));
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction (store->tx_begin_read ());
|
||||
ASSERT_EQ (store->peer_count (transaction), 0);
|
||||
ASSERT_EQ (store->peer.count (transaction), 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3864,7 +3864,7 @@ TEST (ledger, migrate_lmdb_to_rocksdb)
|
|||
|
||||
store.online_weight.put (transaction, 100, nano::amount (2));
|
||||
store.frontier.put (transaction, nano::block_hash (2), nano::account (5));
|
||||
store.peer_put (transaction, endpoint_key);
|
||||
store.peer.put (transaction, endpoint_key);
|
||||
|
||||
store.pending.put (transaction, nano::pending_key (nano::genesis_account, send->hash ()), nano::pending_info (nano::genesis_account, 100, nano::epoch::epoch_0));
|
||||
store.pruned.put (transaction, send->hash ());
|
||||
|
@ -3895,7 +3895,7 @@ TEST (ledger, migrate_lmdb_to_rocksdb)
|
|||
auto block1 = rocksdb_store.block_get (rocksdb_transaction, send->hash ());
|
||||
|
||||
ASSERT_EQ (*send, *block1);
|
||||
ASSERT_TRUE (rocksdb_store.peer_exists (rocksdb_transaction, endpoint_key));
|
||||
ASSERT_TRUE (rocksdb_store.peer.exists (rocksdb_transaction, endpoint_key));
|
||||
ASSERT_EQ (rocksdb_store.version_get (rocksdb_transaction), version);
|
||||
ASSERT_EQ (rocksdb_store.frontier.get (rocksdb_transaction, 2), 5);
|
||||
nano::confirmation_height_info confirmation_height_info;
|
||||
|
|
|
@ -3577,10 +3577,10 @@ TEST (node, peers)
|
|||
{
|
||||
// Add a peer to the database
|
||||
auto transaction (store.tx_begin_write ());
|
||||
store.peer_put (transaction, endpoint_key);
|
||||
store.peer.put (transaction, endpoint_key);
|
||||
|
||||
// Add a peer which is not contactable
|
||||
store.peer_put (transaction, nano::endpoint_key{ boost::asio::ip::address_v6::any ().to_bytes (), 55555 });
|
||||
store.peer.put (transaction, nano::endpoint_key{ boost::asio::ip::address_v6::any ().to_bytes (), 55555 });
|
||||
}
|
||||
|
||||
node2->start ();
|
||||
|
@ -3605,8 +3605,8 @@ TEST (node, peers)
|
|||
|
||||
// Uncontactable peer should not be stored
|
||||
auto transaction (store.tx_begin_read ());
|
||||
ASSERT_EQ (store.peer_count (transaction), 1);
|
||||
ASSERT_TRUE (store.peer_exists (transaction, endpoint_key));
|
||||
ASSERT_EQ (store.peer.count (transaction), 1);
|
||||
ASSERT_TRUE (store.peer.exists (transaction, endpoint_key));
|
||||
|
||||
node2->stop ();
|
||||
}
|
||||
|
@ -3626,7 +3626,7 @@ TEST (node, peer_cache_restart)
|
|||
{
|
||||
// Add a peer to the database
|
||||
auto transaction (store.tx_begin_write ());
|
||||
store.peer_put (transaction, endpoint_key);
|
||||
store.peer.put (transaction, endpoint_key);
|
||||
}
|
||||
node2->start ();
|
||||
ASSERT_TIMELY (10s, !node2->network.empty ());
|
||||
|
@ -3649,8 +3649,8 @@ TEST (node, peer_cache_restart)
|
|||
auto & store = node3->store;
|
||||
{
|
||||
auto transaction (store.tx_begin_read ());
|
||||
ASSERT_EQ (store.peer_count (transaction), 1);
|
||||
ASSERT_TRUE (store.peer_exists (transaction, endpoint_key));
|
||||
ASSERT_EQ (store.peer.count (transaction), 1);
|
||||
ASSERT_TRUE (store.peer.exists (transaction, endpoint_key));
|
||||
}
|
||||
ASSERT_TIMELY (10s, !node3->network.empty ());
|
||||
// Confirm that the peers match with the endpoints we are expecting
|
||||
|
|
|
@ -1865,7 +1865,7 @@ int main (int argc, char * const * argv)
|
|||
auto node = inactive_node->node;
|
||||
auto transaction (node->store.tx_begin_read ());
|
||||
|
||||
for (auto i (node->store.peers_begin (transaction)), n (node->store.peers_end ()); i != n; ++i)
|
||||
for (auto i (node->store.peer.begin (transaction)), n (node->store.peer.end ()); i != n; ++i)
|
||||
{
|
||||
std::cout << boost::str (boost::format ("%1%\n") % nano::endpoint (boost::asio::ip::address_v6 (i->first.address_bytes ()), i->first.port ()));
|
||||
}
|
||||
|
|
|
@ -232,7 +232,7 @@ bool copy_database (boost::filesystem::path const & data_path, boost::program_op
|
|||
}
|
||||
if (vm.count ("peer_clear"))
|
||||
{
|
||||
node.node->store.peer_clear (store.tx_begin_write ());
|
||||
node.node->store.peer.clear (store.tx_begin_write ());
|
||||
}
|
||||
if (vm.count ("confirmation_height_clear"))
|
||||
{
|
||||
|
@ -545,7 +545,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
if (!node.node->init_error ())
|
||||
{
|
||||
auto transaction (node.node->store.tx_begin_write ());
|
||||
node.node->store.peer_clear (transaction);
|
||||
node.node->store.peer.clear (transaction);
|
||||
std::cout << "Database peers are removed" << std::endl;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -192,7 +192,7 @@ void nano::mdb_store::open_databases (bool & error_a, nano::transaction const &
|
|||
error_a |= mdb_dbi_open (env.tx (transaction_a), "unchecked", flags, &unchecked) != 0;
|
||||
error_a |= mdb_dbi_open (env.tx (transaction_a), "online_weight", flags, &online_weight_handle) != 0;
|
||||
error_a |= mdb_dbi_open (env.tx (transaction_a), "meta", flags, &meta) != 0;
|
||||
error_a |= mdb_dbi_open (env.tx (transaction_a), "peers", flags, &peers) != 0;
|
||||
error_a |= mdb_dbi_open (env.tx (transaction_a), "peers", flags, &peer_handle) != 0;
|
||||
error_a |= mdb_dbi_open (env.tx (transaction_a), "pruned", flags, &pruned_handle) != 0;
|
||||
error_a |= mdb_dbi_open (env.tx (transaction_a), "confirmation_height", flags, &confirmation_height_handle) != 0;
|
||||
error_a |= mdb_dbi_open (env.tx (transaction_a), "accounts", flags, &accounts_v0) != 0;
|
||||
|
@ -872,7 +872,7 @@ MDB_dbi nano::mdb_store::table_to_dbi (tables table_a) const
|
|||
case tables::meta:
|
||||
return meta;
|
||||
case tables::peers:
|
||||
return peers;
|
||||
return peer_handle;
|
||||
case tables::pruned:
|
||||
return pruned_handle;
|
||||
case tables::confirmation_height:
|
||||
|
@ -881,7 +881,7 @@ MDB_dbi nano::mdb_store::table_to_dbi (tables table_a) const
|
|||
return final_vote_handle;
|
||||
default:
|
||||
release_assert (false);
|
||||
return peers;
|
||||
return peer_handle;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ public:
|
|||
* Endpoints for peers
|
||||
* nano::endpoint_key -> no_value
|
||||
*/
|
||||
MDB_dbi peers{ 0 };
|
||||
MDB_dbi peer_handle{ 0 };
|
||||
|
||||
/*
|
||||
* Confirmation height of an account, and the hash for the block at that height
|
||||
|
|
|
@ -765,7 +765,7 @@ void nano::node::long_inactivity_cleanup ()
|
|||
if (perform_cleanup)
|
||||
{
|
||||
store.online_weight.clear (transaction);
|
||||
store.peer_clear (transaction);
|
||||
store.peer.clear (transaction);
|
||||
logger.always_log ("Removed records of peers and online weight after a long period of inactivity");
|
||||
}
|
||||
}
|
||||
|
@ -1206,7 +1206,7 @@ boost::optional<uint64_t> nano::node::work_generate_blocking (nano::root const &
|
|||
void nano::node::add_initial_peers ()
|
||||
{
|
||||
auto transaction (store.tx_begin_read ());
|
||||
for (auto i (store.peers_begin (transaction)), n (store.peers_end ()); i != n; ++i)
|
||||
for (auto i (store.peer.begin (transaction)), n (store.peer.end ()); i != n; ++i)
|
||||
{
|
||||
nano::endpoint endpoint (boost::asio::ip::address_v6 (i->first.address_bytes ()), i->first.port ());
|
||||
if (!network.reachout (endpoint, config.allow_local_peers))
|
||||
|
|
|
@ -483,7 +483,7 @@ uint64_t nano::rocksdb_store::count (nano::transaction const & transaction_a, ta
|
|||
// Peers/online weight are small enough that they can just be iterated to get accurate counts.
|
||||
if (table_a == tables::peers)
|
||||
{
|
||||
for (auto i (peers_begin (transaction_a)), n (peers_end ()); i != n; ++i)
|
||||
for (auto i (peer.begin (transaction_a)), n (peer.end ()); i != n; ++i)
|
||||
{
|
||||
++sum;
|
||||
}
|
||||
|
@ -557,7 +557,7 @@ int nano::rocksdb_store::drop (nano::write_transaction const & transaction_a, ta
|
|||
if (table_a == tables::peers)
|
||||
{
|
||||
int status = 0;
|
||||
for (auto i = peers_begin (transaction_a), n = peers_end (); i != n; ++i)
|
||||
for (auto i = peer.begin (transaction_a), n = peer.end (); i != n; ++i)
|
||||
{
|
||||
status = del (transaction_a, tables::peers, nano::rocksdb_val (i->first));
|
||||
release_assert (success (status));
|
||||
|
|
|
@ -230,12 +230,12 @@ bool nano::transport::tcp_channels::store_all (bool clear_peers)
|
|||
auto transaction (node.store.tx_begin_write ({ tables::peers }));
|
||||
if (clear_peers)
|
||||
{
|
||||
node.store.peer_clear (transaction);
|
||||
node.store.peer.clear (transaction);
|
||||
}
|
||||
for (auto endpoint : endpoints)
|
||||
{
|
||||
nano::endpoint_key endpoint_key (endpoint.address ().to_v6 ().to_bytes (), endpoint.port ());
|
||||
node.store.peer_put (transaction, std::move (endpoint_key));
|
||||
node.store.peer.put (transaction, std::move (endpoint_key));
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
|
|
|
@ -202,12 +202,12 @@ bool nano::transport::udp_channels::store_all (bool clear_peers)
|
|||
auto transaction (node.store.tx_begin_write ({ tables::peers }));
|
||||
if (clear_peers)
|
||||
{
|
||||
node.store.peer_clear (transaction);
|
||||
node.store.peer.clear (transaction);
|
||||
}
|
||||
for (auto endpoint : endpoints)
|
||||
{
|
||||
nano::endpoint_key endpoint_key (endpoint.address ().to_v6 ().to_bytes (), endpoint.port ());
|
||||
node.store.peer_put (transaction, std::move (endpoint_key));
|
||||
node.store.peer.put (transaction, std::move (endpoint_key));
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
|
|
|
@ -7655,7 +7655,7 @@ TEST (rpc, telemetry_single)
|
|||
|
||||
// Wait until peers are stored as they are done in the background
|
||||
auto peers_stored = false;
|
||||
ASSERT_TIMELY (10s, node1.store.peer_count (node1.store.tx_begin_read ()) != 0);
|
||||
ASSERT_TIMELY (10s, node1.store.peer.count (node1.store.tx_begin_read ()) != 0);
|
||||
|
||||
// Missing port
|
||||
boost::property_tree::ptree request;
|
||||
|
@ -7731,7 +7731,7 @@ TEST (rpc, telemetry_all)
|
|||
rpc.start ();
|
||||
|
||||
// Wait until peers are stored as they are done in the background
|
||||
ASSERT_TIMELY (10s, node1.store.peer_count (node1.store.tx_begin_read ()) != 0);
|
||||
ASSERT_TIMELY (10s, node1.store.peer.count (node1.store.tx_begin_read ()) != 0);
|
||||
|
||||
// First need to set up the cached data
|
||||
std::atomic<bool> done{ false };
|
||||
|
|
|
@ -59,6 +59,7 @@ add_library(
|
|||
store/pending_store_partial.hpp
|
||||
store/online_weight_partial.hpp
|
||||
store/pruned_store_partial.hpp
|
||||
store/peer_store_partial.hpp
|
||||
store/confirmation_height_store_partial.hpp
|
||||
store/final_vote_store_partial.hpp)
|
||||
|
||||
|
|
|
@ -105,12 +105,13 @@ bool nano::write_transaction::contains (nano::tables table_a) const
|
|||
return impl->contains (table_a);
|
||||
}
|
||||
|
||||
nano::block_store::block_store (nano::frontier_store & frontier_store_a, nano::account_store & account_store_a, nano::pending_store & pending_store_a, nano::online_weight_store & online_weight_store_a, nano::pruned_store & pruned_store_a, nano::confirmation_height_store & confirmation_height_store_a, nano::final_vote_store & final_vote_store_a) :
|
||||
nano::block_store::block_store (nano::frontier_store & frontier_store_a, nano::account_store & account_store_a, nano::pending_store & pending_store_a, nano::online_weight_store & online_weight_store_a, nano::pruned_store & pruned_store_a, nano::peer_store & peer_store_a, nano::confirmation_height_store & confirmation_height_store_a, nano::final_vote_store & final_vote_store_a) :
|
||||
frontier (frontier_store_a),
|
||||
account (account_store_a),
|
||||
pending (pending_store_a),
|
||||
online_weight (online_weight_store_a),
|
||||
pruned (pruned_store_a),
|
||||
peer (peer_store_a),
|
||||
confirmation_height (confirmation_height_store_a),
|
||||
final_vote (final_vote_store_a)
|
||||
{
|
||||
|
|
|
@ -670,6 +670,21 @@ public:
|
|||
virtual void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::pending_key, nano::pending_info>, nano::store_iterator<nano::pending_key, nano::pending_info>)> const & action_a) const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Manages peer storage and iteration
|
||||
*/
|
||||
class peer_store
|
||||
{
|
||||
public:
|
||||
virtual void put (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) = 0;
|
||||
virtual void del (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) = 0;
|
||||
virtual bool exists (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) const = 0;
|
||||
virtual size_t count (nano::transaction const & transaction_a) const = 0;
|
||||
virtual void clear (nano::write_transaction const & transaction_a) = 0;
|
||||
virtual nano::store_iterator<nano::endpoint_key, nano::no_value> begin (nano::transaction const & transaction_a) const = 0;
|
||||
virtual nano::store_iterator<nano::endpoint_key, nano::no_value> end () const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Manages online weight storage and iteration
|
||||
*/
|
||||
|
@ -746,7 +761,7 @@ public:
|
|||
class block_store
|
||||
{
|
||||
public:
|
||||
explicit block_store (nano::frontier_store &, nano::account_store &, nano::pending_store &, nano::online_weight_store &, nano::pruned_store &, nano::confirmation_height_store &, nano::final_vote_store &);
|
||||
explicit block_store (nano::frontier_store &, nano::account_store &, nano::pending_store &, nano::online_weight_store &, nano::pruned_store &, nano::peer_store &, nano::confirmation_height_store &, nano::final_vote_store &);
|
||||
virtual ~block_store () = default;
|
||||
virtual void initialize (nano::write_transaction const &, nano::genesis const &, nano::ledger_cache &) = 0;
|
||||
virtual void block_put (nano::write_transaction const &, nano::block_hash const &, nano::block const &) = 0;
|
||||
|
@ -792,13 +807,7 @@ public:
|
|||
|
||||
pruned_store & pruned;
|
||||
|
||||
virtual void peer_put (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) = 0;
|
||||
virtual void peer_del (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) = 0;
|
||||
virtual bool peer_exists (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) const = 0;
|
||||
virtual size_t peer_count (nano::transaction const & transaction_a) const = 0;
|
||||
virtual void peer_clear (nano::write_transaction const & transaction_a) = 0;
|
||||
virtual nano::store_iterator<nano::endpoint_key, nano::no_value> peers_begin (nano::transaction const & transaction_a) const = 0;
|
||||
virtual nano::store_iterator<nano::endpoint_key, nano::no_value> peers_end () const = 0;
|
||||
peer_store & peer;
|
||||
|
||||
confirmation_height_store & confirmation_height;
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <nano/secure/store/final_vote_store_partial.hpp>
|
||||
#include <nano/secure/store/frontier_store_partial.hpp>
|
||||
#include <nano/secure/store/online_weight_partial.hpp>
|
||||
#include <nano/secure/store/peer_store_partial.hpp>
|
||||
#include <nano/secure/store/pending_store_partial.hpp>
|
||||
#include <nano/secure/store/pruned_store_partial.hpp>
|
||||
|
||||
|
@ -47,6 +48,7 @@ class block_store_partial : public block_store
|
|||
nano::pending_store_partial<Val, Derived_Store> pending_store_partial;
|
||||
nano::online_weight_store_partial<Val, Derived_Store> online_weight_store_partial;
|
||||
nano::pruned_store_partial<Val, Derived_Store> pruned_store_partial;
|
||||
nano::peer_store_partial<Val, Derived_Store> peer_store_partial;
|
||||
nano::confirmation_height_store_partial<Val, Derived_Store> confirmation_height_store_partial;
|
||||
nano::final_vote_store_partial<Val, Derived_Store> final_vote_store_partial;
|
||||
|
||||
|
@ -62,16 +64,18 @@ public:
|
|||
friend class nano::pending_store_partial<Val, Derived_Store>;
|
||||
friend class nano::online_weight_store_partial<Val, Derived_Store>;
|
||||
friend class nano::pruned_store_partial<Val, Derived_Store>;
|
||||
friend class nano::peer_store_partial<Val, Derived_Store>;
|
||||
friend class nano::confirmation_height_store_partial<Val, Derived_Store>;
|
||||
friend class nano::final_vote_store_partial<Val, Derived_Store>;
|
||||
|
||||
block_store_partial () :
|
||||
block_store{ frontier_store_partial, account_store_partial, pending_store_partial, online_weight_store_partial, pruned_store_partial, confirmation_height_store_partial, final_vote_store_partial },
|
||||
block_store{ frontier_store_partial, account_store_partial, pending_store_partial, online_weight_store_partial, pruned_store_partial, peer_store_partial, confirmation_height_store_partial, final_vote_store_partial },
|
||||
frontier_store_partial{ *this },
|
||||
account_store_partial{ *this },
|
||||
pending_store_partial{ *this },
|
||||
online_weight_store_partial{ *this },
|
||||
pruned_store_partial{ *this },
|
||||
peer_store_partial{ *this },
|
||||
confirmation_height_store_partial{ *this },
|
||||
final_vote_store_partial{ *this }
|
||||
{
|
||||
|
@ -249,11 +253,6 @@ public:
|
|||
return nano::store_iterator<nano::unchecked_key, nano::unchecked_info> (nullptr);
|
||||
}
|
||||
|
||||
nano::store_iterator<nano::endpoint_key, nano::no_value> peers_end () const override
|
||||
{
|
||||
return nano::store_iterator<nano::endpoint_key, nano::no_value> (nullptr);
|
||||
}
|
||||
|
||||
nano::store_iterator<nano::block_hash, nano::block_w_sideband> blocks_end () const override
|
||||
{
|
||||
return nano::store_iterator<nano::block_hash, nano::block_w_sideband> (nullptr);
|
||||
|
@ -332,34 +331,6 @@ public:
|
|||
release_assert_success (*this, status);
|
||||
}
|
||||
|
||||
void peer_put (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) override
|
||||
{
|
||||
auto status = put_key (transaction_a, tables::peers, endpoint_a);
|
||||
release_assert_success (*this, status);
|
||||
}
|
||||
|
||||
void peer_del (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) override
|
||||
{
|
||||
auto status (del (transaction_a, tables::peers, endpoint_a));
|
||||
release_assert_success (*this, status);
|
||||
}
|
||||
|
||||
bool peer_exists (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) const override
|
||||
{
|
||||
return exists (transaction_a, tables::peers, nano::db_val<Val> (endpoint_a));
|
||||
}
|
||||
|
||||
size_t peer_count (nano::transaction const & transaction_a) const override
|
||||
{
|
||||
return count (transaction_a, tables::peers);
|
||||
}
|
||||
|
||||
void peer_clear (nano::write_transaction const & transaction_a) override
|
||||
{
|
||||
auto status = drop (transaction_a, tables::peers);
|
||||
release_assert_success (*this, status);
|
||||
}
|
||||
|
||||
bool exists (nano::transaction const & transaction_a, tables table_a, nano::db_val<Val> const & key_a) const
|
||||
{
|
||||
return static_cast<const Derived_Store &> (*this).exists (transaction_a, table_a, key_a);
|
||||
|
@ -404,11 +375,6 @@ public:
|
|||
return make_iterator<nano::unchecked_key, nano::unchecked_info> (transaction_a, tables::unchecked, nano::db_val<Val> (key_a));
|
||||
}
|
||||
|
||||
nano::store_iterator<nano::endpoint_key, nano::no_value> peers_begin (nano::transaction const & transaction_a) const override
|
||||
{
|
||||
return make_iterator<nano::endpoint_key, nano::no_value> (transaction_a, tables::peers);
|
||||
}
|
||||
|
||||
size_t unchecked_count (nano::transaction const & transaction_a) override
|
||||
{
|
||||
return count (transaction_a, tables::unchecked);
|
||||
|
|
|
@ -1509,14 +1509,14 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (boost::filesystem::path const & data
|
|||
rocksdb_store->online_weight.put (rocksdb_transaction, i->first, i->second);
|
||||
}
|
||||
|
||||
for (auto i (store.peers_begin (lmdb_transaction)), n (store.peers_end ()); i != n; ++i)
|
||||
for (auto i (store.peer.begin (lmdb_transaction)), n (store.peer.end ()); i != n; ++i)
|
||||
{
|
||||
rocksdb_store->peer_put (rocksdb_transaction, i->first);
|
||||
rocksdb_store->peer.put (rocksdb_transaction, i->first);
|
||||
}
|
||||
|
||||
// Compare counts
|
||||
error |= store.unchecked_count (lmdb_transaction) != rocksdb_store->unchecked_count (rocksdb_transaction);
|
||||
error |= store.peer_count (lmdb_transaction) != rocksdb_store->peer_count (rocksdb_transaction);
|
||||
error |= store.peer.count (lmdb_transaction) != rocksdb_store->peer.count (rocksdb_transaction);
|
||||
error |= store.pruned.count (lmdb_transaction) != rocksdb_store->pruned.count (rocksdb_transaction);
|
||||
error |= store.final_vote.count (lmdb_transaction) != rocksdb_store->final_vote.count (rocksdb_transaction);
|
||||
error |= store.online_weight.count (lmdb_transaction) != rocksdb_store->online_weight.count (rocksdb_transaction);
|
||||
|
|
70
nano/secure/store/peer_store_partial.hpp
Normal file
70
nano/secure/store/peer_store_partial.hpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
#pragma once
|
||||
|
||||
#include <nano/secure/blockstore_partial.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T>
|
||||
void parallel_traversal (std::function<void (T const &, T const &, bool const)> const & action);
|
||||
}
|
||||
|
||||
namespace nano
|
||||
{
|
||||
template <typename Val, typename Derived_Store>
|
||||
class block_store_partial;
|
||||
|
||||
template <typename Val, typename Derived_Store>
|
||||
void release_assert_success (block_store_partial<Val, Derived_Store> const & block_store, const int status);
|
||||
|
||||
template <typename Val, typename Derived_Store>
|
||||
class peer_store_partial : public peer_store
|
||||
{
|
||||
private:
|
||||
nano::block_store_partial<Val, Derived_Store> & block_store;
|
||||
|
||||
friend void release_assert_success<Val, Derived_Store> (block_store_partial<Val, Derived_Store> const & block_store, const int status);
|
||||
|
||||
public:
|
||||
explicit peer_store_partial (nano::block_store_partial<Val, Derived_Store> & block_store_a) :
|
||||
block_store (block_store_a){};
|
||||
|
||||
void put (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) override
|
||||
{
|
||||
auto status = block_store.put_key (transaction_a, tables::peers, endpoint_a);
|
||||
release_assert_success (block_store, status);
|
||||
}
|
||||
|
||||
void del (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) override
|
||||
{
|
||||
auto status (block_store.del (transaction_a, tables::peers, endpoint_a));
|
||||
release_assert_success (block_store, status);
|
||||
}
|
||||
|
||||
bool exists (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) const override
|
||||
{
|
||||
return block_store.exists (transaction_a, tables::peers, nano::db_val<Val> (endpoint_a));
|
||||
}
|
||||
|
||||
size_t count (nano::transaction const & transaction_a) const override
|
||||
{
|
||||
return block_store.count (transaction_a, tables::peers);
|
||||
}
|
||||
|
||||
void clear (nano::write_transaction const & transaction_a) override
|
||||
{
|
||||
auto status = block_store.drop (transaction_a, tables::peers);
|
||||
release_assert_success (block_store, status);
|
||||
}
|
||||
|
||||
nano::store_iterator<nano::endpoint_key, nano::no_value> begin (nano::transaction const & transaction_a) const override
|
||||
{
|
||||
return block_store.template make_iterator<nano::endpoint_key, nano::no_value> (transaction_a, tables::peers);
|
||||
}
|
||||
|
||||
nano::store_iterator<nano::endpoint_key, nano::no_value> end () const override
|
||||
{
|
||||
return nano::store_iterator<nano::endpoint_key, nano::no_value> (nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
|
@ -41,7 +41,7 @@ void nano::wait_peer_connections (nano::system & system_a)
|
|||
else
|
||||
{
|
||||
auto transaction = node->store.tx_begin_read ();
|
||||
return total += node->store.peer_count (transaction);
|
||||
return total += node->store.peer.count (transaction);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue