mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-22 11:18:25 +00:00
Add publishAggregateAndProofsV2 (#6546)
* added new endpoint version(v2) for validator aggregate and proof * review improvements * introduced nim template for proof executiion --------- Co-authored-by: Pedro Miranda <pedro.miranda@nimbus.team>
This commit is contained in:
parent
ed2422112c
commit
7b6caebf6e
@ -2648,7 +2648,8 @@ proc broadcastBlsToExecutionChange*(
|
|||||||
node.broadcast(topic, bls_to_execution_change)
|
node.broadcast(topic, bls_to_execution_change)
|
||||||
|
|
||||||
proc broadcastAggregateAndProof*(
|
proc broadcastAggregateAndProof*(
|
||||||
node: Eth2Node, proof: phase0.SignedAggregateAndProof):
|
node: Eth2Node,
|
||||||
|
proof: phase0.SignedAggregateAndProof | electra.SignedAggregateAndProof):
|
||||||
Future[SendResult] {.async: (raises: [CancelledError], raw: true).} =
|
Future[SendResult] {.async: (raises: [CancelledError], raw: true).} =
|
||||||
let topic = getAggregateAndProofsTopic(
|
let topic = getAggregateAndProofsTopic(
|
||||||
node.forkDigestAtEpoch(node.getWallEpoch))
|
node.forkDigestAtEpoch(node.getWallEpoch))
|
||||||
|
@ -890,6 +890,48 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||||||
"Unexpected server failure, while sending aggregate and proof")
|
"Unexpected server failure, while sending aggregate and proof")
|
||||||
RestApiResponse.jsonMsgResponse(AggregateAndProofValidationSuccess)
|
RestApiResponse.jsonMsgResponse(AggregateAndProofValidationSuccess)
|
||||||
|
|
||||||
|
# https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Validator/publishAggregateAndProofsV2
|
||||||
|
router.api2(MethodPost, "/eth/v2/validator/aggregate_and_proofs") do (
|
||||||
|
contentBody: Option[ContentBody]) -> RestApiResponse:
|
||||||
|
|
||||||
|
if contentBody.isNone():
|
||||||
|
return RestApiResponse.jsonError(Http400, EmptyRequestBodyError)
|
||||||
|
|
||||||
|
let
|
||||||
|
headerVersion = request.headers.getString("Eth-Consensus-Version")
|
||||||
|
consensusVersion = ConsensusFork.init(headerVersion)
|
||||||
|
if consensusVersion.isNone():
|
||||||
|
return RestApiResponse.jsonError(Http400, FailedToObtainConsensusForkError)
|
||||||
|
|
||||||
|
var proofs: seq[Future[SendResult]]
|
||||||
|
template addDecodedProofs(ProofType: untyped) =
|
||||||
|
let dres = decodeBody(seq[ProofType], contentBody.get())
|
||||||
|
if dres.isErr():
|
||||||
|
return RestApiResponse.jsonError(Http400,
|
||||||
|
InvalidAggregateAndProofObjectError,
|
||||||
|
$dres.error())
|
||||||
|
for proof in dres.get():
|
||||||
|
proofs.add(node.router.routeSignedAggregateAndProof(proof))
|
||||||
|
|
||||||
|
case consensusVersion.get():
|
||||||
|
of ConsensusFork.Phase0 .. ConsensusFork.Deneb:
|
||||||
|
addDecodedProofs(phase0.SignedAggregateAndProof)
|
||||||
|
of ConsensusFork.Electra:
|
||||||
|
addDecodedProofs(electra.SignedAggregateAndProof)
|
||||||
|
|
||||||
|
await allFutures(proofs)
|
||||||
|
for future in proofs:
|
||||||
|
if future.completed():
|
||||||
|
let res = future.value()
|
||||||
|
if res.isErr():
|
||||||
|
return RestApiResponse.jsonError(Http400,
|
||||||
|
AggregateAndProofValidationError,
|
||||||
|
$res.error())
|
||||||
|
else:
|
||||||
|
return RestApiResponse.jsonError(Http500,
|
||||||
|
"Unexpected server failure, while sending aggregate and proof")
|
||||||
|
RestApiResponse.jsonMsgResponse(AggregateAndProofValidationSuccess)
|
||||||
|
|
||||||
# https://ethereum.github.io/beacon-APIs/#/Validator/prepareBeaconCommitteeSubnet
|
# https://ethereum.github.io/beacon-APIs/#/Validator/prepareBeaconCommitteeSubnet
|
||||||
router.api2(MethodPost,
|
router.api2(MethodPost,
|
||||||
"/eth/v1/validator/beacon_committee_subscriptions") do (
|
"/eth/v1/validator/beacon_committee_subscriptions") do (
|
||||||
|
@ -243,6 +243,7 @@ RestJson.useDefaultSerializationFor(
|
|||||||
deneb_mev.ExecutionPayloadAndBlobsBundle,
|
deneb_mev.ExecutionPayloadAndBlobsBundle,
|
||||||
deneb_mev.SignedBlindedBeaconBlock,
|
deneb_mev.SignedBlindedBeaconBlock,
|
||||||
deneb_mev.SignedBuilderBid,
|
deneb_mev.SignedBuilderBid,
|
||||||
|
electra.AggregateAndProof,
|
||||||
electra.Attestation,
|
electra.Attestation,
|
||||||
electra.AttesterSlashing,
|
electra.AttesterSlashing,
|
||||||
electra.BeaconBlock,
|
electra.BeaconBlock,
|
||||||
@ -257,6 +258,7 @@ RestJson.useDefaultSerializationFor(
|
|||||||
electra.LightClientHeader,
|
electra.LightClientHeader,
|
||||||
electra.LightClientOptimisticUpdate,
|
electra.LightClientOptimisticUpdate,
|
||||||
electra.LightClientUpdate,
|
electra.LightClientUpdate,
|
||||||
|
electra.SignedAggregateAndProof,
|
||||||
electra.SignedBeaconBlock,
|
electra.SignedBeaconBlock,
|
||||||
electra.TrustedAttestation,
|
electra.TrustedAttestation,
|
||||||
electra_mev.BlindedBeaconBlock,
|
electra_mev.BlindedBeaconBlock,
|
||||||
|
@ -87,6 +87,13 @@ proc publishAggregateAndProofs*(
|
|||||||
meth: MethodPost.}
|
meth: MethodPost.}
|
||||||
## https://ethereum.github.io/beacon-APIs/#/Validator/publishAggregateAndProofs
|
## https://ethereum.github.io/beacon-APIs/#/Validator/publishAggregateAndProofs
|
||||||
|
|
||||||
|
proc publishAggregateAndProofsV2*(
|
||||||
|
body: seq[phase0.SignedAggregateAndProof | electra.SignedAggregateAndProof]
|
||||||
|
): RestPlainResponse {.
|
||||||
|
rest, endpoint: "/eth/v2/validator/aggregate_and_proofs",
|
||||||
|
meth: MethodPost.}
|
||||||
|
## https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Validator/publishAggregateAndProofsV2
|
||||||
|
|
||||||
proc prepareBeaconCommitteeSubnet*(
|
proc prepareBeaconCommitteeSubnet*(
|
||||||
body: seq[RestCommitteeSubscription]
|
body: seq[RestCommitteeSubscription]
|
||||||
): RestPlainResponse {.
|
): RestPlainResponse {.
|
||||||
|
@ -264,7 +264,8 @@ proc routeAttestation*(
|
|||||||
attestation, subnet_id, checkSignature = true, checkValidator = true)
|
attestation, subnet_id, checkSignature = true, checkValidator = true)
|
||||||
|
|
||||||
proc routeSignedAggregateAndProof*(
|
proc routeSignedAggregateAndProof*(
|
||||||
router: ref MessageRouter, proof: phase0.SignedAggregateAndProof,
|
router: ref MessageRouter,
|
||||||
|
proof: phase0.SignedAggregateAndProof | electra.SignedAggregateAndProof,
|
||||||
checkSignature = true):
|
checkSignature = true):
|
||||||
Future[SendResult] {.async: (raises: [CancelledError]).} =
|
Future[SendResult] {.async: (raises: [CancelledError]).} =
|
||||||
## Validate and broadcast aggregate
|
## Validate and broadcast aggregate
|
||||||
|
Loading…
x
Reference in New Issue
Block a user