Complete Deneb bn side for /eth/v2/validator/blocks/{slot} (#5146)

* Complete Deneb bn side for /eth/v2/validator/blocks/{slot}

* Address review feedback

* More review feedback

* Tighten up when condition

* Update beacon_chain/rpc/rest_validator_api.nim

Co-authored-by: tersec <tersec@users.noreply.github.com>

---------

Co-authored-by: tersec <tersec@users.noreply.github.com>
This commit is contained in:
henridf 2023-07-11 21:35:55 +02:00 committed by GitHub
parent a2adbf809f
commit f13f23e21b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 17 deletions

View File

@ -395,14 +395,6 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
let res =
case node.dag.cfg.consensusForkAtEpoch(qslot.epoch)
of ConsensusFork.Deneb:
# TODO
# We should return a block with sidecars here
# https://github.com/ethereum/beacon-APIs/pull/302/files
# The code paths leading to makeBeaconBlockForHeadAndSlot are already
# partially refactored to make it possible to return the blobs from
# the call, but the signature of the call needs to be changed furhter
# to access the blobs here.
discard $denebImplementationMissing
await makeBeaconBlockForHeadAndSlot(
deneb.ExecutionPayloadForSigning,
node, qrandao, proposer, qgraffiti, qhead, qslot)
@ -418,17 +410,43 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
return RestApiResponse.jsonError(Http400, InvalidSlotValueError)
if res.isErr():
return RestApiResponse.jsonError(Http400, res.error())
res.get.blck
res.get
return
if contentType == sszMediaType:
let headers = [("eth-consensus-version", message.kind.toString())]
withBlck(message):
withBlck(message.blck):
let data =
when blck is deneb.BeaconBlock:
let bundle = message.blobsBundleOpt.get()
let blockRoot = hash_tree_root(blck)
var sidecars = newSeqOfCap[BlobSidecar](bundle.blobs.len)
for i in 0..<bundle.blobs.len:
let sidecar = deneb.BlobSidecar(
block_root: blockRoot,
index: BlobIndex(i),
slot: blck.slot,
block_parent_root: blck.parent_root,
proposer_index: blck.proposer_index,
blob: bundle.blobs[i],
kzg_commitment: bundle.kzgs[i],
kzg_proof: bundle.proofs[i]
)
sidecars.add(sidecar)
DenebBlockContents(
`block`: blck,
blob_sidecars: List[BlobSidecar,
Limit MAX_BLOBS_PER_BLOCK].init(sidecars))
elif blck is phase0.BeaconBlock or blck is altair.BeaconBlock or
blck is bellatrix.BeaconBlock or blck is capella.BeaconBlock:
blck
else:
static: raiseAssert "produceBlockV2 received unexpected version"
if contentType == sszMediaType:
let headers = [("eth-consensus-version", message.blck.kind.toString())]
RestApiResponse.sszResponse(blck, headers)
elif contentType == jsonMediaType:
withBlck(message):
RestApiResponse.jsonResponseWVersion(blck, message.kind)
else:
raiseAssert "preferredContentType() returns invalid content type"
elif contentType == jsonMediaType:
RestApiResponse.jsonResponseWVersion(blck, message.blck.kind)
else:
raiseAssert "preferredContentType() returns invalid content type"
# https://ethereum.github.io/beacon-APIs/#/Validator/produceBlindedBlock
# https://github.com/ethereum/beacon-APIs/blob/v2.4.0/apis/validator/blinded_block.yaml