Skip to content

Commit

Permalink
Renaming active_transactions::start/add to insert/insert_impl to more…
Browse files Browse the repository at this point in the history
… closely match the behavior that's expected.
  • Loading branch information
clemahieu committed Feb 11, 2020
1 parent a2fcd08 commit 2d20d85
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 44 deletions.
8 changes: 4 additions & 4 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,13 @@ TEST (active_transactions, keep_local)
}
auto open1 (std::make_shared<nano::state_block> (key1.pub, 0, key1.pub, node.config.receive_minimum.number (), send1->hash (), key1.prv, key1.pub, *system.work.generate (key1.pub)));
node.process_active (open1);
node.active.start (open1);
node.active.insert (open1);
auto open2 (std::make_shared<nano::state_block> (key2.pub, 0, key2.pub, node.config.receive_minimum.number (), send2->hash (), key2.prv, key2.pub, *system.work.generate (key2.pub)));
node.process_active (open2);
node.active.start (open2);
node.active.insert (open2);
auto open3 (std::make_shared<nano::state_block> (key3.pub, 0, key3.pub, node.config.receive_minimum.number (), send3->hash (), key3.prv, key3.pub, *system.work.generate (key3.pub)));
node.process_active (open3);
node.active.start (open3);
node.active.insert (open3);
ASSERT_EQ (3, node.active.size ());
system.deadline_set (10s);
// bound elections, should drop after one loop
Expand Down Expand Up @@ -504,7 +504,7 @@ TEST (active_transactions, inactive_votes_cache_multiple_votes)
}
ASSERT_EQ (1, node.active.inactive_votes_cache_size ());
// Start election
node.active.start (send1);
node.active.insert (send1);
{
nano::lock_guard<std::mutex> active_guard (node.active.mutex);
auto it (node.active.roots.begin ());
Expand Down
14 changes: 7 additions & 7 deletions nano/core_test/conflicts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEST (conflicts, start_stop)
node1.work_generate_blocking (*send1);
ASSERT_EQ (nano::process_result::progress, node1.process (*send1).code);
ASSERT_EQ (0, node1.active.size ());
auto election1 = node1.active.start (send1);
auto election1 = node1.active.insert (send1);
ASSERT_EQ (1, node1.active.size ());
{
nano::lock_guard<std::mutex> guard (node1.active.mutex);
Expand All @@ -36,10 +36,10 @@ TEST (conflicts, add_existing)
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key1.pub, 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
node1.work_generate_blocking (*send1);
ASSERT_EQ (nano::process_result::progress, node1.process (*send1).code);
node1.active.start (send1);
node1.active.insert (send1);
nano::keypair key2;
auto send2 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
auto election1 = node1.active.start (send2);
auto election1 = node1.active.insert (send2);
ASSERT_EQ (1, node1.active.size ());
auto vote1 (std::make_shared<nano::vote> (key2.pub, key2.prv, 0, send2));
node1.active.vote (vote1);
Expand All @@ -61,12 +61,12 @@ TEST (conflicts, add_two)
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key1.pub, 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
node1.work_generate_blocking (*send1);
ASSERT_EQ (nano::process_result::progress, node1.process (*send1).code);
node1.active.start (send1);
node1.active.insert (send1);
nano::keypair key2;
auto send2 (std::make_shared<nano::send_block> (send1->hash (), key2.pub, 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
node1.work_generate_blocking (*send2);
ASSERT_EQ (nano::process_result::progress, node1.process (*send2).code);
node1.active.start (send2);
node1.active.insert (send2);
ASSERT_EQ (2, node1.active.size ());
}

Expand Down Expand Up @@ -204,8 +204,8 @@ TEST (conflicts, dependency)
ASSERT_EQ (nano::process_result::progress, node1->process (*send1).code);
ASSERT_EQ (nano::process_result::progress, node1->process (*state_open1).code);
ASSERT_EQ (0, node1->active.size ());
auto election1 = node1->active.start (send1);
node1->active.start (state_open1);
auto election1 = node1->active.insert (send1);
node1->active.insert (state_open1);
ASSERT_EQ (2, node1->active.size ());
// Check dependency for send block
{
Expand Down
24 changes: 12 additions & 12 deletions nano/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ TEST (votes, check_signature)
auto transaction (node1.store.tx_begin_write ());
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *send1).code);
}
auto election1 = node1.active.start (send1);
auto election1 = node1.active.insert (send1);
{
nano::lock_guard<std::mutex> lock (node1.active.mutex);
ASSERT_EQ (1, election1.first->last_votes.size ());
Expand All @@ -761,7 +761,7 @@ TEST (votes, add_one)
node1.work_generate_blocking (*send1);
auto transaction (node1.store.tx_begin_write ());
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *send1).code);
auto election1 = node1.active.start (send1);
auto election1 = node1.active.insert (send1);
nano::unique_lock<std::mutex> lock (node1.active.mutex);
ASSERT_EQ (1, election1.first->last_votes.size ());
lock.unlock ();
Expand Down Expand Up @@ -789,7 +789,7 @@ TEST (votes, add_two)
node1.work_generate_blocking (*send1);
auto transaction (node1.store.tx_begin_write ());
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *send1).code);
auto election1 = node1.active.start (send1);
auto election1 = node1.active.insert (send1);
nano::unique_lock<std::mutex> lock (node1.active.mutex);
lock.unlock ();
nano::keypair key2;
Expand Down Expand Up @@ -824,7 +824,7 @@ TEST (votes, add_existing)
auto transaction (node1.store.tx_begin_write ());
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *send1).code);
}
auto election1 = node1.active.start (send1);
auto election1 = node1.active.insert (send1);
auto vote1 (std::make_shared<nano::vote> (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 1, send1));
ASSERT_EQ (nano::vote_code::vote, node1.active.vote (vote1));
// Block is already processed from vote
Expand Down Expand Up @@ -869,7 +869,7 @@ TEST (votes, add_old)
node1.work_generate_blocking (*send1);
auto transaction (node1.store.tx_begin_write ());
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *send1).code);
auto election1 = node1.active.start (send1);
auto election1 = node1.active.insert (send1);
auto vote1 (std::make_shared<nano::vote> (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 2, send1));
auto channel (std::make_shared<nano::transport::channel_udp> (node1.network.udp_channels, node1.network.endpoint (), node1.network_params.protocol.protocol_version));
node1.vote_processor.vote_blocking (vote1, channel);
Expand Down Expand Up @@ -904,8 +904,8 @@ TEST (votes, add_old_different_account)
auto transaction (node1.store.tx_begin_write ());
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *send1).code);
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *send2).code);
auto election1 = node1.active.start (send1);
auto election2 = node1.active.start (send2);
auto election1 = node1.active.insert (send1);
auto election2 = node1.active.insert (send2);
ASSERT_EQ (1, election1.first->last_votes_size ());
ASSERT_EQ (1, election2.first->last_votes_size ());
auto vote1 (std::make_shared<nano::vote> (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 2, send1));
Expand Down Expand Up @@ -941,7 +941,7 @@ TEST (votes, add_cooldown)
node1.work_generate_blocking (*send1);
auto transaction (node1.store.tx_begin_write ());
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *send1).code);
auto election1 = node1.active.start (send1);
auto election1 = node1.active.insert (send1);
auto vote1 (std::make_shared<nano::vote> (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 1, send1));
auto channel (std::make_shared<nano::transport::channel_udp> (node1.network.udp_channels, node1.network.endpoint (), node1.network_params.protocol.protocol_version));
node1.vote_processor.vote_blocking (vote1, channel);
Expand Down Expand Up @@ -2644,10 +2644,10 @@ TEST (ledger, block_hash_account_conflict)
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *receive1).code);
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *send2).code);
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *open_epoch1).code);
auto election1 = node1.active.start (send1);
auto election2 = node1.active.start (receive1);
auto election3 = node1.active.start (send2);
auto election4 = node1.active.start (open_epoch1);
auto election1 = node1.active.insert (send1);
auto election2 = node1.active.insert (receive1);
auto election3 = node1.active.insert (send2);
auto election4 = node1.active.insert (open_epoch1);
nano::lock_guard<std::mutex> lock (node1.active.mutex);
auto winner1 (*election1.first->tally ().begin ());
auto winner2 (*election2.first->tally ().begin ());
Expand Down
4 changes: 2 additions & 2 deletions nano/core_test/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ TEST (receivable_processor, confirm_insufficient_pos)
auto block1 (std::make_shared<nano::send_block> (genesis.hash (), 0, 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
node1.work_generate_blocking (*block1);
ASSERT_EQ (nano::process_result::progress, node1.process (*block1).code);
node1.active.start (block1);
node1.active.insert (block1);
nano::keypair key1;
auto vote (std::make_shared<nano::vote> (key1.pub, key1.prv, 0, block1));
nano::confirm_ack con1 (vote);
Expand All @@ -390,7 +390,7 @@ TEST (receivable_processor, confirm_sufficient_pos)
auto block1 (std::make_shared<nano::send_block> (genesis.hash (), 0, 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
node1.work_generate_blocking (*block1);
ASSERT_EQ (nano::process_result::progress, node1.process (*block1).code);
node1.active.start (block1);
node1.active.insert (block1);
auto vote (std::make_shared<nano::vote> (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 0, block1));
nano::confirm_ack con1 (vote);
node1.network.process_message (con1, node1.network.udp_channels.create (node1.network.endpoint ()));
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ TEST (node, rep_self_vote)
node0->work_generate_blocking (*block0);
ASSERT_EQ (nano::process_result::progress, node0->process (*block0).code);
auto & active (node0->active);
auto election1 = active.start (block0);
auto election1 = active.insert (block0);
node0->block_processor.generator.add (block0->hash ());
system.deadline_set (1s);
// Wait until representatives are activated & make vote
Expand Down
22 changes: 11 additions & 11 deletions nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void nano::active_transactions::search_frontiers (nano::transaction const & tran
if (info.block_count > confirmation_height_info.height && !this->confirmation_height_processor.is_processing_block (info.head))
{
auto block (this->node.store.block_get (transaction_a, info.head));
if (this->start (block, true).first)
if (this->insert (block, true).first)
{
++elections_count;
// Calculate votes for local representatives
Expand Down Expand Up @@ -232,7 +232,7 @@ void nano::active_transactions::election_escalate (std::shared_ptr<nano::electio
previous_l = node.store.block_get (transaction_l, previous_hash_l);
if (previous_l != nullptr && blocks.find (previous_hash_l) == blocks.end () && !node.block_confirmed_or_being_confirmed (transaction_l, previous_hash_l))
{
add (std::move (previous_l), true);
insert_impl (std::move (previous_l), true);
escalated_l = true;
}
}
Expand All @@ -246,7 +246,7 @@ void nano::active_transactions::election_escalate (std::shared_ptr<nano::electio
auto source_l (node.store.block_get (transaction_l, source_hash_l));
if (source_l != nullptr && !node.block_confirmed_or_being_confirmed (transaction_l, source_hash_l))
{
add (std::move (source_l), true);
insert_impl (std::move (source_l), true);
escalated_l = true;
}
}
Expand Down Expand Up @@ -567,13 +567,7 @@ void nano::active_transactions::stop ()
roots.clear ();
}

std::pair<std::shared_ptr<nano::election>, bool> nano::active_transactions::start (std::shared_ptr<nano::block> block_a, bool const skip_delay_a, std::function<void(std::shared_ptr<nano::block>)> const & confirmation_action_a)
{
nano::lock_guard<std::mutex> lock (mutex);
return add (block_a, skip_delay_a, confirmation_action_a);
}

std::pair<std::shared_ptr<nano::election>, bool> nano::active_transactions::add (std::shared_ptr<nano::block> block_a, bool const skip_delay_a, std::function<void(std::shared_ptr<nano::block>)> const & confirmation_action_a)
std::pair<std::shared_ptr<nano::election>, bool> nano::active_transactions::insert_impl (std::shared_ptr<nano::block> block_a, bool const skip_delay_a, std::function<void(std::shared_ptr<nano::block>)> const & confirmation_action_a)
{
std::pair<std::shared_ptr<nano::election>, bool> result = { nullptr, false };
if (!stopped)
Expand Down Expand Up @@ -603,6 +597,12 @@ std::pair<std::shared_ptr<nano::election>, bool> nano::active_transactions::add
return result;
}

std::pair<std::shared_ptr<nano::election>, bool> nano::active_transactions::insert (std::shared_ptr<nano::block> block_a, bool const skip_delay_a, std::function<void(std::shared_ptr<nano::block>)> const & confirmation_action_a)
{
nano::lock_guard<std::mutex> lock (mutex);
return insert_impl (block_a, skip_delay_a, confirmation_action_a);
}

// Validate a vote and apply it to the current election if one exists
nano::vote_code nano::active_transactions::vote (std::shared_ptr<nano::vote> vote_a)
{
Expand Down Expand Up @@ -724,7 +724,7 @@ void nano::active_transactions::update_difficulty (std::shared_ptr<nano::block>

// Restart election for the upgraded block, previously dropped from elections
lock.lock ();
add (existing_block);
insert_impl (existing_block);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions nano/node/active_transactions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class active_transactions final
// Start an election for a block
// Call action with confirmed block, may be different than what we started with
// clang-format off
std::pair<std::shared_ptr<nano::election>, bool> start (std::shared_ptr<nano::block>, bool const = false, std::function<void(std::shared_ptr<nano::block>)> const & = [](std::shared_ptr<nano::block>) {});
std::pair<std::shared_ptr<nano::election>, bool> insert (std::shared_ptr<nano::block>, bool const = false, std::function<void(std::shared_ptr<nano::block>)> const & = [](std::shared_ptr<nano::block>) {});
// clang-format on
// Distinguishes replay votes, cannot be determined if the block is not in any election
nano::vote_code vote (std::shared_ptr<nano::vote>);
Expand Down Expand Up @@ -135,7 +135,7 @@ class active_transactions final
private:
// Call action with confirmed block, may be different than what we started with
// clang-format off
std::pair<std::shared_ptr<nano::election>, bool> add (std::shared_ptr<nano::block>, bool const = false, std::function<void(std::shared_ptr<nano::block>)> const & = [](std::shared_ptr<nano::block>) {});
std::pair<std::shared_ptr<nano::election>, bool> insert_impl (std::shared_ptr<nano::block>, bool const = false, std::function<void(std::shared_ptr<nano::block>)> const & = [](std::shared_ptr<nano::block>) {});
// clang-format on
void request_loop ();
void search_frontiers (nano::transaction const &);
Expand Down
2 changes: 1 addition & 1 deletion nano/node/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ void nano::block_processor::process_batch (nano::unique_lock<std::mutex> & lock_
void nano::block_processor::process_live (nano::block_hash const & hash_a, std::shared_ptr<nano::block> block_a, const bool watch_work_a)
{
// Start collecting quorum on block
node.active.start (block_a, false);
node.active.insert (block_a, false);
//add block to watcher if desired after block has been added to active
if (watch_work_a)
{
Expand Down
4 changes: 2 additions & 2 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ void nano::node::process_fork (nano::transaction const & transaction_a, std::sha
if (ledger_block && !block_confirmed_or_being_confirmed (transaction_a, ledger_block->hash ()))
{
std::weak_ptr<nano::node> this_w (shared_from_this ());
if (active.start (ledger_block, false, [this_w, root](std::shared_ptr<nano::block>) {
if (active.insert (ledger_block, false, [this_w, root](std::shared_ptr<nano::block>) {
if (auto this_l = this_w.lock ())
{
auto attempt (this_l->bootstrap_initiator.current_attempt ());
Expand Down Expand Up @@ -1077,7 +1077,7 @@ void nano::node::add_initial_peers ()

void nano::node::block_confirm (std::shared_ptr<nano::block> block_a)
{
active.start (block_a, false);
active.insert (block_a, false);
network.broadcast_confirm_req (block_a);
// Calculate votes for local representatives
if (config.enable_voting && wallets.rep_counts ().voting > 0 && active.active (*block_a))
Expand Down
4 changes: 2 additions & 2 deletions nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2013,7 +2013,7 @@ TEST (rpc, process_subtype_open)
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, send).code);
}
scoped_io_thread_name_change scoped_thread_name_io;
node1.active.start (std::make_shared<nano::state_block> (send));
node1.active.insert (std::make_shared<nano::state_block> (send));
nano::state_block open (key.pub, 0, key.pub, nano::Gxrb_ratio, send.hash (), key.prv, key.pub, *node1.work_generate_blocking (key.pub));
nano::node_rpc_config node_rpc_config;
nano::ipc::ipc_server ipc_server (node1, node_rpc_config);
Expand Down Expand Up @@ -2072,7 +2072,7 @@ TEST (rpc, process_subtype_receive)
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, send).code);
}
scoped_io_thread_name_change scoped_thread_name_io;
node1.active.start (std::make_shared<nano::state_block> (send));
node1.active.insert (std::make_shared<nano::state_block> (send));
nano::state_block receive (nano::test_genesis_key.pub, send.hash (), nano::test_genesis_key.pub, nano::genesis_amount, send.hash (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *node1.work_generate_blocking (send.hash ()));
nano::node_rpc_config node_rpc_config;
nano::ipc::ipc_server ipc_server (node1, node_rpc_config);
Expand Down

0 comments on commit 2d20d85

Please sign in to comment.