initial VC Electra publishBlock support (#6189)
This commit is contained in:
parent
749a45695f
commit
8a30cffbcc
|
@ -345,6 +345,7 @@ type
|
||||||
capella.SignedBeaconBlock |
|
capella.SignedBeaconBlock |
|
||||||
phase0.SignedBeaconBlock |
|
phase0.SignedBeaconBlock |
|
||||||
DenebSignedBlockContents |
|
DenebSignedBlockContents |
|
||||||
|
ElectraSignedBlockContents |
|
||||||
ForkedMaybeBlindedBeaconBlock
|
ForkedMaybeBlindedBeaconBlock
|
||||||
|
|
||||||
EncodeArrays* =
|
EncodeArrays* =
|
||||||
|
@ -403,8 +404,8 @@ type
|
||||||
|
|
||||||
RestBlockTypes* = phase0.BeaconBlock | altair.BeaconBlock |
|
RestBlockTypes* = phase0.BeaconBlock | altair.BeaconBlock |
|
||||||
bellatrix.BeaconBlock | capella.BeaconBlock |
|
bellatrix.BeaconBlock | capella.BeaconBlock |
|
||||||
deneb.BlockContents | capella_mev.BlindedBeaconBlock |
|
deneb.BlockContents | deneb_mev.BlindedBeaconBlock |
|
||||||
deneb_mev.BlindedBeaconBlock
|
electra.BlockContents | electra_mev.BlindedBeaconBlock
|
||||||
|
|
||||||
func readStrictHexChar(c: char, radix: static[uint8]): Result[int8, cstring] =
|
func readStrictHexChar(c: char, radix: static[uint8]): Result[int8, cstring] =
|
||||||
## Converts an hex char to an int
|
## Converts an hex char to an int
|
||||||
|
@ -3970,14 +3971,8 @@ proc decodeBytes*[T: DecodeConsensysTypes](
|
||||||
forked = ForkedBlindedBeaconBlock(
|
forked = ForkedBlindedBeaconBlock(
|
||||||
kind: ConsensusFork.Deneb, denebData: blck)
|
kind: ConsensusFork.Deneb, denebData: blck)
|
||||||
ok(ProduceBlindedBlockResponse(forked))
|
ok(ProduceBlindedBlockResponse(forked))
|
||||||
of ConsensusFork.Capella:
|
of ConsensusFork.Phase0 .. ConsensusFork.Capella:
|
||||||
let
|
err("Unable to decode blinded block for pre-Deneb forks")
|
||||||
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")
|
|
||||||
else:
|
else:
|
||||||
err("Unsupported Content-Type")
|
err("Unsupported Content-Type")
|
||||||
|
|
||||||
|
@ -4036,10 +4031,7 @@ proc decodeBytes*[T: ProduceBlockResponseV3](
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return err("Incorrect `Eth-Consensus-Block-Value` header value")
|
return err("Incorrect `Eth-Consensus-Block-Value` header value")
|
||||||
withConsensusFork(fork):
|
withConsensusFork(fork):
|
||||||
when consensusFork >= ConsensusFork.Electra:
|
when consensusFork >= ConsensusFork.Deneb:
|
||||||
debugRaiseAssert "eth2 rest serialization"
|
|
||||||
return err("electra missing")
|
|
||||||
elif consensusFork >= ConsensusFork.Deneb:
|
|
||||||
if blinded:
|
if blinded:
|
||||||
let contents =
|
let contents =
|
||||||
? readSszResBytes(consensusFork.BlindedBlockContents, value)
|
? readSszResBytes(consensusFork.BlindedBlockContents, value)
|
||||||
|
|
|
@ -148,6 +148,11 @@ proc publishBlock*(body: DenebSignedBlockContents): RestPlainResponse {.
|
||||||
meth: MethodPost.}
|
meth: MethodPost.}
|
||||||
## https://ethereum.github.io/beacon-APIs/#/Beacon/publishBlock
|
## 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*(
|
proc publishSszBlock*(
|
||||||
client: RestClientRef,
|
client: RestClientRef,
|
||||||
blck: ForkySignedBeaconBlock
|
blck: ForkySignedBeaconBlock
|
||||||
|
|
|
@ -585,7 +585,9 @@ template BlockContents*(
|
||||||
|
|
||||||
template BlindedBlockContents*(
|
template BlindedBlockContents*(
|
||||||
kind: static ConsensusFork): auto =
|
kind: static ConsensusFork): auto =
|
||||||
when kind == ConsensusFork.Deneb:
|
when kind == ConsensusFork.Electra:
|
||||||
|
typedesc[electra_mev.BlindedBeaconBlock]
|
||||||
|
elif kind == ConsensusFork.Deneb:
|
||||||
typedesc[deneb_mev.BlindedBeaconBlock]
|
typedesc[deneb_mev.BlindedBeaconBlock]
|
||||||
else:
|
else:
|
||||||
{.error: "BlindedBlockContents does not support " & $kind.}
|
{.error: "BlindedBlockContents does not support " & $kind.}
|
||||||
|
@ -1496,3 +1498,25 @@ template init*(T: type ForkedMaybeBlindedBeaconBlock,
|
||||||
blindedData: blck),
|
blindedData: blck),
|
||||||
consensusValue: cvalue,
|
consensusValue: cvalue,
|
||||||
executionValue: evalue)
|
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)
|
||||||
|
|
|
@ -2260,8 +2260,7 @@ proc publishBlock*(
|
||||||
of ConsensusFork.Deneb:
|
of ConsensusFork.Deneb:
|
||||||
publishBlock(it, data.denebData)
|
publishBlock(it, data.denebData)
|
||||||
of ConsensusFork.Electra:
|
of ConsensusFork.Electra:
|
||||||
debugRaiseAssert "electra missing"
|
publishBlock(it, data.electraData)
|
||||||
publishBlock(it, data.denebData)
|
|
||||||
do:
|
do:
|
||||||
if apiResponse.isErr():
|
if apiResponse.isErr():
|
||||||
handleCommunicationError()
|
handleCommunicationError()
|
||||||
|
|
Loading…
Reference in New Issue