new pool attester slashings endpoint version (V2) for electra ()

* new pool attester slashings endpoint version (V2) for electra

* formatting

---------

Co-authored-by: Pedro Miranda <pedro.miranda@nimbus.team>
This commit is contained in:
Pedro Miranda 2024-09-28 01:00:26 +01:00 committed by GitHub
parent a441695c51
commit 4beb890385
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 78 additions and 2 deletions

View File

@ -1509,6 +1509,55 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
$res.error)
RestApiResponse.jsonMsgResponse(AttesterSlashingValidationSuccess)
# https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Beacon/getPoolAttesterSlashingsV2
router.api2(MethodGet, "/eth/v2/beacon/pool/attester_slashings") do (
) -> RestApiResponse:
let contextFork =
node.dag.cfg.consensusForkAtEpoch(node.currentSlot.epoch)
withConsensusFork(contextFork):
when consensusFork < ConsensusFork.Electra:
RestApiResponse.jsonResponseWVersion(
toSeq(node.validatorChangePool.phase0_attester_slashings),
contextFork)
else:
RestApiResponse.jsonResponseWVersion(
toSeq(node.validatorChangePool.electra_attester_slashings),
contextFork)
# https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Beacon/submitPoolAttesterSlashingsV2
router.api(MethodPost, "/eth/v2/beacon/pool/attester_slashings") do (
contentBody: Option[ContentBody]) -> RestApiResponse:
let
headerVersion = request.headers.getString("Eth-Consensus-Version")
consensusVersion = ConsensusFork.init(headerVersion)
if consensusVersion.isNone():
return RestApiResponse.jsonError(Http400, FailedToObtainConsensusForkError)
if contentBody.isNone():
return RestApiResponse.jsonError(Http400, EmptyRequestBodyError)
template decodeAttesterSlashing(AttesterSlashingType: untyped) =
let dres = decodeBody(AttesterSlashingType, contentBody.get())
if dres.isErr():
return RestApiResponse.jsonError(Http400,
InvalidAttesterSlashingObjectError,
$dres.error)
let res = await node.router.routeAttesterSlashing(dres.get())
if res.isErr():
return RestApiResponse.jsonError(Http400,
AttesterSlashingValidationError,
$res.error)
return RestApiResponse.jsonMsgResponse(AttesterSlashingValidationSuccess)
case consensusVersion.get():
of ConsensusFork.Phase0 .. ConsensusFork.Deneb:
decodeAttesterSlashing(phase0.AttesterSlashing)
of ConsensusFork.Electra:
decodeAttesterSlashing(electra.AttesterSlashing)
# https://ethereum.github.io/beacon-APIs/#/Beacon/getPoolProposerSlashings
router.api2(MethodGet, "/eth/v1/beacon/pool/proposer_slashings") do (
) -> RestApiResponse:

View File

@ -359,6 +359,18 @@ proc submitPoolAttesterSlashings*(body: phase0.AttesterSlashing):
meth: MethodPost.}
## https://ethereum.github.io/beacon-APIs/#/Beacon/submitPoolAttesterSlashings
proc getPoolAttesterSlashingsV2Plain*(): RestPlainResponse {.
rest, endpoint: "/eth/v2/beacon/pool/attester_slashings",
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Beacon/getPoolAttesterSlashingsV2
proc submitPoolAttesterSlashings*(
body: phase0.AttesterSlashing | electra.AttesterSlashing
): RestPlainResponse {.
rest, endpoint: "/eth/v1/beacon/pool/attester_slashings",
meth: MethodPost.}
## https://ethereum.github.io/beacon-APIs/#/Beacon/submitPoolAttesterSlashings
proc getPoolProposerSlashings*(): RestResponse[GetPoolProposerSlashingsResponse] {.
rest, endpoint: "/eth/v1/beacon/pool/proposer_slashings",
meth: MethodGet.}
@ -369,7 +381,9 @@ proc submitPoolProposerSlashings*(body: ProposerSlashing): RestPlainResponse {.
meth: MethodPost.}
## https://ethereum.github.io/beacon-APIs/#/Beacon/submitPoolProposerSlashings
proc submitPoolSyncCommitteeSignatures*(body: seq[RestSyncCommitteeMessage]): RestPlainResponse {.
proc submitPoolSyncCommitteeSignatures*(
body: seq[RestSyncCommitteeMessage]
): RestPlainResponse {.
rest, endpoint: "/eth/v1/beacon/pool/sync_committees",
meth: MethodPost.}
## https://ethereum.github.io/beacon-APIs/#/Beacon/submitPoolSyncCommitteeSignatures

View File

@ -483,7 +483,8 @@ proc routeSignedVoluntaryExit*(
return ok()
proc routeAttesterSlashing*(
router: ref MessageRouter, slashing: phase0.AttesterSlashing):
router: ref MessageRouter,
slashing: phase0.AttesterSlashing | electra.AttesterSlashing):
Future[SendResult] {.async: (raises: [CancelledError]).} =
block:
let res =

View File

@ -3975,6 +3975,18 @@
"body": [{"operator": "jstructcmps", "start": ["data"],"value": [{"attestation_1": {"attesting_indices": [""], "signature": "", "data": {"slot": "", "index": "", "beacon_block_root": "", "source": {"epoch": "", "root": ""}, "target": {"epoch": "", "root": ""}}}, "attestation_2": {"attesting_indices": [""], "signature": "", "data": {"slot": "", "index": "", "beacon_block_root": "", "source": {"epoch": "", "root": ""}, "target": {"epoch": "", "root": ""}}}}]}]
}
},
{
"topics": ["beacon", "pool_attester_slashings_electra"],
"request": {
"url": "/eth/v2/beacon/pool/attester_slashings",
"headers": {"Accept": "application/json"}
},
"response": {
"status": {"operator": "equals", "value": "200"},
"headers": [{"key": "Content-Type", "value": "application/json", "operator": "equals"}, {"key": "eth-consensus-version", "value": ["phase0", "altair", "bellatrix"], "operator": "oneof"}],
"body": [{"operator": "jstructcmps", "start": ["data"],"value": [{"attestation_1": {"attesting_indices": [""], "signature": "", "data": {"slot": "", "index": "", "beacon_block_root": "", "source": {"epoch": "", "root": ""}, "target": {"epoch": "", "root": ""}}}, "attestation_2": {"attesting_indices": [""], "signature": "", "data": {"slot": "", "index": "", "beacon_block_root": "", "source": {"epoch": "", "root": ""}, "target": {"epoch": "", "root": ""}}}}]}]
}
},
{
"topics": ["beacon", "pool_proposer_slashings"],
"request": {