Skip to content

Commit

Permalink
Fix RPC relay chain interface
Browse files Browse the repository at this point in the history
Use `sp_core::Bytes` as `payload` to encode the values correctly as `hex` string.
  • Loading branch information
bkchr committed Sep 22, 2024
1 parent 6ff41dc commit 7104745
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions cumulus/client/relay-chain-rpc-interface/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -122,6 +122,12 @@ pub async fn create_client_and_start_light_client_worker(
Ok(client)
}

#[derive(Serialize)]
struct PayloadToHex<'a> {
#[serde(with = "sp_core::bytes")]
payload: &'a [u8],
}

/// Client that maps RPC methods and deserializes results
#[derive(Clone)]
pub struct RelayChainRpcClient {
Expand Down Expand Up @@ -153,27 +159,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.
Expand Down

0 comments on commit 7104745

Please sign in to comment.