@@ -5,164 +5,21 @@ import "./DeliveryUtils.sol";
5
5
6
6
/// @notice Abstract contract for managing asynchronous payloads
7
7
abstract contract RequestQueue is DeliveryUtils {
8
- // slots [207-257] reserved for gap
9
- uint256 [50 ] _gap_queue_async;
10
-
11
-
12
- /// @notice Initiates a batch of payloads
13
- /// @param maxFees_ The fees data
14
- /// @param auctionManager_ The auction manager address
15
- /// @return requestCount The ID of the batch
16
- function batch (
17
- uint256 maxFees_ ,
18
- address auctionManager_ ,
19
- address consumeFrom_ ,
20
- bytes memory onCompleteData_
21
- ) external returns (uint40 requestCount ) {
22
- address appGateway = _getCoreAppGateway (msg .sender );
23
- return _batch (appGateway, auctionManager_, consumeFrom_, maxFees_, onCompleteData_);
24
- }
25
-
26
- /// @notice Initiates a batch of payloads
27
- /// @dev it checks fees, payload limits and creates the payload submit params array after assigning proper levels
28
- /// @dev It also modifies the deploy payloads as needed by contract factory plug
29
- /// @dev Stores request metadata and submits the request to watcher precompile
30
- function _batch (
31
- address appGateway_ ,
32
- address auctionManager_ ,
33
- address consumeFrom_ ,
34
- uint256 maxFees_ ,
35
- bytes memory onCompleteData_
36
- ) internal returns (uint40 requestCount ) {
37
- if (queuePayloadParams.length == 0 ) return 0 ;
38
-
39
- BatchParams memory params = BatchParams ({
40
- appGateway: appGateway_,
41
- auctionManager: _getAuctionManager (auctionManager_),
42
- maxFees: maxFees_,
43
- onCompleteData: onCompleteData_,
44
- onlyReadRequests: false ,
45
- queryCount: 0 ,
46
- finalizeCount: 0
47
- });
48
-
49
- // Split the function into smaller parts
50
- (
51
- PayloadSubmitParams[] memory payloadSubmitParamsArray ,
52
- bool onlyReadRequests ,
53
- uint256 queryCount ,
54
- uint256 finalizeCount
55
- ) = _createPayloadSubmitParamsArray ();
56
-
57
- params.onlyReadRequests = onlyReadRequests;
58
- params.queryCount = queryCount;
59
- params.finalizeCount = finalizeCount;
60
-
61
- _checkBatch (consumeFrom_, params.appGateway, params.maxFees);
62
- return _submitBatchRequest (payloadSubmitParamsArray, consumeFrom_, params);
63
- }
64
-
65
8
function _submitBatchRequest (
66
9
PayloadSubmitParams[] memory payloadSubmitParamsArray ,
67
10
address consumeFrom_ ,
68
11
BatchParams memory params
69
12
) internal returns (uint40 requestCount ) {
70
- RequestMetadata memory requestMetadata = RequestMetadata ({
71
- appGateway: params.appGateway,
72
- auctionManager: params.auctionManager,
73
- maxFees: params.maxFees,
74
- winningBid: Bid ({fee: 0 , transmitter: address (0 ), extraData: new bytes (0 )}),
75
- onCompleteData: params.onCompleteData,
76
- onlyReadRequests: params.onlyReadRequests,
77
- consumeFrom: consumeFrom_,
78
- queryCount: params.queryCount,
79
- finalizeCount: params.finalizeCount
80
- });
81
-
82
- requestCount = watcherPrecompile__ ().submitRequest (payloadSubmitParamsArray);
83
- requests[requestCount] = requestMetadata;
84
-
85
- if (params.onlyReadRequests) {
86
- watcherPrecompile__ ().startProcessingRequest (requestCount, address (0 ));
87
- }
88
-
89
- uint256 watcherFees = watcherPrecompileLimits ().getTotalFeesRequired (
90
- params.queryCount,
91
- params.finalizeCount,
92
- 0 ,
93
- 0
94
- );
95
- if (watcherFees > params.maxFees) revert InsufficientFees ();
96
- uint256 maxTransmitterFees = params.maxFees - watcherFees;
97
-
98
13
emit PayloadSubmitted (
99
14
requestCount,
100
15
params.appGateway,
101
16
payloadSubmitParamsArray,
102
- maxTransmitterFees ,
17
+ params.maxFees - watcherFees ,
103
18
params.auctionManager,
104
19
params.onlyReadRequests
105
20
);
106
21
}
107
22
108
- function _getAuctionManager (address auctionManager_ ) internal view returns (address ) {
109
- return
110
- auctionManager_ == address (0 )
111
- ? IAddressResolver (addressResolver__).defaultAuctionManager ()
112
- : auctionManager_;
113
- }
114
-
115
- function _checkBatch (
116
- address consumeFrom_ ,
117
- address appGateway_ ,
118
- uint256 maxFees_
119
- ) internal view {
120
- if (queuePayloadParams.length > REQUEST_PAYLOAD_COUNT_LIMIT)
121
- revert RequestPayloadCountLimitExceeded ();
122
-
123
- if (
124
- ! IFeesManager (addressResolver__.feesManager ()).isUserCreditsEnough (
125
- consumeFrom_,
126
- appGateway_,
127
- maxFees_
128
- )
129
- ) revert InsufficientFees ();
130
- }
131
-
132
- /// @notice Creates an array of payload details
133
- /// @return payloadDetailsArray An array of payload details
134
- function _createPayloadSubmitParamsArray ()
135
- internal
136
- returns (
137
- PayloadSubmitParams[] memory payloadDetailsArray ,
138
- bool onlyReadRequests ,
139
- uint256 queryCount ,
140
- uint256 finalizeCount
141
- )
142
- {
143
- payloadDetailsArray = new PayloadSubmitParams [](queuePayloadParams.length );
144
- onlyReadRequests = queuePayloadParams[0 ].callType == CallType.READ;
145
-
146
- uint256 currentLevel = 0 ;
147
- for (uint256 i = 0 ; i < queuePayloadParams.length ; i++ ) {
148
- if (queuePayloadParams[i].callType == CallType.READ) {
149
- queryCount++ ;
150
- } else {
151
- onlyReadRequests = false ;
152
- finalizeCount++ ;
153
- }
154
-
155
- // Update level for calls
156
- if (i > 0 && queuePayloadParams[i].isParallel != Parallel.ON) {
157
- currentLevel = currentLevel + 1 ;
158
- }
159
-
160
- payloadDetailsArray[i] = _createPayloadDetails (currentLevel, queuePayloadParams[i]);
161
- }
162
-
163
- clearQueue ();
164
- }
165
-
166
23
function _createDeployPayloadDetails (
167
24
QueuePayloadParams memory queuePayloadParams_
168
25
) internal returns (bytes memory payload , address target ) {
@@ -184,40 +41,4 @@ abstract contract RequestQueue is DeliveryUtils {
184
41
// getting app gateway for deployer as the plug is connected to the app gateway
185
42
target = getDeliveryHelperPlugAddress (queuePayloadParams_.chainSlug);
186
43
}
187
-
188
- /// @notice Creates the payload details for a given call parameters
189
- /// @param queuePayloadParams_ The call parameters
190
- /// @return payloadDetails The payload details
191
- function _createPayloadDetails (
192
- uint256 level_ ,
193
- QueuePayloadParams memory queuePayloadParams_
194
- ) internal returns (PayloadSubmitParams memory ) {
195
- bytes memory payload = queuePayloadParams_.payload;
196
- address target = queuePayloadParams_.target;
197
- if (queuePayloadParams_.callType == CallType.DEPLOY) {
198
- (payload, target) = _createDeployPayloadDetails (queuePayloadParams_);
199
- }
200
-
201
- if (queuePayloadParams_.value > chainMaxMsgValueLimit[queuePayloadParams_.chainSlug])
202
- revert MaxMsgValueLimitExceeded ();
203
-
204
- return
205
- PayloadSubmitParams ({
206
- levelNumber: level_,
207
- chainSlug: queuePayloadParams_.chainSlug,
208
- callType: queuePayloadParams_.callType,
209
- isParallel: queuePayloadParams_.isParallel,
210
- writeFinality: queuePayloadParams_.writeFinality,
211
- asyncPromise: queuePayloadParams_.asyncPromise,
212
- switchboard: queuePayloadParams_.switchboard,
213
- target: target,
214
- appGateway: queuePayloadParams_.appGateway,
215
- gasLimit: queuePayloadParams_.gasLimit == 0
216
- ? 10_000_000
217
- : queuePayloadParams_.gasLimit,
218
- value: queuePayloadParams_.value,
219
- readAt: queuePayloadParams_.readAt,
220
- payload: payload
221
- });
222
- }
223
44
}
0 commit comments