Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the "bulk_pull" bootstrapping message to accept a block hash as… #973

Merged
merged 4 commits into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions rai/core_test/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,21 @@ TEST (bulk_pull, get_next_on_open)
ASSERT_EQ (request->current, request->request->end);
}

TEST (bulk_pull, by_block)
{
rai::system system (24000, 1);
auto connection (std::make_shared<rai::bootstrap_server> (nullptr, system.nodes[0]));
rai::genesis genesis;
std::unique_ptr<rai::bulk_pull> req (new rai::bulk_pull{});
req->start = genesis.hash ();
req->end.clear ();
connection->requests.push (std::unique_ptr<rai::message>{});
auto request (std::make_shared<rai::bulk_pull_server> (connection, std::move (req)));
auto block (request->get_next ());
ASSERT_NE (nullptr, block);
ASSERT_EQ (block->hash (), genesis.hash ());
}

TEST (bootstrap_processor, DISABLED_process_none)
{
rai::system system (24000, 1);
Expand Down
52 changes: 33 additions & 19 deletions rai/node/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,11 @@ void rai::bootstrap_server::run_next ()
/**
* Handle a request for the pull of all blocks associated with an account
* The account is supplied as the "start" member, and the final block to
* send is the "end" member
* send is the "end" member. The "start" member may also be a block
* hash, in which case the that hash is used as the start of a chain
* to send. To determine if "start" is interpretted as an account or
* hash, the ledger is checked to see if the block specified exists,
* if not then it is interpretted as an account.
*/
void rai::bulk_pull_server::set_current_end ()
{
Expand All @@ -1547,33 +1551,43 @@ void rai::bulk_pull_server::set_current_end ()
}
request->end.clear ();
}
rai::account_info info;
auto no_address (connection->node->store.account_get (transaction, request->start, info));
if (no_address)
{

if (connection->node->store.block_exists (transaction, request->start)) {
if (connection->node->config.logging.bulk_pull_logging ())
{
BOOST_LOG (connection->node->log) << boost::str (boost::format ("Request for unknown account: %1%") % request->start.to_account ());
BOOST_LOG (connection->node->log) << boost::str (boost::format ("Bulk pull request for block hash: %1%") % request->start.to_string ());
}
current = request->end;
}
else
{
if (!request->end.is_zero ())

current = request->start;
} else {
rai::account_info info;
auto no_address (connection->node->store.account_get (transaction, request->start, info));
if (no_address)
{
auto account (connection->node->ledger.account (transaction, request->end));
if (account == request->start)
{
current = info.head;
}
else
if (connection->node->config.logging.bulk_pull_logging ())
{
current = request->end;
BOOST_LOG (connection->node->log) << boost::str (boost::format ("Request for unknown account: %1%") % request->start.to_account ());
}
current = request->end;
}
else
{
current = info.head;
if (!request->end.is_zero ())
{
auto account (connection->node->ledger.account (transaction, request->end));
if (account == request->start)
{
current = info.head;
}
else
{
current = request->end;
}
}
else
{
current = info.head;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but the last else could be simplified to

current = info.head;
if (!request->end.is_zero () 
    && request->start != connection->node->ledger.account (transaction, request->end))
{
	current = request->end;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or even

if (!request->end.is_zero () 
    && request->start != connection->node->ledger.account (transaction, request->end))
{
	current = request->end;
}
else
{
	current = info.head;
}

}
}
}
Expand Down