diff --git a/full-node/src/json_rpc_service.rs b/full-node/src/json_rpc_service.rs index 8b35ee77c6..0a6d4c3c3d 100644 --- a/full-node/src/json_rpc_service.rs +++ b/full-node/src/json_rpc_service.rs @@ -570,7 +570,7 @@ fn spawn_client_main_task( client_main_task = task; match request_process.request() { - methods::MethodCall::chainHead_unstable_header { + methods::MethodCall::chainHead_v1_header { follow_subscription, .. } => { @@ -585,10 +585,10 @@ fn spawn_client_main_task( // TODO racy; doesn't handle situation where follow subscription stops } else { request_process - .respond(methods::Response::chainHead_unstable_header(None)); + .respond(methods::Response::chainHead_v1_header(None)); } } - methods::MethodCall::chainHead_unstable_unpin { + methods::MethodCall::chainHead_v1_unpin { follow_subscription, hash_or_hashes, } => { @@ -614,14 +614,12 @@ fn spawn_client_main_task( match outcome_rx.await { Err(_) => { - request_process.respond( - methods::Response::chainHead_unstable_unpin(()), - ); + request_process + .respond(methods::Response::chainHead_v1_unpin(())); } Ok(Ok(())) => { - request_process.respond( - methods::Response::chainHead_unstable_unpin(()), - ); + request_process + .respond(methods::Response::chainHead_v1_unpin(())); } Ok(Err(())) => { request_process.fail(service::ErrorResponse::InvalidParams); @@ -645,7 +643,7 @@ fn spawn_client_main_task( match subscription_start.request() { // TODO: enforce limit to number of subscriptions - methods::MethodCall::chainHead_unstable_follow { with_runtime } => { + methods::MethodCall::chainHead_v1_follow { with_runtime } => { let (tx, rx) = async_channel::bounded(16); let subscription_id = chain_head_subscriptions::spawn_chain_head_subscription_task( diff --git a/full-node/src/json_rpc_service/chain_head_subscriptions.rs b/full-node/src/json_rpc_service/chain_head_subscriptions.rs index 328f1d6da9..10d7c7abcb 100644 --- a/full-node/src/json_rpc_service/chain_head_subscriptions.rs +++ b/full-node/src/json_rpc_service/chain_head_subscriptions.rs @@ -45,10 +45,10 @@ pub struct Config { /// Receiver for actions that the JSON-RPC client wants to perform. pub receiver: async_channel::Receiver, - /// `chainHead_unstable_follow` subscription start handle. + /// `chainHead_v1_follow` subscription start handle. pub chain_head_follow_subscription: service::SubscriptionStartProcess, - /// Parameter that was passed by the user when requesting `chainHead_unstable_follow`. + /// Parameter that was passed by the user when requesting `chainHead_v1_follow`. pub with_runtime: bool, /// Consensus service of the chain. @@ -68,7 +68,7 @@ pub enum Message { }, } -/// Spawns a new tasks dedicated to handling a `chainHead_unstable_follow` subscription. +/// Spawns a new tasks dedicated to handling a `chainHead_v1_follow` subscription. /// /// Returns the identifier of the subscription. pub async fn spawn_chain_head_subscription_task(config: Config) -> String { @@ -93,7 +93,7 @@ pub async fn spawn_chain_head_subscription_task(config: Config) -> String { pinned_blocks.insert(consensus_service_subscription.finalized_block_hash); json_rpc_subscription - .send_notification(methods::ServerToClient::chainHead_unstable_followEvent { + .send_notification(methods::ServerToClient::chainHead_v1_followEvent { subscription: (&json_rpc_subscription_id).into(), result: methods::FollowEvent::Initialized { finalized_block_hash: methods::HashHexString( @@ -115,7 +115,7 @@ pub async fn spawn_chain_head_subscription_task(config: Config) -> String { for block in consensus_service_subscription.non_finalized_blocks_ancestry_order { pinned_blocks.insert(block.block_hash); json_rpc_subscription - .send_notification(methods::ServerToClient::chainHead_unstable_followEvent { + .send_notification(methods::ServerToClient::chainHead_v1_followEvent { subscription: (&json_rpc_subscription_id).into(), result: methods::FollowEvent::NewBlock { block_hash: methods::HashHexString(block.block_hash), @@ -134,7 +134,7 @@ pub async fn spawn_chain_head_subscription_task(config: Config) -> String { if block.is_new_best { current_best_block = block.block_hash; json_rpc_subscription - .send_notification(methods::ServerToClient::chainHead_unstable_followEvent { + .send_notification(methods::ServerToClient::chainHead_v1_followEvent { subscription: (&json_rpc_subscription_id).into(), result: methods::FollowEvent::BestBlockChanged { best_block_hash: methods::HashHexString(block.block_hash), @@ -172,8 +172,7 @@ pub async fn spawn_chain_head_subscription_task(config: Config) -> String { match wake_up_reason { WakeUpReason::ForegroundClosed => return, WakeUpReason::Foreground(Message::Header { request }) => { - let methods::MethodCall::chainHead_unstable_header { hash, .. } = - request.request() + let methods::MethodCall::chainHead_v1_header { hash, .. } = request.request() else { unreachable!() }; @@ -190,7 +189,7 @@ pub async fn spawn_chain_head_subscription_task(config: Config) -> String { match database_outcome { Ok(Some(header)) => { - request.respond(methods::Response::chainHead_unstable_header(Some( + request.respond(methods::Response::chainHead_v1_header(Some( methods::HexString(header), ))) } @@ -228,35 +227,31 @@ pub async fn spawn_chain_head_subscription_task(config: Config) -> String { }) => { pinned_blocks.insert(block.block_hash); json_rpc_subscription - .send_notification( - methods::ServerToClient::chainHead_unstable_followEvent { - subscription: (&json_rpc_subscription_id).into(), - result: methods::FollowEvent::NewBlock { - block_hash: methods::HashHexString(block.block_hash), - new_runtime: if let (Some(new_runtime), true) = - (&block.runtime_update, config.with_runtime) - { - Some(convert_runtime_spec(new_runtime.runtime_version())) - } else { - None - }, - parent_block_hash: methods::HashHexString(block.parent_hash), + .send_notification(methods::ServerToClient::chainHead_v1_followEvent { + subscription: (&json_rpc_subscription_id).into(), + result: methods::FollowEvent::NewBlock { + block_hash: methods::HashHexString(block.block_hash), + new_runtime: if let (Some(new_runtime), true) = + (&block.runtime_update, config.with_runtime) + { + Some(convert_runtime_spec(new_runtime.runtime_version())) + } else { + None }, + parent_block_hash: methods::HashHexString(block.parent_hash), }, - ) + }) .await; if block.is_new_best { current_best_block = block.block_hash; json_rpc_subscription - .send_notification( - methods::ServerToClient::chainHead_unstable_followEvent { - subscription: (&json_rpc_subscription_id).into(), - result: methods::FollowEvent::BestBlockChanged { - best_block_hash: methods::HashHexString(block.block_hash), - }, + .send_notification(methods::ServerToClient::chainHead_v1_followEvent { + subscription: (&json_rpc_subscription_id).into(), + result: methods::FollowEvent::BestBlockChanged { + best_block_hash: methods::HashHexString(block.block_hash), }, - ) + }) .await; } } @@ -268,49 +263,43 @@ pub async fn spawn_chain_head_subscription_task(config: Config) -> String { }, ) => { json_rpc_subscription - .send_notification( - methods::ServerToClient::chainHead_unstable_followEvent { - subscription: (&json_rpc_subscription_id).into(), - result: methods::FollowEvent::Finalized { - // As specified in the JSON-RPC spec, the list must be ordered - // in increasing block number. Consequently we have to reverse - // the list. - finalized_blocks_hashes: finalized_blocks_newest_to_oldest - .into_iter() - .map(methods::HashHexString) - .rev() - .collect(), - pruned_blocks_hashes: pruned_blocks_hashes - .into_iter() - .map(methods::HashHexString) - .collect(), - }, + .send_notification(methods::ServerToClient::chainHead_v1_followEvent { + subscription: (&json_rpc_subscription_id).into(), + result: methods::FollowEvent::Finalized { + // As specified in the JSON-RPC spec, the list must be ordered + // in increasing block number. Consequently we have to reverse + // the list. + finalized_blocks_hashes: finalized_blocks_newest_to_oldest + .into_iter() + .map(methods::HashHexString) + .rev() + .collect(), + pruned_blocks_hashes: pruned_blocks_hashes + .into_iter() + .map(methods::HashHexString) + .collect(), }, - ) + }) .await; if best_block_hash != current_best_block { current_best_block = best_block_hash; json_rpc_subscription - .send_notification( - methods::ServerToClient::chainHead_unstable_followEvent { - subscription: (&json_rpc_subscription_id).into(), - result: methods::FollowEvent::BestBlockChanged { - best_block_hash: methods::HashHexString(best_block_hash), - }, + .send_notification(methods::ServerToClient::chainHead_v1_followEvent { + subscription: (&json_rpc_subscription_id).into(), + result: methods::FollowEvent::BestBlockChanged { + best_block_hash: methods::HashHexString(best_block_hash), }, - ) + }) .await; } } WakeUpReason::ConsensusSubscriptionStop => { json_rpc_subscription - .send_notification( - methods::ServerToClient::chainHead_unstable_followEvent { - subscription: (&json_rpc_subscription_id).into(), - result: methods::FollowEvent::Stop {}, - }, - ) + .send_notification(methods::ServerToClient::chainHead_v1_followEvent { + subscription: (&json_rpc_subscription_id).into(), + result: methods::FollowEvent::Stop {}, + }) .await; } } diff --git a/full-node/tests/author.rs b/full-node/tests/author.rs index 24b5f71578..084936d442 100644 --- a/full-node/tests/author.rs +++ b/full-node/tests/author.rs @@ -47,7 +47,7 @@ fn basic_block_generated() { loop { client.send_json_rpc_request( - r#"{"jsonrpc":"2.0","id":1,"method":"chainHead_unstable_follow","params":[false]}"# + r#"{"jsonrpc":"2.0","id":1,"method":"chainHead_v1_follow","params":[false]}"# .to_owned(), ); @@ -60,11 +60,11 @@ fn basic_block_generated() { match json_rpc::methods::parse_notification(&client.next_json_rpc_response().await) .unwrap() { - json_rpc::methods::ServerToClient::chainHead_unstable_followEvent { + json_rpc::methods::ServerToClient::chainHead_v1_followEvent { result: json_rpc::methods::FollowEvent::NewBlock { .. }, .. } => return, // Test success - json_rpc::methods::ServerToClient::chainHead_unstable_followEvent { + json_rpc::methods::ServerToClient::chainHead_v1_followEvent { result: json_rpc::methods::FollowEvent::Stop { .. }, .. } => break, diff --git a/lib/src/json_rpc/methods.rs b/lib/src/json_rpc/methods.rs index 070a55e07d..a45f63c9ab 100644 --- a/lib/src/json_rpc/methods.rs +++ b/lib/src/json_rpc/methods.rs @@ -452,41 +452,41 @@ define_methods! { system_version() -> Cow<'a, str>, // The functions below are experimental and are defined in the document https://github.com/paritytech/json-rpc-interface-spec/ - chainHead_unstable_body( + chainHead_v1_body( #[rename = "followSubscription"] follow_subscription: Cow<'a, str>, hash: HashHexString ) -> ChainHeadBodyCallReturn<'a>, - chainHead_unstable_call( + chainHead_v1_call( #[rename = "followSubscription"] follow_subscription: Cow<'a, str>, hash: HashHexString, function: Cow<'a, str>, #[rename = "callParameters"] call_parameters: HexString ) -> ChainHeadBodyCallReturn<'a>, - chainHead_unstable_follow( + chainHead_v1_follow( #[rename = "withRuntime"] with_runtime: bool ) -> Cow<'a, str>, - chainHead_unstable_header( + chainHead_v1_header( #[rename = "followSubscription"] follow_subscription: Cow<'a, str>, hash: HashHexString ) -> Option, - chainHead_unstable_stopOperation( + chainHead_v1_stopOperation( #[rename = "followSubscription"] follow_subscription: Cow<'a, str>, #[rename = "operationId"] operation_id: Cow<'a, str> ) -> (), - chainHead_unstable_storage( + chainHead_v1_storage( #[rename = "followSubscription"] follow_subscription: Cow<'a, str>, hash: HashHexString, items: Vec, #[rename = "childTrie"] child_trie: Option ) -> ChainHeadStorageReturn<'a>, - chainHead_unstable_continue( + chainHead_v1_continue( #[rename = "followSubscription"] follow_subscription: Cow<'a, str>, #[rename = "operationId"] operation_id: Cow<'a, str> ) -> (), - chainHead_unstable_unfollow( + chainHead_v1_unfollow( #[rename = "followSubscription"] follow_subscription: Cow<'a, str> ) -> (), - chainHead_unstable_unpin( + chainHead_v1_unpin( #[rename = "followSubscription"] follow_subscription: Cow<'a, str>, #[rename = "hashOrHashes"] hash_or_hashes: HashHexStringSingleOrArray ) -> (), @@ -523,7 +523,7 @@ define_methods! { state_storage(subscription: Cow<'a, str>, result: StorageChangeSet) -> (), // The functions below are experimental and are defined in the document https://github.com/paritytech/json-rpc-interface-spec/ - chainHead_unstable_followEvent(subscription: Cow<'a, str>, result: FollowEvent<'a>) -> (), + chainHead_v1_followEvent(subscription: Cow<'a, str>, result: FollowEvent<'a>) -> (), transactionWatch_unstable_watchEvent(subscription: Cow<'a, str>, result: TransactionWatchEvent<'a>) -> (), // This function is a custom addition in smoldot. As of the writing of this comment, there is @@ -1265,7 +1265,7 @@ mod tests { fn no_params_refused() { // No `params` field in the request. let err = super::parse_jsonrpc_client_to_server( - r#"{"jsonrpc":"2.0","id":2,"method":"chainHead_unstable_follow"}"#, + r#"{"jsonrpc":"2.0","id":2,"method":"chainHead_v1_follow"}"#, ); assert!(matches!( @@ -1273,7 +1273,7 @@ mod tests { Err(super::ParseClientToServerError::Method { request_id: "2", error: super::MethodError::MissingParameters { - rpc_method: "chainHead_unstable_follow" + rpc_method: "chainHead_v1_follow" } }) )); diff --git a/lib/src/json_rpc/service/client_main_task.rs b/lib/src/json_rpc/service/client_main_task.rs index ef3497308b..c596fd20a4 100644 --- a/lib/src/json_rpc/service/client_main_task.rs +++ b/lib/src/json_rpc/service/client_main_task.rs @@ -439,14 +439,14 @@ impl ClientMainTask { | methods::MethodCall::rpc_methods { .. } | methods::MethodCall::sudo_unstable_p2pDiscover { .. } | methods::MethodCall::sudo_unstable_version { .. } - | methods::MethodCall::chainHead_unstable_body { .. } - | methods::MethodCall::chainHead_unstable_call { .. } - | methods::MethodCall::chainHead_unstable_continue { .. } + | methods::MethodCall::chainHead_v1_body { .. } + | methods::MethodCall::chainHead_v1_call { .. } + | methods::MethodCall::chainHead_v1_continue { .. } | methods::MethodCall::chainHead_unstable_finalizedDatabase { .. } - | methods::MethodCall::chainHead_unstable_header { .. } - | methods::MethodCall::chainHead_unstable_stopOperation { .. } - | methods::MethodCall::chainHead_unstable_storage { .. } - | methods::MethodCall::chainHead_unstable_unpin { .. } => { + | methods::MethodCall::chainHead_v1_header { .. } + | methods::MethodCall::chainHead_v1_stopOperation { .. } + | methods::MethodCall::chainHead_v1_storage { .. } + | methods::MethodCall::chainHead_v1_unpin { .. } => { // Simple one-request-one-response. return Event::HandleRequest { request_process: RequestProcess { @@ -470,7 +470,7 @@ impl ClientMainTask { | methods::MethodCall::transaction_v1_broadcast { .. } | methods::MethodCall::transactionWatch_unstable_submitAndWatch { .. } | methods::MethodCall::sudo_network_unstable_watch { .. } - | methods::MethodCall::chainHead_unstable_follow { .. } => { + | methods::MethodCall::chainHead_v1_follow { .. } => { // Subscription starting requests. // We must check the maximum number of subscriptions. @@ -543,7 +543,7 @@ impl ClientMainTask { } | methods::MethodCall::transactionWatch_unstable_unwatch { subscription, .. } | methods::MethodCall::sudo_network_unstable_unwatch { subscription, .. } - | methods::MethodCall::chainHead_unstable_unfollow { + | methods::MethodCall::chainHead_v1_unfollow { follow_subscription: subscription, .. } => { @@ -573,8 +573,8 @@ impl ClientMainTask { methods::MethodCall::sudo_network_unstable_unwatch { .. } => methods::Response::sudo_network_unstable_unwatch(()), - methods::MethodCall::chainHead_unstable_unfollow { .. } => { - methods::Response::chainHead_unstable_unfollow(()) + methods::MethodCall::chainHead_v1_unfollow { .. } => { + methods::Response::chainHead_v1_unfollow(()) } _ => unreachable!(), } @@ -1168,8 +1168,8 @@ impl SubscriptionStartProcess { methods::MethodCall::sudo_network_unstable_watch { .. } => { methods::Response::sudo_network_unstable_watch(Cow::Borrowed(&self.subscription_id)) } - methods::MethodCall::chainHead_unstable_follow { .. } => { - methods::Response::chainHead_unstable_follow(Cow::Borrowed(&self.subscription_id)) + methods::MethodCall::chainHead_v1_follow { .. } => { + methods::Response::chainHead_v1_follow(Cow::Borrowed(&self.subscription_id)) } _ => unreachable!(), } diff --git a/light-base/src/json_rpc_service/background.rs b/light-base/src/json_rpc_service/background.rs index fd8b5c1935..7bebb276f1 100644 --- a/light-base/src/json_rpc_service/background.rs +++ b/light-base/src/json_rpc_service/background.rs @@ -767,15 +767,15 @@ pub(super) async fn run( } // Non-legacy-API functions. - methods::MethodCall::chainHead_unstable_body { .. } - | methods::MethodCall::chainHead_unstable_call { .. } - | methods::MethodCall::chainHead_unstable_continue { .. } - | methods::MethodCall::chainHead_unstable_follow { .. } - | methods::MethodCall::chainHead_unstable_header { .. } - | methods::MethodCall::chainHead_unstable_stopOperation { .. } - | methods::MethodCall::chainHead_unstable_storage { .. } - | methods::MethodCall::chainHead_unstable_unfollow { .. } - | methods::MethodCall::chainHead_unstable_unpin { .. } + methods::MethodCall::chainHead_v1_body { .. } + | methods::MethodCall::chainHead_v1_call { .. } + | methods::MethodCall::chainHead_v1_continue { .. } + | methods::MethodCall::chainHead_v1_follow { .. } + | methods::MethodCall::chainHead_v1_header { .. } + | methods::MethodCall::chainHead_v1_stopOperation { .. } + | methods::MethodCall::chainHead_v1_storage { .. } + | methods::MethodCall::chainHead_v1_unfollow { .. } + | methods::MethodCall::chainHead_v1_unpin { .. } | methods::MethodCall::chainSpec_v1_chainName { .. } | methods::MethodCall::chainSpec_v1_genesisHash { .. } | methods::MethodCall::chainSpec_v1_properties { .. } @@ -1646,7 +1646,7 @@ pub(super) async fn run( .await; } - methods::MethodCall::chainHead_unstable_body { + methods::MethodCall::chainHead_v1_body { follow_subscription, hash, } => { @@ -1658,7 +1658,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::Response::chainHead_unstable_body( + methods::Response::chainHead_v1_body( methods::ChainHeadBodyCallReturn::LimitReached {}, ) .to_json_response(request_id_json), @@ -1698,7 +1698,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::Response::chainHead_unstable_body( + methods::Response::chainHead_v1_body( methods::ChainHeadBodyCallReturn::LimitReached {}, ) .to_json_response(request_id_json), @@ -1742,7 +1742,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::Response::chainHead_unstable_body( + methods::Response::chainHead_v1_body( methods::ChainHeadBodyCallReturn::Started { operation_id: (&operation_id).into(), }, @@ -1772,7 +1772,7 @@ pub(super) async fn run( })); } - methods::MethodCall::chainHead_unstable_call { + methods::MethodCall::chainHead_v1_call { follow_subscription, hash, function, @@ -1786,7 +1786,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::Response::chainHead_unstable_call( + methods::Response::chainHead_v1_call( methods::ChainHeadBodyCallReturn::LimitReached {}, ) .to_json_response(request_id_json), @@ -1817,7 +1817,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::Response::chainHead_unstable_call( + methods::Response::chainHead_v1_call( methods::ChainHeadBodyCallReturn::LimitReached {}, ) .to_json_response(request_id_json), @@ -1864,7 +1864,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::Response::chainHead_unstable_call( + methods::Response::chainHead_v1_call( methods::ChainHeadBodyCallReturn::LimitReached {}, ) .to_json_response(request_id_json), @@ -1917,7 +1917,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::Response::chainHead_unstable_call( + methods::Response::chainHead_v1_call( methods::ChainHeadBodyCallReturn::Started { operation_id: (&operation_id).into(), }, @@ -1946,18 +1946,18 @@ pub(super) async fn run( })); } - methods::MethodCall::chainHead_unstable_continue { .. } => { + methods::MethodCall::chainHead_v1_continue { .. } => { // TODO: not implemented properly let _ = me .responses_tx .send( - methods::Response::chainHead_unstable_continue(()) + methods::Response::chainHead_v1_continue(()) .to_json_response(request_id_json), ) .await; } - methods::MethodCall::chainHead_unstable_storage { + methods::MethodCall::chainHead_v1_storage { follow_subscription, hash, items, @@ -1971,7 +1971,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::Response::chainHead_unstable_storage( + methods::Response::chainHead_v1_storage( methods::ChainHeadStorageReturn::LimitReached {}, ) .to_json_response(request_id_json), @@ -2020,7 +2020,7 @@ pub(super) async fn run( &me.platform, Warn, &me.log_target, - "chainHead_unstable_storage has been called with a non-null childTrie. \ + "chainHead_v1_storage has been called with a non-null childTrie. \ This isn't supported by smoldot yet." ); continue; @@ -2064,7 +2064,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::Response::chainHead_unstable_storage( + methods::Response::chainHead_v1_storage( methods::ChainHeadStorageReturn::LimitReached {}, ) .to_json_response(request_id_json), @@ -2104,7 +2104,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::Response::chainHead_unstable_storage( + methods::Response::chainHead_v1_storage( methods::ChainHeadStorageReturn::Started { operation_id: (&operation_id).into(), discarded_items: items.len(), @@ -2133,7 +2133,7 @@ pub(super) async fn run( })); } - methods::MethodCall::chainHead_unstable_stopOperation { + methods::MethodCall::chainHead_v1_stopOperation { follow_subscription, operation_id, } => { @@ -2154,13 +2154,13 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::Response::chainHead_unstable_stopOperation(()) + methods::Response::chainHead_v1_stopOperation(()) .to_json_response(request_id_json), ) .await; } - methods::MethodCall::chainHead_unstable_follow { with_runtime } => { + methods::MethodCall::chainHead_v1_follow { with_runtime } => { // Check that the number of existing subscriptions is below the limit. // TODO: configurable limit if me.chain_head_follow_subscriptions.len() >= 2 { @@ -2205,7 +2205,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::Response::chainHead_unstable_follow(Cow::Borrowed( + methods::Response::chainHead_v1_follow(Cow::Borrowed( &subscription_id, )) .to_json_response(request_id_json), @@ -2238,7 +2238,7 @@ pub(super) async fn run( } } - methods::MethodCall::chainHead_unstable_unfollow { + methods::MethodCall::chainHead_v1_unfollow { follow_subscription, } => { if let Some(subscription) = me @@ -2253,13 +2253,13 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::Response::chainHead_unstable_unfollow(()) + methods::Response::chainHead_v1_unfollow(()) .to_json_response(request_id_json), ) .await; } - methods::MethodCall::chainHead_unstable_header { + methods::MethodCall::chainHead_v1_header { follow_subscription, hash, } => { @@ -2271,7 +2271,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::Response::chainHead_unstable_header(None) + methods::Response::chainHead_v1_header(None) .to_json_response(request_id_json), ) .await; @@ -2297,7 +2297,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::Response::chainHead_unstable_header(Some( + methods::Response::chainHead_v1_header(Some( methods::HexString(block.clone()), )) .to_json_response(request_id_json), @@ -2305,7 +2305,7 @@ pub(super) async fn run( .await; } - methods::MethodCall::chainHead_unstable_unpin { + methods::MethodCall::chainHead_v1_unpin { follow_subscription, hash_or_hashes, } => { @@ -2317,7 +2317,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::Response::chainHead_unstable_unpin(()) + methods::Response::chainHead_v1_unpin(()) .to_json_response(request_id_json), ) .await; @@ -2394,7 +2394,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::Response::chainHead_unstable_unpin(()) + methods::Response::chainHead_v1_unpin(()) .to_json_response(request_id_json), ) .await; @@ -3745,7 +3745,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::Initialized { finalized_block_hash: methods::HashHexString(finalized_block_hash), @@ -3781,7 +3781,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::NewBlock { block_hash: methods::HashHexString(hash), @@ -3818,7 +3818,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::BestBlockChanged { best_block_hash: methods::HashHexString(hash), @@ -3889,7 +3889,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::BestBlockChanged { best_block_hash: methods::HashHexString( @@ -3905,7 +3905,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::Finalized { finalized_blocks_hashes: vec![methods::HashHexString(hash)], @@ -3923,7 +3923,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::BestBlockChanged { best_block_hash: methods::HashHexString(hash), @@ -3944,7 +3944,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::NewBlock { block_hash: methods::HashHexString(block_hash), @@ -3974,7 +3974,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::BestBlockChanged { best_block_hash: methods::HashHexString(block_hash), @@ -4024,7 +4024,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::BestBlockChanged { best_block_hash: methods::HashHexString( @@ -4040,7 +4040,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::Finalized { finalized_blocks_hashes: vec![methods::HashHexString(hash)], @@ -4058,7 +4058,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::BestBlockChanged { best_block_hash: methods::HashHexString(hash), @@ -4079,7 +4079,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::NewBlock { block_hash: methods::HashHexString(block_hash), @@ -4097,7 +4097,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::BestBlockChanged { best_block_hash: methods::HashHexString(block_hash), @@ -4194,7 +4194,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result, } @@ -4250,7 +4250,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::OperationBodyDone { operation_id: operation_id.clone().into(), @@ -4265,7 +4265,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::OperationInaccessible { operation_id: operation_id.clone().into(), @@ -4358,7 +4358,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::OperationStorageItems { operation_id: Cow::Borrowed(&operation_id), @@ -4426,7 +4426,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::OperationStorageDone { operation_id: Cow::Borrowed(&operation_id), @@ -4463,7 +4463,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::OperationInaccessible { operation_id: Cow::Borrowed(&operation_id), @@ -4497,7 +4497,7 @@ pub(super) async fn run( let _ = me .responses_tx .send( - methods::ServerToClient::chainHead_unstable_followEvent { + methods::ServerToClient::chainHead_v1_followEvent { subscription: Cow::Borrowed(&subscription_id), result: methods::FollowEvent::Stop {}, } diff --git a/wasm-node/CHANGELOG.md b/wasm-node/CHANGELOG.md index b609df1370..6c4e238feb 100644 --- a/wasm-node/CHANGELOG.md +++ b/wasm-node/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Changed + +- All `chainHead_unstable`-prefixed JSON-RPC functions have been renamed to `chainHead_v1`, in accordance with the latest changes in the JSON-RPC API specification. ([#1748](https://github.com/smol-dot/smoldot/pull/1748)) + ### Fixed - Fix `QueueFullError` being thrown even when the number of requests is way below the value passed to `jsonRpcMaxPendingRequests`. ([#1747](https://github.com/smol-dot/smoldot/pull/1747)) diff --git a/wasm-node/javascript/test/chainHead.mjs b/wasm-node/javascript/test/chainHead.mjs index fc698bdb79..d48f62c416 100644 --- a/wasm-node/javascript/test/chainHead.mjs +++ b/wasm-node/javascript/test/chainHead.mjs @@ -21,12 +21,12 @@ import { start } from "../dist/mjs/index-nodejs.js"; const westendSpec = fs.readFileSync('./test/westend.json', 'utf8'); -test('chainHead_unstable_follow works', async t => { +test('chainHead_v1_follow works', async t => { const client = start({ logCallback: () => { } }); await client .addChain({ chainSpec: westendSpec }) .then((chain) => { - chain.sendJsonRpc('{"jsonrpc":"2.0","id":1,"method":"chainHead_unstable_follow","params":[false]}'); + chain.sendJsonRpc('{"jsonrpc":"2.0","id":1,"method":"chainHead_v1_follow","params":[false]}'); return chain; }) .then(async (chain) => { @@ -47,18 +47,18 @@ test('chainHead_unstable_follow works', async t => { .then(() => client.terminate()); }); -test('chainHead_unstable_unfollow works', async t => { +test('chainHead_v1_unfollow works', async t => { const client = start({ logCallback: () => { } }); await client .addChain({ chainSpec: westendSpec }) .then((chain) => { - chain.sendJsonRpc('{"jsonrpc":"2.0","id":1,"method":"chainHead_unstable_follow","params":[false]}'); + chain.sendJsonRpc('{"jsonrpc":"2.0","id":1,"method":"chainHead_v1_follow","params":[false]}'); return chain; }) .then(async (chain) => { const parsed = JSON.parse(await chain.nextJsonRpcResponse()); t.assert(parsed.id === 1); - chain.sendJsonRpc('{"jsonrpc":"2.0","id":2,"method":"chainHead_unstable_unfollow","params":[' + JSON.stringify(parsed.result) + ']}'); + chain.sendJsonRpc('{"jsonrpc":"2.0","id":2,"method":"chainHead_v1_unfollow","params":[' + JSON.stringify(parsed.result) + ']}'); return chain; }) .then(async (chain) => { @@ -73,12 +73,12 @@ test('chainHead_unstable_unfollow works', async t => { .then(() => client.terminate()); }); -test('chainHead_unstable_body works', async t => { +test('chainHead_v1_body works', async t => { const client = start({ logCallback: () => { } }); await client .addChain({ chainSpec: westendSpec }) .then((chain) => { - chain.sendJsonRpc('{"jsonrpc":"2.0","id":1,"method":"chainHead_unstable_follow","params":[false]}'); + chain.sendJsonRpc('{"jsonrpc":"2.0","id":1,"method":"chainHead_v1_follow","params":[false]}'); return chain; }) .then(async (chain) => { @@ -88,18 +88,18 @@ test('chainHead_unstable_body works', async t => { }) .then(async ([chain, followSubscription]) => { const parsed = JSON.parse(await chain.nextJsonRpcResponse()); - t.assert(parsed.method == "chainHead_unstable_followEvent" && parsed.params.subscription == followSubscription); + t.assert(parsed.method == "chainHead_v1_followEvent" && parsed.params.subscription == followSubscription); if (parsed.params.result.event == "initialized") { if (parsed.params.result.finalizedBlockHash.toLowerCase() != "0x9d34c5a7a8ad8d73c7690a41f7a9d1a7c46e21dc8fb1638aee6ef07f45b65158") t.fail(parsed); - chain.sendJsonRpc(JSON.stringify({ "jsonrpc": "2.0", "id": 1, "method": "chainHead_unstable_body", "params": [followSubscription, parsed.params.result.finalizedBlockHash] })); + chain.sendJsonRpc(JSON.stringify({ "jsonrpc": "2.0", "id": 1, "method": "chainHead_v1_body", "params": [followSubscription, parsed.params.result.finalizedBlockHash] })); } return chain; }) .then(async (chain) => { while (true) { const parsed = JSON.parse(await chain.nextJsonRpcResponse()); - if (parsed.method == "chainHead_unstable_followEvent" && parsed.params.result.event == "operationInaccessible") { + if (parsed.method == "chainHead_v1_followEvent" && parsed.params.result.event == "operationInaccessible") { t.pass(); break; }