From 128f6c79fcbbc06bd3c507f6b08d0af98a492192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= <git@kchr.de> Date: Sun, 22 Sep 2024 23:04:33 +0200 Subject: [PATCH] Fix RPC relay chain interface (#5796) Use `sp_core::Bytes` as `payload` to encode the values correctly as `hex` string. --- .../src/rpc_client.rs | 34 ++++++++++--------- prdoc/pr_5796.prdoc | 8 +++++ 2 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 prdoc/pr_5796.prdoc diff --git a/cumulus/client/relay-chain-rpc-interface/src/rpc_client.rs b/cumulus/client/relay-chain-rpc-interface/src/rpc_client.rs index 381f4a046a4..d8e5abaddc6 100644 --- a/cumulus/client/relay-chain-rpc-interface/src/rpc_client.rs +++ b/cumulus/client/relay-chain-rpc-interface/src/rpc_client.rs @@ -23,7 +23,7 @@ use jsonrpsee::{ rpc_params, }; use prometheus::Registry; -use serde::de::DeserializeOwned; +use serde::{de::DeserializeOwned, Serialize}; use serde_json::Value as JsonValue; use std::collections::{btree_map::BTreeMap, VecDeque}; use tokio::sync::mpsc::Sender as TokioSender; @@ -122,6 +122,9 @@ pub async fn create_client_and_start_light_client_worker( Ok(client) } +#[derive(Serialize)] +struct PayloadToHex<'a>(#[serde(with = "sp_core::bytes")] &'a [u8]); + /// Client that maps RPC methods and deserializes results #[derive(Clone)] pub struct RelayChainRpcClient { @@ -153,27 +156,26 @@ impl RelayChainRpcClient { &self, method_name: &str, hash: RelayHash, - payload_bytes: &[u8], + payload: &[u8], ) -> RelayChainResult<sp_core::Bytes> { + let payload = PayloadToHex(payload); + let params = rpc_params! { method_name, - payload_bytes, + payload, hash }; - let res = self - .request_tracing::<sp_core::Bytes, _>("state_call", params, |err| { - tracing::trace!( - target: LOG_TARGET, - %method_name, - %hash, - error = %err, - "Error during call to 'state_call'.", - ); - }) - .await?; - - Ok(res) + self.request_tracing::<sp_core::Bytes, _>("state_call", params, |err| { + tracing::trace!( + target: LOG_TARGET, + %method_name, + %hash, + error = %err, + "Error during call to 'state_call'.", + ); + }) + .await } /// Call a call to `state_call` rpc method. diff --git a/prdoc/pr_5796.prdoc b/prdoc/pr_5796.prdoc new file mode 100644 index 00000000000..76958e3db4f --- /dev/null +++ b/prdoc/pr_5796.prdoc @@ -0,0 +1,8 @@ +title: "Fix RPC relay chain interface" + +doc: + +crates: + - name: cumulus-relay-chain-rpc-interface + bump: none + validate: false -- GitLab