From b0e46d26465c71b8d14c0d316e4d036767b2ce82 Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 7 Nov 2022 09:29:23 +1000 Subject: [PATCH 1/2] Avoid using lazy_static --- Cargo.lock | 1 - zebra-rpc/Cargo.toml | 1 - zebra-rpc/src/methods/get_block_template_rpcs.rs | 5 ++++- .../src/methods/get_block_template_rpcs/constants.rs | 12 ++---------- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6cebea2cfde..1b92ee66571 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5384,7 +5384,6 @@ dependencies = [ "jsonrpc-core", "jsonrpc-derive", "jsonrpc-http-server", - "lazy_static", "num_cpus", "proptest", "proptest-derive", diff --git a/zebra-rpc/Cargo.toml b/zebra-rpc/Cargo.toml index 167a7ecb99c..67b3ee3696a 100644 --- a/zebra-rpc/Cargo.toml +++ b/zebra-rpc/Cargo.toml @@ -37,7 +37,6 @@ tracing = "0.1.37" tracing-futures = "0.2.5" hex = { version = "0.4.3", features = ["serde"] } -lazy_static = "1.4.0" serde = { version = "1.0.147", features = ["serde_derive"] } proptest = { version = "0.10.1", optional = true } diff --git a/zebra-rpc/src/methods/get_block_template_rpcs.rs b/zebra-rpc/src/methods/get_block_template_rpcs.rs index 47591702a73..6f9c8e7a9f4 100644 --- a/zebra-rpc/src/methods/get_block_template_rpcs.rs +++ b/zebra-rpc/src/methods/get_block_template_rpcs.rs @@ -329,7 +329,10 @@ where min_time: 0, // Hardcoded list of block fields the miner is allowed to change. - mutable: constants::GET_BLOCK_TEMPLATE_MUTABLE_FIELD.to_vec(), + mutable: constants::GET_BLOCK_TEMPLATE_MUTABLE_FIELD + .iter() + .map(ToString::to_string) + .collect(), // A range of valid nonces that goes from `u32::MIN` to `u32::MAX`. nonce_range: constants::GET_BLOCK_TEMPLATE_NONCE_RANGE_FIELD.to_string(), diff --git a/zebra-rpc/src/methods/get_block_template_rpcs/constants.rs b/zebra-rpc/src/methods/get_block_template_rpcs/constants.rs index 83fd691ad6b..2db3ed05ef7 100644 --- a/zebra-rpc/src/methods/get_block_template_rpcs/constants.rs +++ b/zebra-rpc/src/methods/get_block_template_rpcs/constants.rs @@ -1,15 +1,7 @@ //! Constant values used in mining rpcs methods. -use lazy_static::lazy_static; - /// A range of valid nonces that goes from `u32::MIN` to `u32::MAX` as a string. pub const GET_BLOCK_TEMPLATE_NONCE_RANGE_FIELD: &str = "00000000ffffffff"; -lazy_static! { - /// A hardcoded list of fields that the miner can change from the block. - pub static ref GET_BLOCK_TEMPLATE_MUTABLE_FIELD: Vec = vec![ - "time".to_string(), - "transactions".to_string(), - "prevblock".to_string() - ]; -} +/// A hardcoded list of fields that the miner can change from the block. +pub const GET_BLOCK_TEMPLATE_MUTABLE_FIELD: &[&str] = &["time", "transactions", "prevblock"]; From ca3e85a98da5e0ac8df53efad781245ad2100697 Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 7 Nov 2022 09:29:46 +1000 Subject: [PATCH 2/2] Add some missing documentation --- .../types/default_roots.rs | 5 +++- .../types/get_block_template.rs | 28 +++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/zebra-rpc/src/methods/get_block_template_rpcs/types/default_roots.rs b/zebra-rpc/src/methods/get_block_template_rpcs/types/default_roots.rs index 93272944c88..20e1f341b24 100644 --- a/zebra-rpc/src/methods/get_block_template_rpcs/types/default_roots.rs +++ b/zebra-rpc/src/methods/get_block_template_rpcs/types/default_roots.rs @@ -5,7 +5,10 @@ use zebra_chain::block::{ ChainHistoryBlockTxAuthCommitmentHash, ChainHistoryMmrRootHash, }; -/// Documentation to be added in #5452 or #5455. +/// The block header roots for [`GetBlockTemplate.transactions`]. +/// +/// If the transactions in the block template are modified, these roots must be recalculated +/// [according to the specification](https://zcash.github.io/rpc/getblocktemplate.html). #[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)] pub struct DefaultRoots { /// The merkle root of the transaction IDs in the block. diff --git a/zebra-rpc/src/methods/get_block_template_rpcs/types/get_block_template.rs b/zebra-rpc/src/methods/get_block_template_rpcs/types/get_block_template.rs index 983b301171e..022262f80a8 100644 --- a/zebra-rpc/src/methods/get_block_template_rpcs/types/get_block_template.rs +++ b/zebra-rpc/src/methods/get_block_template_rpcs/types/get_block_template.rs @@ -12,35 +12,47 @@ use crate::methods::{ /// Documentation to be added after we document all the individual fields. #[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)] pub struct GetBlockTemplate { - /// Add documentation. + /// The getblocktemplate RPC capabilities supported by Zebra. + /// + /// At the moment, Zebra does not support any of the extra capabilities from the specification: + /// - `proposal`: + /// - `longpoll`: + /// - `serverlist`: pub capabilities: Vec, /// The version of the block format. /// Always 4 for new Zcash blocks. - // - // TODO: add a default block version constant to zebra-chain. pub version: u32, - /// Add documentation. + /// The hash of the previous block. #[serde(rename = "previousblockhash")] pub previous_block_hash: GetBlockHash, - /// Add documentation. + /// The block commitment for the new block's header. + /// + /// Same as [`DefaultRoots.block_commitments_hash`], see that field for details. #[serde(rename = "blockcommitmentshash")] #[serde(with = "hex")] pub block_commitments_hash: ChainHistoryBlockTxAuthCommitmentHash, - /// Add documentation. + /// Legacy backwards-compatibility header root field. + /// + /// Same as [`DefaultRoots.block_commitments_hash`], see that field for details. #[serde(rename = "lightclientroothash")] #[serde(with = "hex")] pub light_client_root_hash: ChainHistoryBlockTxAuthCommitmentHash, - /// Add documentation. + /// Legacy backwards-compatibility header root field. + /// + /// Same as [`DefaultRoots.block_commitments_hash`], see that field for details. #[serde(rename = "finalsaplingroothash")] #[serde(with = "hex")] pub final_sapling_root_hash: ChainHistoryBlockTxAuthCommitmentHash, - /// Add documentation. + /// The block header roots for [`GetBlockTemplate.transactions`]. + /// + /// If the transactions in the block template are modified, these roots must be recalculated + /// [according to the specification](https://zcash.github.io/rpc/getblocktemplate.html). #[serde(rename = "defaultroots")] pub default_roots: DefaultRoots,