Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove networkConfig parameters #963

Merged
merged 4 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions lib/src/json_rpc/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,13 @@ define_methods! {
// The functions below are experimental and are defined in the document https://github.com/paritytech/json-rpc-interface-spec/
chainHead_unstable_body(
#[rename = "followSubscription"] follow_subscription: Cow<'a, str>,
hash: HashHexString,
#[rename = "networkConfig"] network_config: Option<NetworkConfig>
hash: HashHexString
) -> Cow<'a, str>,
chainHead_unstable_call(
#[rename = "followSubscription"] follow_subscription: Cow<'a, str>,
hash: HashHexString,
function: Cow<'a, str>,
#[rename = "callParameters"] call_parameters: HexString,
#[rename = "networkConfig"] network_config: Option<NetworkConfig>
#[rename = "callParameters"] call_parameters: HexString
) -> Cow<'a, str>,
chainHead_unstable_follow(
#[rename = "withRuntime"] with_runtime: bool
Expand All @@ -479,8 +477,7 @@ define_methods! {
#[rename = "followSubscription"] follow_subscription: Cow<'a, str>,
hash: HashHexString,
items: Vec<ChainHeadStorageRequestItem>,
#[rename = "childTrie"] child_trie: Option<HexString>,
#[rename = "networkConfig"] network_config: Option<NetworkConfig>
#[rename = "childTrie"] child_trie: Option<HexString>
) -> Cow<'a, str>,
chainHead_unstable_storageContinue(
#[rename = "subscription"] subscription: Cow<'a, str>
Expand Down Expand Up @@ -998,16 +995,6 @@ pub struct HeaderDigest {
pub logs: Vec<HexString>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct NetworkConfig {
#[serde(rename = "totalAttempts")]
pub total_attempts: u32,
#[serde(rename = "maxParallel")]
pub max_parallel: u32, // TODO: NonZeroU32?
#[serde(rename = "timeoutMs")]
pub timeout_ms: u32,
}

#[derive(Debug, Clone)]
pub struct RpcMethods {
pub methods: Vec<String>,
Expand Down
59 changes: 12 additions & 47 deletions light-base/src/json_rpc_service/background/chain_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use alloc::{
vec::Vec,
};
use core::{
cmp, iter,
iter,
num::{NonZeroU32, NonZeroUsize},
time::Duration,
};
Expand Down Expand Up @@ -800,7 +800,6 @@ impl<TPlat: PlatformRef> ChainHeadFollowTask<TPlat> {
async fn start_chain_head_body(&mut self, request: service::SubscriptionStartProcess) {
let methods::MethodCall::chainHead_unstable_body {
hash,
network_config,
..
} = request.request()
else {
Expand All @@ -820,12 +819,6 @@ impl<TPlat: PlatformRef> ChainHeadFollowTask<TPlat> {
}
};

let network_config = network_config.unwrap_or(methods::NetworkConfig {
max_parallel: 1,
timeout_ms: 4000,
total_attempts: 3,
});

let mut subscription = request.accept();
let subscription_id = subscription.subscription_id().to_owned();

Expand All @@ -843,12 +836,9 @@ impl<TPlat: PlatformRef> ChainHeadFollowTask<TPlat> {
body: true,
justifications: false,
},
cmp::min(10, network_config.total_attempts),
Duration::from_millis(u64::from(cmp::min(
20000,
network_config.timeout_ms,
))),
NonZeroU32::new(network_config.max_parallel.clamp(1, 5)).unwrap(),
3,
Duration::from_secs(20),
NonZeroU32::new(2).unwrap(),
);

// Drive the future, but cancel execution if the JSON-RPC client
Expand Down Expand Up @@ -900,7 +890,6 @@ impl<TPlat: PlatformRef> ChainHeadFollowTask<TPlat> {
hash,
items,
child_trie,
network_config,
..
} = request.request()
else {
Expand All @@ -918,12 +907,6 @@ impl<TPlat: PlatformRef> ChainHeadFollowTask<TPlat> {
}
};

let network_config = network_config.unwrap_or(methods::NetworkConfig {
max_parallel: 1,
timeout_ms: 8000,
total_attempts: 3,
});

if child_trie.is_some() {
// TODO: implement this
request.fail(json_rpc::parse::ErrorResponse::ServerError(
Expand Down Expand Up @@ -998,12 +981,9 @@ impl<TPlat: PlatformRef> ChainHeadFollowTask<TPlat> {
&hash.0,
decoded_header.state_root,
queries.into_iter(),
cmp::min(10, network_config.total_attempts),
Duration::from_millis(u64::from(cmp::min(
20000,
network_config.timeout_ms,
))),
NonZeroU32::new(network_config.max_parallel.clamp(1, 5)).unwrap(),
3,
Duration::from_secs(20),
NonZeroU32::new(2).unwrap(),
);

// Drive the future, but cancel execution if the JSON-RPC client
Expand Down Expand Up @@ -1102,30 +1082,18 @@ impl<TPlat: PlatformRef> ChainHeadFollowTask<TPlat> {
}

async fn start_chain_head_call(&mut self, request: service::SubscriptionStartProcess) {
let (hash, function_to_call, call_parameters, network_config) = {
let (hash, function_to_call, call_parameters) = {
let methods::MethodCall::chainHead_unstable_call {
hash,
function,
call_parameters,
network_config,
..
} = request.request()
else {
unreachable!()
};

let network_config = network_config.unwrap_or(methods::NetworkConfig {
max_parallel: 1,
timeout_ms: 8000,
total_attempts: 3,
});

(
hash,
function.into_owned(),
call_parameters.0,
network_config,
)
(hash, function.into_owned(), call_parameters.0)
};

// Determine whether the requested block hash is valid and start the call.
Expand Down Expand Up @@ -1180,12 +1148,9 @@ impl<TPlat: PlatformRef> ChainHeadFollowTask<TPlat> {
let call_future = pre_runtime_call.start(
&function_to_call,
iter::once(&call_parameters),
cmp::min(10, network_config.total_attempts),
Duration::from_millis(u64::from(cmp::min(
20000,
network_config.timeout_ms,
))),
NonZeroU32::new(network_config.max_parallel.clamp(1, 5)).unwrap(),
3,
Duration::from_secs(20),
NonZeroU32::new(2).unwrap(),
);

// Drive the future, but cancel execution if the JSON-RPC client unsubscribes.
Expand Down
1 change: 1 addition & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Changed

- Remove `networkConfig` parameter from all `chainHead` JSON-RPC functions, in accordance with the latest changes to the JSON-RPC API specification. ([#963](https://github.com/smol-dot/smoldot/pull/963))
- A JSON-RPC error is now returned if the JSON-RPC client tries to open more than two simultaneous `chainHead_unstable_follow` subscriptions, in accordance with the latest changes in the JSON-RPC API specification. ([#962](https://github.com/smol-dot/smoldot/pull/962))

## 1.0.13 - 2023-07-16
Expand Down