From eb767a2b325a304e196fca87dd8e644f1e8086d6 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Sat, 10 Sep 2022 13:25:55 +0200 Subject: [PATCH] Add support for system_nodeRoles (#2725) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- bin/light-base/src/json_rpc_service.rs | 5 ++++- bin/light-base/src/json_rpc_service/getters.rs | 17 ++++++++++++++++- bin/wasm-node/CHANGELOG.md | 4 ++++ src/json_rpc/methods.rs | 13 ++++++++++++- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/bin/light-base/src/json_rpc_service.rs b/bin/light-base/src/json_rpc_service.rs index 8b5785471c..be0e7483fb 100644 --- a/bin/light-base/src/json_rpc_service.rs +++ b/bin/light-base/src/json_rpc_service.rs @@ -918,6 +918,10 @@ impl Background { self.system_name(request_id, &state_machine_request_id) .await; } + methods::MethodCall::system_nodeRoles {} => { + self.system_node_roles(request_id, &state_machine_request_id) + .await; + } methods::MethodCall::system_peers {} => { self.system_peers(request_id, &state_machine_request_id) .await; @@ -1109,7 +1113,6 @@ impl Background { | methods::MethodCall::system_addReservedPeer { .. } | methods::MethodCall::system_dryRun { .. } | methods::MethodCall::system_networkState { .. } - | methods::MethodCall::system_nodeRoles { .. } | methods::MethodCall::system_removeReservedPeer { .. } | methods::MethodCall::network_unstable_subscribeEvents { .. } | methods::MethodCall::network_unstable_unsubscribeEvents { .. }) => { diff --git a/bin/light-base/src/json_rpc_service/getters.rs b/bin/light-base/src/json_rpc_service/getters.rs index 53ad29393d..eac46e18ed 100644 --- a/bin/light-base/src/json_rpc_service/getters.rs +++ b/bin/light-base/src/json_rpc_service/getters.rs @@ -19,7 +19,7 @@ use super::{Background, Platform}; -use alloc::{format, string::ToString as _, sync::Arc, vec::Vec}; +use alloc::{borrow::Cow, format, string::ToString as _, sync::Arc, vec::Vec}; use core::num::NonZeroUsize; use smoldot::{ header, @@ -251,6 +251,21 @@ impl Background { .await; } + /// Handles a call to [`methods::MethodCall::system_nodeRoles`]. + pub(super) async fn system_node_roles( + self: &Arc, + request_id: &str, + state_machine_request_id: &requests_subscriptions::RequestId, + ) { + self.requests_subscriptions + .respond( + state_machine_request_id, + methods::Response::system_nodeRoles(Cow::Borrowed(&[methods::NodeRole::Light])) + .to_json_response(request_id), + ) + .await; + } + /// Handles a call to [`methods::MethodCall::system_peers`]. pub(super) async fn system_peers( self: &Arc, diff --git a/bin/wasm-node/CHANGELOG.md b/bin/wasm-node/CHANGELOG.md index bcfd97a94f..6cff939c36 100644 --- a/bin/wasm-node/CHANGELOG.md +++ b/bin/wasm-node/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Added + +- Add support for the `system_nodeRoles` JSON-RPC method. ([#2725](https://github.com/paritytech/smoldot/pull/2725)) + ## 0.6.32 - 2022-09-07 ### Fixed diff --git a/src/json_rpc/methods.rs b/src/json_rpc/methods.rs index 83b836f094..3af43dfb33 100644 --- a/src/json_rpc/methods.rs +++ b/src/json_rpc/methods.rs @@ -393,7 +393,7 @@ define_methods! { /// Returns, as an opaque string, the name of the client serving these JSON-RPC requests. system_name() -> Cow<'a, str>, system_networkState() -> (), // TODO: - system_nodeRoles() -> (), // TODO: + system_nodeRoles() -> Cow<'a, [NodeRole]>, system_peers() -> Vec, system_properties() -> Box, system_removeReservedPeer() -> (), // TODO: @@ -900,6 +900,17 @@ pub enum MaybeRuntimeSpec<'a> { Invalid { error: String }, // TODO: String because it's more convenient; improve } +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +pub enum NodeRole { + // Note that "Light" isn't in the Substrate source code and is a custom addition. + #[serde(rename = "Light")] + Light, + #[serde(rename = "Full")] + Full, + #[serde(rename = "Authority")] + Authority, +} + #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct RuntimeSpec<'a> { #[serde(rename = "specName")]