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

Fix mismatched channel owners #4750

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ void nano::node::keepalive (std::string const & address_a, uint16_t port_a)

void nano::node::inbound (const nano::message & message, const std::shared_ptr<nano::transport::channel> & channel)
{
debug_assert (channel->owner () == shared_from_this ()); // This node should be the channel owner
Copy link
Contributor

Choose a reason for hiding this comment

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

We could have owner return a naked pointer and compare against 'this' since we're not intending to manage lifetime. I'm fine with keeping this though since it's just test code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, if it was compiled in release then this should be done, but I try to avoid naked pointers unless absolutely necessary to avoid shooting myself in the foot accidentally.


debug_assert (message.header.network == network_params.network.current_network);
debug_assert (message.header.version_using >= network_params.network.protocol_version_min);

Expand Down
5 changes: 5 additions & 0 deletions nano/node/transport/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ nano::endpoint nano::transport::channel::get_peering_endpoint () const
}
}

std::shared_ptr<nano::node> nano::transport::channel::owner () const
{
return node.shared ();
}

void nano::transport::channel::operator() (nano::object_stream & obs) const
{
obs.write ("endpoint", get_endpoint ());
Expand Down
2 changes: 2 additions & 0 deletions nano/node/transport/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class channel
nano::endpoint get_peering_endpoint () const;
void set_peering_endpoint (nano::endpoint endpoint);

std::shared_ptr<nano::node> owner () const;

mutable nano::mutex channel_mutex;

private:
Expand Down