[Pruning] Use pruned blocks in rep crawler (#2975)
* [Pruning] Use pruned blocks in rep crawler * Use const reference for hash-root pair
This commit is contained in:
parent
c9ddc53f41
commit
d1b62a09b1
3 changed files with 11 additions and 13 deletions
|
@ -238,10 +238,10 @@ void nano::network::flood_block_many (std::deque<std::shared_ptr<nano::block>> b
|
|||
}
|
||||
}
|
||||
|
||||
void nano::network::send_confirm_req (std::shared_ptr<nano::transport::channel> channel_a, std::shared_ptr<nano::block> block_a)
|
||||
void nano::network::send_confirm_req (std::shared_ptr<nano::transport::channel> channel_a, std::pair<nano::block_hash, nano::block_hash> const & hash_root_a)
|
||||
{
|
||||
// Confirmation request with hash + root
|
||||
nano::confirm_req req (block_a->hash (), block_a->root ());
|
||||
nano::confirm_req req (hash_root_a.first, hash_root_a.second);
|
||||
channel_a->send (req);
|
||||
}
|
||||
|
||||
|
@ -284,7 +284,7 @@ void nano::network::broadcast_confirm_req_base (std::shared_ptr<nano::block> blo
|
|||
while (!endpoints_a->empty () && count < max_reps)
|
||||
{
|
||||
auto channel (endpoints_a->back ());
|
||||
send_confirm_req (channel, block_a);
|
||||
send_confirm_req (channel, std::make_pair (block_a->hash (), block_a->root ().as_block_hash ()));
|
||||
endpoints_a->pop_back ();
|
||||
count++;
|
||||
}
|
||||
|
|
|
@ -147,7 +147,7 @@ public:
|
|||
void send_keepalive (std::shared_ptr<nano::transport::channel>);
|
||||
void send_keepalive_self (std::shared_ptr<nano::transport::channel>);
|
||||
void send_node_id_handshake (std::shared_ptr<nano::transport::channel>, boost::optional<nano::uint256_union> const & query, boost::optional<nano::uint256_union> const & respond_to);
|
||||
void send_confirm_req (std::shared_ptr<nano::transport::channel>, std::shared_ptr<nano::block>);
|
||||
void send_confirm_req (std::shared_ptr<nano::transport::channel> channel_a, std::pair<nano::block_hash, nano::block_hash> const & hash_root_a);
|
||||
void broadcast_confirm_req (std::shared_ptr<nano::block>);
|
||||
void broadcast_confirm_req_base (std::shared_ptr<nano::block>, std::shared_ptr<std::vector<std::shared_ptr<nano::transport::channel>>>, unsigned, bool = false);
|
||||
void broadcast_confirm_req_batched_many (std::unordered_map<std::shared_ptr<nano::transport::channel>, std::deque<std::pair<nano::block_hash, nano::root>>>, std::function<void()> = nullptr, unsigned = broadcast_interval_ms, bool = false);
|
||||
|
|
|
@ -133,35 +133,33 @@ std::vector<std::shared_ptr<nano::transport::channel>> nano::rep_crawler::get_cr
|
|||
void nano::rep_crawler::query (std::vector<std::shared_ptr<nano::transport::channel>> const & channels_a)
|
||||
{
|
||||
auto transaction (node.store.tx_begin_read ());
|
||||
std::shared_ptr<nano::block> block (node.store.block_random (transaction));
|
||||
auto hash (block->hash ());
|
||||
auto hash_root (node.ledger.hash_root_random (transaction));
|
||||
{
|
||||
nano::lock_guard<std::mutex> lock (active_mutex);
|
||||
// Don't send same block multiple times in tests
|
||||
if (node.network_params.network.is_dev_network ())
|
||||
{
|
||||
for (auto i (0); active.count (hash) != 0 && i < 4; ++i)
|
||||
for (auto i (0); active.count (hash_root.first) != 0 && i < 4; ++i)
|
||||
{
|
||||
block = node.store.block_random (transaction);
|
||||
hash = block->hash ();
|
||||
hash_root = node.ledger.hash_root_random (transaction);
|
||||
}
|
||||
}
|
||||
active.insert (hash);
|
||||
active.insert (hash_root.first);
|
||||
}
|
||||
if (!channels_a.empty ())
|
||||
{
|
||||
node.active.erase_recently_confirmed (hash);
|
||||
node.active.erase_recently_confirmed (hash_root.first);
|
||||
}
|
||||
for (auto i (channels_a.begin ()), n (channels_a.end ()); i != n; ++i)
|
||||
{
|
||||
debug_assert (*i != nullptr);
|
||||
on_rep_request (*i);
|
||||
node.network.send_confirm_req (*i, block);
|
||||
node.network.send_confirm_req (*i, hash_root);
|
||||
}
|
||||
|
||||
// A representative must respond with a vote within the deadline
|
||||
std::weak_ptr<nano::node> node_w (node.shared ());
|
||||
node.alarm.add (std::chrono::steady_clock::now () + std::chrono::seconds (5), [node_w, hash]() {
|
||||
node.alarm.add (std::chrono::steady_clock::now () + std::chrono::seconds (5), [node_w, hash = hash_root.first]() {
|
||||
if (auto node_l = node_w.lock ())
|
||||
{
|
||||
node_l->rep_crawler.remove (hash);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue