Remove rolled back blocks list (#2447)
* Remove rolled back blocks list * Don't stop initial rollback election
This commit is contained in:
parent
ad1691acd1
commit
fd4551f73a
4 changed files with 6 additions and 57 deletions
|
@ -2810,33 +2810,6 @@ TEST (node, block_processor_reject_state)
|
|||
ASSERT_TRUE (node.ledger.block_exists (send2->hash ()));
|
||||
}
|
||||
|
||||
TEST (node, block_processor_reject_rolled_back)
|
||||
{
|
||||
nano::system system;
|
||||
nano::node_config node_config (nano::get_available_port (), system.logging);
|
||||
node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
|
||||
auto & node = *system.add_node (node_config);
|
||||
nano::genesis genesis;
|
||||
auto send1 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
|
||||
node.work_generate_blocking (*send1);
|
||||
node.block_processor.add (send1);
|
||||
node.block_processor.flush ();
|
||||
ASSERT_TRUE (node.ledger.block_exists (send1->hash ()));
|
||||
auto send2 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - 2 * nano::Gxrb_ratio, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
|
||||
node.work_generate_blocking (*send2);
|
||||
// Force block send2 & rolling back block send1
|
||||
node.block_processor.force (send2);
|
||||
node.block_processor.flush ();
|
||||
ASSERT_FALSE (node.ledger.block_exists (send1->hash ()));
|
||||
ASSERT_TRUE (node.ledger.block_exists (send2->hash ()));
|
||||
ASSERT_TRUE (node.active.empty ());
|
||||
// Block send1 cannot be processed & start fork resolution election
|
||||
node.block_processor.add (send1);
|
||||
node.block_processor.flush ();
|
||||
ASSERT_FALSE (node.ledger.block_exists (send1->hash ()));
|
||||
ASSERT_TRUE (node.active.empty ());
|
||||
}
|
||||
|
||||
TEST (node, block_processor_full)
|
||||
{
|
||||
nano::system system;
|
||||
|
|
|
@ -75,7 +75,7 @@ void nano::block_processor::add (nano::unchecked_info const & info_a)
|
|||
auto hash (info_a.block->hash ());
|
||||
auto filter_hash (filter_item (hash, info_a.block->block_signature ()));
|
||||
nano::lock_guard<std::mutex> lock (mutex);
|
||||
if (blocks_filter.find (filter_hash) == blocks_filter.end () && rolled_back.get<tag_hash> ().find (hash) == rolled_back.get<tag_hash> ().end ())
|
||||
if (blocks_filter.find (filter_hash) == blocks_filter.end ())
|
||||
{
|
||||
if (info_a.verified == nano::signature_verification::unknown && (info_a.block->type () == nano::block_type::state || info_a.block->type () == nano::block_type::open || !info_a.account.is_zero ()))
|
||||
{
|
||||
|
@ -326,26 +326,16 @@ void nano::block_processor::process_batch (nano::unique_lock<std::mutex> & lock_
|
|||
{
|
||||
node.logger.always_log (boost::str (boost::format ("%1% blocks rolled back") % rollback_list.size ()));
|
||||
}
|
||||
lock_a.lock ();
|
||||
// Prevent rolled back blocks second insertion
|
||||
auto inserted (rolled_back.get<tag_sequence> ().push_back (successor->hash ()));
|
||||
if (inserted.second)
|
||||
{
|
||||
// Possible election winner change
|
||||
rolled_back.get<tag_hash> ().erase (hash);
|
||||
// Prevent overflow
|
||||
if (rolled_back.size () > rolled_back_max)
|
||||
{
|
||||
rolled_back.get<tag_sequence> ().pop_front ();
|
||||
}
|
||||
}
|
||||
lock_a.unlock ();
|
||||
// Deleting from votes cache & wallet work watcher, stop active transaction
|
||||
for (auto & i : rollback_list)
|
||||
{
|
||||
node.votes_cache.remove (i->hash ());
|
||||
node.wallets.watcher->remove (i);
|
||||
node.active.erase (*i);
|
||||
// Stop all rolled back active transactions except initial
|
||||
if (i->hash () != successor->hash ())
|
||||
{
|
||||
node.active.erase (*i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,17 +63,6 @@ private:
|
|||
std::deque<std::shared_ptr<nano::block>> forced;
|
||||
nano::block_hash filter_item (nano::block_hash const &, nano::signature const &);
|
||||
std::unordered_set<nano::block_hash> blocks_filter;
|
||||
// clang-format off
|
||||
class tag_sequence {};
|
||||
class tag_hash {};
|
||||
boost::multi_index_container<nano::block_hash,
|
||||
boost::multi_index::indexed_by<
|
||||
boost::multi_index::sequenced<boost::multi_index::tag<tag_sequence>>,
|
||||
boost::multi_index::hashed_unique<boost::multi_index::tag<tag_hash>,
|
||||
boost::multi_index::identity<nano::block_hash>>>>
|
||||
rolled_back;
|
||||
// clang-format on
|
||||
static size_t const rolled_back_max = 1024;
|
||||
nano::condition_variable condition;
|
||||
nano::node & node;
|
||||
nano::write_database_queue & write_database_queue;
|
||||
|
|
|
@ -86,7 +86,6 @@ std::unique_ptr<seq_con_info_component> collect_seq_con_info (block_processor &
|
|||
size_t blocks_count = 0;
|
||||
size_t blocks_filter_count = 0;
|
||||
size_t forced_count = 0;
|
||||
size_t rolled_back_count = 0;
|
||||
|
||||
{
|
||||
nano::lock_guard<std::mutex> guard (block_processor.mutex);
|
||||
|
@ -94,7 +93,6 @@ std::unique_ptr<seq_con_info_component> collect_seq_con_info (block_processor &
|
|||
blocks_count = block_processor.blocks.size ();
|
||||
blocks_filter_count = block_processor.blocks_filter.size ();
|
||||
forced_count = block_processor.forced.size ();
|
||||
rolled_back_count = block_processor.rolled_back.size ();
|
||||
}
|
||||
|
||||
auto composite = std::make_unique<seq_con_info_composite> (name);
|
||||
|
@ -102,7 +100,6 @@ std::unique_ptr<seq_con_info_component> collect_seq_con_info (block_processor &
|
|||
composite->add_component (std::make_unique<seq_con_info_leaf> (seq_con_info{ "blocks", blocks_count, sizeof (decltype (block_processor.blocks)::value_type) }));
|
||||
composite->add_component (std::make_unique<seq_con_info_leaf> (seq_con_info{ "blocks_filter", blocks_filter_count, sizeof (decltype (block_processor.blocks_filter)::value_type) }));
|
||||
composite->add_component (std::make_unique<seq_con_info_leaf> (seq_con_info{ "forced", forced_count, sizeof (decltype (block_processor.forced)::value_type) }));
|
||||
composite->add_component (std::make_unique<seq_con_info_leaf> (seq_con_info{ "rolled_back", rolled_back_count, sizeof (decltype (block_processor.rolled_back)::value_type) }));
|
||||
composite->add_component (collect_seq_con_info (block_processor.generator, "generator"));
|
||||
return composite;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue