-
Notifications
You must be signed in to change notification settings - Fork 2
/
IIsmpHost.sol
231 lines (198 loc) · 7.49 KB
/
IIsmpHost.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// Copyright (C) Polytope Labs Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pragma solidity ^0.8.17;
import {StateCommitment, StateMachineHeight} from "./IConsensusClient.sol";
import {IDispatcher} from "./IDispatcher.sol";
import {PostRequest, PostResponse, GetResponse, GetRequest} from "./Message.sol";
// Some metadata about the request fee
struct FeeMetadata {
// the relayer fee
uint256 fee;
// user who initiated the request
address sender;
}
struct ResponseReceipt {
// commitment of the response object
bytes32 responseCommitment;
// address of the relayer responsible for this response delivery
address relayer;
}
// Various frozen states of the IIsmpHost
enum FrozenStatus {
// Host is operating normally
None,
// Host is currently disallowing incoming datagrams
Incoming,
// Host is currently disallowing outgoing messages
Outgoing,
// All actions have been frozen
All
}
/**
* @title The Ismp Host Interface
* @author Polytope Labs ([email protected])
*
* @notice The Ismp Host interface sits at the core of the interoperable state machine protocol,
* It which encapsulates the interfaces required for ISMP datagram handlers and modules.
*
* @dev The IsmpHost provides the necessary storage interface for the ISMP handlers to process
* ISMP messages, the IsmpDispatcher provides the interfaces applications use for dispatching requests
* and responses. This host implementation delegates all verification logic to the IHandler contract.
* It is only responsible for dispatching incoming & outgoing messages as well as managing
* the state of the ISMP protocol.
*/
interface IIsmpHost is IDispatcher {
/**
* @return the host admin
*/
function admin() external returns (address);
/**
* @return the state machine identifier for the connected hyperbridge instance
*/
function hyperbridge() external view returns (bytes memory);
/**
* @return the host timestamp
*/
function timestamp() external view returns (uint256);
/**
* @dev Returns the fisherman responsible for vetoing the given state machine height.
* @return the `fisherman` address
*/
function vetoes(uint256 paraId, uint256 height) external view returns (address);
/**
* @return the `frozen` status
*/
function frozen() external view returns (FrozenStatus);
/**
* @dev Returns the fee required for 3rd party applications to access hyperbridge state commitments.
* @return the `stateCommitmentFee`
*/
function stateCommitmentFee() external view returns (uint256);
/**
* @notice Charges the stateCommitmentFee to 3rd party applications.
* If native tokens are provided, will attempt to swap them for the stateCommitmentFee.
* If not enough native tokens are supplied, will revert.
*
* If no native tokens are provided then it will try to collect payment from the calling contract in
* the IIsmpHost.feeToken.
*
* @param height - state machine height
* @return the state commitment at `height`
*/
function stateMachineCommitment(StateMachineHeight memory height) external payable returns (StateCommitment memory);
/**
* @param height - state machine height
* @return the state machine commitment update time at `height`
*/
function stateMachineCommitmentUpdateTime(StateMachineHeight memory height) external returns (uint256);
/**
* @return the consensus client contract
*/
function consensusClient() external view returns (address);
/**
* @return the last updated time of the consensus client
*/
function consensusUpdateTime() external view returns (uint256);
/**
* @return the latest state machine height for the given stateMachineId. If it returns 0, the state machine is unsupported.
*/
function latestStateMachineHeight(uint256 stateMachineId) external view returns (uint256);
/**
* @return the state of the consensus client
*/
function consensusState() external view returns (bytes memory);
/**
* @dev Check the response status for a given request.
* @return `response` status
*/
function responded(bytes32 commitment) external view returns (bool);
/**
* @param commitment - commitment to the request
* @return relayer address
*/
function requestReceipts(bytes32 commitment) external view returns (address);
/**
* @param commitment - commitment to the request of the response
* @return response receipt
*/
function responseReceipts(bytes32 commitment) external view returns (ResponseReceipt memory);
/**
* @param commitment - commitment to the request
* @return existence status of an outgoing request commitment
*/
function requestCommitments(bytes32 commitment) external view returns (FeeMetadata memory);
/**
* @param commitment - commitment to the response
* @return existence status of an outgoing response commitment
*/
function responseCommitments(bytes32 commitment) external view returns (FeeMetadata memory);
/**
* @return the challenge period
*/
function challengePeriod() external view returns (uint256);
/**
* @return the unstaking period
*/
function unStakingPeriod() external view returns (uint256);
/**
* @dev set the new frozen state of the host, only the admin or handler can call this.
* @param newState - the new frozen state
*/
function setFrozenState(FrozenStatus newState) external;
/**
* @dev Store an encoded consensus state
* @param state new consensus state
*/
function storeConsensusState(bytes memory state) external;
/**
* @dev Store the commitment at `state height`
* @param height state machine height
* @param commitment state commitment
*/
function storeStateMachineCommitment(StateMachineHeight memory height, StateCommitment memory commitment) external;
/**
* @dev Delete the state commitment at given state height.
*/
function deleteStateMachineCommitment(StateMachineHeight memory height, address fisherman) external;
/**
* @dev Dispatch an incoming request to destination module
* @param request - post request
*/
function dispatchIncoming(PostRequest memory request, address relayer) external;
/**
* @dev Dispatch an incoming post response to source module
* @param response - post response
*/
function dispatchIncoming(PostResponse memory response, address relayer) external;
/**
* @dev Dispatch an incoming get response to source module
* @param response - get response
*/
function dispatchIncoming(GetResponse memory response, address relayer) external;
/**
* @dev Dispatch an incoming get timeout to source module
* @param timeout - timed-out get request
*/
function dispatchTimeOut(GetRequest memory timeout, FeeMetadata memory meta, bytes32 commitment) external;
/**
* @dev Dispatch an incoming post timeout to source module
* @param timeout - timed-out post request
*/
function dispatchTimeOut(PostRequest memory timeout, FeeMetadata memory meta, bytes32 commitment) external;
/**
* @dev Dispatch an incoming post response timeout to source module
* @param timeout - timed-out post response
*/
function dispatchTimeOut(PostResponse memory timeout, FeeMetadata memory meta, bytes32 commitment) external;
}