Started aligning API spec with implementation.
- Adding some missing fields to structs - Rearranged the endpoints in the rest_api router, and renamed, using an 'implementation_pending' function - Added 'content-type' headers, to distinguish difference with /node/metrics - Updated OpenAPI spec to v0.2.0 - Split /node/fork into /node/chain_id and /beacon/fork - Moved /metrics to /node/metrics - Added example to /node/metrics, since it's text/plain - Moved /node/network to just /network - Added lots of stubs for endpoints which exist in the router - Reordered large parts of the OpenAPI spec - Moved /chain/beacon/... to just /beacon/...
This commit is contained in:
parent
328f11d564
commit
16ec330a79
@ -12,6 +12,11 @@ pub struct HeadResponse {
|
|||||||
pub slot: Slot,
|
pub slot: Slot,
|
||||||
pub block_root: Hash256,
|
pub block_root: Hash256,
|
||||||
pub state_root: Hash256,
|
pub state_root: Hash256,
|
||||||
|
/* Not implemented:
|
||||||
|
pub finalized_slot: Slot,
|
||||||
|
pub finalized_block_root: Hash256,
|
||||||
|
pub justified_slot: Hash256,
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/// HTTP handler to return a `BeaconBlock` at a given `root` or `slot`.
|
/// HTTP handler to return a `BeaconBlock` at a given `root` or `slot`.
|
||||||
|
@ -124,27 +124,17 @@ pub fn start_server<T: BeaconChainTypes>(
|
|||||||
|
|
||||||
// Route the request to the correct handler.
|
// Route the request to the correct handler.
|
||||||
let result = match (req.method(), path.as_ref()) {
|
let result = match (req.method(), path.as_ref()) {
|
||||||
// Methods for Beacon Node
|
// Methods for Client
|
||||||
//TODO: Remove?
|
(&Method::GET, "/node/version") => node::get_version(req),
|
||||||
//(&Method::GET, "/beacon/best_slot") => beacon::get_best_slot::<T>(req),
|
(&Method::GET, "/node/genesis_time") => node::get_genesis_time::<T>(req),
|
||||||
(&Method::GET, "/beacon/head") => beacon::get_head::<T>(req),
|
(&Method::GET, "/node/deposit_contract") => {
|
||||||
(&Method::GET, "/beacon/block") => beacon::get_block::<T>(req),
|
|
||||||
(&Method::GET, "/beacon/blocks") => helpers::implementation_pending_response(req),
|
|
||||||
//TODO Is the below replaced by finalized_checkpoint?
|
|
||||||
(&Method::GET, "/beacon/chainhead") => {
|
|
||||||
helpers::implementation_pending_response(req)
|
helpers::implementation_pending_response(req)
|
||||||
}
|
}
|
||||||
(&Method::GET, "/beacon/block_root") => beacon::get_block_root::<T>(req),
|
(&Method::GET, "/node/syncing") => helpers::implementation_pending_response(req),
|
||||||
(&Method::GET, "/beacon/latest_finalized_checkpoint") => {
|
(&Method::GET, "/node/chain_id") => helpers::implementation_pending_response(req),
|
||||||
beacon::get_latest_finalized_checkpoint::<T>(req)
|
(&Method::GET, "/node/metrics") => metrics::get_prometheus::<T>(req),
|
||||||
}
|
|
||||||
(&Method::GET, "/beacon/state") => beacon::get_state::<T>(req),
|
|
||||||
(&Method::GET, "/beacon/state_root") => beacon::get_state_root::<T>(req),
|
|
||||||
|
|
||||||
//TODO: Add aggreggate/filtered state lookups here, e.g. /beacon/validators/balances
|
// Methods for Network
|
||||||
|
|
||||||
// Methods for Client
|
|
||||||
(&Method::GET, "/metrics") => metrics::get_prometheus::<T>(req),
|
|
||||||
(&Method::GET, "/network/enr") => network::get_enr::<T>(req),
|
(&Method::GET, "/network/enr") => network::get_enr::<T>(req),
|
||||||
(&Method::GET, "/network/peer_count") => network::get_peer_count::<T>(req),
|
(&Method::GET, "/network/peer_count") => network::get_peer_count::<T>(req),
|
||||||
(&Method::GET, "/network/peer_id") => network::get_peer_id::<T>(req),
|
(&Method::GET, "/network/peer_id") => network::get_peer_id::<T>(req),
|
||||||
@ -153,36 +143,54 @@ pub fn start_server<T: BeaconChainTypes>(
|
|||||||
(&Method::GET, "/network/listen_addresses") => {
|
(&Method::GET, "/network/listen_addresses") => {
|
||||||
network::get_listen_addresses::<T>(req)
|
network::get_listen_addresses::<T>(req)
|
||||||
}
|
}
|
||||||
(&Method::GET, "/node/version") => node::get_version(req),
|
(&Method::GET, "/network/stats") => helpers::implementation_pending_response(req),
|
||||||
(&Method::GET, "/node/genesis_time") => node::get_genesis_time::<T>(req),
|
(&Method::GET, "/network/block_discovery") => {
|
||||||
(&Method::GET, "/node/deposit_contract") => {
|
|
||||||
helpers::implementation_pending_response(req)
|
helpers::implementation_pending_response(req)
|
||||||
}
|
}
|
||||||
(&Method::GET, "/node/syncing") => helpers::implementation_pending_response(req),
|
|
||||||
(&Method::GET, "/node/fork") => helpers::implementation_pending_response(req),
|
|
||||||
|
|
||||||
// Methods for Network
|
// Methods for Beacon Node
|
||||||
(&Method::GET, "/network/enr") => network::get_enr::<T>(req),
|
//TODO: Remove?
|
||||||
(&Method::GET, "/network/peer_count") => network::get_peer_count::<T>(req),
|
//(&Method::GET, "/beacon/best_slot") => beacon::get_best_slot::<T>(req),
|
||||||
(&Method::GET, "/network/peer_id") => network::get_peer_id::<T>(req),
|
(&Method::GET, "/beacon/head") => beacon::get_head::<T>(req),
|
||||||
(&Method::GET, "/network/peers") => network::get_peer_list::<T>(req),
|
(&Method::GET, "/beacon/block") => beacon::get_block::<T>(req),
|
||||||
(&Method::GET, "/network/listen_addresses") => {
|
(&Method::GET, "/beacon/block_root") => beacon::get_block_root::<T>(req),
|
||||||
network::get_listen_addresses::<T>(req)
|
(&Method::GET, "/beacon/blocks") => helpers::implementation_pending_response(req),
|
||||||
|
(&Method::GET, "/beacon/fork") => helpers::implementation_pending_response(req),
|
||||||
|
(&Method::GET, "/beacon/latest_finalized_checkpoint") => {
|
||||||
|
beacon::get_latest_finalized_checkpoint::<T>(req)
|
||||||
|
}
|
||||||
|
(&Method::GET, "/beacon/attestations") => {
|
||||||
|
helpers::implementation_pending_response(req)
|
||||||
|
}
|
||||||
|
(&Method::GET, "/beacon/attestations/pending") => {
|
||||||
|
helpers::implementation_pending_response(req)
|
||||||
|
}
|
||||||
|
(&Method::GET, "/beacon/attestations") => {
|
||||||
|
helpers::implementation_pending_response(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Methods for Validator
|
// Methods for Validator
|
||||||
(&Method::GET, "/validator/duties") => validator::get_validator_duties::<T>(req),
|
(&Method::GET, "/beacon/validator/duties") => {
|
||||||
(&Method::GET, "/validator/block") => helpers::implementation_pending_response(req),
|
validator::get_validator_duties::<T>(req)
|
||||||
(&Method::POST, "/validator/block") => {
|
}
|
||||||
|
(&Method::GET, "/beacon/validator/block") => {
|
||||||
helpers::implementation_pending_response(req)
|
helpers::implementation_pending_response(req)
|
||||||
}
|
}
|
||||||
(&Method::GET, "/validator/attestation") => {
|
(&Method::POST, "/beacon/validator/block") => {
|
||||||
helpers::implementation_pending_response(req)
|
helpers::implementation_pending_response(req)
|
||||||
}
|
}
|
||||||
(&Method::POST, "/validator/attestation") => {
|
(&Method::GET, "/beacon/validator/attestation") => {
|
||||||
|
helpers::implementation_pending_response(req)
|
||||||
|
}
|
||||||
|
(&Method::POST, "/beacon/validator/attestation") => {
|
||||||
helpers::implementation_pending_response(req)
|
helpers::implementation_pending_response(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(&Method::GET, "/beacon/state") => beacon::get_state::<T>(req),
|
||||||
|
(&Method::GET, "/beacon/state_root") => beacon::get_state_root::<T>(req),
|
||||||
|
//TODO: Add aggreggate/filtered state lookups here, e.g. /beacon/validators/balances
|
||||||
|
|
||||||
|
// Methods for bootstrap and checking configuration
|
||||||
(&Method::GET, "/spec") => spec::get_spec::<T>(req),
|
(&Method::GET, "/spec") => spec::get_spec::<T>(req),
|
||||||
(&Method::GET, "/spec/slots_per_epoch") => spec::get_slots_per_epoch::<T>(req),
|
(&Method::GET, "/spec/slots_per_epoch") => spec::get_slots_per_epoch::<T>(req),
|
||||||
|
|
||||||
@ -237,6 +245,7 @@ pub fn start_server<T: BeaconChainTypes>(
|
|||||||
fn success_response(body: Body) -> Response<Body> {
|
fn success_response(body: Body) -> Response<Body> {
|
||||||
Response::builder()
|
Response::builder()
|
||||||
.status(StatusCode::OK)
|
.status(StatusCode::OK)
|
||||||
|
.header("content-type", "application/json")
|
||||||
.body(body)
|
.body(body)
|
||||||
.expect("We should always be able to make response from the success body.")
|
.expect("We should always be able to make response from the success body.")
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,14 @@ pub fn get_prometheus<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiR
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
String::from_utf8(buffer)
|
String::from_utf8(buffer)
|
||||||
.map(|string| success_response(Body::from(string)))
|
.map(|string| {
|
||||||
|
let mut response = success_response(Body::from(string));
|
||||||
|
// Need to change the header to text/plain for prometheius
|
||||||
|
response
|
||||||
|
.headers_mut()
|
||||||
|
.insert("content-type", "text/plain; charset=utf-8".parse().unwrap())
|
||||||
|
.unwrap();
|
||||||
|
response
|
||||||
|
})
|
||||||
.map_err(|e| ApiError::ServerError(format!("Failed to encode prometheus info: {:?}", e)))
|
.map_err(|e| ApiError::ServerError(format!("Failed to encode prometheus info: {:?}", e)))
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ pub fn get_listen_addresses<T: BeaconChainTypes>(req: Request<Body>) -> ApiResul
|
|||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// HTTP handle to return the list of libp2p multiaddr the client is listening on.
|
/// HTTP handle to return network port the client is listening on.
|
||||||
///
|
///
|
||||||
/// Returns a list of `Multiaddr`, serialized according to their `serde` impl.
|
/// Returns a list of `Multiaddr`, serialized according to their `serde` impl.
|
||||||
pub fn get_listen_port<T: BeaconChainTypes>(req: Request<Body>) -> ApiResult {
|
pub fn get_listen_port<T: BeaconChainTypes>(req: Request<Body>) -> ApiResult {
|
||||||
|
1084
docs/rest_oapi.yaml
1084
docs/rest_oapi.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user