From 48eb24fd2024f6b2f2adaa0170fafc437c38d84b Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Fri, 4 Nov 2022 20:42:03 -0300 Subject: [PATCH 1/5] add fixed values to getblocktemplate rpc call response --- Cargo.lock | 1 + zebra-chain/src/block.rs | 2 +- zebra-chain/src/block/header.rs | 6 +++++ zebra-chain/src/block/serialize.rs | 4 ++-- zebra-consensus/src/lib.rs | 2 +- zebra-rpc/Cargo.toml | 1 + .../src/methods/get_block_template_rpcs.rs | 23 +++++++++++++------ .../get_block_template_rpcs/constants.rs | 15 ++++++++++++ .../get_block_template@mainnet_10.snap | 15 ++++++++---- .../get_block_template@testnet_10.snap | 15 ++++++++---- zebra-rpc/src/methods/tests/vectors.rs | 22 ++++++++++++++---- 11 files changed, 80 insertions(+), 26 deletions(-) create mode 100644 zebra-rpc/src/methods/get_block_template_rpcs/constants.rs diff --git a/Cargo.lock b/Cargo.lock index 1b92ee66571..6cebea2cfde 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5384,6 +5384,7 @@ dependencies = [ "jsonrpc-core", "jsonrpc-derive", "jsonrpc-http-server", + "lazy_static", "num_cpus", "proptest", "proptest-derive", diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index 390f5fac7b1..a7242641160 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -34,7 +34,7 @@ pub use commitment::{ ChainHistoryBlockTxAuthCommitmentHash, ChainHistoryMmrRootHash, Commitment, CommitmentError, }; pub use hash::Hash; -pub use header::{BlockTimeError, CountedHeader, Header}; +pub use header::{BlockTimeError, CountedHeader, Header, ZCASH_BLOCK_VERSION}; pub use height::Height; pub use serialize::{SerializedBlock, MAX_BLOCK_BYTES}; diff --git a/zebra-chain/src/block/header.rs b/zebra-chain/src/block/header.rs index e30f3eb12e9..a1492b566ba 100644 --- a/zebra-chain/src/block/header.rs +++ b/zebra-chain/src/block/header.rs @@ -146,6 +146,12 @@ const BLOCK_HEADER_LENGTH: usize = /// A CountedHeader has BLOCK_HEADER_LENGTH bytes + 1 or more bytes for the transaction count pub(crate) const MIN_COUNTED_HEADER_LEN: usize = BLOCK_HEADER_LENGTH + 1; +/// The Zcash accepted block version. +/// +/// The consensus rules do not force the block version to be this value but just equal or greater than it. +/// However, it is suggested that submitted block versions to be of this exact value. +pub const ZCASH_BLOCK_VERSION: u32 = 4; + impl TrustedPreallocate for CountedHeader { fn max_allocation() -> u64 { // Every vector type requires a length field of at least one byte for de/serialization. diff --git a/zebra-chain/src/block/serialize.rs b/zebra-chain/src/block/serialize.rs index 8c0907aee99..ad9558000e0 100644 --- a/zebra-chain/src/block/serialize.rs +++ b/zebra-chain/src/block/serialize.rs @@ -13,7 +13,7 @@ use crate::{ work::{difficulty::CompactDifficulty, equihash}, }; -use super::{merkle, Block, CountedHeader, Hash, Header}; +use super::{header::ZCASH_BLOCK_VERSION, merkle, Block, CountedHeader, Hash, Header}; /// The maximum size of a Zcash block, in bytes. /// @@ -77,7 +77,7 @@ impl ZcashDeserialize for Header { // > The block version number MUST be greater than or equal to 4. // // https://zips.z.cash/protocol/protocol.pdf#blockheader - if version < 4 { + if version < ZCASH_BLOCK_VERSION { return Err(SerializationError::Parse("version must be at least 4")); } diff --git a/zebra-consensus/src/lib.rs b/zebra-consensus/src/lib.rs index 1c5fa20886b..cb5d9480a54 100644 --- a/zebra-consensus/src/lib.rs +++ b/zebra-consensus/src/lib.rs @@ -46,7 +46,7 @@ pub mod chain; #[allow(missing_docs)] pub mod error; -pub use block::VerifyBlockError; +pub use block::{VerifyBlockError, MAX_BLOCK_SIGOPS}; pub use chain::VerifyChainError; pub use checkpoint::{ CheckpointList, VerifyCheckpointError, MAX_CHECKPOINT_BYTE_COUNT, MAX_CHECKPOINT_HEIGHT_GAP, diff --git a/zebra-rpc/Cargo.toml b/zebra-rpc/Cargo.toml index 67b3ee3696a..167a7ecb99c 100644 --- a/zebra-rpc/Cargo.toml +++ b/zebra-rpc/Cargo.toml @@ -37,6 +37,7 @@ 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 ae9c004e885..d5427515a0a 100644 --- a/zebra-rpc/src/methods/get_block_template_rpcs.rs +++ b/zebra-rpc/src/methods/get_block_template_rpcs.rs @@ -9,12 +9,14 @@ use tower::{buffer::Buffer, Service, ServiceExt}; use zebra_chain::{ amount::Amount, - block::Height, block::{self, Block}, + block::{Height, MAX_BLOCK_BYTES, ZCASH_BLOCK_VERSION}, chain_tip::ChainTip, serialization::ZcashDeserializeInto, }; -use zebra_consensus::{BlockError, VerifyBlockError, VerifyChainError, VerifyCheckpointError}; +use zebra_consensus::{ + BlockError, VerifyBlockError, VerifyChainError, VerifyCheckpointError, MAX_BLOCK_SIGOPS, +}; use zebra_node_services::mempool; use crate::methods::{ @@ -26,6 +28,7 @@ use crate::methods::{ }; pub mod config; +pub mod constants; pub(crate) mod types; /// getblocktemplate RPC method signatures. @@ -292,7 +295,8 @@ where Ok(GetBlockTemplate { capabilities: vec![], - version: 0, + // The block version + version: ZCASH_BLOCK_VERSION, previous_block_hash: GetBlockHash([0; 32].into()), block_commitments_hash: [0; 32].into(), @@ -332,12 +336,17 @@ where min_time: 0, - mutable: vec![], + // Hardcoded list of block fields the miner is allowed to change. + mutable: constants::GET_BLOCK_TEMPLATE_MUTABLE_FIELD.to_vec(), + + // A range of valid nonces that goes from `u32::MIN` to `u32::MAX`. + nonce_range: constants::GET_BLOCK_TEMPLATE_NONCE_RANGE_FIELD.to_string(), - nonce_range: empty_string.clone(), + // Max legacy signature operations in the block. + sigop_limit: MAX_BLOCK_SIGOPS, - sigop_limit: 0, - size_limit: 0, + // Max block size in bytes + size_limit: MAX_BLOCK_BYTES, cur_time: 0, diff --git a/zebra-rpc/src/methods/get_block_template_rpcs/constants.rs b/zebra-rpc/src/methods/get_block_template_rpcs/constants.rs new file mode 100644 index 00000000000..83fd691ad6b --- /dev/null +++ b/zebra-rpc/src/methods/get_block_template_rpcs/constants.rs @@ -0,0 +1,15 @@ +//! 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() + ]; +} diff --git a/zebra-rpc/src/methods/tests/snapshot/snapshots/get_block_template@mainnet_10.snap b/zebra-rpc/src/methods/tests/snapshot/snapshots/get_block_template@mainnet_10.snap index cb8f20d834b..21fd8d57239 100644 --- a/zebra-rpc/src/methods/tests/snapshot/snapshots/get_block_template@mainnet_10.snap +++ b/zebra-rpc/src/methods/tests/snapshot/snapshots/get_block_template@mainnet_10.snap @@ -1,10 +1,11 @@ --- source: zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs +assertion_line: 128 expression: block_template --- { "capabilities": [], - "version": 0, + "version": 4, "previousblockhash": "0000000000000000000000000000000000000000000000000000000000000000", "blockcommitmentshash": "0000000000000000000000000000000000000000000000000000000000000000", "lightclientroothash": "0000000000000000000000000000000000000000000000000000000000000000", @@ -27,10 +28,14 @@ expression: block_template }, "target": "", "mintime": 0, - "mutable": [], - "noncerange": "", - "sigoplimit": 0, - "sizelimit": 0, + "mutable": [ + "time", + "transactions", + "prevblock" + ], + "noncerange": "00000000ffffffff", + "sigoplimit": 20000, + "sizelimit": 2000000, "curtime": 0, "bits": "", "height": 0 diff --git a/zebra-rpc/src/methods/tests/snapshot/snapshots/get_block_template@testnet_10.snap b/zebra-rpc/src/methods/tests/snapshot/snapshots/get_block_template@testnet_10.snap index cb8f20d834b..21fd8d57239 100644 --- a/zebra-rpc/src/methods/tests/snapshot/snapshots/get_block_template@testnet_10.snap +++ b/zebra-rpc/src/methods/tests/snapshot/snapshots/get_block_template@testnet_10.snap @@ -1,10 +1,11 @@ --- source: zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs +assertion_line: 128 expression: block_template --- { "capabilities": [], - "version": 0, + "version": 4, "previousblockhash": "0000000000000000000000000000000000000000000000000000000000000000", "blockcommitmentshash": "0000000000000000000000000000000000000000000000000000000000000000", "lightclientroothash": "0000000000000000000000000000000000000000000000000000000000000000", @@ -27,10 +28,14 @@ expression: block_template }, "target": "", "mintime": 0, - "mutable": [], - "noncerange": "", - "sigoplimit": 0, - "sizelimit": 0, + "mutable": [ + "time", + "transactions", + "prevblock" + ], + "noncerange": "00000000ffffffff", + "sigoplimit": 20000, + "sizelimit": 2000000, "curtime": 0, "bits": "", "height": 0 diff --git a/zebra-rpc/src/methods/tests/vectors.rs b/zebra-rpc/src/methods/tests/vectors.rs index be2a04416aa..daefd1a4cdd 100644 --- a/zebra-rpc/src/methods/tests/vectors.rs +++ b/zebra-rpc/src/methods/tests/vectors.rs @@ -777,6 +777,12 @@ async fn rpc_getblockhash() { #[cfg(feature = "getblocktemplate-rpcs")] #[tokio::test(flavor = "multi_thread")] async fn rpc_getblocktemplate() { + use crate::methods::get_block_template_rpcs::constants::{ + GET_BLOCK_TEMPLATE_MUTABLE_FIELD, GET_BLOCK_TEMPLATE_NONCE_RANGE_FIELD, + }; + use zebra_chain::block::{MAX_BLOCK_BYTES, ZCASH_BLOCK_VERSION}; + use zebra_consensus::MAX_BLOCK_SIGOPS; + let _init_guard = zebra_test::init(); // Create a continuous chain of mainnet blocks from genesis @@ -824,14 +830,20 @@ async fn rpc_getblocktemplate() { .expect("unexpected error in getblocktemplate RPC call"); assert!(get_block_template.capabilities.is_empty()); - assert_eq!(get_block_template.version, 0); + assert_eq!(get_block_template.version, ZCASH_BLOCK_VERSION); assert!(get_block_template.transactions.is_empty()); assert!(get_block_template.target.is_empty()); assert_eq!(get_block_template.min_time, 0); - assert!(get_block_template.mutable.is_empty()); - assert!(get_block_template.nonce_range.is_empty()); - assert_eq!(get_block_template.sigop_limit, 0); - assert_eq!(get_block_template.size_limit, 0); + assert_eq!( + get_block_template.mutable, + GET_BLOCK_TEMPLATE_MUTABLE_FIELD.to_vec() + ); + assert_eq!( + get_block_template.nonce_range, + GET_BLOCK_TEMPLATE_NONCE_RANGE_FIELD + ); + assert_eq!(get_block_template.sigop_limit, MAX_BLOCK_SIGOPS); + assert_eq!(get_block_template.size_limit, MAX_BLOCK_BYTES); assert_eq!(get_block_template.cur_time, 0); assert!(get_block_template.bits.is_empty()); assert_eq!(get_block_template.height, 0); From 5590d0cab8339748ed97f88fcf40cf144916ec18 Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 7 Nov 2022 22:17:54 +1000 Subject: [PATCH 2/5] suggestion: Avoid new uses of lazy_static (#5559) * Avoid using lazy_static * Add some missing documentation Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- Cargo.lock | 1 - zebra-rpc/Cargo.toml | 1 - .../src/methods/get_block_template_rpcs.rs | 5 +++- .../get_block_template_rpcs/constants.rs | 12 ++------ .../types/default_roots.rs | 5 +++- .../types/get_block_template.rs | 28 +++++++++++++------ 6 files changed, 30 insertions(+), 22 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"]; 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, From 304048efe2a07eec86110d7c3cdeb08bb01f16cc Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Mon, 7 Nov 2022 20:12:54 -0300 Subject: [PATCH 3/5] minor fixes --- zebra-rpc/src/methods/get_block_template_rpcs.rs | 2 +- .../methods/tests/snapshot/get_block_template_rpcs.rs | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/zebra-rpc/src/methods/get_block_template_rpcs.rs b/zebra-rpc/src/methods/get_block_template_rpcs.rs index e58f38ffa7d..f79374bebfa 100644 --- a/zebra-rpc/src/methods/get_block_template_rpcs.rs +++ b/zebra-rpc/src/methods/get_block_template_rpcs.rs @@ -276,7 +276,7 @@ where TODO: create a method Transaction::new_v5_coinbase(network, tip_height, miner_fee), and call it here. - */ + */ let coinbase_tx = if mempool_txs.is_empty() { let empty_string = String::from(""); return Ok(GetBlockTemplate { diff --git a/zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs b/zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs index daec0e53d2c..6ddd6ccf53e 100644 --- a/zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs +++ b/zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs @@ -15,7 +15,9 @@ use zebra_state::LatestChainTip; use zebra_test::mock_service::{MockService, PanicAssertion}; use crate::methods::{ - get_block_template_rpcs::types::{hex_data::HexData, submit_block}, + get_block_template_rpcs::types::{ + get_block_template::GetBlockTemplate, hex_data::HexData, submit_block, + }, GetBlockHash, GetBlockTemplateRpc, GetBlockTemplateRpcImpl, }; @@ -122,10 +124,7 @@ fn snapshot_rpc_getblockhash(block_hash: GetBlockHash, settings: &insta::Setting } /// Snapshot `getblocktemplate` response, using `cargo insta` and JSON serialization. -fn snapshot_rpc_getblocktemplate( - block_template: crate::methods::get_block_template_rpcs::types::get_block_template::GetBlockTemplate, - settings: &insta::Settings, -) { +fn snapshot_rpc_getblocktemplate(block_template: GetBlockTemplate, settings: &insta::Settings) { settings.bind(|| insta::assert_json_snapshot!("get_block_template", block_template)); } From ac93f922486f65e1a337ce5f14c37772f58c1357 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Mon, 7 Nov 2022 20:22:24 -0300 Subject: [PATCH 4/5] move docs to struct --- zebra-rpc/src/methods/get_block_template_rpcs.rs | 5 ----- .../types/get_block_template.rs | 12 ++++-------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/zebra-rpc/src/methods/get_block_template_rpcs.rs b/zebra-rpc/src/methods/get_block_template_rpcs.rs index f79374bebfa..dab76fb942f 100644 --- a/zebra-rpc/src/methods/get_block_template_rpcs.rs +++ b/zebra-rpc/src/methods/get_block_template_rpcs.rs @@ -326,7 +326,6 @@ where Ok(GetBlockTemplate { capabilities: vec![], - // The block version version: ZCASH_BLOCK_VERSION, previous_block_hash: GetBlockHash([0; 32].into()), @@ -348,19 +347,15 @@ where min_time: 0, - // Hardcoded list of block fields the miner is allowed to change. 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(), - // Max legacy signature operations in the block. sigop_limit: MAX_BLOCK_SIGOPS, - // Max block size in bytes size_limit: MAX_BLOCK_BYTES, cur_time: 0, 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 022262f80a8..63840d15a47 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 @@ -74,22 +74,18 @@ pub struct GetBlockTemplate { // TODO: use DateTime32 type? pub min_time: u32, - /// Add documentation. + /// Hardcoded list of block fields the miner is allowed to change. pub mutable: Vec, - /// Add documentation. + /// A range of valid nonces that goes from `u32::MIN` to `u32::MAX`. #[serde(rename = "noncerange")] pub nonce_range: String, - /// Add documentation. - /// - /// The same as `MAX_BLOCK_SIGOPS`. + /// Max legacy signature operations in the block. #[serde(rename = "sigoplimit")] pub sigop_limit: u64, - /// Add documentation. - /// - /// The same as `MAX_BLOCK_BYTES`. + /// Max block size in bytes #[serde(rename = "sizelimit")] pub size_limit: u64, From cb2753f81fc39b8f005311497095eeae21ec5615 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 8 Nov 2022 10:46:08 -0300 Subject: [PATCH 5/5] add fixed values to coinbase tx --- zebra-rpc/src/methods/get_block_template_rpcs.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/zebra-rpc/src/methods/get_block_template_rpcs.rs b/zebra-rpc/src/methods/get_block_template_rpcs.rs index dab76fb942f..348fd9500cf 100644 --- a/zebra-rpc/src/methods/get_block_template_rpcs.rs +++ b/zebra-rpc/src/methods/get_block_template_rpcs.rs @@ -281,7 +281,7 @@ where let empty_string = String::from(""); return Ok(GetBlockTemplate { capabilities: vec![], - version: 0, + version: ZCASH_BLOCK_VERSION, previous_block_hash: GetBlockHash([0; 32].into()), block_commitments_hash: [0; 32].into(), light_client_root_hash: [0; 32].into(), @@ -304,10 +304,13 @@ where }, target: empty_string.clone(), min_time: 0, - mutable: vec![], - nonce_range: empty_string.clone(), - sigop_limit: 0, - size_limit: 0, + mutable: constants::GET_BLOCK_TEMPLATE_MUTABLE_FIELD + .iter() + .map(ToString::to_string) + .collect(), + nonce_range: constants::GET_BLOCK_TEMPLATE_NONCE_RANGE_FIELD.to_string(), + sigop_limit: MAX_BLOCK_SIGOPS, + size_limit: MAX_BLOCK_BYTES, cur_time: 0, bits: empty_string, height: 0,