Skip to content

Commit cddfc15

Browse files
committed
skeleton of changes for nym api batch requests
1 parent b6480f1 commit cddfc15

File tree

4 files changed

+77
-17
lines changed

4 files changed

+77
-17
lines changed

common/client-libs/validator-client/src/client.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,11 @@ impl NymApiClient {
498498
Ok(nodes)
499499
}
500500

501+
/// retrieve basic information for all bonded nodes on the network
502+
pub async fn retrieve_basic_nodes_batch(&self, node_ids: Vec<u32>) -> Result<Vec<SkimmedNode>, ValidatorClientError> {
503+
Ok(self.nym_api.retrieve_basic_nodes_batch(&node_ids).await?.nodes)
504+
}
505+
501506
pub async fn health(&self) -> Result<ApiHealthResponse, ValidatorClientError> {
502507
Ok(self.nym_api.health().await?)
503508
}

common/client-libs/validator-client/src/nym_api/mod.rs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,10 @@ pub trait NymApiClientExt: ApiClient {
256256
self.get_json(
257257
&[
258258
routes::API_VERSION,
259-
"unstable",
259+
routes::UNSTABLE,
260260
routes::NYM_NODES_ROUTES,
261261
"mixnodes",
262-
"skimmed",
262+
routes::SKIMMED,
263263
],
264264
NO_PARAMS,
265265
)
@@ -272,10 +272,10 @@ pub trait NymApiClientExt: ApiClient {
272272
self.get_json(
273273
&[
274274
routes::API_VERSION,
275-
"unstable",
275+
routes::UNSTABLE,
276276
routes::NYM_NODES_ROUTES,
277277
"gateways",
278-
"skimmed",
278+
routes::SKIMMED,
279279
],
280280
NO_PARAMS,
281281
)
@@ -321,9 +321,9 @@ pub trait NymApiClientExt: ApiClient {
321321
self.get_json(
322322
&[
323323
routes::API_VERSION,
324-
"unstable",
324+
routes::UNSTABLE,
325325
routes::NYM_NODES_ROUTES,
326-
"skimmed",
326+
routes::SKIMMED,
327327
"entry-gateways",
328328
"all",
329329
],
@@ -358,9 +358,9 @@ pub trait NymApiClientExt: ApiClient {
358358
self.get_json(
359359
&[
360360
routes::API_VERSION,
361-
"unstable",
361+
routes::UNSTABLE,
362362
routes::NYM_NODES_ROUTES,
363-
"skimmed",
363+
routes::SKIMMED,
364364
"mixnodes",
365365
"active",
366366
],
@@ -395,9 +395,9 @@ pub trait NymApiClientExt: ApiClient {
395395
self.get_json(
396396
&[
397397
routes::API_VERSION,
398-
"unstable",
398+
routes::UNSTABLE,
399399
routes::NYM_NODES_ROUTES,
400-
"skimmed",
400+
routes::SKIMMED,
401401
"mixnodes",
402402
"all",
403403
],
@@ -406,6 +406,31 @@ pub trait NymApiClientExt: ApiClient {
406406
.await
407407
}
408408

409+
/// Send a Post request with a set of node ids. A successful response will contain descriptors
410+
/// for all nodes associated with those node IDs available in the current full topology.
411+
///
412+
/// If a provided node ID is not present there will be no descriptor for that node in the response.
413+
///
414+
/// If no node IDs are provided the response will contain no descriptors.
415+
#[instrument(level = "debug", skip(self))]
416+
async fn retrieve_basic_nodes_batch(
417+
&self,
418+
node_ids: &[NodeId],
419+
) -> Result<CachedNodesResponse<SkimmedNode>, NymAPIError> {
420+
self.post_json(
421+
&[
422+
routes::API_VERSION,
423+
routes::UNSTABLE,
424+
routes::NYM_NODES_ROUTES,
425+
routes::SKIMMED,
426+
routes::BATCH,
427+
],
428+
NO_PARAMS,
429+
node_ids,
430+
)
431+
.await
432+
}
433+
409434
#[instrument(level = "debug", skip(self))]
410435
async fn get_basic_nodes(
411436
&self,
@@ -430,9 +455,9 @@ pub trait NymApiClientExt: ApiClient {
430455
self.get_json(
431456
&[
432457
routes::API_VERSION,
433-
"unstable",
458+
routes::UNSTABLE,
434459
routes::NYM_NODES_ROUTES,
435-
"skimmed",
460+
routes::SKIMMED,
436461
],
437462
&params,
438463
)

common/client-libs/validator-client/src/nym_api/routes.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,7 @@ pub const SERVICE_PROVIDERS: &str = "services";
7171

7272
pub const DETAILS: &str = "details";
7373
pub const NETWORK: &str = "network";
74+
75+
pub const UNSTABLE: &str = "unstable";
76+
pub const SKIMMED: &str = "skimmed";
77+
pub const BATCH: &str = "batch";

nym-api/src/nym_nodes/handlers/unstable/skimmed.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use tracing::trace;
2525
use utoipa::ToSchema;
2626

2727
pub type PaginatedSkimmedNodes = AxumResult<Json<PaginatedCachedNodesResponse<SkimmedNode>>>;
28+
type SkimmedNodes = AxumResult<Json<CachedNodesResponse<SkimmedNode>>>;
2829

2930
/// Given all relevant caches, build part of response for JUST Nym Nodes
3031
fn build_nym_nodes_response<'a, NI>(
@@ -196,7 +197,7 @@ where
196197
pub(super) async fn deprecated_gateways_basic(
197198
state: State<AppState>,
198199
query_params: Query<NodesParams>,
199-
) -> AxumResult<Json<CachedNodesResponse<SkimmedNode>>> {
200+
) -> SkimmedNodes {
200201
// 1. call '/v1/unstable/skimmed/entry-gateways/all'
201202
let all_gateways = entry_gateways_basic_all(state, query_params).await?;
202203

@@ -223,7 +224,7 @@ pub(super) async fn deprecated_gateways_basic(
223224
pub(super) async fn deprecated_mixnodes_basic(
224225
state: State<AppState>,
225226
query_params: Query<NodesParams>,
226-
) -> AxumResult<Json<CachedNodesResponse<SkimmedNode>>> {
227+
) -> SkimmedNodes {
227228
// 1. call '/v1/unstable/nym-nodes/skimmed/mixnodes/active'
228229
let active_mixnodes = mixnodes_basic_active(state, query_params).await?;
229230

@@ -239,7 +240,7 @@ async fn nodes_basic(
239240
state: State<AppState>,
240241
Query(_query_params): Query<NodesParams>,
241242
active_only: bool,
242-
) -> PaginatedSkimmedNodes {
243+
) -> SkimmedNodes {
243244
// unfortunately we have to build the response semi-manually here as we need to add two sources of legacy nodes
244245

245246
// 1. grab all relevant described nym-nodes
@@ -281,10 +282,10 @@ async fn nodes_basic(
281282
legacy_gateways.timestamp(),
282283
]);
283284

284-
Ok(Json(PaginatedCachedNodesResponse::new_full(
285+
Ok(Json(CachedNodesResponse {
285286
refreshed_at,
286287
nodes,
287-
)))
288+
}))
288289
}
289290

290291
#[allow(dead_code)] // not dead, used in OpenAPI docs
@@ -329,6 +330,31 @@ pub(super) async fn nodes_basic_all(
329330
nodes_basic(state, Query(query_params.into()), false).await
330331
}
331332

333+
/// Post request handler taking a json array of NodeId (u32) values and returning descriptors for
334+
/// the provided NodeId values. A successful response will contain descriptors for all nodes
335+
/// associated with those node IDs available in the current full topology.
336+
///
337+
/// If a provided node ID is not present in the current topology there will be no descriptor for
338+
/// that node in the response.
339+
///
340+
/// If no node IDs are provided the response will contain no descriptors.
341+
#[utoipa::path(
342+
tag = "Unstable Nym Nodes batch by Node ID",
343+
get,
344+
params(NodesParamsWithRole),
345+
path = "batch",
346+
context_path = "/v1/unstable/nym-nodes/skimmed",
347+
responses(
348+
(status = 200, body = PaginatedCachedNodesResponseSchema)
349+
)
350+
)]
351+
pub(super) async fn nodes_basic_batch(
352+
state: State<AppState>,
353+
Query(query_params): Query<NodesParamsWithRole>,
354+
) -> SkimmedNodes {
355+
nodes_basic(state, Query(query_params.into()), false).await
356+
}
357+
332358
/// Return Nym Nodes and optionally legacy mixnodes/gateways (if `no-legacy` flag is not used)
333359
/// that are currently bonded and are in the **active set**
334360
#[utoipa::path(

0 commit comments

Comments
 (0)