Skip to content

Commit 7739c8f

Browse files
committed
refactor: update runTxIfCompleted method to include transaction ID parameter
1 parent 6620000 commit 7739c8f

File tree

10 files changed

+23
-25
lines changed

10 files changed

+23
-25
lines changed

src/core/Coordinator.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ abstract contract Coordinator is ICoordinator, TxAuthManagerBase, TxManagerBase,
3131

3232
if (!_isCompletedAuth(txIDHash)) revert AuthNotCompleted(txIDHash);
3333

34-
_runTxIfCompleted(msg_);
34+
_runTxIfCompleted(txIDHash, msg_);
3535

3636
emit TxExecuted(abi.encodePacked(txIDHash), msg.sender);
3737
}

src/core/DelegatedLogicHandler.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ abstract contract DelegatedLogicHandler is TxAuthManagerBase, TxManagerBase, Pac
100100
_delegateWithData(TX_MANAGER, abi.encodeWithSelector(ITxManager.createTx.selector, txID, src));
101101
}
102102

103-
function _runTxIfCompleted(MsgInitiateTx.Data calldata msg_) internal virtual override {
104-
_delegateWithData(TX_MANAGER, abi.encodeWithSelector(ITxManager.runTxIfCompleted.selector, msg_));
103+
function _runTxIfCompleted(bytes32 txID, MsgInitiateTx.Data calldata msg_) internal virtual override {
104+
_delegateWithData(TX_MANAGER, abi.encodeWithSelector(ITxManager.runTxIfCompleted.selector, txID, msg_));
105105
}
106106

107107
function _isTxRecorded(bytes32 txID) internal view virtual override returns (bool) {

src/core/ITxManager.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {IIBCHandler} from "@hyperledger-labs/yui-ibc-solidity/contracts/core/25-
1010
interface ITxManager {
1111
function initialize(IIBCHandler handler, IContractModule module) external;
1212
function createTx(bytes32 txID, MsgInitiateTx.Data calldata src) external;
13-
function runTxIfCompleted(MsgInitiateTx.Data calldata msg_) external;
13+
function runTxIfCompleted(bytes32 txID, MsgInitiateTx.Data calldata msg_) external;
1414
function isTxRecorded(bytes32 txID) external view returns (bool);
1515
function getCoordinatorState(bytes32 txID) external view returns (CoordinatorState.Data memory);
1616
function handlePacket(Packet calldata packet) external returns (bytes memory acknowledgement);

src/core/TxManager.sol

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ contract TxManager is
3535
_createTx(txID, src);
3636
}
3737

38-
function runTxIfCompleted(MsgInitiateTx.Data calldata msg_) external override nonReentrant {
39-
_runTxIfCompleted(msg_);
38+
function runTxIfCompleted(bytes32 txID, MsgInitiateTx.Data calldata msg_) external override nonReentrant {
39+
_runTxIfCompleted(txID, msg_);
4040
}
4141

4242
function isTxRecorded(bytes32 txID) external view override returns (bool) {
@@ -72,13 +72,12 @@ contract TxManager is
7272
t.txStatus[txID] = MsgInitiateTxResponse.InitiateTxStatus.INITIATE_TX_STATUS_PENDING;
7373
}
7474

75-
function _runTxIfCompleted(MsgInitiateTx.Data calldata msg_) internal virtual override {
76-
bytes32 txIDHash = sha256(MsgInitiateTx.encode(msg_));
75+
function _runTxIfCompleted(bytes32 txID, MsgInitiateTx.Data calldata msg_) internal virtual override {
7776
CrossStore.TxStorage storage t = _getTxStorage();
78-
if (!_isTxRecorded(txIDHash)) return;
79-
if (t.txStatus[txIDHash] == MsgInitiateTxResponse.InitiateTxStatus.INITIATE_TX_STATUS_VERIFIED) return;
80-
t.txStatus[txIDHash] = MsgInitiateTxResponse.InitiateTxStatus.INITIATE_TX_STATUS_VERIFIED;
81-
_runTx(txIDHash, msg_);
77+
if (!_isTxRecorded(txID)) return;
78+
if (t.txStatus[txID] == MsgInitiateTxResponse.InitiateTxStatus.INITIATE_TX_STATUS_VERIFIED) return;
79+
t.txStatus[txID] = MsgInitiateTxResponse.InitiateTxStatus.INITIATE_TX_STATUS_VERIFIED;
80+
_runTx(txID, msg_);
8281
}
8382

8483
function _isTxRecorded(bytes32 txID) internal view virtual override returns (bool) {

src/core/TxManagerBase.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {CoordinatorState} from "../proto/cross/core/atomic/simple/AtomicSimple.s
66

77
abstract contract TxManagerBase {
88
function _createTx(bytes32 txID, MsgInitiateTx.Data calldata src) internal virtual;
9-
function _runTxIfCompleted(MsgInitiateTx.Data calldata msg_) internal virtual;
9+
function _runTxIfCompleted(bytes32 txID, MsgInitiateTx.Data calldata msg_) internal virtual;
1010
function _isTxRecorded(bytes32 txID) internal view virtual returns (bool);
1111
function _getCoordinatorState(bytes32 txID) internal view virtual returns (CoordinatorState.Data memory);
1212
}

test/Authenticator.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ contract MockTxManager is TxManagerBase {
3838
override
3939
{}
4040

41-
function _runTxIfCompleted(MsgInitiateTx.Data calldata msg_) internal virtual override {}
41+
function _runTxIfCompleted(bytes32, MsgInitiateTx.Data calldata) internal virtual override {}
4242

4343
function _isTxRecorded(
4444
bytes32 /*txID*/

test/Coordinator.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ contract MockTxManager is TxManagerBase, ICrossError {
4242

4343
function _createTx(bytes32, MsgInitiateTx.Data calldata) internal virtual override {}
4444

45-
function _runTxIfCompleted(MsgInitiateTx.Data calldata) internal virtual override {
45+
function _runTxIfCompleted(bytes32, MsgInitiateTx.Data calldata) internal virtual override {
4646
++runCount;
4747
}
4848

test/DelegatedLogicHandler.t.sol

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ contract MockTxManager is ITxManager, MockStore {
9696
txStorage.nonce[txID] = src.nonce;
9797
}
9898

99-
function runTxIfCompleted(MsgInitiateTx.Data calldata msg_) external override {
100-
bytes32 txID = sha256(MsgInitiateTx.encode(msg_));
99+
function runTxIfCompleted(bytes32 txID, MsgInitiateTx.Data calldata msg_) external override {
101100
txStorage.status[txID] = MsgInitiateTxResponse.InitiateTxStatus.INITIATE_TX_STATUS_VERIFIED;
102101
txStorage.nonce[txID] = 1;
103102
}
@@ -184,8 +183,8 @@ contract DelegatedLogicHandlerHarness is DelegatedLogicHandler, MockStore {
184183
_createTx(txID, src);
185184
}
186185

187-
function exposed_runTxIfCompleted(MsgInitiateTx.Data calldata msg_) public {
188-
_runTxIfCompleted(msg_);
186+
function exposed_runTxIfCompleted(bytes32 txID, MsgInitiateTx.Data calldata msg_) public {
187+
_runTxIfCompleted(txID, msg_);
189188
}
190189

191190
function exposed_isTxRecorded(bytes32 txID) public returns (bool) {
@@ -360,7 +359,7 @@ contract DelegatedLogicHandlerTest is Test, ICrossError {
360359
function test_runTxIfCompleted_DelegatesToTxManager() public {
361360
bytes32 expectedTxID = sha256(MsgInitiateTx.encode(txMsg));
362361

363-
harness.exposed_runTxIfCompleted(txMsg);
362+
harness.exposed_runTxIfCompleted(expectedTxID, txMsg);
364363

365364
assertEq(
366365
uint256(harness.readTx_status(expectedTxID)),

test/Initiator.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ contract MockTxManager is TxManagerBase {
3535
++createTxCount;
3636
}
3737

38-
function _runTxIfCompleted(MsgInitiateTx.Data calldata msg_) internal virtual override {}
38+
function _runTxIfCompleted(bytes32 txID, MsgInitiateTx.Data calldata msg_) internal virtual override {}
3939

4040
function _isTxRecorded(bytes32 txID) internal view virtual override returns (bool) {
4141
return txExists[txID];

test/TxManager.t.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ contract TxManagerTest is Test, ICrossError {
271271
uint256(MsgInitiateTxResponse.InitiateTxStatus.INITIATE_TX_STATUS_PENDING),
272272
"Status should be PENDING"
273273
);
274-
harness.runTxIfCompleted(txMsg);
274+
harness.runTxIfCompleted(txID, txMsg);
275275
assertEq(harness.runCount(), 1, "MockTxRunner should be called once");
276276
assertEq(harness.lastRunTxID(), txID, "MockTxRunner should be called with correct txID");
277277
assertEq(
@@ -282,7 +282,7 @@ contract TxManagerTest is Test, ICrossError {
282282
}
283283

284284
function test_runTxIfCompleted_DoesNothingForUnknownTx() public {
285-
harness.runTxIfCompleted(txMsg);
285+
harness.runTxIfCompleted(txID, txMsg);
286286
assertEq(harness.runCount(), 0, "MockTxRunner should not be called");
287287
assertEq(
288288
uint256(harness.getTxStatus(txID)),
@@ -293,14 +293,14 @@ contract TxManagerTest is Test, ICrossError {
293293

294294
function test_runTxIfCompleted_DoesNothingIfAlreadyVerified() public {
295295
harness.createTx(txID, txMsg);
296-
harness.runTxIfCompleted(txMsg); // First run
296+
harness.runTxIfCompleted(txID, txMsg); // First run
297297
assertEq(harness.runCount(), 1, "MockTxRunner should be called once");
298298
assertEq(
299299
uint256(harness.getTxStatus(txID)),
300300
uint256(MsgInitiateTxResponse.InitiateTxStatus.INITIATE_TX_STATUS_VERIFIED),
301301
"Status should be VERIFIED"
302302
);
303-
harness.runTxIfCompleted(txMsg); // Second run
303+
harness.runTxIfCompleted(txID, txMsg); // Second run
304304
assertEq(harness.runCount(), 1, "MockTxRunner should not be called again");
305305
assertEq(
306306
uint256(harness.getTxStatus(txID)),

0 commit comments

Comments
 (0)