feat(build): Windows/MinGW support + P2P node_id dedup + NAT-safe IP blocking + hello compat#101
Open
m0ssa99 wants to merge 24 commits into
Open
feat(build): Windows/MinGW support + P2P node_id dedup + NAT-safe IP blocking + hello compat#101m0ssa99 wants to merge 24 commits into
m0ssa99 wants to merge 24 commits into
Conversation
…into windows_su
…d-compatible hello message deserializer
…optimize performance
fix(network): enhance connection error handling for Windows-specific cases fix(cmake): update bcrypt linking for MinGW and improve compatibility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_idwas added todlt_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)bcryptglobally when building with MinGW (-lbcryptis required by Boost.UUID and OpenSSL on Windows but not auto-linked by MinGW toolchains).add_custom_commandfor MSVC/MinGW (usescat-parts.exe) and Linux/macOS (usescat_parts.pyviafind_package(Python)). Previously MSVC usedadd_custom_targetwithout anOUTPUT, which broke incremental builds and parallel make.plugins/chain/CMakeLists.txtno longer linksgraphene::p2por 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_iddeduplication (dlt_p2p_messages.hpp,dlt_p2p_node.hpp,dlt_p2p_node.cpp)Added
node_id(a 33-byte compressed secp256k1 public key) todlt_hello_message. On hello, the node checks whether an active connection to the samenode_idalready 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_exceptionon message type 5100The
FC_REFLECT-based deserializer (msg.as<dlt_hello_message>()) expects every reflected field to be present. Legacy nodes (withoutnode_id) send a 62-byte hello; new nodes send 95 bytes. Receiving a legacy hello produced:Fix: replaced
msg.as<>()withunpack_hello_compat()— a field-by-field deserializer that readsnode_idonly whends.remaining() >= sizeof(node_id_t). Legacy peers getnode_id = zero_idand continue to work normally.protocol_versionintentionally stays at1— 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::datastreamonly 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. Ifcount > 1, skip the IP ban, log a warning, and let the caller disconnect only the offending connection.6.
reindexshared file size — fixes MSVC/MinGW signed overflow (database.hpp)Changed
1024l * 1024l * 1024l * 8lto1024l * 1024l * 1024l * 8Ullin thereindex()default parameter. Thelsuffix is 32-bit on MSVC (long= 32 bits on Windows), causing a signed integer overflow when computing 8 GiB.Ullforces 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 constantNTP_WARN_THRESHOLD_USsets 2 s on_WIN32and 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. Theshared_memory_corruption_exceptioncatch inp2p_plugin.cppis also removed since the chain plugin no longer relies on P2P to trigger recovery.Files changed
CMakeLists.txtlibraries/chain/CMakeLists.txtlibraries/chain/include/graphene/chain/database.hppreindexoverflow:8l→8Ulllibraries/network/dlt_p2p_node.cppunpack_hello_compat, NAT-aware IP blocklibraries/network/include/graphene/network/dlt_p2p_messages.hppnode_idfield todlt_hello_messagelibraries/network/include/graphene/network/dlt_p2p_node.hppfind_active_peer_by_node_iddeclarationplugins/chain/CMakeLists.txtgraphene::p2plink and private includeplugins/chain/plugin.cppplugins/p2p/p2p_plugin.cppshared_memory_corruption_exceptioncatchplugins/witness/witness.cppthirdparty/fc