Skip to content

fix(core/txpool): stop delivering special tx events under the pool lock - #2519

Open
gzliudan wants to merge 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:fix-special-tx-feed-under-lock
Open

fix(core/txpool): stop delivering special tx events under the pool lock#2519
gzliudan wants to merge 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:fix-special-tx-feed-under-lock

Conversation

@gzliudan

Copy link
Copy Markdown
Collaborator

Proposed changes

Problem

A mainnet node froze for ~2h40m while RPC stayed responsive: no new blocks were imported. debug.stacks() showed the full failure chain:

  1. A peer lost its transaction broadcaster (broadcastTransactions exited while the peer stayed alive).
  2. eth/peer.go AsyncSendTransactions blocked forever on p.txBroadcast, which no longer had a reader.
  3. txBroadcastLoop stopped draining pm.txsCh and became a stalled txFeed subscriber.
  4. LegacyPool.promoteSpecialTx called pool.txFeed.Send while holding pool.mu, so Feed.Send pinned the pool write lock for hours.

Result: 131 goroutines piled up in LegacyPool.Add, 20 in Pending, runReorg never ran, and the node stopped importing blocks.

Fix

Route the special tx event through queueTxEvent, the same path every other transaction in add() uses. The event is delivered by runReorg after pool.mu is released, so a stalled subscriber can no longer pin the pool lock. This also aligns the XDPoS-specific path with the upstream geth design.

Behavior change

Remote adds (sync=false) now deliver the NewTxsEvent for special txs after the next reorg run instead of synchronously inside Add — identical to normal transactions. Local adds (sync=true) still deliver before Add returns. No consensus, RPC, or API surface changes.

Scope / follow-up

This fixes the pool-side amplifier only. The peer-side defect that starts the chain (eth/peer.go: broadcastTransactions can exit while the peer stays alive, leaving AsyncSendTransactions blocked forever) is tracked separately and needs its own fix. Until then, a stalled subscriber plus a full pm.txsCh can block the reorg goroutine, but no longer Add/Pending.

Types of changes

What types of changes does your code introduce to XDC network?
Put an in the boxes that apply

  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Changes that don't change source code or tests
  • docs: Documentation only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that neither fixes a bug nor adds a feature
  • revert: Revert something
  • style: Changes that do not affect the meaning of the code
  • test: Adding missing tests or correcting existing tests

Impacted Components

Which parts of the codebase does this PR touch?
Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Tested on a private network from the genesis block and monitored the chain operating correctly for multiple epochs.
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 67cae42b-e486-4009-8986-bef598bc545b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gzliudan
gzliudan force-pushed the fix-special-tx-feed-under-lock branch 3 times, most recently from 2e75b6c to 41160b4 Compare August 16, 2026 14:06
promoteSpecialTx called txFeed.Send while holding pool.mu, so a subscriber that
stopped draining froze the whole pool. On mainnet a peer lost its transaction
broadcaster, AsyncSendTransactions blocked, txBroadcastLoop stopped draining
pm.txsCh, and the resulting Feed.Send pinned pool.mu for hours: 131 goroutines
piled up in Add, 20 in Pending, runReorg never ran and the node stopped
importing blocks while RPC stayed responsive.

Route the event through queueTxEvent like every other path in add(), so
runReorg delivers it after releasing the lock.

Add TestSpecialTxPromotionDoesNotBlockOnTxFeed. It subscribes twice, with a
channel that is never read and one that is, so it pins down both invariants:
adding a special tx must not block behind a stalled subscriber, and the event
must still reach the subscribers that are keeping up.

This fixes the pool-side amplifier only. The peer-side defect that starts the
failure chain (eth/peer.go: broadcastTransactions can exit while the peer stays
alive, so AsyncSendTransactions blocks forever) is tracked separately. With a
stalled subscriber, a full pm.txsCh can now block only the reorg goroutine
instead of every Add.

Delivery timing changes slightly: for remote adds the special tx event is now
sent after the next reorg run instead of synchronously inside Add, matching all
other transactions. Local adds still deliver before Add returns.
@gzliudan
gzliudan force-pushed the fix-special-tx-feed-under-lock branch from 41160b4 to d7614e7 Compare August 16, 2026 14:43
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.

2 participants