Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,25 @@ public void processResponse(Message message) {
handleReplyTxIds((ReplyTxIds) message);
} else if (message instanceof ReplyTxs) {
handleReplyTxs((ReplyTxs) message);
} else if (message instanceof MsgDone) {
handleDone();
} else {
log.warn("Unexpected message type: {}", message.getClass().getSimpleName());
}
}

/**
* The client terminated the tx-submission protocol with MsgDone. The state machine has already
* advanced to {@link TxSubmissionState#Done} (see {@link TxSubmissionState}), so the inbound
* handler stops routing to this agent and the session can be torn down; a fresh agent is created
* when the peer reconnects. Drop any in-flight bookkeeping so nothing leaks.
*/
private void handleDone() {
log.info("Received MsgDone from client - tx-submission protocol terminated, agent is Done");
outstandingTxIds.clear();
pendingRequest = null;
}

private void handleInit() {
log.info("Received Init message from client - transitioning to Idle state");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.bloxbean.cardano.yaci.core.protocol.Message;
import com.bloxbean.cardano.yaci.core.protocol.State;
import com.bloxbean.cardano.yaci.core.protocol.txsubmission.messges.MsgDone;
import com.bloxbean.cardano.yaci.core.protocol.txsubmission.messges.ReplyTxIds;
import com.bloxbean.cardano.yaci.core.protocol.txsubmission.messges.ReplyTxs;
import com.bloxbean.cardano.yaci.core.protocol.txsubmission.messges.RequestTxIds;
Expand Down Expand Up @@ -44,6 +45,8 @@ public boolean hasAgency(boolean isClient) {
public State nextState(Message message) {
if (message instanceof ReplyTxIds)
return Idle;
else if (message instanceof MsgDone)
return Done;
else
return this;
}
Expand All @@ -58,6 +61,8 @@ public boolean hasAgency(boolean isClient) {
public State nextState(Message message) {
if (message instanceof ReplyTxIds)
return Idle;
else if (message instanceof MsgDone) // defensive: honour client termination

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@nemo83 Should we exclude this state transition as it is not part of the spec? So ideally it should never reach to this point.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

return Done;
else
return this;
}
Expand All @@ -72,6 +77,8 @@ public boolean hasAgency(boolean isClient) {
public State nextState(Message message) {
if (message instanceof ReplyTxs)
return Idle;
else if (message instanceof MsgDone) // defensive: honour client termination

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as before.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same here — removed the defensive MsgDone transition from Txs as well.

return Done;
else
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,33 @@ void testEmptyReplyTxIds() {
assertEquals(0, requestTxIds.getAckTxIds()); // No transactions to acknowledge
}

@Test
void testMsgDoneFromTxIdsBlockingTransitionsToDone() {
// Move to Idle, then have the server send a blocking RequestTxIds so we land in TxIdsBlocking
agent.receiveResponse(new Init());
assertEquals(TxSubmissionState.Idle, agent.getCurrentState());

agent.sendRequest(new RequestTxIds(true, (short) 0, (short) 10));
assertEquals(TxSubmissionState.TxIdsBlocking, agent.getCurrentState());
assertFalse(agent.isDone());

// Client terminates the protocol with MsgDone while we are blocking-waiting.
// Before the fix the agent stayed wedged in TxIdsBlocking forever; now it must reach Done.
agent.receiveResponse(new MsgDone());

assertEquals(TxSubmissionState.Done, agent.getCurrentState());
assertTrue(agent.isDone());
assertEquals(0, agent.getOutstandingTxCount());
}

@Test
void testMsgDoneStateTransitionsForAllClientAgencyStates() {
// The terminal MsgDone transition must hold for every state where the client has agency.
assertEquals(TxSubmissionState.Done, TxSubmissionState.TxIdsBlocking.nextState(new MsgDone()));
assertEquals(TxSubmissionState.Done, TxSubmissionState.TxIdsNonBlocking.nextState(new MsgDone()));
assertEquals(TxSubmissionState.Done, TxSubmissionState.Txs.nextState(new MsgDone()));
}

@Test
void testConfigurationValidation() {
// Valid config should not log warnings
Expand Down
Loading