Exchange node capabilities when performing network handshake#5043
Conversation
9057d2b to
117001f
Compare
Test Results for Commit b0786c2Pull Request 5043: Results Test Case Results
Last updated: 2026-03-19 16:05:08 UTC |
117001f to
2decca4
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds a v3 node-id handshake extension to advertise optional node capability flags to peers during TCP handshakes, enabling discovery/routing toward specialized service providers.
Changes:
- Introduces
handshake_versionand a v3node_id_handshakeresponse payload carrying capability flags. - Propagates capability flags from handshake responses into
tcp_channelstate for later use. - Adds
enum_flagsandnode_capabilitiesutilities plus tests covering v3 serialization/signing and flag exchange.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| nano/node/transport/tcp_server.hpp | Updates handshake response API and realtime transition to carry capability flags. |
| nano/node/transport/tcp_server.cpp | Passes negotiated handshake version and stores peer capability flags on channel creation. |
| nano/node/transport/tcp_channels.hpp | Extends create() to accept optional capability flags. |
| nano/node/transport/tcp_channels.cpp | Persists capability flags onto newly created channels. |
| nano/node/transport/channel.hpp | Adds per-channel storage/accessors for peer capability flags. |
| nano/node/nodeconfig.hpp | Adds testing-only capability override flag set. |
| nano/node/node.hpp | Exposes node::get_capabilities() API. |
| nano/node/node.cpp | Implements get_capabilities() (currently override-only, TODO for real config/state). |
| nano/node/network.hpp | Updates handshake response preparation to use handshake_version. |
| nano/node/network.cpp | Builds v2/v3 handshake responses; v3 includes capabilities. |
| nano/messages/node_id_handshake.hpp | Adds handshake v3 payload + handshake_version and replaces v2 optional with a variant ext. |
| nano/messages/node_id_handshake.cpp | Implements v3 flagging, (de)serialization, signing preimage, and accessors for genesis/flags. |
| nano/lib/utility.hpp | Adds nano::overloaded helper for std::visit. |
| nano/lib/node_capabilities.hpp | Defines capability enum + flags type. |
| nano/lib/node_capabilities.cpp | Implements capability string conversion and instantiates enum_flags formatting helpers. |
| nano/lib/enum_flags_templ.hpp | Adds streaming/to_string templates for enum_flags. |
| nano/lib/enum_flags.hpp | Adds enum_flags bitfield wrapper. |
| nano/lib/CMakeLists.txt | Registers node capabilities sources in the lib target. |
| nano/core_test/tcp_server.cpp | Adds integration test validating capability flag exchange via v3 handshake. |
| nano/core_test/message.cpp | Updates handshake tests and adds v3 serialization/signature tests. |
| nano/core_test/enums.cpp | Adds unit tests for enum_flags behavior and formatting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
6160f54 to
bf32284
Compare
There was a problem hiding this comment.
Pull request overview
Adds a V3 node ID handshake extension so peers can exchange advertised node capabilities during the TCP handshake, enabling discovery of specialized service providers on the network.
Changes:
- Introduces
handshake_versionand a V3 handshake response payload carryingnode_capabilities_flags. - Propagates negotiated capability flags into
transport::channel/tcp_channelviatcp_channels::create(...). - Adds a new
enum_flags<>utility plus tests for V3 handshake serialization/signatures and end-to-end flag exchange.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| nano/node/transport/tcp_server.hpp | Plumbs handshake version + capability flags through realtime upgrade path. |
| nano/node/transport/tcp_server.cpp | Uses handshake_version for response generation; stores peer flags on channel creation. |
| nano/node/transport/tcp_channels.hpp | Extends channel creation API to accept capability flags (defaulted). |
| nano/node/transport/tcp_channels.cpp | Sets capability flags on newly created TCP channels. |
| nano/node/transport/channel.hpp | Adds capability flags storage/accessors on channels. |
| nano/node/nodeconfig.hpp | Adds test-only capability override to node_flags. |
| nano/node/node.hpp | Exposes node::get_capabilities() for handshake response population. |
| nano/node/node.cpp | Implements get_capabilities() (currently override-or-empty, TODO for real config/state). |
| nano/node/network.hpp | Updates handshake response preparation API to accept handshake version. |
| nano/node/network.cpp | Generates V2/V3 response payloads; verifies genesis via new response accessor. |
| nano/messages/node_id_handshake.hpp | Adds handshake_version, V3 payload, and variant-based extension storage + accessors. |
| nano/messages/node_id_handshake.cpp | Implements V3 serialization/deserialization/signing and header version flag handling. |
| nano/lib/utility.hpp | Adds nano::overloaded helper for std::visit multi-lambda usage. |
| nano/lib/node_capabilities.hpp | Introduces node capability enum + flags alias. |
| nano/lib/node_capabilities.cpp | Implements capability string conversion and flag printing/to_string instantiations. |
| nano/lib/enum_flags_templ.hpp | Adds templated operator<</to_string for enum_flags<>. |
| nano/lib/enum_flags.hpp | Adds enum_flags<> type-safe bitflag wrapper. |
| nano/lib/CMakeLists.txt | Adds new node capabilities sources to nano_lib. |
| nano/core_test/tcp_server.cpp | Updates handshake tests and adds e2e test for exchanging capability flags. |
| nano/core_test/message.cpp | Updates handshake response tests; adds V3 serialization + signature tests. |
| nano/core_test/enums.cpp | Adds unit tests for enum_flags<> formatting/behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Introduce `enum_flags<E>` template providing a std::bitset-like API for power-of-2 flag enums with set/reset/test operations, bitwise operators, and magic_enum-based string conversion.
Extend the handshake protocol to advertise node capabilities as a bitfield in the response payload. Replace the v2 optional with a variant over v1/v2/v3 payloads and propagate capabilities to the channel on connection.
bf32284 to
b0786c2
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a V3 node_id_handshake format that allows peers to exchange and persist optional node capability flags during the TCP handshake, enabling future request routing to specialized nodes.
Changes:
- Added handshake V3 support using a versioned
response_payload::ext(std::variant) carrying capability flags. - Plumbed advertised capability flags from handshake response into
transport::channelviatcp_channels::create(...). - Introduced
enum_flags<>+node_capabilitiesdefinitions and added unit tests for V3 serialization/signature and flag exchange.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| nano/node/transport/tcp_server.hpp | Updates handshake response API to use handshake_version; plumbs capabilities into realtime channel creation. |
| nano/node/transport/tcp_server.cpp | Uses negotiated handshake version; passes received capability flags into channel creation. |
| nano/node/transport/tcp_channels.hpp | Extends create(...) to accept capability flags (default {}). |
| nano/node/transport/tcp_channels.cpp | Stores capability flags on newly created channels. |
| nano/node/transport/channel.hpp | Adds thread-safe getters/setters and storage for per-peer capability flags. |
| nano/node/nodeconfig.hpp | Adds capabilities_override test hook for forcing advertised capabilities. |
| nano/node/node.hpp | Adds node::get_capabilities() API. |
| nano/node/node.cpp | Implements get_capabilities() (currently override-or-empty with TODO). |
| nano/node/network.hpp | Updates handshake response preparation to take handshake_version. |
| nano/node/network.cpp | Builds V2/V3 handshake responses; V3 includes capabilities in the signed payload. |
| nano/messages/node_id_handshake.hpp | Adds handshake_version, V3 payload, variant-based extensions, and accessors for genesis/flags. |
| nano/messages/node_id_handshake.cpp | Implements version selection, V3 (de)serialization, and signing/validation over the versioned payload. |
| nano/lib/utility.hpp | Adds nano::overloaded helper for std::visit. |
| nano/lib/node_capabilities.hpp | Defines capability bits and node_capabilities_flags. |
| nano/lib/node_capabilities.cpp | Implements to_string(node_capabilities) and instantiates enum_flags streaming/to_string for capabilities. |
| nano/lib/enum_flags.hpp | Introduces type-safe bitflag wrapper used by capabilities. |
| nano/lib/enum_flags_templ.hpp | Adds streaming/to_string implementations for enum_flags<>. |
| nano/lib/CMakeLists.txt | Wires new lib sources/headers into the build. |
| nano/core_test/tcp_server.cpp | Adds integration test ensuring V3 handshake exchanges and stores capability flags. |
| nano/core_test/message.cpp | Adds V3 serialization and signature tests; updates V2 tests for ext variant. |
| nano/core_test/enums.cpp | Adds unit tests for enum_flags<> behavior and formatting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| { | ||
| static_assert (std::is_standard_layout_v<enum_flags>, "Standard layout required for safe underlying type punning"); | ||
| static_assert (std::is_trivially_copyable_v<enum_flags>, "Trivially copyable required for safe underlying type punning"); | ||
| static_assert (sizeof (enum_flags) == sizeof (underlying_t), "Size of enum_flags must be the same as underlying type"); | ||
| } |
This introduces a V3 node ID handshake that allows nodes to advertise optional capabilities to their peers.
Motivation
This is building toward a network of specialized nodes: nodes that opt into providing additional services beyond standard consensus participation. For example, a node with
topo_indexcapability can serve topologically ordered block data, enabling dramatically faster bootstrapping for peers. A node withvote_storagecan relay historical vote data, helping peers that fall behind to catch up quickly without re-requesting votes from representatives.By advertising these capabilities during the handshake, peers can discover which nodes offer which services and route requests accordingly.