Skip to content

Commit a78dd74

Browse files
authored
add version field to getPendingDeposits and getPendingPartialWithdrawals and implement getPendingConsolidations (#7170)
1 parent ff59a9e commit a78dd74

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

beacon_chain/rpc/rest_beacon_api.nim

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
17321732
else:
17331733
RestApiResponse.jsonError(Http500, InvalidAcceptError)
17341734

1735-
# https://ethereum.github.io/beacon-APIs/?urls.primaryName=v3.0.0#/Beacon/getPendingDeposits
1735+
# https://ethereum.github.io/beacon-APIs/?urls.primaryName=v3.1.0#/Beacon/getPendingDeposits
17361736
router.metricsApi2(
17371737
MethodGet, "/eth/v1/beacon/states/{state_id}/pending_deposits",
17381738
{RestServerMetricsType.Status, Response}) do (
@@ -1752,17 +1752,18 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
17521752
node.withStateForBlockSlotId(bslot):
17531753
return withState(state):
17541754
when consensusFork >= ConsensusFork.Electra:
1755-
RestApiResponse.jsonResponseFinalized(
1755+
RestApiResponse.jsonResponseFinalizedWVersion(
17561756
forkyState.data.pending_deposits,
17571757
node.getStateOptimistic(state),
1758-
node.dag.isFinalized(bslot.bid))
1758+
node.dag.isFinalized(bslot.bid),
1759+
consensusFork)
17591760
else:
17601761
RestApiResponse.jsonError(Http400, SlotFromTheIncorrectForkError,
17611762
$error)
17621763

17631764
RestApiResponse.jsonError(Http404, StateNotFoundError)
17641765

1765-
# https://ethereum.github.io/beacon-APIs/?urls.primaryName=v3.0.0#/Beacon/getPendingPartialWithdrawals
1766+
# https://ethereum.github.io/beacon-APIs/?urls.primaryName=v3.1.0#/Beacon/getPendingPartialWithdrawals
17661767
router.metricsApi2(
17671768
MethodGet, "/eth/v1/beacon/states/{state_id}/pending_partial_withdrawals",
17681769
{RestServerMetricsType.Status, Response}) do (
@@ -1782,10 +1783,42 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
17821783
node.withStateForBlockSlotId(bslot):
17831784
return withState(state):
17841785
when consensusFork >= ConsensusFork.Electra:
1785-
RestApiResponse.jsonResponseFinalized(
1786+
RestApiResponse.jsonResponseFinalizedWVersion(
17861787
forkyState.data.pending_partial_withdrawals,
17871788
node.getStateOptimistic(state),
1788-
node.dag.isFinalized(bslot.bid))
1789+
node.dag.isFinalized(bslot.bid),
1790+
consensusFork)
1791+
else:
1792+
RestApiResponse.jsonError(Http400, SlotFromTheIncorrectForkError,
1793+
$error)
1794+
1795+
RestApiResponse.jsonError(Http404, StateNotFoundError)
1796+
1797+
# https://ethereum.github.io/beacon-APIs/?urls.primaryName=v3.1.0#/Beacon/getPendingConsolidations
1798+
router.metricsApi2(
1799+
MethodGet, "/eth/v1/beacon/states/{state_id}/pending_consolidations",
1800+
{RestServerMetricsType.Status, Response}) do (
1801+
state_id: StateIdent) -> RestApiResponse:
1802+
let
1803+
sid = state_id.valueOr:
1804+
return RestApiResponse.jsonError(Http400, InvalidStateIdValueError,
1805+
$error)
1806+
bslot = node.getBlockSlotId(sid).valueOr:
1807+
if sid.kind == StateQueryKind.Root:
1808+
# TODO (cheatfate): Its impossible to retrieve state by `state_root`
1809+
# in current version of database.
1810+
return RestApiResponse.jsonError(Http500, NoImplementationError)
1811+
return RestApiResponse.jsonError(Http404, StateNotFoundError,
1812+
$error)
1813+
1814+
node.withStateForBlockSlotId(bslot):
1815+
return withState(state):
1816+
when consensusFork >= ConsensusFork.Electra:
1817+
RestApiResponse.jsonResponseFinalizedWVersion(
1818+
forkyState.data.pending_consolidations,
1819+
node.getStateOptimistic(state),
1820+
node.dag.isFinalized(bslot.bid),
1821+
consensusFork)
17891822
else:
17901823
RestApiResponse.jsonError(Http400, SlotFromTheIncorrectForkError,
17911824
$error)

beacon_chain/validators/keystore_management.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,7 @@ proc generateDeposits*(cfg: RuntimeConfig,
16721672
var derivedKey = baseKey
16731673
defer: burnMem(derivedKey)
16741674
derivedKey = deriveChildKey(derivedKey, validatorIdx)
1675-
derivedKey = deriveChildKey(derivedKey, 0) # This is witdrawal key
1675+
derivedKey = deriveChildKey(derivedKey, 0) # This is withdrawal key
16761676
let withdrawalPubKey = derivedKey.toPubKey
16771677
derivedKey = deriveChildKey(derivedKey, 0) # This is the signing key
16781678
let signingPubKey = derivedKey.toPubKey
@@ -1693,7 +1693,7 @@ proc generateDeposits*(cfg: RuntimeConfig,
16931693
var derivedKey = baseKey
16941694
defer: burnMem(derivedKey)
16951695
derivedKey = deriveChildKey(derivedKey, validatorIdx)
1696-
derivedKey = deriveChildKey(derivedKey, 0) # This is witdrawal key
1696+
derivedKey = deriveChildKey(derivedKey, 0) # This is withdrawal key
16971697
let withdrawalPubKey = derivedKey.toPubKey
16981698
derivedKey = deriveChildKey(derivedKey, 0) # This is the signing key
16991699
let signingPubKey = derivedKey.toPubKey

ncli/resttest-rules.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,6 +2623,18 @@
26232623
"body": [{"operator": "jstructcmpns", "value": {"code": 400, "message": ""}}]
26242624
}
26252625
},
2626+
{
2627+
"topics": ["beacon", "states_pending_consolidations"],
2628+
"request": {
2629+
"url": "/eth/v1/beacon/states/head/pending_consolidations",
2630+
"headers": {"Accept": "application/json"}
2631+
},
2632+
"response": {
2633+
"status": {"operator": "equals", "value": "400"},
2634+
"headers": [{"key": "Content-Type", "value": "application/json", "operator": "equals"}],
2635+
"body": [{"operator": "jstructcmpns", "value": {"code": 400, "message": ""}}]
2636+
}
2637+
},
26262638
{
26272639
"topics": ["beacon", "states_pending_deposits"],
26282640
"request": {

0 commit comments

Comments
 (0)