Skip to content

Exchange node capabilities when performing network handshake#5043

Merged
pwojcikdev merged 2 commits intonanocurrency:developfrom
pwojcikdev:handshake-node-capabilities-2
Mar 19, 2026
Merged

Exchange node capabilities when performing network handshake#5043
pwojcikdev merged 2 commits intonanocurrency:developfrom
pwojcikdev:handshake-node-capabilities-2

Conversation

@pwojcikdev
Copy link
Copy Markdown
Contributor

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_index capability can serve topologically ordered block data, enabling dramatically faster bootstrapping for peers. A node with vote_storage can 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.

@pwojcikdev pwojcikdev force-pushed the handshake-node-capabilities-2 branch 2 times, most recently from 9057d2b to 117001f Compare March 17, 2026 18:06
@gr0vity-dev-bot
Copy link
Copy Markdown

gr0vity-dev-bot commented Mar 17, 2026

Test Results for Commit b0786c2

Pull Request 5043: Results
Overall Status:

Test Case Results

  • 5n4pr_conf_10k_bintree: PASS (Duration: 115s)
  • 5n4pr_conf_10k_change: PASS (Duration: 137s)
  • 5n4pr_conf_change_dependant: PASS (Duration: 150s)
  • 5n4pr_conf_change_independant: PASS (Duration: 135s)
  • 5n4pr_conf_send_dependant: PASS (Duration: 144s)
  • 5n4pr_conf_send_independant: PASS (Duration: 132s)
  • 5n4pr_rocks_10k_bintree: PASS (Duration: 125s)
  • 5n4pr_rocks_10k_change: FAIL (Duration: 284s)
  • Log

Last updated: 2026-03-19 16:05:08 UTC

@pwojcikdev pwojcikdev force-pushed the handshake-node-capabilities-2 branch from 117001f to 2decca4 Compare March 18, 2026 22:58
@pwojcikdev pwojcikdev requested a review from Copilot March 19, 2026 00:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_version and a v3 node_id_handshake response payload carrying capability flags.
  • Propagates capability flags from handshake responses into tcp_channel state for later use.
  • Adds enum_flags and node_capabilities utilities 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.

@pwojcikdev pwojcikdev force-pushed the handshake-node-capabilities-2 branch 3 times, most recently from 6160f54 to bf32284 Compare March 19, 2026 12:45
@pwojcikdev pwojcikdev requested a review from Copilot March 19, 2026 12:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_version and a V3 handshake response payload carrying node_capabilities_flags.
  • Propagates negotiated capability flags into transport::channel/tcp_channel via tcp_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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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::channel via tcp_channels::create(...).
  • Introduced enum_flags<> + node_capabilities definitions 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.

Comment on lines +122 to +126
{
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");
}
@pwojcikdev pwojcikdev merged commit 6f405e0 into nanocurrency:develop Mar 19, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants