Skip to content

fix(net): stop invalid INV activity updates and fix block fetch retries - #91

Open
317787106 wants to merge 2 commits into
release_v4.8.3from
fix/invalid_inv
Open

317787106 wants to merge 2 commits into
release_v4.8.3from
fix/invalid_inv

Conversation

@317787106

@317787106 317787106 commented Sep 14, 2026

Copy link
Copy Markdown
Owner

What does this PR do?

Fix block validation, fetch retries, and peer contribution timestamps. A peer can currently refresh activity by announcing an unverified block, and an invalid block response can complete a fetch before validation. A short fetch timeout can also discard retry state, leaving later announcements suppressed by the INV cache.

  • Stop updating lastInteractiveTime from BLOCK INV announcements or unconditional BLOCK dispatch. Update block interaction timestamps in the validated processing paths.
  • Check the raw parent hash and parent/child height relationship. Complete an advertised block fetch and remove the responding provider's request only after preliminary validation succeeds, including Merkle root and signature checks. Invalid data retains its request responsibility for disconnect handling and retry.
  • Preserve broadcast-before-execution behavior once validation and parent/height checks pass. Update blockRcvTime only for the actual provider of a useful block that is successfully processed, or a validated useful block with a missing parent that triggers synchronization. Announcers, old/known blocks, inactive-witness blocks, execution failures, and shutdown early returns receive no contribution credit.
  • Add isBlockIdle() and share provider selection between initial and backup fetches. In-flight transaction requests no longer prevent block fetching; block and sync work still exclude a provider. Select eligible providers using the existing fetch-latency metric without excluding the only available source solely because it exceeds the short timeout.
  • Retain retry state across short timeouts and backup requests, so later advertisers can be discovered despite global INV deduplication. Keep each provider's original request timestamp and timeout responsibility. Final timeout enforcement remains in PeerStatusCheck using ADV_TIME_OUT.
  • Register fetch state before sending requests, synchronize state transitions, and reject stale worker snapshots. On disconnect, reuse pending requests or requeue available sources; clear the INV cache when no alternative exists. Cancel obsolete retry tracking when the local head advances without removing outstanding request responsibility.
  • Update sync-block timestamps after successful validation and processing. Use SYNC_FAIL for state-dependent sync execution failures while retaining provider-specific bad-data handling for deterministic signature/Merkle failures.

Why are these changes required?

Peer activity should reflect validated interaction, and contribution should reflect useful block delivery. Fetch completion, retries, and timeout attribution must agree on whether a provider has fulfilled its request. These changes prevent invalid announcements from refreshing activity, bad responses from prematurely ending a fetch, and short timeouts or concurrent callbacks from losing retry state.

This PR has been tested by:

  • Local ARM64 / JDK 17 run: 74 tests passed across 11 related test classes, including 40 new tests; zero failures, errors, or skipped tests.
  • New coverage includes real signature/Merkle validation, validation/fetch/broadcast/execution ordering, provider-only contribution, sync failure attribution, late same-hash announcements after short timeouts, transaction-busy backup providers, disconnect recovery, final timeout responsibility, stale workers, immediate responses, and head advancement.
  • Existing regressions: BlockMsgHandlerTest, InventoryMsgHandlerTest, AdvServiceTest, SyncServiceTest, TronNetDelegateTest, PeerConnectionTest, and P2pEventHandlerImplTest.
  • ./gradlew checkstyleMain checkstyleTest: passed.
  • Semgrep (p/java, p/security-audit, p/owasp-top-ten): seven changed production files scanned, zero findings or parsing errors.
  • Full-repository tests and manual network testing have not been run. Retry scenarios are deterministic local tests, not production-log replay.

Follow up

Integration assumes the separate libp2p fixes from its v2.3.0 branch and the MessageCount concurrency fix from another developer's PR are available. This PR does not update dependency versions. Normal sync-completion semantics and chain-summary request timeouts remain a separate change.

Extra details

Targets release_v4.8.3. Existing public method signatures, wire formats, database formats, and user configuration remain unchanged; new APIs are Java 8 compatible. The implementation covers block-fetch correctness and contribution semantics without introducing peer scoring or connection-rotation policies.

@317787106 317787106 changed the title fix(net): fix the bug of update lastactivetime with invalid inv fix(net): stop invalid INV activity updates and fix block fetch retries Sep 17, 2026
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