@@ -25,8 +25,15 @@ import {
25
25
} from "./interface.js" ;
26
26
import { PayloadIdCache } from "./payloadIdCache.js" ;
27
27
28
+ export type ExecutionEngineModules = {
29
+ signal : AbortSignal ;
30
+ metrics ?: IMetrics | null ;
31
+ } ;
32
+
28
33
export type ExecutionEngineHttpOpts = {
29
34
urls : string [ ] ;
35
+ retryAttempts : number ;
36
+ retryDelay : number ;
30
37
timeout ?: number ;
31
38
/**
32
39
* 256 bit jwt secret in hex format without the leading 0x. If provided, the execution engine
@@ -44,6 +51,8 @@ export const defaultExecutionEngineHttpOpts: ExecutionEngineHttpOpts = {
44
51
* port/url, one can override this and skip providing a jwt secret.
45
52
*/
46
53
urls : [ "http://localhost:8551" ] ,
54
+ retryAttempts : 3 ,
55
+ retryDelay : 2000 ,
47
56
timeout : 12000 ,
48
57
} ;
49
58
@@ -65,12 +74,12 @@ export class ExecutionEngineHttp implements IExecutionEngine {
65
74
readonly payloadIdCache = new PayloadIdCache ( ) ;
66
75
private readonly rpc : IJsonRpcHttpClient ;
67
76
68
- constructor ( opts : ExecutionEngineHttpOpts , signal : AbortSignal , metrics ?: IMetrics | null ) {
77
+ constructor ( opts : ExecutionEngineHttpOpts , { metrics , signal } : ExecutionEngineModules ) {
69
78
this . rpc = new JsonRpcHttpClient ( opts . urls , {
79
+ ...opts ,
70
80
signal,
71
- timeout : opts . timeout ,
72
- jwtSecret : opts . jwtSecretHex ? fromHex ( opts . jwtSecretHex ) : undefined ,
73
81
metrics : metrics ?. executionEnginerHttpClient ,
82
+ jwtSecret : opts . jwtSecretHex ? fromHex ( opts . jwtSecretHex ) : undefined ,
74
83
} ) ;
75
84
}
76
85
@@ -103,12 +112,15 @@ export class ExecutionEngineHttp implements IExecutionEngine {
103
112
const method = "engine_newPayloadV1" ;
104
113
const serializedExecutionPayload = serializeExecutionPayload ( executionPayload ) ;
105
114
const { status, latestValidHash, validationError} = await this . rpc
106
- . fetch < EngineApiRpcReturnTypes [ typeof method ] , EngineApiRpcParamTypes [ typeof method ] > (
107
- { method, params : [ serializedExecutionPayload ] } ,
115
+ . fetchWithRetries < EngineApiRpcReturnTypes [ typeof method ] , EngineApiRpcParamTypes [ typeof method ] > (
116
+ {
117
+ method,
118
+ params : [ serializedExecutionPayload ] ,
119
+ } ,
108
120
notifyNewPayloadOpts
109
121
)
110
122
// If there are errors by EL like connection refused, internal error, they need to be
111
- // treated seperate from being INVALID. For now, just pass the error upstream.
123
+ // treated separate from being INVALID. For now, just pass the error upstream.
112
124
. catch ( ( e : Error ) : EngineApiRpcReturnTypes [ typeof method ] => {
113
125
if ( e instanceof HttpRpcError || e instanceof ErrorJsonRpcResponse ) {
114
126
return { status : ExecutePayloadStatus . ELERROR , latestValidHash : null , validationError : e . message } ;
@@ -201,14 +213,19 @@ export class ExecutionEngineHttp implements IExecutionEngine {
201
213
}
202
214
: undefined ;
203
215
204
- // TODO: propogate latestValidHash to the forkchoice, for now ignore it as we
205
- // currently do not propogate the validation status up the forkchoice
216
+ // If we are just fcUing and not asking execution for payload, retry is not required
217
+ // and we can move on, as the next fcU will be issued soon on the new slot
218
+ const fcUReqOpts =
219
+ payloadAttributes !== undefined ? forkchoiceUpdatedV1Opts : { ...forkchoiceUpdatedV1Opts , retryAttempts : 1 } ;
206
220
const {
207
221
payloadStatus : { status, latestValidHash : _latestValidHash , validationError} ,
208
222
payloadId,
209
- } = await this . rpc . fetch < EngineApiRpcReturnTypes [ typeof method ] , EngineApiRpcParamTypes [ typeof method ] > (
210
- { method, params : [ { headBlockHash, safeBlockHash, finalizedBlockHash} , apiPayloadAttributes ] } ,
211
- forkchoiceUpdatedV1Opts
223
+ } = await this . rpc . fetchWithRetries < EngineApiRpcReturnTypes [ typeof method ] , EngineApiRpcParamTypes [ typeof method ] > (
224
+ {
225
+ method,
226
+ params : [ { headBlockHash, safeBlockHash, finalizedBlockHash} , apiPayloadAttributes ] ,
227
+ } ,
228
+ fcUReqOpts
212
229
) ;
213
230
214
231
switch ( status ) {
@@ -253,11 +270,16 @@ export class ExecutionEngineHttp implements IExecutionEngine {
253
270
*/
254
271
async getPayload ( payloadId : PayloadId ) : Promise < bellatrix . ExecutionPayload > {
255
272
const method = "engine_getPayloadV1" ;
256
- const executionPayloadRpc = await this . rpc . fetch <
273
+ const executionPayloadRpc = await this . rpc . fetchWithRetries <
257
274
EngineApiRpcReturnTypes [ typeof method ] ,
258
275
EngineApiRpcParamTypes [ typeof method ]
259
- > ( { method, params : [ payloadId ] } , getPayloadOpts ) ;
260
-
276
+ > (
277
+ {
278
+ method,
279
+ params : [ payloadId ] ,
280
+ } ,
281
+ getPayloadOpts
282
+ ) ;
261
283
return parseExecutionPayload ( executionPayloadRpc ) ;
262
284
}
263
285
0 commit comments