Slightly more efficient way of storing duplicates (#1364)
This commit is contained in:
parent
aec6a2e384
commit
937dad5a00
3 changed files with 37 additions and 20 deletions
|
@ -1256,20 +1256,39 @@ TEST (bulk_pull_account, basics)
|
|||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
auto connection (std::make_shared<nano::bootstrap_server> (nullptr, system.nodes[0]));
|
||||
std::unique_ptr<nano::bulk_pull_account> req (new nano::bulk_pull_account{});
|
||||
req->account = key1.pub;
|
||||
req->minimum_amount = 5;
|
||||
req->flags = nano::bulk_pull_account_flags ();
|
||||
connection->requests.push (std::unique_ptr<nano::message>{});
|
||||
auto request (std::make_shared<nano::bulk_pull_account_server> (connection, std::move (req)));
|
||||
ASSERT_FALSE (request->invalid_request);
|
||||
ASSERT_FALSE (request->pending_include_address);
|
||||
ASSERT_FALSE (request->pending_address_only);
|
||||
ASSERT_EQ (request->current_key.account, key1.pub);
|
||||
ASSERT_EQ (request->current_key.hash, 0);
|
||||
auto block_data (request->get_next ());
|
||||
ASSERT_EQ (send2->hash (), block_data.first.get ()->hash);
|
||||
ASSERT_EQ (nano::uint128_union (10), block_data.second.get ()->amount);
|
||||
ASSERT_EQ (nano::genesis_account, block_data.second.get ()->source);
|
||||
ASSERT_EQ (nullptr, request->get_next ().first.get ());
|
||||
|
||||
{
|
||||
std::unique_ptr<nano::bulk_pull_account> req (new nano::bulk_pull_account{});
|
||||
req->account = key1.pub;
|
||||
req->minimum_amount = 5;
|
||||
req->flags = nano::bulk_pull_account_flags ();
|
||||
connection->requests.push (std::unique_ptr<nano::message>{});
|
||||
auto request (std::make_shared<nano::bulk_pull_account_server> (connection, std::move (req)));
|
||||
ASSERT_FALSE (request->invalid_request);
|
||||
ASSERT_FALSE (request->pending_include_address);
|
||||
ASSERT_FALSE (request->pending_address_only);
|
||||
ASSERT_EQ (request->current_key.account, key1.pub);
|
||||
ASSERT_EQ (request->current_key.hash, 0);
|
||||
auto block_data (request->get_next ());
|
||||
ASSERT_EQ (send2->hash (), block_data.first.get ()->hash);
|
||||
ASSERT_EQ (nano::uint128_union (10), block_data.second.get ()->amount);
|
||||
ASSERT_EQ (nano::genesis_account, block_data.second.get ()->source);
|
||||
ASSERT_EQ (nullptr, request->get_next ().first.get ());
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<nano::bulk_pull_account> req (new nano::bulk_pull_account{});
|
||||
req->account = key1.pub;
|
||||
req->minimum_amount = 0;
|
||||
req->flags = nano::bulk_pull_account_flags::pending_address_only;
|
||||
auto request (std::make_shared<nano::bulk_pull_account_server> (connection, std::move (req)));
|
||||
ASSERT_TRUE (request->pending_address_only);
|
||||
auto block_data (request->get_next ());
|
||||
ASSERT_NE (nullptr, block_data.first.get ());
|
||||
ASSERT_NE (nullptr, block_data.second.get ());
|
||||
ASSERT_EQ (nano::genesis_account, block_data.second.get ()->source);
|
||||
block_data = request->get_next ();
|
||||
ASSERT_EQ (nullptr, block_data.first.get ());
|
||||
ASSERT_EQ (nullptr, block_data.second.get ());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2433,7 +2433,7 @@ std::pair<std::unique_ptr<nano::pending_key>, std::unique_ptr<nano::pending_info
|
|||
*/
|
||||
if (pending_address_only)
|
||||
{
|
||||
if (deduplication.count (info.source) != 0)
|
||||
if (!deduplication.insert (info.source).second)
|
||||
{
|
||||
/*
|
||||
* If the deduplication map gets too
|
||||
|
@ -2448,8 +2448,6 @@ std::pair<std::unique_ptr<nano::pending_key>, std::unique_ptr<nano::pending_info
|
|||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
deduplication.insert ({ info.source, true });
|
||||
}
|
||||
|
||||
result.first = std::unique_ptr<nano::pending_key> (new nano::pending_key (key));
|
||||
|
|
|
@ -289,7 +289,7 @@ public:
|
|||
std::shared_ptr<nano::bootstrap_server> connection;
|
||||
std::unique_ptr<nano::bulk_pull_account> request;
|
||||
std::shared_ptr<std::vector<uint8_t>> send_buffer;
|
||||
std::unordered_map<nano::uint256_union, bool> deduplication;
|
||||
std::unordered_set<nano::uint256_union> deduplication;
|
||||
nano::pending_key current_key;
|
||||
bool pending_address_only;
|
||||
bool pending_include_address;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue