Skip to content

Enable support for additional getblock RPC use cases without impacting the method's performance where possible - Option 4 #11416

Description

@natalieesk

Context

This is an implementation of Option 4 from #8390

Tech notes

Option 4

Keep the existing verbosity levels and allow users to, instead of providing a verbosity level, provide a query with exact fields they're interested in on a per-request basis by replacing Zebra's getblock method's verbosity argument type with an enum:

Example
pub trait Rpc {
    fn get_block(&self, hash_or_height: String, query: BlockQuery) -> BoxFuture<Result<GetBlock>>;
    ..
}

#[derive(Debug, Eq, PartialEq, Hash, serde::Deserialize)]
enum BlockField {
    Hash,
    Height,
    Time,
    Confirmations,
    AuthDataRoot,
    MerkleRoot,
    ..
}

#[derive(serde::Deserialize)]
#[serde(untagged)]
enum BlockQuery {
    #[serde(alias = "0")]
    Raw,
    #[serde(alias = "1")]
    Json,
    #[serde(alias = "2")]
    Verbose,
    Fields(HashSet<BlockField>),
}

And replace the zebra_state::Request::BlockHeader(HashOrHeight) variant with a Request::BlockQuery(BlockQuery) variant, and its response variant, BlockHeader(Option<Arc<block::Header>>), with:

Example
enum BlockQueryTx {
    Full(zebra_chain::Transaction),
    Id(transaction::Hash),
}

enum Response {
    BlockQuery {
        // optional version of every field on Header, could add nested options for sapling/orchard tree fields too
        version: Option<u32>,
        previous_block_hash: Option<Hash>,
        merkle_root: Option<merkle::Root>,
        ..
        transactions: Vec<zebra_chain::Transaction>
    }
}

This has the added benefit of allowing for requesting specific block data from the state service without adding new state requests going forward, instead of expecting just a particular Response variant, it would expect the BlockQuery variant with the requested combination of fields being Some.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions