Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes TSAN issues. #4547

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,14 +647,14 @@ TEST (node, fork_keep)
.work (*system.work.generate (nano::dev::genesis->hash ()))
.build ();
node1.process_active (send1);
node2.process_active (send1);
node2.process_active (builder.make_block ().from (*send1).build ());
ASSERT_TIMELY_EQ (5s, 1, node1.active.size ());
ASSERT_TIMELY_EQ (5s, 1, node2.active.size ());
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
// Fill node with forked blocks
node1.process_active (send2);
ASSERT_TIMELY (5s, node1.active.active (*send2));
node2.process_active (send2);
node2.process_active (builder.make_block ().from (*send2).build ());
ASSERT_TIMELY (5s, node2.active.active (*send2));
auto election1 (node2.active.election (nano::qualified_root (nano::dev::genesis->hash (), nano::dev::genesis->hash ())));
ASSERT_NE (nullptr, election1);
Expand Down
11 changes: 7 additions & 4 deletions nano/core_test/peer_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ TEST (peer_container, tcp_channel_cleanup_works)
// Disable the confirm_req messages avoiding them to affect the last_packet_set time
node_flags.disable_rep_crawler = true;
auto & node1 = *system.add_node (node_config, node_flags);
auto outer_node1 = nano::test::add_outer_node (system, node_flags);
outer_node1->config.network_params.network.keepalive_period = std::chrono::minutes (10);
auto outer_node2 = nano::test::add_outer_node (system, node_flags);
outer_node2->config.network_params.network.keepalive_period = std::chrono::minutes (10);

auto config1 = node_config;
config1.network_params.network.keepalive_period = std::chrono::minutes (10);
auto outer_node1 = nano::test::add_outer_node (system, config1, node_flags);
auto config2 = config1;
config2.network_params.network.keepalive_period = std::chrono::minutes (10);
auto outer_node2 = nano::test::add_outer_node (system, config2, node_flags);
auto now = std::chrono::steady_clock::now ();
auto channel1 = nano::test::establish_tcp (system, node1, outer_node1->network.endpoint ());
ASSERT_NE (nullptr, channel1);
Expand Down
15 changes: 15 additions & 0 deletions nano/lib/blockbuilders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,21 @@ nano::send_block_builder::send_block_builder ()
make_block ();
}

nano::send_block_builder & nano::send_block_builder::from (nano::send_block const & other_block)
{
block->work = other_block.work;
build_state |= build_flags::work_present;
block->signature = other_block.signature;
build_state |= build_flags::signature_present;
block->hashables.balance = other_block.hashables.balance;
build_state |= build_flags::balance_present;
block->hashables.destination = other_block.hashables.destination;
build_state |= build_flags::link_present;
block->hashables.previous = other_block.hashables.previous;
build_state |= build_flags::previous_present;
return *this;
}

nano::send_block_builder & nano::send_block_builder::make_block ()
{
construct_block ();
Expand Down
2 changes: 2 additions & 0 deletions nano/lib/blockbuilders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ class send_block_builder : public abstract_builder<nano::send_block, send_block_
public:
/** Creates a send block builder by calling make_block() */
send_block_builder ();
/** Initialize from an existing block */
send_block_builder & from (nano::send_block const & block);
/** Creates a new block with fields, signature and work set to sentinel values. All fields must be set or zeroed for build() to succeed. */
send_block_builder & make_block ();
/** Sets all hashables, signature and work to zero. */
Expand Down
10 changes: 9 additions & 1 deletion nano/test_common/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ std::shared_ptr<nano::transport::channel_tcp> nano::test::establish_tcp (nano::t
return result;
}

std::shared_ptr<nano::node> nano::test::add_outer_node (nano::test::system & system_a, nano::node_config const & config_a, nano::node_flags flags_a)
{
auto outer_node = std::make_shared<nano::node> (system_a.io_ctx, nano::unique_path (), config_a, system_a.work, flags_a);
outer_node->start ();
system_a.nodes.push_back (outer_node);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By adding it to nodes, any subsequent nodes will connect to this node.
This should be added to the disconnected nodes set.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return outer_node;
}

std::shared_ptr<nano::node> nano::test::add_outer_node (nano::test::system & system_a, nano::node_flags flags_a)
{
auto outer_node = std::make_shared<nano::node> (system_a.io_ctx, system_a.get_available_port (), nano::unique_path (), system_a.work, flags_a);
Expand Down Expand Up @@ -55,4 +63,4 @@ uint16_t nano::test::speculatively_choose_a_free_tcp_bind_port ()
acceptor.close ();

return port;
}
}
3 changes: 3 additions & 0 deletions nano/test_common/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ namespace test
/** Waits until a TCP connection is established and returns the TCP channel on success*/
std::shared_ptr<nano::transport::channel_tcp> establish_tcp (nano::test::system &, nano::node &, nano::endpoint const &);

/** Adds a node to the system without establishing connections */
std::shared_ptr<nano::node> add_outer_node (nano::test::system & system, nano::node_config const & config_a, nano::node_flags = nano::node_flags ());

/** Adds a node to the system without establishing connections */
std::shared_ptr<nano::node> add_outer_node (nano::test::system & system, nano::node_flags = nano::node_flags ());

Expand Down
Loading