Skip to content

feat(build): Windows/MinGW support + P2P node_id dedup + NAT-safe IP blocking + hello compat#101

Open
m0ssa99 wants to merge 24 commits into
VIZ-Blockchain:fix-witnessfrom
m0ssa99:windows_su
Open

feat(build): Windows/MinGW support + P2P node_id dedup + NAT-safe IP blocking + hello compat#101
m0ssa99 wants to merge 24 commits into
VIZ-Blockchain:fix-witnessfrom
m0ssa99:windows_su

Conversation

@m0ssa99
Copy link
Copy Markdown

@m0ssa99 m0ssa99 commented May 15, 2026

Windows/MinGW support + P2P node_id deduplication + NAT-aware IP blocking + backward-compatible hello deserialization

Overview

This PR adds full Windows (MSVC + MinGW) build support and fixes several P2P networking regressions introduced when node_id was added to dlt_hello_message. It also decouples the chain plugin from a hard dependency on the P2P plugin.


1. Windows / MinGW build support (CMakeLists.txt, libraries/chain/CMakeLists.txt, plugins/chain/CMakeLists.txt)

  • bcrypt: Link bcrypt globally when building with MinGW (-lbcrypt is required by Boost.UUID and OpenSSL on Windows but not auto-linked by MinGW toolchains).
  • hardfork.hpp generation: Unified add_custom_command for MSVC/MinGW (uses cat-parts.exe) and Linux/macOS (uses cat_parts.py via find_package(Python)). Previously MSVC used add_custom_target without an OUTPUT, which broke incremental builds and parallel make.
  • Chain plugin circular dependency removed: plugins/chain/CMakeLists.txt no longer links graphene::p2p or includes the P2P private headers. This removes a circular dependency (chain → p2p → chain) that caused linker errors on MSVC and required careful link ordering on MinGW.

2. Fiber cancellation and dead fiber management (dlt_p2p_node.cpp)

Improved handling of Boost.Fiber cancellation exceptions (fiber_interrupted, future_error). Dead fibers are now tracked and joined before destruction to avoid crashes during node shutdown or peer disconnect races.

3. Per-peer node_id deduplication (dlt_p2p_messages.hpp, dlt_p2p_node.hpp, dlt_p2p_node.cpp)

Added node_id (a 33-byte compressed secp256k1 public key) to dlt_hello_message. On hello, the node checks whether an active connection to the same node_id already exists and rejects the duplicate. This correctly handles the case where the same node reconnects on a different port without mistakenly deduplicating unrelated nodes that share a NAT IP.

4. Backward-compatible hello deserialization — fixes out_of_range_exception on message type 5100

The FC_REFLECT-based deserializer (msg.as<dlt_hello_message>()) expects every reflected field to be present. Legacy nodes (without node_id) send a 62-byte hello; new nodes send 95 bytes. Receiving a legacy hello produced:

Error processing message type 5100 from peer <ip>:<port>: 8 out_of_range_exception: Out of Range
read datastream of length 62 over by 1

Fix: replaced msg.as<>() with unpack_hello_compat() — a field-by-field deserializer that reads node_id only when ds.remaining() >= sizeof(node_id_t). Legacy peers get node_id = zero_id and continue to work normally. protocol_version intentionally stays at 1 — a bump would cause old nodes to disable block exchange on version mismatch, which is worse than the missing field.

The reverse direction (new node → old node) was already safe: fc::datastream only throws on over-read, not on leftover bytes, so old nodes silently ignore the extra 33 bytes.

5. NAT-aware IP blocking (dlt_p2p_node.cpp)

block_incoming_ip() previously blocked the entire IP on any misbehaving connection. In a NAT scenario (multiple nodes sharing one public IP on different ports), this would ban all legitimate peers from that network. Fix: before inserting into _blocked_ips, count active peers with the same IP. If count > 1, skip the IP ban, log a warning, and let the caller disconnect only the offending connection.

6. reindex shared file size — fixes MSVC/MinGW signed overflow (database.hpp)

Changed 1024l * 1024l * 1024l * 8l to 1024l * 1024l * 1024l * 8Ull in the reindex() default parameter. The l suffix is 32-bit on MSVC (long = 32 bits on Windows), causing a signed integer overflow when computing 8 GiB. Ull forces 64-bit arithmetic on all platforms.

7. Windows NTP drift threshold (plugins/witness/witness.cpp)

The Windows system clock has ~15ms resolution and higher jitter than Linux's CLOCK_REALTIME. The existing 250 ms NTP warn threshold fires as a false positive on Windows even on well-synchronized machines. A compile-time constant NTP_WARN_THRESHOLD_US sets 2 s on _WIN32 and 250 ms elsewhere.

8. Auto-recovery decoupled from P2P plugin (plugins/chain/plugin.cpp, plugins/p2p/p2p_plugin.cpp)

Removed direct p2p_plugin::pause_block_processing() / resume_block_processing() calls from the chain plugin's auto-recovery path. These calls required the chain plugin to link against the P2P plugin (causing the circular dependency above) and could crash if P2P was not yet started. Recovery now proceeds without pausing P2P; the P2P layer handles the resulting transient errors through its existing retry and disconnect logic. The shared_memory_corruption_exception catch in p2p_plugin.cpp is also removed since the chain plugin no longer relies on P2P to trigger recovery.


Files changed

File Change
CMakeLists.txt MinGW bcrypt link
libraries/chain/CMakeLists.txt Unified hardfork.hpp generation for all platforms
libraries/chain/include/graphene/chain/database.hpp Fix reindex overflow: 8l8Ull
libraries/network/dlt_p2p_node.cpp Fiber handling, node_id dedup, unpack_hello_compat, NAT-aware IP block
libraries/network/include/graphene/network/dlt_p2p_messages.hpp Add node_id field to dlt_hello_message
libraries/network/include/graphene/network/dlt_p2p_node.hpp find_active_peer_by_node_id declaration
plugins/chain/CMakeLists.txt Remove graphene::p2p link and private include
plugins/chain/plugin.cpp Remove P2P pause/resume from auto-recovery
plugins/p2p/p2p_plugin.cpp Remove shared_memory_corruption_exception catch
plugins/witness/witness.cpp Platform-specific NTP drift threshold
thirdparty/fc Submodule update

m0ssa99 added 24 commits May 14, 2026 21:41
fix(network): enhance connection error handling for Windows-specific cases
fix(cmake): update bcrypt linking for MinGW and improve compatibility
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.

1 participant