Skip to content

Commit

Permalink
FIX TESTS
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed May 26, 2024
1 parent a1aa85b commit d0f724f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
33 changes: 15 additions & 18 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand All @@ -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;
Expand All @@ -800,30 +800,27 @@ 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 ()
.previous (latest)
.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)
Expand Down
1 change: 1 addition & 0 deletions nano/node/active_elections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ bool nano::active_elections::publish (std::shared_ptr<nano::block> 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;
Expand Down
6 changes: 6 additions & 0 deletions nano/node/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nano::mutex> guard{ mutex };
return last_blocks.contains (hash);
}

// TODO: Remove the need for .to_string () calls
void nano::election::operator() (nano::object_stream & obs) const
{
Expand Down
6 changes: 4 additions & 2 deletions nano/node/election.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ class election final : public std::enable_shared_from_this<election>
nano::election_behavior behavior () const;
nano::election_state state () const;

std::unordered_map<nano::account, nano::vote_info> votes () const;
std::unordered_map<nano::block_hash, std::shared_ptr<nano::block>> blocks () const;
bool contains (nano::block_hash const &) const;

private:
nano::tally_t tally_impl () const;
bool confirmed_locked () const;
Expand Down Expand Up @@ -188,8 +192,6 @@ class election final : public std::enable_shared_from_this<election>

public: // Only used in tests
void force_confirm ();
std::unordered_map<nano::account, nano::vote_info> votes () const;
std::unordered_map<nano::block_hash, std::shared_ptr<nano::block>> blocks () const;

friend class confirmation_solicitor_different_hash_Test;
friend class confirmation_solicitor_bypass_max_requests_cap_Test;
Expand Down

0 comments on commit d0f724f

Please sign in to comment.