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

chain_getBlock extrinsics encoding #1010

Closed
pgherveou opened this issue Jun 12, 2023 · 1 comment · Fixed by #1024
Closed

chain_getBlock extrinsics encoding #1010

pgherveou opened this issue Jun 12, 2023 · 1 comment · Fixed by #1024
Assignees

Comments

@pgherveou
Copy link
Contributor

When I query the chain_getBlock extrinsics, subxt deserialize the extrinsics bytes with scale

#[derive(Clone, Debug)]
pub struct ChainBlockExtrinsic(pub Vec<u8>);
impl<'a> ::serde::Deserialize<'a> for ChainBlockExtrinsic {
fn deserialize<D>(de: D) -> Result<Self, D::Error>
where
D: ::serde::Deserializer<'a>,
{
let r = impl_serde::serialize::deserialize(de)?;
let bytes = Decode::decode(&mut &r[..])
.map_err(|e| ::serde::de::Error::custom(format!("Decode error: {e}")))?;
Ok(ChainBlockExtrinsic(bytes))
}
}

As a result if I compare the result of substrate export-blocks command or if I make a raw query to the rpc, I get different values for these extrinsics. If the subxt client is just supposed to return the result of the API call it should not try to interpret the payload.

Instead we should probably use something like this

pub struct ChainBlockExtrinsic(#[serde(with = "impl_serde::serialize")] pub Vec<u8>);
@jsdw
Copy link
Collaborator

jsdw commented Jun 12, 2023

I think that's a fair comment; all that Decode::decode is doing is removing the Compact(length) bytes from the beginning anyway and allocating a new vec in the process. Probably we can handle this "down the line" easily enough, avoid an extra allocation and have a slgihtly "purer" RPC call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants