From c8a35e60f77ace0c167232149e6c1fdd14b29ed2 Mon Sep 17 00:00:00 2001 From: arya2 Date: Tue, 10 Jan 2023 12:57:41 -0500 Subject: [PATCH] Applies cleanup suggestions from code review --- .../methods/get_block_template_rpcs/constants.rs | 5 +++++ zebra-state/src/service.rs | 16 ++++++++-------- zebra-state/src/service/check.rs | 4 ++-- zebra-state/src/service/write.rs | 4 +--- 4 files changed, 16 insertions(+), 13 deletions(-) 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..712be0066e8 100644 --- a/zebra-rpc/src/methods/get_block_template_rpcs/constants.rs +++ b/zebra-rpc/src/methods/get_block_template_rpcs/constants.rs @@ -26,6 +26,11 @@ pub const GET_BLOCK_TEMPLATE_MUTABLE_FIELD: &[&str] = &[ ]; /// A hardcoded list of Zebra's getblocktemplate RPC capabilities. +/// +/// See: +/// - +/// - +/// - pub const GET_BLOCK_TEMPLATE_CAPABILITIES_FIELD: &[&str] = &["proposal"]; /// The max estimated distance to the chain tip for the getblocktemplate method. 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.