Skip to content

Make destination plug execution failure non-blocking or terminal - #441

Open
XirGabby wants to merge 1 commit into
SocketDotTech:masterfrom
XirGabby:fix/destination-execution-failure
Open

XirGabby wants to merge 1 commit into
SocketDotTech:masterfrom
XirGabby:fix/destination-execution-failure

Conversation

@XirGabby

Copy link
Copy Markdown

Problem

SocketDst.execute() marks a message executed and then calls the destination plug's inbound() directly. If the plug reverts, the whole transaction reverts, so messageExecuted[msgId] = true, fee accounting, and ExecutionSuccess are all rolled back. The message is left retryable forever with no terminal state, and one bad message can revert an entire SocketBatcher.executeBatch(), rolling back earlier successful executions in the same batch.

This contradicts the comment on _execute() itself, which says message execution failure is not blocking the system.

Fixes #437.

Fix

  • contracts/socket/SocketDst.sol: wrap the plug call in _execute() in try/catch. On success the behavior is unchanged (fees updated, ExecutionSuccess emitted). On failure the message stays consumed (messageExecuted was set before verification) and the failure is recorded: ExecutionFailed for revert strings, ExecutionFailedBytes for custom errors / raw revert data.
  • contracts/interfaces/ISocket.sol: declare ExecutionFailed(bytes32 msgId, string result) and ExecutionFailedBytes(bytes32 msgId, bytes result) next to ExecutionSuccess, so the failed terminal state is protocol-level instead of only existing as local declarations in tests.
  • No change to SocketBatcher: once execute() no longer reverts on plug failure, the batch loop continues past the failed message on its own. Reverts for other reasons (e.g. MessageAlreadyExecuted, verification failures) still abort the batch, as before.

Tests

Both failure modes were reproduced before the fix (the plug revert bubbled up through Socket.execute() and reverted the whole call) and pass after it:

  • test/socket/SocketDst.t.sol — testExecuteMessageWithFailingPlug: Counter.remoteSubOperation with an amount above the destination counter. Asserts execute() does not revert, ExecutionFailedBytes is emitted with the InvalidAmount() selector, messageExecuted stays true, the destination counter is untouched, and a retry reverts with MessageAlreadyExecuted.
  • test/socket/SocketBatcher.t.sol — testExecuteBatchContinuesAfterFailingPlug: a good add (100) followed by a failing sub (150, counter is 100 after the add) in one executeBatch. Asserts the batch completes, the good message executes (counter = 100), the failing one emits ExecutionFailedBytes, both messages are consumed, and retrying the failed one reverts with MessageAlreadyExecuted.

Full suite: 140 passed, 6 failed — the 6 failures are pre-existing on master (verified by running the suite on the pristine tree): 2 testFail* tests removed in newer forge, and 4 fork tests that need RPC env vars (MAINNET_RPC, SEPOLIA_RPC, OPTIMISM_SEPOLIA_RPC).

Open question for maintainers

The exact fee policy on failed destination execution is a protocol decision. This PR follows the shape suggested in the issue: execution fees are credited only on success, so an executor that spends gas on a failed plug call gets no fee credit for it. Happy to change that if the intended policy is different.

Notes

  • The repo's fx-portal/contracts submodule URL is dead (repo moved to 0xPolygon/fx-portal, 404 at the old path). I populated lib/contracts locally from 0xPolygon/fx-portal at the pinned commit to build/test; no submodule config is changed in this PR.

SocketDst.execute() called the destination plug's inbound() directly, so
a plug revert rolled back the whole transaction: the replay guard, fee
accounting and ExecutionSuccess were all undone, leaving the message
retryable forever with no terminal state. One bad message could also
revert a whole SocketBatcher.executeBatch().

Wrap the plug call in try/catch in _execute(): success still updates
execution fees and emits ExecutionSuccess; failure emits ExecutionFailed
(for revert strings) or ExecutionFailedBytes (for custom errors / raw
revert data) and the message stays consumed via messageExecuted. The
new events are declared on ISocket next to ExecutionSuccess. No change
to SocketBatcher is needed: once execute() no longer reverts on plug
failure, the batch loop continues past the failed message.

Fixes SocketDotTech#437
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.

Make destination plug execution failure non-blocking or terminal

1 participant