Skip to content

Commit 140262a

Browse files
authored
Merge pull request #51 from datachainlab/delete-txMsg
2 parents 06346be + 1333d5b commit 140262a

25 files changed

+834
-217
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"fmt:sol": "forge fmt",
1212
"coverage:sol": "forge coverage --report lcov --ir-minimum",
1313
"snapshot": "forge snapshot",
14-
"snapshot:diff": "forge snapshot --diff --diff-sort absolute-desc"
14+
"snapshot:diff": "forge snapshot --diff"
1515
},
1616
"dependencies": {
1717
"@hyperledger-labs/yui-ibc-solidity": "git+https://github.com/hyperledger-labs/yui-ibc-solidity.git#v0.3.40",

pkg/contract/crosssimplemodule/crosssimplemodule.go

Lines changed: 174 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/contract/txauthmanager/txauthmanager.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/contract/txmanager/txmanager.go

Lines changed: 165 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/Authenticator.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ abstract contract Authenticator is IAuthenticator, TxAuthManagerBase, TxManagerB
3737

3838
bool completed = _sign(txID, accounts);
3939
if (completed) {
40-
_runTxIfCompleted(txID);
40+
emit TxAuthCompleted(txID);
4141
}
4242

4343
emit TxSigned(msg.sender, txID, AuthType.AuthMode.AUTH_MODE_LOCAL);
@@ -52,7 +52,7 @@ abstract contract Authenticator is IAuthenticator, TxAuthManagerBase, TxManagerB
5252

5353
bool completed = _sign(txID, msg_.signers);
5454
if (completed) {
55-
_runTxIfCompleted(txID);
55+
emit TxAuthCompleted(txID);
5656
}
5757

5858
emit TxSigned(msg.sender, txID, AuthType.AuthMode.AUTH_MODE_EXTENSION);

src/core/Coordinator.sol

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,41 @@ pragma solidity ^0.8.20;
33

44
import {ICoordinator} from "./ICoordinator.sol";
55
import {TxManagerBase} from "./TxManagerBase.sol";
6+
import {TxAuthManagerBase} from "./TxAuthManagerBase.sol";
67
import {ICrossError} from "./ICrossError.sol";
8+
import {ICrossEvent} from "./ICrossEvent.sol";
9+
import {TxIDUtils} from "./TxIDUtils.sol";
710

811
import {
912
QueryCoordinatorStateRequest,
1013
QueryCoordinatorStateResponse,
1114
CoordinatorState
1215
} from "../proto/cross/core/atomic/simple/AtomicSimple.sol";
16+
import {MsgInitiateTx} from "../proto/cross/core/initiator/Initiator.sol";
17+
18+
abstract contract Coordinator is ICoordinator, TxAuthManagerBase, TxManagerBase, ICrossError, ICrossEvent {
19+
using TxIDUtils for MsgInitiateTx.Data;
20+
21+
function executeTx(MsgInitiateTx.Data calldata msg_) external override {
22+
uint64 rh = msg_.timeout_height.revision_height;
23+
if (rh != 0 && (block.number + 1 > uint256(rh))) {
24+
revert MessageTimeoutHeight(block.number, rh);
25+
}
26+
// slither-disable-next-line timestamp
27+
if (msg_.timeout_timestamp > 0 && (block.timestamp + 1 > msg_.timeout_timestamp)) {
28+
revert MessageTimeoutTimestamp(block.timestamp, msg_.timeout_timestamp);
29+
}
30+
31+
bytes32 txID = msg_.computeTxId();
32+
33+
if (!_isTxRecorded(txID)) revert TxIDNotFound(txID);
34+
35+
if (!_isCompletedAuth(txID)) revert AuthNotCompleted(txID);
36+
_runTxIfCompleted(txID, msg_);
37+
38+
emit TxExecuted(abi.encodePacked(txID), msg.sender);
39+
}
1340

14-
abstract contract Coordinator is TxManagerBase, ICoordinator, ICrossError {
1541
function coordinatorState(QueryCoordinatorStateRequest.Data calldata req)
1642
external
1743
view

src/core/CrossStore.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity ^0.8.20;
33

44
import {IAuthExtensionVerifier} from "./IAuthExtensionVerifier.sol";
55
import {IContractModule} from "./IContractModule.sol";
6-
import {MsgInitiateTx, MsgInitiateTxResponse} from "../proto/cross/core/initiator/Initiator.sol";
6+
import {MsgInitiateTxResponse} from "../proto/cross/core/initiator/Initiator.sol";
77
import {Account} from "../proto/cross/core/auth/Auth.sol";
88
import {CoordinatorState, ContractTransactionState} from "../proto/cross/core/atomic/simple/AtomicSimple.sol";
99
import {IIBCHandler} from "@hyperledger-labs/yui-ibc-solidity/contracts/core/25-handler/IIBCHandler.sol";
@@ -30,7 +30,7 @@ abstract contract CrossStore {
3030
}
3131

3232
struct TxStorage {
33-
mapping(bytes32 => MsgInitiateTx.Data) txMsg;
33+
mapping(bytes32 => Account.Data[]) txCoordSigners;
3434
mapping(bytes32 => MsgInitiateTxResponse.InitiateTxStatus) txStatus;
3535
mapping(bytes32 => mapping(uint256 => ContractTransactionState.Data)) states;
3636
IContractModule contractModule;

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(bytes32 txID) internal virtual override {
104-
_delegateWithData(TX_MANAGER, abi.encodeWithSelector(ITxManager.runTxIfCompleted.selector, txID));
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/ICoordinator.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import {
55
QueryCoordinatorStateRequest,
66
QueryCoordinatorStateResponse
77
} from "../proto/cross/core/atomic/simple/AtomicSimple.sol";
8+
import {MsgInitiateTx} from "../proto/cross/core/initiator/Initiator.sol";
89

910
interface ICoordinator {
11+
function executeTx(MsgInitiateTx.Data calldata msg_) external;
12+
1013
function coordinatorState(QueryCoordinatorStateRequest.Data calldata req)
1114
external
1215
view

src/core/ICrossError.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ interface ICrossError {
99
error MessageTimeoutHeight(uint256 blockNumber, uint64 timeoutVersionHeight);
1010
error MessageTimeoutTimestamp(uint256 blockTimestamp, uint64 timeoutTimestamp);
1111
error TxIDAlreadyExists(bytes32 txIDHash);
12+
error TxIDNotFound(bytes32 txIDHash);
1213
error AuthStateAlreadyInitialized(bytes32 txID);
1314
error IDNotFound(bytes32 txID);
1415
error InvalidTxIDLength();
1516
error InvalidSignersLength();
1617
error SignerMustEqualSender();
1718
error AuthAlreadyCompleted(bytes32 txID);
19+
error AuthNotCompleted(bytes32 txID);
1820
error TxAlreadyExists(bytes32 txID);
1921
error TxAlreadyVerified(bytes32 txID);
2022
error CoordinatorStateNotFound(bytes32 txID);

0 commit comments

Comments
 (0)