feat: implement new beacon APIs(accessors for pending_deposits/pending_partial_withdrawals) (#7006)

Resolves #7003


  Added two endpoints as https://github.com/ethereum/beacon-APIs/pull/500 proposed:
- `/eth/v1/beacon/states/{state_id}/pending_deposits`
- `/eth/v1/beacon/states/{state_id}/pending_partial_withdrawals`
This commit is contained in:
Jun Song
2025-03-17 10:46:50 +09:00
committed by GitHub
parent 3a555f571f
commit 50b5a72c58
3 changed files with 177 additions and 0 deletions

View File

@@ -1119,6 +1119,72 @@ pub fn serve<T: BeaconChainTypes>(
},
);
// GET beacon/states/{state_id}/pending_deposits
let get_beacon_state_pending_deposits = beacon_states_path
.clone()
.and(warp::path("pending_deposits"))
.and(warp::path::end())
.then(
|state_id: StateId,
task_spawner: TaskSpawner<T::EthSpec>,
chain: Arc<BeaconChain<T>>| {
task_spawner.blocking_json_task(Priority::P1, move || {
let (data, execution_optimistic, finalized) = state_id
.map_state_and_execution_optimistic_and_finalized(
&chain,
|state, execution_optimistic, finalized| {
let Ok(deposits) = state.pending_deposits() else {
return Err(warp_utils::reject::custom_bad_request(
"Pending deposits not found".to_string(),
));
};
Ok((deposits.clone(), execution_optimistic, finalized))
},
)?;
Ok(api_types::ExecutionOptimisticFinalizedResponse {
data,
execution_optimistic: Some(execution_optimistic),
finalized: Some(finalized),
})
})
},
);
// GET beacon/states/{state_id}/pending_partial_withdrawals
let get_beacon_state_pending_partial_withdrawals = beacon_states_path
.clone()
.and(warp::path("pending_partial_withdrawals"))
.and(warp::path::end())
.then(
|state_id: StateId,
task_spawner: TaskSpawner<T::EthSpec>,
chain: Arc<BeaconChain<T>>| {
task_spawner.blocking_json_task(Priority::P1, move || {
let (data, execution_optimistic, finalized) = state_id
.map_state_and_execution_optimistic_and_finalized(
&chain,
|state, execution_optimistic, finalized| {
let Ok(withdrawals) = state.pending_partial_withdrawals() else {
return Err(warp_utils::reject::custom_bad_request(
"Pending withdrawals not found".to_string(),
));
};
Ok((withdrawals.clone(), execution_optimistic, finalized))
},
)?;
Ok(api_types::ExecutionOptimisticFinalizedResponse {
data,
execution_optimistic: Some(execution_optimistic),
finalized: Some(finalized),
})
})
},
);
// GET beacon/headers
//
// Note: this endpoint only returns information about blocks in the canonical chain. Given that
@@ -4667,6 +4733,8 @@ pub fn serve<T: BeaconChainTypes>(
.uor(get_beacon_state_committees)
.uor(get_beacon_state_sync_committees)
.uor(get_beacon_state_randao)
.uor(get_beacon_state_pending_deposits)
.uor(get_beacon_state_pending_partial_withdrawals)
.uor(get_beacon_headers)
.uor(get_beacon_headers_block_id)
.uor(get_beacon_block)