Skip to content

fix(net): sync p2p fixes from libp2p release-v2.3.0 (part 3) - #7098

Merged
kuny0707 merged 7 commits into
tronprotocol:release_v4.8.3from
317787106:feature/p2p_v230_migration_v3
Nov 10, 2026
Merged

kuny0707 merged 7 commits into
tronprotocol:release_v4.8.3from
317787106:feature/p2p_v230_migration_v3

Conversation

@317787106

@317787106 317787106 commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Synchronize java-tron's in-tree :p2p module with all twelve libp2p PRs merged after java-tron #7065. The source comparison on release-v2.3.0 runs from 5bae7b902f45a9bbd71e492026b4c2c0b6ef0767 through 94dbc75896dc68c72934276c8d3143b4a3540363.

Upstream PR Merged commit Change
libp2p #169 5f30d68 Account pending TCP writes, evict connections under outbound-budget pressure, and enforce write deadlines.
libp2p #170 94dbc75 Preserve trusted inbound HELLO capacity and return early admission rejection reasons.
libp2p #171 06ec836 Upgrade snappy-java to 1.1.10.12 and Bouncy Castle to 1.86.
libp2p #172 6937e61 Remove the handshake/disconnect lock inversion and handle disconnect/registration races.
libp2p #173 1437beb Deduplicate hashes during DNS subtree traversal.
libp2p #174 8889168 Stop buffered decoding after connection closure and bound fatal-error payload logging.
libp2p #175 88c19be Harden DNS TXT/address validation, isolate resolver caches, fix public-key compression, and correct publishing order/name handling.
libp2p #176 357e0d7 Publish DNS roots when links or signing keys change and allow replacement of roots with unrecoverable signers.
libp2p #177 5224937 Keep NEIGHBORS replies below the packet-size limit and discard remote IPv6 zone identifiers.
libp2p #178 1f4d931 Probe the least recently updated bucket entry and restore the retry budget after a compatible PONG.
libp2p #179 ceeac6d Publish PING state before sending to prevent fast-PONG races.
libp2p #180 29da652 Bound raw HELLO/STATUS endpoint fields and normalize retained protobuf payloads.

Include the following java-tron integration changes:

  • Share raw address-field checks through NetUtil.validAddressFields() and apply them to P2P HELLO/STATUS and application-layer HELLO, before Node conversion. Preserve application HELLO's optional from behavior and existing IPv6 fallback for invalid IPv4 values within the length limit.
  • Stop serving remaining FetchInvData items after disconnection and skip the final transaction batch; ignore already-disconnected peers at the application message entry point.
  • Prepare inventory broadcast batches and update advertisement state under the AdvService monitor, then send the prepared inventory after releasing it.
  • Prevent repeated successful relay HELLO authentication from appending duplicate trusted IPs.
  • Reject a nonempty, explicitly configured node.discovery.external.ip unless it is an IPv4 literal. Empty settings retain automatic detection and LAN fallback.
  • For java-tron's own runtime IP blacklist, select matching connections under the admission lock and close them after releasing it. Preserve silent closure, policy publication before selection, and admission checks.

Align the root bcprov declaration with bcpkix/transitive bcutil at 1.86 and regenerate dependency-verification checksums. Adapt the import to java-tron's logging and existing tests. The moved DNS full-sync test uses local signed TXT records instead of a live public DNS tree. Keep source provenance and DNS migration instructions in p2p/README.md; list the upstream PRs here. Correct the TCP handler examples to use messageTypes, declare the channel map, include the required imports, and place public classes in separate Java files.

Why are these changes required?

Backlogged TCP writes can retain resources, disconnect/registration races can stall or corrupt peer lifecycle handling, and queued frames can continue processing after closure. The discovery and DNS fixes address oversized responses, incorrect probe selection, redundant traversal, validation gaps, and stale publication decisions. The java-tron changes complete the integration by stopping downstream work after disconnect, keeping inventory sends outside the advertisement-state critical section, avoiding repeated trust-list growth, and reporting invalid advertised IPv4 configuration before networking starts. The README corrections let consumers compile the documented handler against the actual API.

This PR has been tested by:

Local validation on macOS ARM64 / JDK 17:

  • Initial migration (13b06ae7ca): the full ./gradlew test suite passed with 5,639 tests, 16 skipped, and zero failures/errors. This included the signature/address compatibility, P-256, precompiled-contract, batch-signature and multisignature tests.
  • Shared validation helper (3d3eaa5921): all 643 P2P tests passed (4 skipped), together with 24 framework HELLO/handshake/dispatch tests.
  • Downstream follow-ups (b675a2685d): 95 targeted framework tests passed. The blacklist follow-up also passed 41 P2P tests and 37 framework management/lifecycle tests; the two lifecycle cases overlap with the earlier framework run.
  • Regression tests reproduced continued FetchInvData processing, disconnected-peer dispatch, duplicate relay trust entries, acceptance of invalid explicit IPv4 configuration, and blacklist disconnect callbacks inheriting the admission lock before the fixes, then passed afterward.
  • README corrections (b53a84d0d2): the three Java source examples compiled with javac --release 8, and registration of the example's TEST message type passed.
  • Inventory broadcast follow-up (c68a7397a9): all 12 targeted framework tests passed (AdvServiceTest: 3; P2pEventHandlerImplTest: 9). The bounded concurrent-cleanup regression failed with the previous lock scope and passed after the adjustment; it also verifies the inventory/fetch messages and peer cleanup.
  • On the final source tree (c68a7397a9), ./gradlew clean build -x test passed, including FullNode, standalone P2P and tools packaging. The CI Checkstyle gate (:framework:checkstyleMain :framework:checkstyleTest :plugins:checkstyleMain), P2P main/test Checkstyle, bash .github/scripts/check_math_usage.sh, and git diff --check passed.

