Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Nano 12.1 Patch Release
  • Loading branch information
bbedward committed Apr 21, 2018
2 parents 51d9ba2 + f69b3ac commit 15210f5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 48 deletions.
2 changes: 1 addition & 1 deletion banano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ TEST (node, bootstrap_connection_scaling)
rai::system system (24000, 1);
auto & node1 (*system.nodes[0]);
node1.bootstrap_initiator.bootstrap ();
auto & attempt = node1.bootstrap_initiator.attempt;
auto attempt (node1.bootstrap_initiator.current_attempt ());
ASSERT_EQ (34, attempt->target_connections (25000));
ASSERT_EQ (4, attempt->target_connections (0));
ASSERT_EQ (64, attempt->target_connections (50000));
Expand Down
72 changes: 31 additions & 41 deletions banano/node/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,14 +524,6 @@ void rai::bulk_pull_client::request ()
{
std::unique_lock<std::mutex> lock (connection->attempt->mutex);
BOOST_LOG (connection->node->log) << boost::str (boost::format ("%1% accounts in pull queue") % connection->attempt->pulls.size ());
if (connection->attempt->forks_in_progress.size () > 0)
{
BOOST_LOG (connection->node->log) << boost::str (boost::format ("Forks being resolved (roots):"));
for (auto i (connection->attempt->forks_in_progress.begin ()), n (connection->attempt->forks_in_progress.end ()); i != n; ++i)
{
BOOST_LOG (connection->node->log) << boost::str (boost::format ("%1%") % i->to_string ());
}
}
}
auto this_l (shared_from_this ());
connection->start_timeout ();
Expand Down Expand Up @@ -946,8 +938,7 @@ bool rai::bootstrap_attempt::still_pulling ()
auto running (!stopped);
auto more_pulls (!pulls.empty ());
auto still_pulling (pulling > 0);
auto more_forks (!forks_in_progress.empty ());
return running && (more_pulls || still_pulling || more_forks);
return running && (more_pulls || still_pulling);
}

void rai::bootstrap_attempt::run ()
Expand Down Expand Up @@ -1032,38 +1023,32 @@ void rai::bootstrap_attempt::process_fork (MDB_txn * transaction_a, std::shared_
{
std::lock_guard<std::mutex> lock (mutex);
auto root (block_a->root ());
if (forks_attempted.find (root) == forks_attempted.end ())
{
if (!node->store.block_exists (transaction_a, block_a->hash ()) && (node->store.block_exists (transaction_a, root) || node->store.account_exists (transaction_a, root)))
{
std::shared_ptr<rai::block> ledger_block (node->ledger.forked_block (transaction_a, *block_a));
if (ledger_block)
if (!node->store.block_exists (transaction_a, block_a->hash ()) && (node->store.block_exists (transaction_a, root) || node->store.account_exists (transaction_a, root)))
{
std::shared_ptr<rai::block> ledger_block (node->ledger.forked_block (transaction_a, *block_a));
if (ledger_block)
{
std::weak_ptr<rai::bootstrap_attempt> this_w (shared_from_this ());
if (!node->active.start (transaction_a, std::make_pair (ledger_block, block_a), [this_w, root](std::shared_ptr<rai::block>, bool resolved) {
if (auto this_l = this_w.lock ())
{
if (resolved)
{
rai::transaction transaction (this_l->node->store.environment, nullptr, false);
auto account (this_l->node->ledger.store.frontier_get (transaction, root));
if (!account.is_zero ())
{
this_l->requeue_pull (rai::pull_info (account, root, root));
}
else if (this_l->node->ledger.store.account_exists (transaction, root))
{
this_l->requeue_pull (rai::pull_info (root, rai::block_hash (0), rai::block_hash (0)));
}
}
}
}))
{
BOOST_LOG (node->log) << boost::str (boost::format ("Resolving fork between our block: %1% and block %2% both with root %3%") % ledger_block->hash ().to_string () % block_a->hash ().to_string () % block_a->root ().to_string ());
forks_in_progress.insert (root);
forks_attempted.insert (root);
std::weak_ptr<rai::bootstrap_attempt> this_w (shared_from_this ());
node->active.start (transaction_a, std::make_pair (ledger_block, block_a), [this_w, root](std::shared_ptr<rai::block>, bool resolved) {
if (auto this_l = this_w.lock ())
{
if (resolved)
{
rai::transaction transaction (this_l->node->store.environment, nullptr, false);
auto account (this_l->node->ledger.store.frontier_get (transaction, root));
if (!account.is_zero ())
{
this_l->requeue_pull (rai::pull_info (account, root, root));
}
else if (this_l->node->ledger.store.account_exists (transaction, root))
{
this_l->requeue_pull (rai::pull_info (root, rai::block_hash (0), rai::block_hash (0)));
}
}
std::lock_guard<std::mutex> lock (this_l->mutex);
this_l->forks_in_progress.erase (root);
this_l->condition.notify_all ();
}
});
node->network.broadcast_confirm_req (ledger_block);
node->network.broadcast_confirm_req (block_a);
}
Expand Down Expand Up @@ -1351,9 +1336,14 @@ void rai::bootstrap_initiator::add_observer (std::function<void(bool)> const & o
}

bool rai::bootstrap_initiator::in_progress ()
{
return current_attempt () != nullptr;
}

std::shared_ptr<rai::bootstrap_attempt> rai::bootstrap_initiator::current_attempt ()
{
std::lock_guard<std::mutex> lock (mutex);
return attempt != nullptr;
return attempt;
}

void rai::bootstrap_initiator::stop ()
Expand Down
7 changes: 3 additions & 4 deletions banano/node/bootstrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ class bootstrap_attempt : public std::enable_shared_from_this<bootstrap_attempt>
unsigned target_connections (size_t pulls_remaining);
bool should_log ();
std::chrono::steady_clock::time_point next_log;
std::unordered_set<rai::block_hash> forks_attempted;
std::unordered_set<rai::block_hash> forks_in_progress;
std::deque<std::weak_ptr<rai::bootstrap_client>> clients;
std::weak_ptr<rai::bootstrap_client> connection_frontier_request;
std::weak_ptr<rai::frontier_req_client> frontiers;
Expand Down Expand Up @@ -191,13 +189,14 @@ class bootstrap_initiator
void notify_listeners (bool);
void add_observer (std::function<void(bool)> const &);
bool in_progress ();
std::shared_ptr<rai::bootstrap_attempt> current_attempt ();
void process_fork (MDB_txn *, std::shared_ptr<rai::block>);
void stop ();

private:
rai::node & node;
std::shared_ptr<rai::bootstrap_attempt> attempt;
bool stopped;

private:
std::mutex mutex;
std::condition_variable condition;
std::vector<std::function<void(bool)>> observers;
Expand Down
4 changes: 2 additions & 2 deletions banano/node/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ void rai::rpc_handler::block_create ()
}
if (type == "state")
{
if (previous_text.is_initialized () && !representative.is_zero () && !balance.is_zero () && (!link.is_zero () || link_text.is_initialized ()))
if (previous_text.is_initialized () && !representative.is_zero () && (!link.is_zero () || link_text.is_initialized ()))
{
if (work == 0)
{
Expand Down Expand Up @@ -1731,7 +1731,7 @@ class history_visitor : public rai::block_visitor
{
tree.put ("type", "send");
}
tree.put ("account", block_a.hashables.account.to_account ());
tree.put ("account", block_a.hashables.link.to_account ());
tree.put ("amount", (previous_balance - balance).convert_to<std::string> ());
}
else
Expand Down

0 comments on commit 15210f5

Please sign in to comment.