Skip to content

Commit

Permalink
Fix POST to eth/v1/builder/blinded_blocks missing header Eth-Consensu…
Browse files Browse the repository at this point in the history
…s-Version. (#6256)

* Fix submitBlindededBlock() do not send consensus-version HTTP header.

* Address review comments.
  • Loading branch information
cheatfate authored May 3, 2024
1 parent 7bef68c commit 484f489
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 17 deletions.
21 changes: 17 additions & 4 deletions beacon_chain/spec/mev/rest_deneb_mev_calls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,21 @@ proc getHeaderDeneb*(slot: Slot,
meth: MethodGet, connection: {Dedicated, Close}.}
## https://github.com/ethereum/builder-specs/blob/v0.4.0/apis/builder/header.yaml

proc submitBlindedBlock*(body: deneb_mev.SignedBlindedBeaconBlock
): RestPlainResponse {.
rest, endpoint: "/eth/v1/builder/blinded_blocks",
meth: MethodPost, connection: {Dedicated, Close}.}
proc submitBlindedBlockPlain*(
body: deneb_mev.SignedBlindedBeaconBlock
): RestPlainResponse {.
rest, endpoint: "/eth/v1/builder/blinded_blocks",
meth: MethodPost, connection: {Dedicated, Close}.}
## https://github.com/ethereum/builder-specs/blob/v0.4.0/apis/builder/blinded_blocks.yaml

proc submitBlindedBlock*(
client: RestClientRef,
body: deneb_mev.SignedBlindedBeaconBlock
): Future[RestPlainResponse] {.
async: (raises: [CancelledError, RestEncodingError, RestDnsResolveError,
RestCommunicationError]).} =
## https://github.com/ethereum/builder-specs/blob/v0.4.0/apis/builder/blinded_blocks.yaml
await client.submitBlindedBlockPlain(
body,
extraHeaders = @[("eth-consensus-version", toString(ConsensusFork.Deneb))]
)
21 changes: 17 additions & 4 deletions beacon_chain/spec/mev/rest_electra_mev_calls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,21 @@ proc getHeaderElectra*(slot: Slot,
meth: MethodGet, connection: {Dedicated, Close}.}
## https://github.com/ethereum/builder-specs/blob/v0.4.0/apis/builder/header.yaml

proc submitBlindedBlock*(body: electra_mev.SignedBlindedBeaconBlock
): RestPlainResponse {.
rest, endpoint: "/eth/v1/builder/blinded_blocks",
meth: MethodPost, connection: {Dedicated, Close}.}
proc submitBlindedBlockPlain*(
body: electra_mev.SignedBlindedBeaconBlock
): RestPlainResponse {.
rest, endpoint: "/eth/v1/builder/blinded_blocks",
meth: MethodPost, connection: {Dedicated, Close}.}
## https://github.com/ethereum/builder-specs/blob/v0.4.0/apis/builder/blinded_blocks.yaml

proc submitBlindedBlock*(
client: RestClientRef,
body: electra_mev.SignedBlindedBeaconBlock
): Future[RestPlainResponse] {.
async: (raises: [CancelledError, RestEncodingError, RestDnsResolveError,
RestCommunicationError]).} =
## https://github.com/ethereum/builder-specs/blob/v0.4.0/apis/builder/blinded_blocks.yaml
await client.submitBlindedBlockPlain(
body,
extraHeaders = @[("eth-consensus-version", toString(ConsensusFork.Electra))]
)
22 changes: 13 additions & 9 deletions beacon_chain/validators/message_router_mev.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import metrics
import stew/assign2
import ../beacon_node

from eth/async_utils import awaitWithTimeout
from ../spec/datatypes/bellatrix import SignedBeaconBlock
from ../spec/mev/rest_deneb_mev_calls import submitBlindedBlock
from ../spec/mev/rest_electra_mev_calls import submitBlindedBlock
Expand Down Expand Up @@ -59,16 +58,21 @@ proc unblindAndRouteBlockMEV*(
# protection check
let response =
try:
awaitWithTimeout(
payloadBuilderRestClient.submitBlindedBlock(blindedBlock),
BUILDER_BLOCK_SUBMISSION_DELAY_TOLERANCE):
return err("Submitting blinded block timed out")
await payloadBuilderRestClient.submitBlindedBlock(blindedBlock).
wait(BUILDER_BLOCK_SUBMISSION_DELAY_TOLERANCE)
# From here on, including error paths, disallow local EL production by
# returning Opt.some, regardless of whether on head or newBlock.
except RestDecodingError as exc:
return err("REST decoding error submitting blinded block: " & exc.msg)
except RestError as exc:
return err("exception in submitBlindedBlock: " & exc.msg)
except AsyncTimeoutError:
return err("Submitting blinded block timed out")
except RestEncodingError as exc:
return err(
"REST encoding error submitting blinded block, reason " & exc.msg)
except RestDnsResolveError as exc:
return err(
"REST unable to resolve remote host, reason " & exc.msg)
except RestCommunicationError as exc:
return err(
"REST unable to communicate with remote host, reason " & exc.msg)

const httpOk = 200
if response.status != httpOk:
Expand Down

0 comments on commit 484f489

Please sign in to comment.