initial VC Electra publishBlock support (#6189)

This commit is contained in:
tersec 2024-04-09 14:54:05 +00:00 committed by GitHub
parent 749a45695f
commit 8a30cffbcc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 37 additions and 17 deletions

View File

@ -345,6 +345,7 @@ type
capella.SignedBeaconBlock |
phase0.SignedBeaconBlock |
DenebSignedBlockContents |
ElectraSignedBlockContents |
ForkedMaybeBlindedBeaconBlock
EncodeArrays* =
@ -403,8 +404,8 @@ type
RestBlockTypes* = phase0.BeaconBlock | altair.BeaconBlock |
bellatrix.BeaconBlock | capella.BeaconBlock |
deneb.BlockContents | capella_mev.BlindedBeaconBlock |
deneb_mev.BlindedBeaconBlock
deneb.BlockContents | deneb_mev.BlindedBeaconBlock |
electra.BlockContents | electra_mev.BlindedBeaconBlock
func readStrictHexChar(c: char, radix: static[uint8]): Result[int8, cstring] =
## Converts an hex char to an int
@ -3970,14 +3971,8 @@ proc decodeBytes*[T: DecodeConsensysTypes](
forked = ForkedBlindedBeaconBlock(
kind: ConsensusFork.Deneb, denebData: blck)
ok(ProduceBlindedBlockResponse(forked))
of ConsensusFork.Capella:
let
blck = ? readSszResBytes(capella_mev.BlindedBeaconBlock, value)
forked = ForkedBlindedBeaconBlock(
kind: ConsensusFork.Capella, capellaData: blck)
ok(ProduceBlindedBlockResponse(forked))
of ConsensusFork.Bellatrix, ConsensusFork.Altair, ConsensusFork.Phase0:
err("Unable to decode blinded block for Bellatrix, Altair, and Phase0 forks")
of ConsensusFork.Phase0 .. ConsensusFork.Capella:
err("Unable to decode blinded block for pre-Deneb forks")
else:
err("Unsupported Content-Type")
@ -4036,10 +4031,7 @@ proc decodeBytes*[T: ProduceBlockResponseV3](
except ValueError:
return err("Incorrect `Eth-Consensus-Block-Value` header value")
withConsensusFork(fork):
when consensusFork >= ConsensusFork.Electra:
debugRaiseAssert "eth2 rest serialization"
return err("electra missing")
elif consensusFork >= ConsensusFork.Deneb:
when consensusFork >= ConsensusFork.Deneb:
if blinded:
let contents =
? readSszResBytes(consensusFork.BlindedBlockContents, value)

View File

@ -148,6 +148,11 @@ proc publishBlock*(body: DenebSignedBlockContents): RestPlainResponse {.
meth: MethodPost.}
## https://ethereum.github.io/beacon-APIs/#/Beacon/publishBlock
proc publishBlock*(body: ElectraSignedBlockContents): RestPlainResponse {.
rest, endpoint: "/eth/v1/beacon/blocks",
meth: MethodPost.}
## https://ethereum.github.io/beacon-APIs/#/Beacon/publishBlock
proc publishSszBlock*(
client: RestClientRef,
blck: ForkySignedBeaconBlock

View File

@ -585,7 +585,9 @@ template BlockContents*(
template BlindedBlockContents*(
kind: static ConsensusFork): auto =
when kind == ConsensusFork.Deneb:
when kind == ConsensusFork.Electra:
typedesc[electra_mev.BlindedBeaconBlock]
elif kind == ConsensusFork.Deneb:
typedesc[deneb_mev.BlindedBeaconBlock]
else:
{.error: "BlindedBlockContents does not support " & $kind.}
@ -1496,3 +1498,25 @@ template init*(T: type ForkedMaybeBlindedBeaconBlock,
blindedData: blck),
consensusValue: cvalue,
executionValue: evalue)
template init*(T: type ForkedMaybeBlindedBeaconBlock,
blck: electra.BlockContents,
evalue: Opt[UInt256], cvalue: Opt[UInt256]): T =
ForkedMaybeBlindedBeaconBlock(
kind: ConsensusFork.Electra,
electraData: electra_mev.MaybeBlindedBeaconBlock(
isBlinded: false,
data: blck),
consensusValue: cvalue,
executionValue: evalue)
template init*(T: type ForkedMaybeBlindedBeaconBlock,
blck: electra_mev.BlindedBeaconBlock,
evalue: Opt[UInt256], cvalue: Opt[UInt256]): T =
ForkedMaybeBlindedBeaconBlock(
kind: ConsensusFork.Electra,
electraData: electra_mev.MaybeBlindedBeaconBlock(
isBlinded: true,
blindedData: blck),
consensusValue: cvalue,
executionValue: evalue)

View File

@ -2260,8 +2260,7 @@ proc publishBlock*(
of ConsensusFork.Deneb:
publishBlock(it, data.denebData)
of ConsensusFork.Electra:
debugRaiseAssert "electra missing"
publishBlock(it, data.denebData)
publishBlock(it, data.electraData)
do:
if apiResponse.isErr():
handleCommunicationError()