Skip to content

Commit

Permalink
Add support for system_nodeRoles (#2725)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
tomaka and mergify[bot] authored Sep 10, 2022
1 parent b193cab commit eb767a2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
5 changes: 4 additions & 1 deletion bin/light-base/src/json_rpc_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,10 @@ impl<TPlat: Platform> Background<TPlat> {
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;
Expand Down Expand Up @@ -1109,7 +1113,6 @@ impl<TPlat: Platform> Background<TPlat> {
| 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 { .. }) => {
Expand Down
17 changes: 16 additions & 1 deletion bin/light-base/src/json_rpc_service/getters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -251,6 +251,21 @@ impl<TPlat: Platform> Background<TPlat> {
.await;
}

/// Handles a call to [`methods::MethodCall::system_nodeRoles`].
pub(super) async fn system_node_roles(
self: &Arc<Self>,
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<Self>,
Expand Down
4 changes: 4 additions & 0 deletions bin/wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion src/json_rpc/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SystemPeer>,
system_properties() -> Box<serde_json::value::RawValue>,
system_removeReservedPeer() -> (), // TODO:
Expand Down Expand Up @@ -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")]
Expand Down

0 comments on commit eb767a2

Please sign in to comment.