Skip to content

Set RPC echo check logic as trait default implementation#2278

Open
gabrielbosio wants to merge 6 commits into
nextfrom
rpc-verification-layer
Open

Set RPC echo check logic as trait default implementation#2278
gabrielbosio wants to merge 6 commits into
nextfrom
rpc-verification-layer

Conversation

@gabrielbosio

Copy link
Copy Markdown
Collaborator

Closes #2276.

Base automatically changed from verify-block-number-echo to next June 22, 2026 14:19
@gabrielbosio
gabrielbosio force-pushed the rpc-verification-layer branch from c37add1 to 36e84d5 Compare June 22, 2026 14:39
@gabrielbosio

Copy link
Copy Markdown
Collaborator Author

Keeping this PR as draft until we complete the rest of the sub issues of #2241

@gabrielbosio gabrielbosio changed the title Centralize RPC response verification in trait defaults Centralize RPC response checks in a verifying wrapper Jun 29, 2026
@gabrielbosio
gabrielbosio force-pushed the rpc-verification-layer branch from 36e84d5 to 2ddc69a Compare June 29, 2026 16:00
@gabrielbosio
gabrielbosio force-pushed the rpc-verification-layer branch from 2ddc69a to bda7d55 Compare June 29, 2026 16:06
@gabrielbosio
gabrielbosio marked this pull request as ready for review June 29, 2026 20:16
@gabrielbosio gabrielbosio changed the title Centralize RPC response checks in a verifying wrapper Set RPC verifying logic as trait default implementation Jun 29, 2026
@gabrielbosio gabrielbosio changed the title Set RPC verifying logic as trait default implementation Set RPC echo check logic as trait default implementation Jun 29, 2026
gabrielbosio and others added 2 commits July 2, 2026 16:35

@SantiagoPittella SantiagoPittella left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good, I don't love the idea of the _unchecked methods but probably is for the best at least for now. We can keep track of this on a separate issue.

I guess another options could be to have a wrapper struct and keep NodeRpcClient as pure transport. Add a wrapper that owns verification:

pub struct VerifyingRpcClient<T>(T);

impl<T: NodeRpcClient> NodeRpcClient for VerifyingRpcClient<T> {
    async fn get_block_header_by_number(&self, block_num, include_mmr_proof)
        -> Result<(BlockHeader, Option<MmrProof>), RpcError>
    {
        let (h, p) = self.0.get_block_header_by_number(block_num, include_mmr_proof).await?;
        verify_block_num(block_num, h.block_num())?;
        Ok((h, p))
    }
    // ...
}

Or something like using two traits, one for raw impl and another for validations:

// What implementors write
pub trait RpcTransport: Send + Sync {
    async fn get_block_header_by_number(&self, ..) -> Result<..>;   // raw
    // ...
}

// What callers use.
pub trait NodeRpcClient: Send + Sync {
    async fn get_block_header_by_number(&self, ..) -> Result<..>;   // verified
    // ...
}

impl<T: RpcTransport> NodeRpcClient for T {
    async fn get_block_header_by_number(&self, block_num, mmr) -> Result<..> {
        let (h, p) = RpcTransport::get_block_header_by_number(self, block_num, mmr).await?;
        verify_block_num(block_num, h.block_num())?;
        Ok((h, p))
    }
    // ...
}

@igamigo

igamigo commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

It looks good, I don't love the idea of the _unchecked methods but probably is for the best at least for now. We can keep track of this on a separate issue.

I guess another options could be to have a wrapper struct and keep NodeRpcClient as pure transport. Add a wrapper that owns verification:

Or something like using two traits, one for raw impl and another for validations:

Yes, the first one of these approaches is pretty much what I was envisioning when we first discussed this feature. It's a bit boilerplatey, but should work out fine and be pretty flexible. The second one also sounds good, and we could also seal the trait. For names we could also use fetch_* or send_*_req, etc.

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 this pull request may close these issues.

Move RPC echo checks from RPC client implementation to an unified verification layer

4 participants