The full repository test suite was not rerun after the initial migration. Local checks cover ARM64/JDK 17; the remaining platform/JDK combinations are covered by the PR's CI matrix. Manual node/load testing was not performed for this PR.

Follow up

  • Handle atomic trust-list snapshot publication and the retention/revocation policy for dynamically learned SR trust separately. This PR only deduplicates additions from successful relay authentication.
  • Track further libp2p changes separately, including queued physical closure during write-budget eviction, configurable write budgets/backpressure, timeout diagnostics, and DNS recovery/resource limits. Node-only DNS publication retry recovery for Aliyun and Route53 should also be addressed upstream, with any accepted fix synchronized separately. JVM direct-memory defaults are unchanged and require workload validation before adjustment.

Extra details

  • Pending-write protection uses a 200 MiB per-connection threshold, a 500 MiB shared eviction trigger, and a fixed 10-second deadline per incomplete write. Partial progress does not extend that deadline. The shared threshold triggers eviction based on framed bytes; it is not a hard cap on JVM direct-memory usage.
  • Both trusted and ordinary pending inbound HELLOs count toward one total. Ordinary connections are admitted below 32; trusted connections may use capacity up to 40 total. The per-IP pending limit remains two and the absolute HELLO deadline remains 10 seconds.
  • Raw endpoint address limits are 15 bytes for IPv4 and 45 bytes for IPv6, checked before decoding/conversion. An invalid nonempty raw IPv6 field rejects HELLO/STATUS even when IPv4 is usable.
  • Publishers whose public X coordinate has leading hexadecimal zeros should regenerate and verify DNS tree URLs with their existing private key, then update affected subscriber treeUrls and cross-tree knownTreeUrls. Upgrading clients or republishing alone does not repair a previously distributed incorrect URL; key rotation is not required.
  • No Protobuf schemas or consensus/state-transition code are modified.

Port tronprotocol/libp2p#171: upgrade snappy-java to 1.1.10.12 and
Bouncy Castle bcprov, bcpkix and bcutil to 1.86. Align the root bcprov
declaration with the vendored P2P dependency and regenerate SHA-256
verification metadata. The new checksums match the upstream import.
Synchronize the in-tree P2P module from libp2p release-v2.3.0 at
5bae7b902f45a9bbd71e492026b4c2c0b6ef0767 through
94dbc75896dc68c72934276c8d3143b4a3540363, following java-tron#7065.
Include libp2p#169, tronprotocol#170 and tronprotocol#172-tronprotocol#180; import tronprotocol#171 separately.

Retain java-tron's blocked-IP policy, logging conventions, existing
payload normalization and handshake deadline coverage. Apply the raw
IPv4/IPv6 bounds and IPv6 validation to application-layer HELLO as well.
Preserve existing tests when upstream introduces a class with the same
name, and use local signed TXT records for the moved DNS sync test.

Record the upstream PR mapping and DNS URL/signing-key migration notes
in p2p/README.md. Leave wire formats and consensus rules unchanged.

Validate on macOS ARM64 / JDK 17 with clean build -x test, the full test
suite (5,639 tests, 16 skipped, zero failures/errors), the CI Checkstyle
gate plus P2P main/test Checkstyle, check_math_usage.sh and diff --check.
Extract raw IPv4/IPv6 address bounds and IPv6 syntax checks into
NetUtil.validAddressFields for P2P HELLO, STATUS and application HELLO.
Validate the raw fields before converting and validating the Node,
preserving the existing endpoint normalization and optional-from rules.
Stop FetchInvData retrieval and final transaction-batch sends after
disconnection, and ignore disconnected peers at application dispatch.
Deduplicate trust entries added after relay HELLO authentication and
reject invalid explicit IPv4 discovery addresses during configuration.

Select manually blocked channels under the admission lock and close
them after releasing it, retaining silent closure and admission checks.
Keep the README focused on module behavior and source provenance;
leave the upstream PR list for the pull request description.

Add regression coverage for the downstream handling and EventLoop
blacklist closure. Validate targeted framework/P2P tests, Checkstyle,
the forbidden-Math gate and a clean build without the full test suite.
@github-actions
github-actions Bot requested a review from xxo1shine November 10, 2026 07:41
317787106 added a commit to 317787106/java-tron that referenced this pull request Nov 10, 2026
Keep the overlapping HELLO address validation and regression coverage in PR tronprotocol#7098, leaving this branch focused on sync request-cache cleanup.
Use messageTypes and declare the channel map so the documented handler compiles. Include required imports and identify the separate Java source files.

Closes JT-909
@lvs0075 lvs0075 added this to the GreatVoyage-v4.8.3 milestone Nov 10, 2026
Keep batch preparation synchronized and perform inventory sends after releasing the service monitor. Cover concurrent peer cleanup with a bounded regression test.
@github-actions
github-actions Bot requested a review from xxo1shine November 10, 2026 10:43
Check the runtime blocked-IP policy before pending admission and before sending a rejection HELLO. Cover blocked sources with temporary bans or saturated quotas and policy changes during admission.
private void disconnect() {
logger.warn("Close peer {}, pending outbound data limit exceeded",
channel.getInetSocketAddress());
channel.close();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Non-blocking Follow-up] The move of sendInv() outside the AdvService monitor breaks the previously reported lock cycles, so I consider the original deadlock concern addressed.

Always queuing physical eviction closure, including when already on the victim's EventLoop, can remain an upstream hardening follow-up to reduce callback reentrancy risks for future callers. This should preserve immediate logical disconnection and correct write-budget accounting.

The additional hardening does not need to block this PR.

@kuny0707
kuny0707 merged commit c3462b2 into tronprotocol:release_v4.8.3 Nov 10, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants