Skip to content

Commit

Permalink
Applies cleanup suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
arya2 committed Jan 10, 2023
1 parent d75e17a commit 9ce7d8a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
6 changes: 6 additions & 0 deletions zebra-rpc/src/methods/get_block_template_rpcs/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
/// <https://en.bitcoin.it/wiki/BIP_0023#Mutations>
pub const GET_BLOCK_TEMPLATE_MUTABLE_FIELD: &[&str] = &[
// Standard mutations, copied from zcashd
"time",
Expand All @@ -26,6 +28,8 @@ pub const GET_BLOCK_TEMPLATE_MUTABLE_FIELD: &[&str] = &[
];

/// A hardcoded list of Zebra's getblocktemplate RPC capabilities.
///
/// <https://en.bitcoin.it/wiki/BIP_0023#Block_Proposal>
pub const GET_BLOCK_TEMPLATE_CAPABILITIES_FIELD: &[&str] = &["proposal"];

/// The max estimated distance to the chain tip for the getblocktemplate method.
Expand All @@ -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.
/// >
/// > <https://zips.z.cash/protocol/protocol.pdf#blockheader>
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.
Expand Down
16 changes: 8 additions & 8 deletions zebra-state/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1718,14 +1718,14 @@ impl Service<ReadRequest> 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
Expand Down
4 changes: 2 additions & 2 deletions zebra-state/src/service/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 1 addition & 3 deletions zebra-state/src/service/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down

0 comments on commit 9ce7d8a

Please sign in to comment.