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

suggestion: Avoid new uses of lazy_static #5559

Merged
merged 4 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion zebra-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
5 changes: 4 additions & 1 deletion zebra-rpc/src/methods/get_block_template_rpcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
12 changes: 2 additions & 10 deletions zebra-rpc/src/methods/get_block_template_rpcs/constants.rs
Original file line number Diff line number Diff line change
@@ -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<String> = 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"];
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`: <https://en.bitcoin.it/wiki/BIP_0023#Block_Proposal>
/// - `longpoll`: <https://en.bitcoin.it/wiki/BIP_0022#Optional:_Long_Polling>
/// - `serverlist`: <https://en.bitcoin.it/wiki/BIP_0023#Logical_Services>
pub capabilities: Vec<String>,

/// 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,

Expand Down