Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class JsonRpcHttpClient implements IJsonRpcHttpClient {
return this.fetchJson({jsonrpc: "2.0", id: this.id++, ...payload}, opts);
},
{
retries: opts?.retryAttempts ?? this.opts?.retryAttempts ?? 1,
retries: opts?.retryAttempts ?? this.opts?.retryAttempts ?? 0,
retryDelay: opts?.retryDelay ?? this.opts?.retryDelay ?? 0,
shouldRetry: opts?.shouldRetry,
signal: this.opts?.signal,
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/execution/builder/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class ExecutionBuilderHttp implements IExecutionBuilder {
async submitBlindedBlock(
signedBlindedBlock: allForks.SignedBlindedBeaconBlock
): Promise<allForks.SignedBeaconBlockOrContents> {
const res = await this.api.submitBlindedBlock(signedBlindedBlock, {retryAttempts: 3});
const res = await this.api.submitBlindedBlock(signedBlindedBlock, {retryAttempts: 2});
ApiError.assert(res, "execution.builder.submitBlindedBlock");
const {data} = res.response;

Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/src/execution/engine/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const defaultExecutionEngineHttpOpts: ExecutionEngineHttpOpts = {
* port/url, one can override this and skip providing a jwt secret.
*/
urls: ["http://localhost:8551"],
retryAttempts: 3,
retryAttempts: 2,
retryDelay: 2000,
timeout: 12000,
};
Expand Down Expand Up @@ -305,7 +305,7 @@ export class ExecutionEngineHttp implements IExecutionEngine {
// If we are just fcUing and not asking execution for payload, retry is not required
// and we can move on, as the next fcU will be issued soon on the new slot
const fcUReqOpts =
payloadAttributes !== undefined ? forkchoiceUpdatedV1Opts : {...forkchoiceUpdatedV1Opts, retryAttempts: 1};
payloadAttributes !== undefined ? forkchoiceUpdatedV1Opts : {...forkchoiceUpdatedV1Opts, retryAttempts: 0};

const request = this.rpcFetchQueue.push({
method,
Expand Down
10 changes: 8 additions & 2 deletions packages/utils/src/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,21 @@ export type RetryOptions = {
*/
export async function retry<A>(fn: (attempt: number) => A | Promise<A>, opts?: RetryOptions): Promise<A> {
const maxRetries = opts?.retries ?? 5;
// The maximum number of attempts is the number of retries + the initial attempt
const maxAttempts = maxRetries + 1;
const shouldRetry = opts?.shouldRetry;

let lastError: Error = Error("RetryError");
for (let i = 1; i <= maxRetries; i++) {
for (let i = 1; i <= maxAttempts; i++) {
try {
return await fn(i);
} catch (e) {
lastError = e as Error;
if (shouldRetry && !shouldRetry(lastError)) {

if (i == maxAttempts) {
// If we have reached the maximum number of attempts, there's no need to check if we should retry
break;
} else if (shouldRetry && !shouldRetry(lastError)) {
break;
} else if (opts?.retryDelay !== undefined) {
await sleep(opts?.retryDelay, opts?.signal);
Expand Down