From d6ed7e48812486053c6c7eb194f4fcf800cb8664 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Fri, 11 Oct 2024 12:27:26 +0100 Subject: [PATCH 1/2] fix: enforce strict timeout for builder to provide bid --- packages/beacon-node/src/api/impl/validator/index.ts | 4 ++-- packages/beacon-node/src/execution/builder/http.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/beacon-node/src/api/impl/validator/index.ts b/packages/beacon-node/src/api/impl/validator/index.ts index e1ea415443b9..41a428f1b7c3 100644 --- a/packages/beacon-node/src/api/impl/validator/index.ts +++ b/packages/beacon-node/src/api/impl/validator/index.ts @@ -85,7 +85,7 @@ import {computeSubnetForCommitteesAtSlot, getPubkeysForIndices, selectBlockProdu export const SYNC_TOLERANCE_EPOCHS = 1; /** - * Cutoff time to wait for execution and builder block production apis to resolve + * Cutoff time to wait from start of the slot for execution and builder block production apis to resolve * Post this time, race execution and builder to pick whatever resolves first * * Empirically the builder block resolves in ~1.5+ seconds, and execution should resolve <1 sec. @@ -631,7 +631,7 @@ export function getValidatorApi( : Promise.reject(new Error("Engine disabled")); const [builder, engine] = await resolveOrRacePromises([builderPromise, enginePromise], { - resolveTimeoutMs: BLOCK_PRODUCTION_RACE_CUTOFF_MS, + resolveTimeoutMs: Math.max(0, BLOCK_PRODUCTION_RACE_CUTOFF_MS - chain.clock.secFromSlot(slot) * 1000), raceTimeoutMs: BLOCK_PRODUCTION_RACE_TIMEOUT_MS, signal: controller.signal, }); diff --git a/packages/beacon-node/src/execution/builder/http.ts b/packages/beacon-node/src/execution/builder/http.ts index 934b874f5ae3..7872c5c17410 100644 --- a/packages/beacon-node/src/execution/builder/http.ts +++ b/packages/beacon-node/src/execution/builder/http.ts @@ -37,6 +37,12 @@ export const defaultExecutionBuilderHttpOpts: ExecutionBuilderHttpOpts = { timeout: 12000, }; +/** + * Duration given to the builder to provide a `SignedBuilderBid` before the deadline + * is reached, aborting the external builder flow in favor of the local build process. + */ +const BUILDER_PROPOSAL_DELAY_TOLERANCE = 1000; + export class ExecutionBuilderHttp implements IExecutionBuilder { readonly api: BuilderApi; readonly config: ChainForkConfig; @@ -115,7 +121,9 @@ export class ExecutionBuilderHttp implements IExecutionBuilder { executionPayloadValue: Wei; blobKzgCommitments?: deneb.BlobKzgCommitments; }> { - const signedBuilderBid = (await this.api.getHeader({slot, parentHash, proposerPubkey})).value(); + const signedBuilderBid = ( + await this.api.getHeader({slot, parentHash, proposerPubkey}, {timeoutMs: BUILDER_PROPOSAL_DELAY_TOLERANCE}) + ).value(); if (!signedBuilderBid) { throw Error("No bid received"); From 8bb3298378b24c846420e9b2adaeb10662044eca Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Fri, 11 Oct 2024 17:59:39 +0100 Subject: [PATCH 2/2] Use math.round --- packages/beacon-node/src/api/impl/validator/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/beacon-node/src/api/impl/validator/index.ts b/packages/beacon-node/src/api/impl/validator/index.ts index 41a428f1b7c3..50b00b63a92c 100644 --- a/packages/beacon-node/src/api/impl/validator/index.ts +++ b/packages/beacon-node/src/api/impl/validator/index.ts @@ -631,7 +631,7 @@ export function getValidatorApi( : Promise.reject(new Error("Engine disabled")); const [builder, engine] = await resolveOrRacePromises([builderPromise, enginePromise], { - resolveTimeoutMs: Math.max(0, BLOCK_PRODUCTION_RACE_CUTOFF_MS - chain.clock.secFromSlot(slot) * 1000), + resolveTimeoutMs: Math.max(0, BLOCK_PRODUCTION_RACE_CUTOFF_MS - Math.round(chain.clock.secFromSlot(slot) * 1000)), raceTimeoutMs: BLOCK_PRODUCTION_RACE_TIMEOUT_MS, signal: controller.signal, });