Implement validor client proposals for Deneb (#5094)
This commit is contained in:
parent
11d18acfeb
commit
fa212515f5
|
@ -110,7 +110,8 @@ type
|
|||
altair.SignedBeaconBlock |
|
||||
bellatrix.SignedBeaconBlock |
|
||||
capella.SignedBeaconBlock |
|
||||
phase0.SignedBeaconBlock
|
||||
phase0.SignedBeaconBlock |
|
||||
DenebSignedBlockContents
|
||||
|
||||
EncodeArrays* =
|
||||
seq[Attestation] |
|
||||
|
|
|
@ -167,6 +167,11 @@ proc publishBlock*(body: capella.SignedBeaconBlock): RestPlainResponse {.
|
|||
meth: MethodPost.}
|
||||
## https://ethereum.github.io/beacon-APIs/#/Beacon/publishBlock
|
||||
|
||||
proc publishBlock*(body: DenebSignedBlockContents): RestPlainResponse {.
|
||||
rest, endpoint: "/eth/v1/beacon/blocks",
|
||||
meth: MethodPost.}
|
||||
## https://ethereum.github.io/beacon-APIs/#/Beacon/publishBlock
|
||||
|
||||
proc publishSszBlock*(
|
||||
client: RestClientRef,
|
||||
blck: ForkySignedBeaconBlock
|
||||
|
|
|
@ -331,7 +331,7 @@ type
|
|||
|
||||
DenebBlockContents* = object
|
||||
`block`*: deneb.BeaconBlock
|
||||
blob_sidecars*: List[SignedBlobSidecar, Limit MAX_BLOBS_PER_BLOCK]
|
||||
blob_sidecars*: List[BlobSidecar, Limit MAX_BLOBS_PER_BLOCK]
|
||||
|
||||
ProduceBlockResponseV2* = object
|
||||
case kind*: ConsensusFork
|
||||
|
|
|
@ -1842,7 +1842,7 @@ proc produceBlockV2*(
|
|||
|
||||
proc publishBlock*(
|
||||
vc: ValidatorClientRef,
|
||||
data: ForkedSignedBeaconBlock,
|
||||
data: RestPublishedSignedBlockContents,
|
||||
strategy: ApiStrategyKind
|
||||
): Future[bool] {.async.} =
|
||||
const
|
||||
|
@ -1869,12 +1869,7 @@ proc publishBlock*(
|
|||
of ConsensusFork.Capella:
|
||||
publishBlock(it, data.capellaData)
|
||||
of ConsensusFork.Deneb:
|
||||
debugRaiseAssert $denebImplementationMissing &
|
||||
": validator_client/api.nim:publishBlock (1)"
|
||||
let f = newFuture[RestPlainResponse]("")
|
||||
f.fail(new RestError)
|
||||
f
|
||||
|
||||
publishBlock(it, data.denebData)
|
||||
do:
|
||||
if apiResponse.isErr():
|
||||
handleCommunicationError()
|
||||
|
@ -1885,7 +1880,8 @@ proc publishBlock*(
|
|||
of 200:
|
||||
ApiResponse[bool].ok(true)
|
||||
of 202:
|
||||
debug BlockBroadcasted, node = node, blck = shortLog(data)
|
||||
debug BlockBroadcasted, node = node,
|
||||
blck = shortLog(ForkedSignedBeaconBlock.init(data))
|
||||
ApiResponse[bool].ok(true)
|
||||
of 400:
|
||||
handle400()
|
||||
|
@ -1919,11 +1915,8 @@ proc publishBlock*(
|
|||
of ConsensusFork.Capella:
|
||||
publishBlock(it, data.capellaData)
|
||||
of ConsensusFork.Deneb:
|
||||
debugRaiseAssert $denebImplementationMissing &
|
||||
": validator_client/api.nim:publishBlock (2)"
|
||||
let f = newFuture[RestPlainResponse]("")
|
||||
f.fail(new RestError)
|
||||
f
|
||||
publishBlock(it, data.denebData)
|
||||
|
||||
do:
|
||||
if apiResponse.isErr():
|
||||
handleCommunicationError()
|
||||
|
@ -1934,7 +1927,8 @@ proc publishBlock*(
|
|||
of 200:
|
||||
return true
|
||||
of 202:
|
||||
debug BlockBroadcasted, node = node, blck = shortLog(data)
|
||||
debug BlockBroadcasted, node = node,
|
||||
blck = shortLog(ForkedSignedBeaconBlock.init(data))
|
||||
return true
|
||||
of 400:
|
||||
handle400()
|
||||
|
|
|
@ -21,9 +21,12 @@ const
|
|||
logScope: service = ServiceName
|
||||
|
||||
type
|
||||
BlobList = List[BlobSidecar, Limit MAX_BLOBS_PER_BLOCK]
|
||||
|
||||
PreparedBeaconBlock = object
|
||||
blockRoot*: Eth2Digest
|
||||
data*: ForkedBeaconBlock
|
||||
blobsOpt*: Opt[BlobList]
|
||||
|
||||
PreparedBlindedBeaconBlock = object
|
||||
blockRoot*: Eth2Digest
|
||||
|
@ -59,25 +62,29 @@ proc produceBlock(
|
|||
of ConsensusFork.Phase0:
|
||||
let blck = produceBlockResponse.phase0Data
|
||||
return Opt.some(PreparedBeaconBlock(blockRoot: hash_tree_root(blck),
|
||||
data: ForkedBeaconBlock.init(blck)))
|
||||
data: ForkedBeaconBlock.init(blck),
|
||||
blobsOpt: Opt.none(BlobList)))
|
||||
of ConsensusFork.Altair:
|
||||
let blck = produceBlockResponse.altairData
|
||||
return Opt.some(PreparedBeaconBlock(blockRoot: hash_tree_root(blck),
|
||||
data: ForkedBeaconBlock.init(blck)))
|
||||
data: ForkedBeaconBlock.init(blck),
|
||||
blobsOpt: Opt.none(BlobList)))
|
||||
of ConsensusFork.Bellatrix:
|
||||
let blck = produceBlockResponse.bellatrixData
|
||||
return Opt.some(PreparedBeaconBlock(blockRoot: hash_tree_root(blck),
|
||||
data: ForkedBeaconBlock.init(blck)))
|
||||
data: ForkedBeaconBlock.init(blck),
|
||||
blobsOpt: Opt.none(BlobList)))
|
||||
of ConsensusFork.Capella:
|
||||
let blck = produceBlockResponse.capellaData
|
||||
return Opt.some(PreparedBeaconBlock(blockRoot: hash_tree_root(blck),
|
||||
data: ForkedBeaconBlock.init(blck)))
|
||||
data: ForkedBeaconBlock.init(blck),
|
||||
blobsOpt: Opt.none(BlobList)))
|
||||
of ConsensusFork.Deneb:
|
||||
debugRaiseAssert $denebImplementationMissing
|
||||
# TODO return blobs as well
|
||||
let blck = produceBlockResponse.denebData.`block`
|
||||
let blobs = produceBlockResponse.denebData.blob_sidecars
|
||||
return Opt.some(PreparedBeaconBlock(blockRoot: hash_tree_root(blck),
|
||||
data: ForkedBeaconBlock.init(blck)))
|
||||
data: ForkedBeaconBlock.init(blck),
|
||||
blobsOpt: Opt.some(blobs)))
|
||||
|
||||
|
||||
proc produceBlindedBlock(
|
||||
|
@ -298,13 +305,63 @@ proc publishBlock(vc: ValidatorClientRef, currentSlot, slot: Slot,
|
|||
error "An unexpected error occurred while signing block",
|
||||
error_name = exc.name, error_msg = exc.msg
|
||||
return
|
||||
signedBlock = ForkedSignedBeaconBlock.init(preparedBlock.data,
|
||||
preparedBlock.blockRoot,
|
||||
signature)
|
||||
|
||||
signedBlockContents =
|
||||
case preparedBlock.data.kind
|
||||
of ConsensusFork.Phase0:
|
||||
RestPublishedSignedBlockContents(kind: ConsensusFork.Phase0,
|
||||
phase0Data: phase0.SignedBeaconBlock(
|
||||
message: preparedBlock.data.phase0Data,
|
||||
root: preparedBlock.blockRoot,
|
||||
signature: signature))
|
||||
of ConsensusFork.Altair:
|
||||
RestPublishedSignedBlockContents(kind: ConsensusFork.Altair,
|
||||
altairData: altair.SignedBeaconBlock(
|
||||
message: preparedBlock.data.altairData,
|
||||
root: preparedBlock.blockRoot,
|
||||
signature: signature))
|
||||
of ConsensusFork.Bellatrix:
|
||||
RestPublishedSignedBlockContents(kind: ConsensusFork.Bellatrix,
|
||||
bellatrixData: bellatrix.SignedBeaconBlock(
|
||||
message: preparedBlock.data.bellatrixData,
|
||||
root: preparedBlock.blockRoot,
|
||||
signature: signature))
|
||||
of ConsensusFork.Capella:
|
||||
RestPublishedSignedBlockContents(kind: ConsensusFork.Capella,
|
||||
capellaData: capella.SignedBeaconBlock(
|
||||
message: preparedBlock.data.capellaData,
|
||||
root: preparedBlock.blockRoot,
|
||||
signature: signature))
|
||||
of ConsensusFork.Deneb:
|
||||
let blobs = preparedBlock.blobsOpt.get()
|
||||
var signed: seq[SignedBlobSidecar] = @[]
|
||||
for i in 0..<blobs.len:
|
||||
let res = validator.getBlobSignature(fork, genesisRoot,
|
||||
slot, blobs[i])
|
||||
if res.isErr():
|
||||
warn "Unable to sign blob",
|
||||
reason = res.error()
|
||||
return
|
||||
let signature = res.get()
|
||||
signed.add(deneb.SignedBlobSidecar(
|
||||
message: blobs[i],
|
||||
signature: signature))
|
||||
|
||||
let signedList =
|
||||
List[SignedBlobSidecar, Limit MAX_BLOBS_PER_BLOCK].init(signed)
|
||||
RestPublishedSignedBlockContents(kind: ConsensusFork.Deneb,
|
||||
denebData: DenebSignedBlockContents(
|
||||
signed_block: deneb.SignedBeaconBlock(
|
||||
message: preparedBlock.data.denebData,
|
||||
root: preparedBlock.blockRoot,
|
||||
signature: signature),
|
||||
signed_blob_sidecars: signedList
|
||||
))
|
||||
|
||||
res =
|
||||
try:
|
||||
debug "Sending block"
|
||||
await vc.publishBlock(signedBlock, ApiStrategyKind.First)
|
||||
await vc.publishBlock(signedBlockContents, ApiStrategyKind.First)
|
||||
except ValidatorApiError as exc:
|
||||
warn "Unable to publish block", reason = exc.getFailureReason()
|
||||
return
|
||||
|
|
|
@ -618,7 +618,7 @@ proc getBlockSignature*(v: AttachedValidator, fork: Fork,
|
|||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-alpha.3/specs/deneb/validator.md#constructing-the-signedblobsidecars
|
||||
proc getBlobSignature*(v: AttachedValidator, fork: Fork,
|
||||
genesis_validators_root: Eth2Digest, slot: Slot,
|
||||
blob: BlobSidecar): Future[SignatureResult] {.async.} =
|
||||
blob: BlobSidecar): SignatureResult =
|
||||
return
|
||||
case v.kind
|
||||
of ValidatorKind.Local:
|
||||
|
|
Loading…
Reference in New Issue