diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 28fe121b30..b730b489a4 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -769,6 +769,8 @@ TEST (node, fork_multi_flip) auto election = nano::test::start_election (system, node2, send2->hash ()); ASSERT_NE (nullptr, election); + ASSERT_TIMELY (5s, election->contains (send1->hash ())); + nano::test::confirm (node1.ledger, send1); ASSERT_TIMELY (5s, node2.block_or_pruned_exists (send1->hash ())); ASSERT_TRUE (nano::test::block_or_pruned_none_exists (node2, { send2, send3 })); auto winner = *election->tally ().begin (); @@ -781,17 +783,15 @@ TEST (node, fork_multi_flip) TEST (node, fork_bootstrap_flip) { nano::test::system system; - nano::test::system system0; - nano::test::system system1; nano::node_config config0{ system.get_available_port () }; config0.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled; nano::node_flags node_flags; node_flags.disable_bootstrap_bulk_push_client = true; node_flags.disable_lazy_bootstrap = true; - auto & node1 = *system0.add_node (config0, node_flags); + auto & node1 = *system.add_node (config0, node_flags); + system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); nano::node_config config1 (system.get_available_port ()); - auto & node2 = *system1.add_node (config1, node_flags); - system0.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); + auto & node2 = *system.make_disconnected_node (config1, node_flags); nano::block_hash latest = node1.latest (nano::dev::genesis_key.pub); nano::keypair key1; nano::send_block_builder builder; @@ -800,7 +800,7 @@ TEST (node, fork_bootstrap_flip) .destination (key1.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*system0.work.generate (latest)) + .work (*system.work.generate (latest)) .build (); nano::keypair key2; auto send2 = builder.make_block () @@ -808,22 +808,19 @@ TEST (node, fork_bootstrap_flip) .destination (key2.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*system0.work.generate (latest)) + .work (*system.work.generate (latest)) .build (); // Insert but don't rebroadcast, simulating settled blocks ASSERT_EQ (nano::block_status::progress, node1.ledger.process (node1.ledger.tx_begin_write (), send1)); ASSERT_EQ (nano::block_status::progress, node2.ledger.process (node2.ledger.tx_begin_write (), send2)); - ASSERT_TRUE (node2.ledger.any.block_exists (node2.ledger.tx_begin_read (), send2->hash ())); - node2.bootstrap_initiator.bootstrap (node1.network.endpoint ()); // Additionally add new peer to confirm & replace bootstrap block - auto again (true); - system0.deadline_set (50s); - system1.deadline_set (50s); - while (again) - { - ASSERT_NO_ERROR (system0.poll ()); - ASSERT_NO_ERROR (system1.poll ()); - again = !node2.ledger.any.block_exists (node2.ledger.tx_begin_read (), send1->hash ()); - } + nano::test::confirm (node1.ledger, send1); + ASSERT_TIMELY (1s, node1.ledger.any.block_exists (node1.ledger.tx_begin_read (), send1->hash ())); + ASSERT_TIMELY (1s, node2.ledger.any.block_exists (node2.ledger.tx_begin_read (), send2->hash ())); + + // Additionally add new peer to confirm & replace bootstrap block + node2.network.merge_peer (node1.network.endpoint ()); + + ASSERT_TIMELY (10s, node2.ledger.any.block_exists (node2.ledger.tx_begin_read (), send1->hash ())); } TEST (node, fork_open) diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index 780b22d39c..fe1817b042 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -526,6 +526,7 @@ bool nano::active_elections::publish (std::shared_ptr const & block node.vote_cache_processor.trigger (block_a->hash ()); node.stats.inc (nano::stat::type::active, nano::stat::detail::election_block_conflict); + node.logger.debug (nano::log::type::active_elections, "Block was added to an existing election: {}", block_a->hash ().to_string ()); } } return result; diff --git a/nano/node/election.cpp b/nano/node/election.cpp index 8e4854db2e..868b8a9ff8 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -756,6 +756,12 @@ nano::election_state nano::election::state () const return state_m; } +bool nano::election::contains (nano::block_hash const & hash) const +{ + nano::lock_guard guard{ mutex }; + return last_blocks.contains (hash); +} + // TODO: Remove the need for .to_string () calls void nano::election::operator() (nano::object_stream & obs) const { diff --git a/nano/node/election.hpp b/nano/node/election.hpp index 6111191e2b..b65d2f1c0f 100644 --- a/nano/node/election.hpp +++ b/nano/node/election.hpp @@ -138,6 +138,10 @@ class election final : public std::enable_shared_from_this nano::election_behavior behavior () const; nano::election_state state () const; + std::unordered_map votes () const; + std::unordered_map> blocks () const; + bool contains (nano::block_hash const &) const; + private: nano::tally_t tally_impl () const; bool confirmed_locked () const; @@ -188,8 +192,6 @@ class election final : public std::enable_shared_from_this public: // Only used in tests void force_confirm (); - std::unordered_map votes () const; - std::unordered_map> blocks () const; friend class confirmation_solicitor_different_hash_Test; friend class confirmation_solicitor_bypass_max_requests_cap_Test;