fix(txsubmission): handle client MsgDone in server agent to avoid mempool stall - #164
fix(txsubmission): handle client MsgDone in server agent to avoid mempool stall#164nemo83 wants to merge 3 commits into
Conversation
…pool stall
The N2N TxSubmission server agent never handled a client MsgDone. When a peer
terminated the protocol with MsgDone while the server was blocking-waiting in
TxIdsBlocking, TxSubmissionState.TxIdsBlocking.nextState() returned `this`, so
the agent stayed wedged in TxIdsBlocking forever. Because the client holds
agency in that state, the server could never send another RequestTxIds
("Cannot request tx IDs in state: TxIdsBlocking"), and since the agent never
became Done, MiniProtoServerInboundHandler kept it registered ("No agent found
to handle protocol ..."). Net effect: the node silently stops ingesting mempool
transactions while chain-sync/block-fetch keep working.
Fix: transition to Done on MsgDone from the client-agency states
(TxIdsBlocking per spec; TxIdsNonBlocking/Txs defensively), and handle MsgDone
in TxSubmissionServerAgent.processResponse so it terminates cleanly instead of
logging "Unexpected message type". Once Done, the inbound handler stops routing
to the agent and a fresh agent is created when the peer reconnects.
Adds unit tests for the MsgDone -> Done transition.
Removed comments explaining state transition logic in TxIdsBlocking.
satran004
left a comment
There was a problem hiding this comment.
Looks good. Just a minor comment in State class.
| public State nextState(Message message) { | ||
| if (message instanceof ReplyTxIds) | ||
| return Idle; | ||
| else if (message instanceof MsgDone) // defensive: honour client termination |
There was a problem hiding this comment.
@nemo83 Should we exclude this state transition as it is not part of the spec? So ideally it should never reach to this point.
There was a problem hiding this comment.
Good call — agreed. Removed this transition; MsgDone is only legal in TxIdsBlocking per the spec, so TxIdsNonBlocking now just ignores it and stays put. Pushed in 53eea24.
| public State nextState(Message message) { | ||
| if (message instanceof ReplyTxs) | ||
| return Idle; | ||
| else if (message instanceof MsgDone) // defensive: honour client termination |
There was a problem hiding this comment.
Same here — removed the defensive MsgDone transition from Txs as well.
Review — handle client
|
…Blocking Per review feedback, MsgDone is only legal in TxIdsBlocking under the node-to-node tx-submission spec; the client can never send it in TxIdsNonBlocking or Txs. Remove the two defensive transitions (which also tripped the SonarQube duplication gate) and update the test to assert those states ignore MsgDone. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Updated per @satran004's review (53eea24). Removed the two defensive Updated As a side effect this also removes the duplicated branches that tripped the SonarQube "duplication on new code" gate. |
|



Problem
The N2N TxSubmission server agent never handled a client
MsgDone. When a peerterminates the tx-submission mini-protocol with
MsgDonewhile the server isblocking-waiting in
TxIdsBlocking, the state machine dropped it on the floor:TxSubmissionState.TxIdsBlocking.nextState()only transitioned onReplyTxIds, soMsgDonereturnedthis→ the agent stayed wedged inTxIdsBlockingforever.TxIdsBlockingthe client holds agency, so the server can never send anotherRequestTxIds→ repeatedWARN Cannot request tx IDs in state: TxIdsBlocking.Done,MiniProtoServerInboundHandlerkeeps itregistered and later logs
No agent found to handle protocol ....TxSubmissionServerAgent.processResponse()had noMsgDonebranch, so it also loggedWARN Unexpected message type: MsgDone.Net effect: the node silently stops ingesting mempool transactions while
chain-sync and block-fetch keep working normally. Observed in production: the mempool
feed went dead and never recovered until the process was restarted.
Fix
TxSubmissionState: transition toDoneonMsgDonefrom the client-agency states —TxIdsBlocking(per the node-to-node tx-submission spec), plusTxIdsNonBlockingandTxsdefensively.TxSubmissionServerAgent.processResponse: handleMsgDoneexplicitly (clear in-flightbookkeeping, log at INFO) instead of falling through to
Unexpected message type.Once the agent reaches
Done, the inbound handler stops routing to it and a fresh agentis created when the peer reconnects — restoring mempool ingestion automatically.
Tests
Adds unit tests to
TxSubmissionServerAgentTest:testMsgDoneFromTxIdsBlockingTransitionsToDone— drives the agent intoTxIdsBlocking,sends
MsgDone, asserts it reachesDone/isDone().testMsgDoneStateTransitionsForAllClientAgencyStates— asserts theMsgDone → Donetransition for
TxIdsBlocking,TxIdsNonBlocking, andTxs.Full suite for the class passes (15 tests, 0 failures).
Scope / risk
Low and localized (2 main-source files). It only adds handling for a legal protocol
message that was previously dropped; the happy path is unchanged.