fix SSZ response for `produceBlindedBlock` (#4943)
* fix SSZ response for `produceBlindedBlock` In `produceBlindedBlock`, we sent the `ForkedBlindedBeaconBlock` when requested to reply in SSZ format. However, expected result is just the inner `ForkyBlindedBeaconBlock` together with `eth-consensus-version`. Note: We do not use SSZ format in our VC for this endpoint at this time, which explains why we haven't noticed earlier. * fix Altair/Phase0
This commit is contained in:
parent
51418a7894
commit
d263f7f0cb
|
@ -483,15 +483,18 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||||
qslot, proposer, qrandao, qskip_randao_verification):
|
qslot, proposer, qrandao, qskip_randao_verification):
|
||||||
return RestApiResponse.jsonError(Http400, InvalidRandaoRevealValue)
|
return RestApiResponse.jsonError(Http400, InvalidRandaoRevealValue)
|
||||||
|
|
||||||
template responsePlain(response: untyped): untyped =
|
template responseVersioned(
|
||||||
|
response: untyped, contextFork: ConsensusFork): untyped =
|
||||||
if contentType == sszMediaType:
|
if contentType == sszMediaType:
|
||||||
RestApiResponse.sszResponse(response)
|
let headers = [("eth-consensus-version", contextFork.toString())]
|
||||||
|
RestApiResponse.sszResponse(response, headers)
|
||||||
elif contentType == jsonMediaType:
|
elif contentType == jsonMediaType:
|
||||||
RestApiResponse.jsonResponsePlain(response)
|
RestApiResponse.jsonResponseWVersion(response, contextFork)
|
||||||
else:
|
else:
|
||||||
RestApiResponse.jsonError(Http500, InvalidAcceptError)
|
RestApiResponse.jsonError(Http500, InvalidAcceptError)
|
||||||
|
|
||||||
case node.dag.cfg.consensusForkAtEpoch(node.currentSlot.epoch)
|
let contextFork = node.dag.cfg.consensusForkAtEpoch(node.currentSlot.epoch)
|
||||||
|
case contextFork
|
||||||
of ConsensusFork.Deneb:
|
of ConsensusFork.Deneb:
|
||||||
# TODO
|
# TODO
|
||||||
# We should return a block with sidecars here
|
# We should return a block with sidecars here
|
||||||
|
@ -503,18 +506,14 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||||
node, qrandao, proposer, qgraffiti, qhead, qslot)
|
node, qrandao, proposer, qgraffiti, qhead, qslot)
|
||||||
if res.isErr():
|
if res.isErr():
|
||||||
return RestApiResponse.jsonError(Http400, res.error())
|
return RestApiResponse.jsonError(Http400, res.error())
|
||||||
return responsePlain(ForkedBlindedBeaconBlock(
|
return responseVersioned(res.get().blindedBlckPart, contextFork)
|
||||||
kind: ConsensusFork.Capella,
|
|
||||||
capellaData: res.get().blindedBlckPart))
|
|
||||||
of ConsensusFork.Bellatrix:
|
of ConsensusFork.Bellatrix:
|
||||||
let res = await makeBlindedBeaconBlockForHeadAndSlot[
|
let res = await makeBlindedBeaconBlockForHeadAndSlot[
|
||||||
bellatrix_mev.BlindedBeaconBlock](
|
bellatrix_mev.BlindedBeaconBlock](
|
||||||
node, qrandao, proposer, qgraffiti, qhead, qslot)
|
node, qrandao, proposer, qgraffiti, qhead, qslot)
|
||||||
if res.isErr():
|
if res.isErr():
|
||||||
return RestApiResponse.jsonError(Http400, res.error())
|
return RestApiResponse.jsonError(Http400, res.error())
|
||||||
return responsePlain(ForkedBlindedBeaconBlock(
|
return responseVersioned(res.get().blindedBlckPart, contextFork)
|
||||||
kind: ConsensusFork.Bellatrix,
|
|
||||||
bellatrixData: res.get().blindedBlckPart))
|
|
||||||
of ConsensusFork.Altair, ConsensusFork.Phase0:
|
of ConsensusFork.Altair, ConsensusFork.Phase0:
|
||||||
# Pre-Bellatrix, this endpoint will return a BeaconBlock
|
# Pre-Bellatrix, this endpoint will return a BeaconBlock
|
||||||
let res = await makeBeaconBlockForHeadAndSlot(
|
let res = await makeBeaconBlockForHeadAndSlot(
|
||||||
|
@ -522,7 +521,8 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||||
proposer, qgraffiti, qhead, qslot)
|
proposer, qgraffiti, qhead, qslot)
|
||||||
if res.isErr():
|
if res.isErr():
|
||||||
return RestApiResponse.jsonError(Http400, res.error())
|
return RestApiResponse.jsonError(Http400, res.error())
|
||||||
return responsePlain(res.get().blck)
|
withBlck(res.get().blck):
|
||||||
|
return responseVersioned(blck, contextFork)
|
||||||
|
|
||||||
# https://ethereum.github.io/beacon-APIs/#/Validator/produceAttestationData
|
# https://ethereum.github.io/beacon-APIs/#/Validator/produceAttestationData
|
||||||
router.api(MethodGet, "/eth/v1/validator/attestation_data") do (
|
router.api(MethodGet, "/eth/v1/validator/attestation_data") do (
|
||||||
|
|
|
@ -1214,7 +1214,7 @@ proc writeValue*[
|
||||||
writer.endRecord()
|
writer.endRecord()
|
||||||
|
|
||||||
proc writeValue*[
|
proc writeValue*[
|
||||||
BlockType: ForkedBeaconBlock|ForkedBlindedBeaconBlock](
|
BlockType: ForkedBeaconBlock](
|
||||||
writer: var JsonWriter[RestJson],
|
writer: var JsonWriter[RestJson],
|
||||||
value: BlockType) {.raises: [IOError, Defect].} =
|
value: BlockType) {.raises: [IOError, Defect].} =
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue