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 2c0e7814e44..ed624e4dc83 100644 --- a/zebra-rpc/src/methods/get_block_template_rpcs/constants.rs +++ b/zebra-rpc/src/methods/get_block_template_rpcs/constants.rs @@ -18,6 +18,8 @@ pub const GET_BLOCK_TEMPLATE_MEMPOOL_LONG_POLL_INTERVAL: u64 = 5; pub const GET_BLOCK_TEMPLATE_NONCE_RANGE_FIELD: &str = "00000000ffffffff"; /// A hardcoded list of fields that the miner can change from the block template. +/// +/// pub const GET_BLOCK_TEMPLATE_MUTABLE_FIELD: &[&str] = &[ // Standard mutations, copied from zcashd "time", @@ -26,6 +28,8 @@ pub const GET_BLOCK_TEMPLATE_MUTABLE_FIELD: &[&str] = &[ ]; /// A hardcoded list of Zebra's getblocktemplate RPC capabilities. +/// +/// pub const GET_BLOCK_TEMPLATE_CAPABILITIES_FIELD: &[&str] = &["proposal"]; /// The max estimated distance to the chain tip for the getblocktemplate method. @@ -34,6 +38,8 @@ pub const GET_BLOCK_TEMPLATE_CAPABILITIES_FIELD: &[&str] = &["proposal"]; /// > A full validator MUST NOT accept blocks with nTime more than two hours in the future /// > according to its clock. This is not strictly a consensus rule because it is nondeterministic, /// > and clock time varies between nodes. +/// > +/// > pub const MAX_ESTIMATED_DISTANCE_TO_NETWORK_CHAIN_TIP: i32 = 100; /// The RPC error code used by `zcashd` for when it's still downloading initial blocks. diff --git a/zebra-state/src/service.rs b/zebra-state/src/service.rs index 5ed7f1e9d34..b8638520dec 100644 --- a/zebra-state/src/service.rs +++ b/zebra-state/src/service.rs @@ -1718,14 +1718,14 @@ impl Service for ReadStateService { tracing::info!("attempting to validate and commit block proposal onto a cloned non-finalized state"); let mut latest_non_finalized_state = state.latest_non_finalized_state(); - // The previous block of a valid proposal must be on the best chain tip. - let Some((_best_tip_height, best_tip_hash) = read::best_tip(&latest_non_finalized_state, &state.db) { - if prepared.block.header.previous_block_hash != best_tip_hash { - return Err("proposal is not based on the current best chain tip: previous block hash must be the best chain tip".into()); - } - } else { - return Err("state is empty: wait for Zebra to sync before submitting a proposal".into()); - } + // The previous block of a valid proposal must be on the best chain tip. + let Some((_best_tip_height, best_tip_hash)) = read::best_tip(&latest_non_finalized_state, &state.db) else { + return Err("state is empty: wait for Zebra to sync before submitting a proposal".into()); + }; + + if prepared.block.header.previous_block_hash != best_tip_hash { + return Err("proposal is not based on the current best chain tip: previous block hash must be the best chain tip".into()); + } // This clone of the non-finalized state is dropped when this closure returns. // The non-finalized state that's used in the rest of the state (including finalizing diff --git a/zebra-state/src/service/check.rs b/zebra-state/src/service/check.rs index 603eb4f3e8d..0b3600ad89b 100644 --- a/zebra-state/src/service/check.rs +++ b/zebra-state/src/service/check.rs @@ -14,13 +14,13 @@ use zebra_chain::{ use crate::{ service::{ block_iter::any_ancestor_blocks, check::difficulty::POW_ADJUSTMENT_BLOCK_SPAN, - non_finalized_state::NonFinalizedState, + finalized_state::ZebraDb, non_finalized_state::NonFinalizedState, }, BoxError, PreparedBlock, ValidateContextError, }; // use self as check -use super::{check, finalized_state::ZebraDb}; +use super::check; // These types are used in doc links #[allow(unused_imports)] diff --git a/zebra-state/src/service/write.rs b/zebra-state/src/service/write.rs index 7b91c09227c..8f33af7b6d1 100644 --- a/zebra-state/src/service/write.rs +++ b/zebra-state/src/service/write.rs @@ -12,7 +12,7 @@ use crate::{ constants::MAX_BLOCK_REORG_HEIGHT, service::{ check, - finalized_state::FinalizedState, + finalized_state::{FinalizedState, ZebraDb}, non_finalized_state::NonFinalizedState, queued_blocks::{QueuedFinalized, QueuedNonFinalized}, BoxError, ChainTipBlock, ChainTipSender, CloneError, @@ -27,8 +27,6 @@ use crate::service::{ non_finalized_state::Chain, }; -use super::finalized_state::ZebraDb; - /// The maximum size of the parent error map. /// /// We allow enough space for multiple concurrent chain forks with errors.