2021-06-03 15:48:40 -07:00
|
|
|
|
//! Top-level semantic block verification for Zebra.
|
|
|
|
|
//!
|
2023-06-01 05:29:03 -07:00
|
|
|
|
//! Verifies blocks using the [`CheckpointVerifier`] or full [`SemanticBlockVerifier`],
|
2021-06-03 15:48:40 -07:00
|
|
|
|
//! depending on the config and block height.
|
2021-06-18 10:43:05 -07:00
|
|
|
|
//!
|
|
|
|
|
//! # Correctness
|
|
|
|
|
//!
|
|
|
|
|
//! Block and transaction verification requests should be wrapped in a timeout, because:
|
|
|
|
|
//! - checkpoint verification waits for previous blocks, and
|
|
|
|
|
//! - full block and transaction verification wait for UTXOs from previous blocks.
|
|
|
|
|
//!
|
|
|
|
|
//! Otherwise, verification of out-of-order and invalid blocks and transactions can hang
|
|
|
|
|
//! indefinitely.
|
2021-06-03 15:48:40 -07:00
|
|
|
|
|
2020-07-20 18:34:23 -07:00
|
|
|
|
use std::{
|
|
|
|
|
future::Future,
|
|
|
|
|
pin::Pin,
|
|
|
|
|
task::{Context, Poll},
|
|
|
|
|
};
|
2021-08-25 08:07:26 -07:00
|
|
|
|
|
|
|
|
|
use displaydoc::Display;
|
|
|
|
|
use futures::{FutureExt, TryFutureExt};
|
2020-09-21 11:54:06 -07:00
|
|
|
|
use thiserror::Error;
|
2023-02-20 21:30:29 -08:00
|
|
|
|
use tokio::task::JoinHandle;
|
2020-09-09 20:16:11 -07:00
|
|
|
|
use tower::{buffer::Buffer, util::BoxService, Service, ServiceExt};
|
2023-02-20 21:30:29 -08:00
|
|
|
|
use tracing::{instrument, Instrument, Span};
|
2020-07-20 18:34:23 -07:00
|
|
|
|
|
2020-09-09 18:53:40 -07:00
|
|
|
|
use zebra_chain::{
|
2023-01-11 15:39:51 -08:00
|
|
|
|
block::{self, Height},
|
2021-06-17 17:05:28 -07:00
|
|
|
|
parameters::Network,
|
2020-09-09 18:53:40 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
use zebra_state as zs;
|
2020-07-20 18:34:23 -07:00
|
|
|
|
|
2020-09-09 20:16:11 -07:00
|
|
|
|
use crate::{
|
2023-06-01 05:29:03 -07:00
|
|
|
|
block::{Request, SemanticBlockVerifier, VerifyBlockError},
|
2021-02-19 16:43:38 -08:00
|
|
|
|
checkpoint::{CheckpointList, CheckpointVerifier, VerifyCheckpointError},
|
2021-08-25 08:07:26 -07:00
|
|
|
|
error::TransactionError,
|
2024-03-12 14:41:44 -07:00
|
|
|
|
transaction, BoxError, Config, ParameterCheckpoint as _,
|
2020-09-09 20:16:11 -07:00
|
|
|
|
};
|
|
|
|
|
|
2021-08-25 08:07:26 -07:00
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests;
|
|
|
|
|
|
|
|
|
|
/// The bound for the chain verifier and transaction verifier buffers.
|
2021-02-08 14:13:55 -08:00
|
|
|
|
///
|
|
|
|
|
/// We choose the verifier buffer bound based on the maximum number of
|
|
|
|
|
/// concurrent verifier users, to avoid contention:
|
2021-08-25 08:07:26 -07:00
|
|
|
|
/// - the `ChainSync` block download and verify stream
|
|
|
|
|
/// - the `Inbound` block download and verify stream
|
|
|
|
|
/// - the `Mempool` transaction download and verify stream
|
|
|
|
|
/// - a block miner component, which we might add in future, and
|
2021-02-08 14:13:55 -08:00
|
|
|
|
/// - 1 extra slot to avoid contention.
|
|
|
|
|
///
|
|
|
|
|
/// We deliberately add extra slots, because they only cost a small amount of
|
|
|
|
|
/// memory, but missing slots can significantly slow down Zebra.
|
2021-08-25 08:07:26 -07:00
|
|
|
|
const VERIFIER_BUFFER_BOUND: usize = 5;
|
2021-02-08 14:13:55 -08:00
|
|
|
|
|
2023-06-01 05:29:03 -07:00
|
|
|
|
/// The block verifier router routes requests to either the checkpoint verifier or the
|
|
|
|
|
/// semantic block verifier, depending on the maximum checkpoint height.
|
2021-06-18 10:43:05 -07:00
|
|
|
|
///
|
|
|
|
|
/// # Correctness
|
|
|
|
|
///
|
|
|
|
|
/// Block verification requests should be wrapped in a timeout, so that
|
2023-06-01 05:29:03 -07:00
|
|
|
|
/// out-of-order and invalid requests do not hang indefinitely. See the [`router`](`crate::router`)
|
2021-06-18 10:43:05 -07:00
|
|
|
|
/// module documentation for details.
|
2023-06-01 05:29:03 -07:00
|
|
|
|
struct BlockVerifierRouter<S, V>
|
2020-09-02 21:23:57 -07:00
|
|
|
|
where
|
2020-09-09 20:16:11 -07:00
|
|
|
|
S: Service<zs::Request, Response = zs::Response, Error = BoxError> + Send + Clone + 'static,
|
2020-09-02 21:23:57 -07:00
|
|
|
|
S::Future: Send + 'static,
|
2021-08-25 08:07:26 -07:00
|
|
|
|
V: Service<transaction::Request, Response = transaction::Response, Error = BoxError>
|
|
|
|
|
+ Send
|
|
|
|
|
+ Clone
|
|
|
|
|
+ 'static,
|
|
|
|
|
V::Future: Send + 'static,
|
2020-09-02 21:23:57 -07:00
|
|
|
|
{
|
2021-12-17 08:31:51 -08:00
|
|
|
|
/// The checkpointing block verifier.
|
|
|
|
|
///
|
|
|
|
|
/// Always used for blocks before `Canopy`, optionally used for the entire checkpoint list.
|
2021-02-19 16:43:38 -08:00
|
|
|
|
checkpoint: CheckpointVerifier<S>,
|
2021-12-17 08:31:51 -08:00
|
|
|
|
|
|
|
|
|
/// The highest permitted checkpoint block.
|
|
|
|
|
///
|
|
|
|
|
/// This height must be in the `checkpoint` verifier's checkpoint list.
|
2020-09-09 20:16:11 -07:00
|
|
|
|
max_checkpoint_height: block::Height,
|
2021-12-17 08:31:51 -08:00
|
|
|
|
|
2023-06-01 05:29:03 -07:00
|
|
|
|
/// The full semantic block verifier, used for blocks after `max_checkpoint_height`.
|
|
|
|
|
block: SemanticBlockVerifier<S, V>,
|
2020-07-20 18:34:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-03 15:48:40 -07:00
|
|
|
|
/// An error while semantically verifying a block.
|
2022-12-07 22:11:33 -08:00
|
|
|
|
//
|
|
|
|
|
// One or both of these error variants are at least 140 bytes
|
2020-09-21 11:54:06 -07:00
|
|
|
|
#[derive(Debug, Display, Error)]
|
2022-12-07 22:11:33 -08:00
|
|
|
|
#[allow(missing_docs)]
|
2023-06-01 05:29:03 -07:00
|
|
|
|
pub enum RouterError {
|
2022-12-07 22:11:33 -08:00
|
|
|
|
/// Block could not be checkpointed
|
|
|
|
|
Checkpoint { source: Box<VerifyCheckpointError> },
|
|
|
|
|
/// Block could not be full-verified
|
|
|
|
|
Block { source: Box<VerifyBlockError> },
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 05:29:03 -07:00
|
|
|
|
impl From<VerifyCheckpointError> for RouterError {
|
2022-12-07 22:11:33 -08:00
|
|
|
|
fn from(err: VerifyCheckpointError) -> Self {
|
2023-06-01 05:29:03 -07:00
|
|
|
|
RouterError::Checkpoint {
|
2022-12-07 22:11:33 -08:00
|
|
|
|
source: Box::new(err),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 05:29:03 -07:00
|
|
|
|
impl From<VerifyBlockError> for RouterError {
|
2022-12-07 22:11:33 -08:00
|
|
|
|
fn from(err: VerifyBlockError) -> Self {
|
2023-06-01 05:29:03 -07:00
|
|
|
|
RouterError::Block {
|
2022-12-07 22:11:33 -08:00
|
|
|
|
source: Box::new(err),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 05:29:03 -07:00
|
|
|
|
impl RouterError {
|
2022-12-07 22:11:33 -08:00
|
|
|
|
/// Returns `true` if this is definitely a duplicate request.
|
|
|
|
|
/// Some duplicate requests might not be detected, and therefore return `false`.
|
|
|
|
|
pub fn is_duplicate_request(&self) -> bool {
|
|
|
|
|
match self {
|
2023-06-01 05:29:03 -07:00
|
|
|
|
RouterError::Checkpoint { source, .. } => source.is_duplicate_request(),
|
|
|
|
|
RouterError::Block { source, .. } => source.is_duplicate_request(),
|
2022-12-07 22:11:33 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-21 11:54:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 05:29:03 -07:00
|
|
|
|
impl<S, V> Service<Request> for BlockVerifierRouter<S, V>
|
2020-07-20 18:34:23 -07:00
|
|
|
|
where
|
2020-09-09 20:16:11 -07:00
|
|
|
|
S: Service<zs::Request, Response = zs::Response, Error = BoxError> + Send + Clone + 'static,
|
2020-07-20 18:34:23 -07:00
|
|
|
|
S::Future: Send + 'static,
|
2021-08-25 08:07:26 -07:00
|
|
|
|
V: Service<transaction::Request, Response = transaction::Response, Error = BoxError>
|
|
|
|
|
+ Send
|
|
|
|
|
+ Clone
|
|
|
|
|
+ 'static,
|
|
|
|
|
V::Future: Send + 'static,
|
2020-07-20 18:34:23 -07:00
|
|
|
|
{
|
2020-08-15 23:20:01 -07:00
|
|
|
|
type Response = block::Hash;
|
2023-06-01 05:29:03 -07:00
|
|
|
|
type Error = RouterError;
|
2020-07-20 18:34:23 -07:00
|
|
|
|
type Future =
|
|
|
|
|
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
|
|
|
|
|
|
2021-02-19 16:43:38 -08:00
|
|
|
|
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
2021-03-26 20:50:46 -07:00
|
|
|
|
// CORRECTNESS
|
|
|
|
|
//
|
|
|
|
|
// The current task must be scheduled for wakeup every time we return
|
|
|
|
|
// `Poll::Pending`.
|
|
|
|
|
//
|
|
|
|
|
// If either verifier is unready, this task is scheduled for wakeup when it becomes
|
|
|
|
|
// ready.
|
2021-02-08 14:13:55 -08:00
|
|
|
|
//
|
2021-02-19 16:43:38 -08:00
|
|
|
|
// We acquire checkpoint readiness before block readiness, to avoid an unlikely
|
|
|
|
|
// hang during the checkpoint to block verifier transition. If the checkpoint and
|
|
|
|
|
// block verifiers are contending for the same buffer/batch, we want the checkpoint
|
|
|
|
|
// verifier to win, so that checkpoint verification completes, and block verification
|
|
|
|
|
// can start. (Buffers and batches have multiple slots, so this contention is unlikely.)
|
|
|
|
|
use futures::ready;
|
|
|
|
|
// The chain verifier holds one slot in each verifier, for each concurrent task.
|
|
|
|
|
// Therefore, any shared buffers or batches polled by these verifiers should double
|
|
|
|
|
// their bounds. (For example, the state service buffer.)
|
2022-12-07 22:11:33 -08:00
|
|
|
|
ready!(self.checkpoint.poll_ready(cx))?;
|
|
|
|
|
ready!(self.block.poll_ready(cx))?;
|
2021-02-08 14:13:55 -08:00
|
|
|
|
Poll::Ready(Ok(()))
|
2020-07-20 18:34:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-11 15:39:51 -08:00
|
|
|
|
fn call(&mut self, request: Request) -> Self::Future {
|
|
|
|
|
let block = request.block();
|
|
|
|
|
|
2020-10-21 21:06:21 -07:00
|
|
|
|
match block.coinbase_height() {
|
2023-01-11 15:39:51 -08:00
|
|
|
|
#[cfg(feature = "getblocktemplate-rpcs")]
|
|
|
|
|
// There's currently no known use case for block proposals below the checkpoint height,
|
|
|
|
|
// so it's okay to immediately return an error here.
|
|
|
|
|
Some(height) if height <= self.max_checkpoint_height && request.is_proposal() => {
|
|
|
|
|
async {
|
|
|
|
|
// TODO: Add a `ValidateProposalError` enum with a `BelowCheckpoint` variant?
|
|
|
|
|
Err(VerifyBlockError::ValidateProposal(
|
|
|
|
|
"block proposals must be above checkpoint height".into(),
|
|
|
|
|
))?
|
|
|
|
|
}
|
|
|
|
|
.boxed()
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-07 22:11:33 -08:00
|
|
|
|
Some(height) if height <= self.max_checkpoint_height => {
|
|
|
|
|
self.checkpoint.call(block).map_err(Into::into).boxed()
|
|
|
|
|
}
|
2020-10-21 21:06:21 -07:00
|
|
|
|
// This also covers blocks with no height, which the block verifier
|
|
|
|
|
// will reject immediately.
|
2023-01-11 15:39:51 -08:00
|
|
|
|
_ => self.block.call(request).map_err(Into::into).boxed(),
|
2020-07-20 18:34:23 -07:00
|
|
|
|
}
|
2020-07-29 03:51:26 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-26 23:12:57 -07:00
|
|
|
|
/// Initialize block and transaction verification services.
|
2021-11-19 15:02:56 -08:00
|
|
|
|
///
|
|
|
|
|
/// Returns a block verifier, transaction verifier,
|
2023-10-26 23:12:57 -07:00
|
|
|
|
/// a [`BackgroundTaskHandles`] with the state checkpoint verify task,
|
2022-07-06 07:13:57 -07:00
|
|
|
|
/// and the maximum configured checkpoint verification height.
|
2020-11-12 11:43:17 -08:00
|
|
|
|
///
|
|
|
|
|
/// The consensus configuration is specified by `config`, and the Zcash network
|
|
|
|
|
/// to verify blocks for is specified by `network`.
|
|
|
|
|
///
|
|
|
|
|
/// The block verification service asynchronously performs semantic verification
|
|
|
|
|
/// checks. Blocks that pass semantic verification are submitted to the supplied
|
|
|
|
|
/// `state_service` for contextual verification before being committed to the chain.
|
2020-07-23 18:47:48 -07:00
|
|
|
|
///
|
2021-08-25 08:07:26 -07:00
|
|
|
|
/// The transaction verification service asynchronously performs semantic verification
|
|
|
|
|
/// checks. Transactions that pass semantic verification return an `Ok` result to the caller.
|
|
|
|
|
///
|
2020-09-09 20:16:11 -07:00
|
|
|
|
/// This function should only be called once for a particular state service.
|
2020-11-12 11:43:17 -08:00
|
|
|
|
///
|
|
|
|
|
/// Dropped requests are cancelled on a best-effort basis, but may continue to be processed.
|
2021-06-18 10:43:05 -07:00
|
|
|
|
///
|
|
|
|
|
/// # Correctness
|
|
|
|
|
///
|
2021-08-25 08:07:26 -07:00
|
|
|
|
/// Block and transaction verification requests should be wrapped in a timeout,
|
|
|
|
|
/// so that out-of-order and invalid requests do not hang indefinitely.
|
2023-06-01 05:29:03 -07:00
|
|
|
|
/// See the [`router`](`crate::router`) module documentation for details.
|
2020-09-11 12:53:19 -07:00
|
|
|
|
#[instrument(skip(state_service))]
|
2020-07-23 18:47:48 -07:00
|
|
|
|
pub async fn init<S>(
|
2020-08-19 19:28:21 -07:00
|
|
|
|
config: Config,
|
2020-07-20 19:24:58 -07:00
|
|
|
|
network: Network,
|
2021-02-19 16:43:38 -08:00
|
|
|
|
mut state_service: S,
|
2021-08-25 08:07:26 -07:00
|
|
|
|
) -> (
|
2023-06-01 05:29:03 -07:00
|
|
|
|
Buffer<BoxService<Request, block::Hash, RouterError>, Request>,
|
2021-08-25 08:07:26 -07:00
|
|
|
|
Buffer<
|
|
|
|
|
BoxService<transaction::Request, transaction::Response, TransactionError>,
|
|
|
|
|
transaction::Request,
|
|
|
|
|
>,
|
2023-02-20 21:30:29 -08:00
|
|
|
|
BackgroundTaskHandles,
|
2022-07-06 07:13:57 -07:00
|
|
|
|
Height,
|
2021-08-25 08:07:26 -07:00
|
|
|
|
)
|
2020-07-20 19:24:58 -07:00
|
|
|
|
where
|
2020-09-09 20:16:11 -07:00
|
|
|
|
S: Service<zs::Request, Response = zs::Response, Error = BoxError> + Send + Clone + 'static,
|
2020-07-20 19:24:58 -07:00
|
|
|
|
S::Future: Send + 'static,
|
|
|
|
|
{
|
2023-10-26 23:12:57 -07:00
|
|
|
|
// Give other tasks priority before spawning the checkpoint task.
|
2021-11-25 08:26:32 -08:00
|
|
|
|
tokio::task::yield_now().await;
|
2021-11-19 15:02:56 -08:00
|
|
|
|
|
2023-02-20 21:30:29 -08:00
|
|
|
|
// Make sure the state contains the known best chain checkpoints, in a separate thread.
|
|
|
|
|
|
|
|
|
|
let checkpoint_state_service = state_service.clone();
|
|
|
|
|
let checkpoint_sync = config.checkpoint_sync;
|
|
|
|
|
let state_checkpoint_verify_handle = tokio::task::spawn(
|
|
|
|
|
// TODO: move this into an async function?
|
|
|
|
|
async move {
|
|
|
|
|
tracing::info!("starting state checkpoint validation");
|
|
|
|
|
|
|
|
|
|
// # Consensus
|
|
|
|
|
//
|
|
|
|
|
// We want to verify all available checkpoints, even if the node is not configured
|
|
|
|
|
// to use them for syncing. Zebra's checkpoints are updated with every release,
|
|
|
|
|
// which makes sure they include the latest settled network upgrade.
|
|
|
|
|
//
|
|
|
|
|
// > A network upgrade is settled on a given network when there is a social
|
|
|
|
|
// > consensus that it has activated with a given activation block hash.
|
|
|
|
|
// > A full validator that potentially risks Mainnet funds or displays Mainnet
|
|
|
|
|
// > transaction information to a user MUST do so only for a block chain that
|
|
|
|
|
// > includes the activation block of the most recent settled network upgrade,
|
|
|
|
|
// > with the corresponding activation block hash. Currently, there is social
|
|
|
|
|
// > consensus that NU5 has activated on the Zcash Mainnet and Testnet with the
|
|
|
|
|
// > activation block hashes given in § 3.12 ‘Mainnet and Testnet’ on p. 20.
|
|
|
|
|
//
|
|
|
|
|
// <https://zips.z.cash/protocol/protocol.pdf#blockchain>
|
2024-03-12 14:41:44 -07:00
|
|
|
|
let full_checkpoints = network.checkpoint_list();
|
2023-12-05 16:52:47 -08:00
|
|
|
|
let mut already_warned = false;
|
2023-02-20 21:30:29 -08:00
|
|
|
|
|
|
|
|
|
for (height, checkpoint_hash) in full_checkpoints.iter() {
|
|
|
|
|
let checkpoint_state_service = checkpoint_state_service.clone();
|
|
|
|
|
let request = zebra_state::Request::BestChainBlockHash(*height);
|
|
|
|
|
|
|
|
|
|
match checkpoint_state_service.oneshot(request).await {
|
|
|
|
|
Ok(zebra_state::Response::BlockHash(Some(state_hash))) => assert_eq!(
|
|
|
|
|
*checkpoint_hash, state_hash,
|
|
|
|
|
"invalid block in state: a previous Zebra instance followed an \
|
|
|
|
|
incorrect chain. Delete and re-sync your state to use the best chain"
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
Ok(zebra_state::Response::BlockHash(None)) => {
|
|
|
|
|
if checkpoint_sync {
|
|
|
|
|
tracing::info!(
|
|
|
|
|
"state is not fully synced yet, remaining checkpoints will be \
|
|
|
|
|
verified during syncing"
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
tracing::warn!(
|
|
|
|
|
"state is not fully synced yet, remaining checkpoints will be \
|
|
|
|
|
verified next time Zebra starts up. Zebra will be less secure \
|
|
|
|
|
until it is restarted. Use consensus.checkpoint_sync = true \
|
|
|
|
|
in zebrad.toml to make sure you are following a valid chain"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(response) => {
|
|
|
|
|
unreachable!("unexpected response type: {response:?} from state request")
|
|
|
|
|
}
|
|
|
|
|
Err(e) => {
|
2023-12-05 16:52:47 -08:00
|
|
|
|
// This error happens a lot in some tests, and it could happen to users.
|
|
|
|
|
if !already_warned {
|
|
|
|
|
tracing::warn!(
|
|
|
|
|
"unexpected error: {e:?} in state request while verifying previous \
|
|
|
|
|
state checkpoints. Is Zebra shutting down?"
|
|
|
|
|
);
|
|
|
|
|
already_warned = true;
|
|
|
|
|
}
|
2023-02-20 21:30:29 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tracing::info!("finished state checkpoint validation");
|
|
|
|
|
}
|
|
|
|
|
.instrument(Span::current()),
|
|
|
|
|
);
|
|
|
|
|
|
2021-08-25 08:07:26 -07:00
|
|
|
|
// transaction verification
|
|
|
|
|
|
2022-01-31 22:24:08 -08:00
|
|
|
|
let transaction = transaction::Verifier::new(network, state_service.clone());
|
2021-08-25 08:07:26 -07:00
|
|
|
|
let transaction = Buffer::new(BoxService::new(transaction), VERIFIER_BUFFER_BOUND);
|
|
|
|
|
|
|
|
|
|
// block verification
|
change(state): Write non-finalized blocks to the state in a separate thread, to avoid network and RPC hangs (#5257)
* Add a new block commit task and channels, that don't do anything yet
* Add last_block_hash_sent to the state service, to avoid database accesses
* Update last_block_hash_sent regardless of commit errors
* Rename a field to StateService.max_queued_finalized_height
* Commit finalized blocks to the state in a separate task
* Check for panics in the block write task
* Wait for the block commit task in tests, and check for errors
* Always run a proptest that sleeps once
* Add extra debugging to state shutdowns
* Work around a RocksDB shutdown bug
* Close the finalized block channel when we're finished with it
* Only reset state queue once per error
* Update some TODOs
* Add a module doc comment
* Drop channels and check for closed channels in the block commit task
* Close state channels and tasks on drop
* Remove some duplicate fields across StateService and ReadStateService
* Try tweaking the shutdown steps
* Update and clarify some comments
* Clarify another comment
* Don't try to cancel RocksDB background work on drop
* Fix up some comments
* Remove some duplicate code
* Remove redundant workarounds for shutdown issues
* Remode a redundant channel close in the block commit task
* Remove a mistaken `!force` shutdown condition
* Remove duplicate force-shutdown code and explain it better
* Improve RPC error logging
* Wait for chain tip updates in the RPC tests
* Wait 2 seconds for chain tip updates before skipping them
* Remove an unnecessary block_in_place()
* Fix some test error messages that were changed by earlier fixes
* Expand some comments, fix typos
Co-authored-by: Marek <mail@marek.onl>
* Actually drop children of failed blocks
* Explain why we drop descendants of failed blocks
* Clarify a comment
* Wait for chain tip updates in a failing test on macOS
* Clean duplicate finalized blocks when the non-finalized state activates
* Send an error when receiving a duplicate finalized block
* Update checkpoint block behaviour, document its consensus rule
* Wait for chain tip changes in inbound_block_height_lookahead_limit test
* Wait for the genesis block to commit in the fake peer set mempool tests
* Disable unreliable mempool verification check in the send transaction test
* Appease rustfmt
* Use clear_finalized_block_queue() everywhere that blocks are dropped
* Document how Finalized and NonFinalized clones are different
* sends non-finalized blocks to the block write task
* passes ZebraDb to commit_new_chain, commit_block, and no_duplicates_in_finalized_chain instead of FinalizedState
* Update zebra-state/src/service/write.rs
Co-authored-by: teor <teor@riseup.net>
* updates comments, renames send_process_queued, other minor cleanup
* update assert_block_can_be_validated comment
* removes `mem` field from StateService
* removes `disk` field from StateService and updates block_iter to use `ZebraDb` instead of the finalized state
* updates tests that use the disk to use read_service.db instead
* moves best_tip to a read fn and returns finalized & non-finalized states from setup instead of the state service
* changes `contextual_validity` to get the network from the finalized_state instead of another param
* swaps out StateService with FinalizedState and NonFinalizedState in tests
* adds NotReadyToBeCommitted error and returns it from validate_and_commit when a blocks parent hash is not in any chain
* removes NonFinalizedWriteCmd and calls, moves update_latest_channels above rsp_tx.send
* makes parent_errors_map an indexmap
* clears non-finalized block queue when the receiver is dropped and when the StateService is being dropped
* sends non-finalized blocks to the block write task
* passes ZebraDb to commit_new_chain, commit_block, and no_duplicates_in_finalized_chain instead of FinalizedState
* updates comments, renames send_process_queued, other minor cleanup
* Update zebra-state/src/service/write.rs
Co-authored-by: teor <teor@riseup.net>
* update assert_block_can_be_validated comment
* removes `mem` field from StateService
* removes `disk` field from StateService and updates block_iter to use `ZebraDb` instead of the finalized state
* updates tests that use the disk to use read_service.db instead
* moves best_tip to a read fn and returns finalized & non-finalized states from setup instead of the state service
* changes `contextual_validity` to get the network from the finalized_state instead of another param
* swaps out StateService with FinalizedState and NonFinalizedState in tests
* adds NotReadyToBeCommitted error and returns it from validate_and_commit when a blocks parent hash is not in any chain
* removes NonFinalizedWriteCmd and calls, moves update_latest_channels above rsp_tx.send
* makes parent_errors_map an indexmap
* clears non-finalized block queue when the receiver is dropped and when the StateService is being dropped
* removes duplicate field definitions on StateService that were a result of a bad merge
* update NotReadyToBeCommitted error message
* Appear rustfmt
* Fix doc links
* Rename a function to initial_contextual_validity()
* Do error tasks on Err, and success tasks on Ok
* Simplify parent_error_map truncation
* Rewrite best_tip() to use tip()
* Rename latest_mem() to latest_non_finalized_state()
```sh
fastmod latest_mem latest_non_finalized_state zebra*
cargo fmt --all
```
* Simplify latest_non_finalized_state() using a new WatchReceiver API
* Expand some error messages
* Send the result after updating the channels, and document why
* wait for chain_tip_update before cancelling download in mempool_cancel_mined
* adds `sent_non_finalized_block_hashes` field to StateService
* adds batched sent_hash insertions and checks sent hashes in queue_and_commit_non_finalized before adding a block to the queue
* check that the `curr_buf` in SentHashes is not empty before pushing it to the `sent_bufs`
* Apply suggestions from code review
Co-authored-by: teor <teor@riseup.net>
* Fix rustfmt
* Check for finalized block heights using zs_contains()
* adds known_utxos field to SentHashes
* updates comment on SentHashes.add method
* Apply suggestions from code review
Co-authored-by: teor <teor@riseup.net>
* return early when there's a duplicate hash in QueuedBlocks.queue instead of panicking
* Make finalized UTXOs near the final checkpoint available for full block verification
* Replace a checkpoint height literal with the actual config
* Update mainnet and testnet checkpoints - 7 October 2022
* Fix some state service init arguments
* Allow more lookahead in the downloader, but less lookahead in the syncer
* Add the latest config to the tests, and fix the latest config check
* Increase the number of finalized blocks checked for non-finalized block UTXO spends
* fix(log): reduce verbose logs for block commits (#5348)
* Remove some verbose block write channel logs
* Only warn about tracing endpoint if the address is actually set
* Use CloneError instead of formatting a non-cloneable error
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Increase block verify timeout
* Work around a known block timeout bug by using a shorter timeout
Co-authored-by: teor <teor@riseup.net>
Co-authored-by: Marek <mail@marek.onl>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-10-11 12:25:45 -07:00
|
|
|
|
let (list, max_checkpoint_height) = init_checkpoint_list(config, network);
|
2020-09-09 20:16:11 -07:00
|
|
|
|
|
2020-09-10 09:49:13 -07:00
|
|
|
|
let tip = match state_service
|
2021-11-02 11:46:57 -07:00
|
|
|
|
.ready()
|
2021-02-19 16:43:38 -08:00
|
|
|
|
.await
|
|
|
|
|
.unwrap()
|
|
|
|
|
.call(zs::Request::Tip)
|
2020-09-09 18:53:40 -07:00
|
|
|
|
.await
|
|
|
|
|
.unwrap()
|
|
|
|
|
{
|
2020-09-09 20:16:11 -07:00
|
|
|
|
zs::Response::Tip(tip) => tip,
|
|
|
|
|
_ => unreachable!("wrong response to Request::Tip"),
|
2020-09-09 18:53:40 -07:00
|
|
|
|
};
|
2023-06-01 05:29:03 -07:00
|
|
|
|
tracing::info!(
|
|
|
|
|
?tip,
|
|
|
|
|
?max_checkpoint_height,
|
|
|
|
|
"initializing block verifier router"
|
|
|
|
|
);
|
2020-07-20 19:24:58 -07:00
|
|
|
|
|
2023-06-01 05:29:03 -07:00
|
|
|
|
let block = SemanticBlockVerifier::new(network, state_service.clone(), transaction.clone());
|
2021-03-10 18:07:37 -08:00
|
|
|
|
let checkpoint = CheckpointVerifier::from_checkpoint_list(list, network, tip, state_service);
|
2023-06-01 05:29:03 -07:00
|
|
|
|
let router = BlockVerifierRouter {
|
2021-08-25 08:07:26 -07:00
|
|
|
|
checkpoint,
|
|
|
|
|
max_checkpoint_height,
|
2021-12-17 08:31:51 -08:00
|
|
|
|
block,
|
2021-08-25 08:07:26 -07:00
|
|
|
|
};
|
|
|
|
|
|
2023-06-01 05:29:03 -07:00
|
|
|
|
let router = Buffer::new(BoxService::new(router), VERIFIER_BUFFER_BOUND);
|
2020-07-20 18:34:23 -07:00
|
|
|
|
|
2023-02-20 21:30:29 -08:00
|
|
|
|
let task_handles = BackgroundTaskHandles {
|
|
|
|
|
state_checkpoint_verify_handle,
|
|
|
|
|
};
|
|
|
|
|
|
2023-06-01 05:29:03 -07:00
|
|
|
|
(router, transaction, task_handles, max_checkpoint_height)
|
2020-07-20 18:34:23 -07:00
|
|
|
|
}
|
change(state): Write non-finalized blocks to the state in a separate thread, to avoid network and RPC hangs (#5257)
* Add a new block commit task and channels, that don't do anything yet
* Add last_block_hash_sent to the state service, to avoid database accesses
* Update last_block_hash_sent regardless of commit errors
* Rename a field to StateService.max_queued_finalized_height
* Commit finalized blocks to the state in a separate task
* Check for panics in the block write task
* Wait for the block commit task in tests, and check for errors
* Always run a proptest that sleeps once
* Add extra debugging to state shutdowns
* Work around a RocksDB shutdown bug
* Close the finalized block channel when we're finished with it
* Only reset state queue once per error
* Update some TODOs
* Add a module doc comment
* Drop channels and check for closed channels in the block commit task
* Close state channels and tasks on drop
* Remove some duplicate fields across StateService and ReadStateService
* Try tweaking the shutdown steps
* Update and clarify some comments
* Clarify another comment
* Don't try to cancel RocksDB background work on drop
* Fix up some comments
* Remove some duplicate code
* Remove redundant workarounds for shutdown issues
* Remode a redundant channel close in the block commit task
* Remove a mistaken `!force` shutdown condition
* Remove duplicate force-shutdown code and explain it better
* Improve RPC error logging
* Wait for chain tip updates in the RPC tests
* Wait 2 seconds for chain tip updates before skipping them
* Remove an unnecessary block_in_place()
* Fix some test error messages that were changed by earlier fixes
* Expand some comments, fix typos
Co-authored-by: Marek <mail@marek.onl>
* Actually drop children of failed blocks
* Explain why we drop descendants of failed blocks
* Clarify a comment
* Wait for chain tip updates in a failing test on macOS
* Clean duplicate finalized blocks when the non-finalized state activates
* Send an error when receiving a duplicate finalized block
* Update checkpoint block behaviour, document its consensus rule
* Wait for chain tip changes in inbound_block_height_lookahead_limit test
* Wait for the genesis block to commit in the fake peer set mempool tests
* Disable unreliable mempool verification check in the send transaction test
* Appease rustfmt
* Use clear_finalized_block_queue() everywhere that blocks are dropped
* Document how Finalized and NonFinalized clones are different
* sends non-finalized blocks to the block write task
* passes ZebraDb to commit_new_chain, commit_block, and no_duplicates_in_finalized_chain instead of FinalizedState
* Update zebra-state/src/service/write.rs
Co-authored-by: teor <teor@riseup.net>
* updates comments, renames send_process_queued, other minor cleanup
* update assert_block_can_be_validated comment
* removes `mem` field from StateService
* removes `disk` field from StateService and updates block_iter to use `ZebraDb` instead of the finalized state
* updates tests that use the disk to use read_service.db instead
* moves best_tip to a read fn and returns finalized & non-finalized states from setup instead of the state service
* changes `contextual_validity` to get the network from the finalized_state instead of another param
* swaps out StateService with FinalizedState and NonFinalizedState in tests
* adds NotReadyToBeCommitted error and returns it from validate_and_commit when a blocks parent hash is not in any chain
* removes NonFinalizedWriteCmd and calls, moves update_latest_channels above rsp_tx.send
* makes parent_errors_map an indexmap
* clears non-finalized block queue when the receiver is dropped and when the StateService is being dropped
* sends non-finalized blocks to the block write task
* passes ZebraDb to commit_new_chain, commit_block, and no_duplicates_in_finalized_chain instead of FinalizedState
* updates comments, renames send_process_queued, other minor cleanup
* Update zebra-state/src/service/write.rs
Co-authored-by: teor <teor@riseup.net>
* update assert_block_can_be_validated comment
* removes `mem` field from StateService
* removes `disk` field from StateService and updates block_iter to use `ZebraDb` instead of the finalized state
* updates tests that use the disk to use read_service.db instead
* moves best_tip to a read fn and returns finalized & non-finalized states from setup instead of the state service
* changes `contextual_validity` to get the network from the finalized_state instead of another param
* swaps out StateService with FinalizedState and NonFinalizedState in tests
* adds NotReadyToBeCommitted error and returns it from validate_and_commit when a blocks parent hash is not in any chain
* removes NonFinalizedWriteCmd and calls, moves update_latest_channels above rsp_tx.send
* makes parent_errors_map an indexmap
* clears non-finalized block queue when the receiver is dropped and when the StateService is being dropped
* removes duplicate field definitions on StateService that were a result of a bad merge
* update NotReadyToBeCommitted error message
* Appear rustfmt
* Fix doc links
* Rename a function to initial_contextual_validity()
* Do error tasks on Err, and success tasks on Ok
* Simplify parent_error_map truncation
* Rewrite best_tip() to use tip()
* Rename latest_mem() to latest_non_finalized_state()
```sh
fastmod latest_mem latest_non_finalized_state zebra*
cargo fmt --all
```
* Simplify latest_non_finalized_state() using a new WatchReceiver API
* Expand some error messages
* Send the result after updating the channels, and document why
* wait for chain_tip_update before cancelling download in mempool_cancel_mined
* adds `sent_non_finalized_block_hashes` field to StateService
* adds batched sent_hash insertions and checks sent hashes in queue_and_commit_non_finalized before adding a block to the queue
* check that the `curr_buf` in SentHashes is not empty before pushing it to the `sent_bufs`
* Apply suggestions from code review
Co-authored-by: teor <teor@riseup.net>
* Fix rustfmt
* Check for finalized block heights using zs_contains()
* adds known_utxos field to SentHashes
* updates comment on SentHashes.add method
* Apply suggestions from code review
Co-authored-by: teor <teor@riseup.net>
* return early when there's a duplicate hash in QueuedBlocks.queue instead of panicking
* Make finalized UTXOs near the final checkpoint available for full block verification
* Replace a checkpoint height literal with the actual config
* Update mainnet and testnet checkpoints - 7 October 2022
* Fix some state service init arguments
* Allow more lookahead in the downloader, but less lookahead in the syncer
* Add the latest config to the tests, and fix the latest config check
* Increase the number of finalized blocks checked for non-finalized block UTXO spends
* fix(log): reduce verbose logs for block commits (#5348)
* Remove some verbose block write channel logs
* Only warn about tracing endpoint if the address is actually set
* Use CloneError instead of formatting a non-cloneable error
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Increase block verify timeout
* Work around a known block timeout bug by using a shorter timeout
Co-authored-by: teor <teor@riseup.net>
Co-authored-by: Marek <mail@marek.onl>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-10-11 12:25:45 -07:00
|
|
|
|
|
|
|
|
|
/// Parses the checkpoint list for `network` and `config`.
|
|
|
|
|
/// Returns the checkpoint list and maximum checkpoint height.
|
|
|
|
|
pub fn init_checkpoint_list(config: Config, network: Network) -> (CheckpointList, Height) {
|
2023-02-20 21:30:29 -08:00
|
|
|
|
// TODO: Zebra parses the checkpoint list three times at startup.
|
change(state): Write non-finalized blocks to the state in a separate thread, to avoid network and RPC hangs (#5257)
* Add a new block commit task and channels, that don't do anything yet
* Add last_block_hash_sent to the state service, to avoid database accesses
* Update last_block_hash_sent regardless of commit errors
* Rename a field to StateService.max_queued_finalized_height
* Commit finalized blocks to the state in a separate task
* Check for panics in the block write task
* Wait for the block commit task in tests, and check for errors
* Always run a proptest that sleeps once
* Add extra debugging to state shutdowns
* Work around a RocksDB shutdown bug
* Close the finalized block channel when we're finished with it
* Only reset state queue once per error
* Update some TODOs
* Add a module doc comment
* Drop channels and check for closed channels in the block commit task
* Close state channels and tasks on drop
* Remove some duplicate fields across StateService and ReadStateService
* Try tweaking the shutdown steps
* Update and clarify some comments
* Clarify another comment
* Don't try to cancel RocksDB background work on drop
* Fix up some comments
* Remove some duplicate code
* Remove redundant workarounds for shutdown issues
* Remode a redundant channel close in the block commit task
* Remove a mistaken `!force` shutdown condition
* Remove duplicate force-shutdown code and explain it better
* Improve RPC error logging
* Wait for chain tip updates in the RPC tests
* Wait 2 seconds for chain tip updates before skipping them
* Remove an unnecessary block_in_place()
* Fix some test error messages that were changed by earlier fixes
* Expand some comments, fix typos
Co-authored-by: Marek <mail@marek.onl>
* Actually drop children of failed blocks
* Explain why we drop descendants of failed blocks
* Clarify a comment
* Wait for chain tip updates in a failing test on macOS
* Clean duplicate finalized blocks when the non-finalized state activates
* Send an error when receiving a duplicate finalized block
* Update checkpoint block behaviour, document its consensus rule
* Wait for chain tip changes in inbound_block_height_lookahead_limit test
* Wait for the genesis block to commit in the fake peer set mempool tests
* Disable unreliable mempool verification check in the send transaction test
* Appease rustfmt
* Use clear_finalized_block_queue() everywhere that blocks are dropped
* Document how Finalized and NonFinalized clones are different
* sends non-finalized blocks to the block write task
* passes ZebraDb to commit_new_chain, commit_block, and no_duplicates_in_finalized_chain instead of FinalizedState
* Update zebra-state/src/service/write.rs
Co-authored-by: teor <teor@riseup.net>
* updates comments, renames send_process_queued, other minor cleanup
* update assert_block_can_be_validated comment
* removes `mem` field from StateService
* removes `disk` field from StateService and updates block_iter to use `ZebraDb` instead of the finalized state
* updates tests that use the disk to use read_service.db instead
* moves best_tip to a read fn and returns finalized & non-finalized states from setup instead of the state service
* changes `contextual_validity` to get the network from the finalized_state instead of another param
* swaps out StateService with FinalizedState and NonFinalizedState in tests
* adds NotReadyToBeCommitted error and returns it from validate_and_commit when a blocks parent hash is not in any chain
* removes NonFinalizedWriteCmd and calls, moves update_latest_channels above rsp_tx.send
* makes parent_errors_map an indexmap
* clears non-finalized block queue when the receiver is dropped and when the StateService is being dropped
* sends non-finalized blocks to the block write task
* passes ZebraDb to commit_new_chain, commit_block, and no_duplicates_in_finalized_chain instead of FinalizedState
* updates comments, renames send_process_queued, other minor cleanup
* Update zebra-state/src/service/write.rs
Co-authored-by: teor <teor@riseup.net>
* update assert_block_can_be_validated comment
* removes `mem` field from StateService
* removes `disk` field from StateService and updates block_iter to use `ZebraDb` instead of the finalized state
* updates tests that use the disk to use read_service.db instead
* moves best_tip to a read fn and returns finalized & non-finalized states from setup instead of the state service
* changes `contextual_validity` to get the network from the finalized_state instead of another param
* swaps out StateService with FinalizedState and NonFinalizedState in tests
* adds NotReadyToBeCommitted error and returns it from validate_and_commit when a blocks parent hash is not in any chain
* removes NonFinalizedWriteCmd and calls, moves update_latest_channels above rsp_tx.send
* makes parent_errors_map an indexmap
* clears non-finalized block queue when the receiver is dropped and when the StateService is being dropped
* removes duplicate field definitions on StateService that were a result of a bad merge
* update NotReadyToBeCommitted error message
* Appear rustfmt
* Fix doc links
* Rename a function to initial_contextual_validity()
* Do error tasks on Err, and success tasks on Ok
* Simplify parent_error_map truncation
* Rewrite best_tip() to use tip()
* Rename latest_mem() to latest_non_finalized_state()
```sh
fastmod latest_mem latest_non_finalized_state zebra*
cargo fmt --all
```
* Simplify latest_non_finalized_state() using a new WatchReceiver API
* Expand some error messages
* Send the result after updating the channels, and document why
* wait for chain_tip_update before cancelling download in mempool_cancel_mined
* adds `sent_non_finalized_block_hashes` field to StateService
* adds batched sent_hash insertions and checks sent hashes in queue_and_commit_non_finalized before adding a block to the queue
* check that the `curr_buf` in SentHashes is not empty before pushing it to the `sent_bufs`
* Apply suggestions from code review
Co-authored-by: teor <teor@riseup.net>
* Fix rustfmt
* Check for finalized block heights using zs_contains()
* adds known_utxos field to SentHashes
* updates comment on SentHashes.add method
* Apply suggestions from code review
Co-authored-by: teor <teor@riseup.net>
* return early when there's a duplicate hash in QueuedBlocks.queue instead of panicking
* Make finalized UTXOs near the final checkpoint available for full block verification
* Replace a checkpoint height literal with the actual config
* Update mainnet and testnet checkpoints - 7 October 2022
* Fix some state service init arguments
* Allow more lookahead in the downloader, but less lookahead in the syncer
* Add the latest config to the tests, and fix the latest config check
* Increase the number of finalized blocks checked for non-finalized block UTXO spends
* fix(log): reduce verbose logs for block commits (#5348)
* Remove some verbose block write channel logs
* Only warn about tracing endpoint if the address is actually set
* Use CloneError instead of formatting a non-cloneable error
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Increase block verify timeout
* Work around a known block timeout bug by using a shorter timeout
Co-authored-by: teor <teor@riseup.net>
Co-authored-by: Marek <mail@marek.onl>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-10-11 12:25:45 -07:00
|
|
|
|
// Instead, cache the checkpoint list for each `network`.
|
2024-03-12 14:41:44 -07:00
|
|
|
|
let list = network.checkpoint_list();
|
change(state): Write non-finalized blocks to the state in a separate thread, to avoid network and RPC hangs (#5257)
* Add a new block commit task and channels, that don't do anything yet
* Add last_block_hash_sent to the state service, to avoid database accesses
* Update last_block_hash_sent regardless of commit errors
* Rename a field to StateService.max_queued_finalized_height
* Commit finalized blocks to the state in a separate task
* Check for panics in the block write task
* Wait for the block commit task in tests, and check for errors
* Always run a proptest that sleeps once
* Add extra debugging to state shutdowns
* Work around a RocksDB shutdown bug
* Close the finalized block channel when we're finished with it
* Only reset state queue once per error
* Update some TODOs
* Add a module doc comment
* Drop channels and check for closed channels in the block commit task
* Close state channels and tasks on drop
* Remove some duplicate fields across StateService and ReadStateService
* Try tweaking the shutdown steps
* Update and clarify some comments
* Clarify another comment
* Don't try to cancel RocksDB background work on drop
* Fix up some comments
* Remove some duplicate code
* Remove redundant workarounds for shutdown issues
* Remode a redundant channel close in the block commit task
* Remove a mistaken `!force` shutdown condition
* Remove duplicate force-shutdown code and explain it better
* Improve RPC error logging
* Wait for chain tip updates in the RPC tests
* Wait 2 seconds for chain tip updates before skipping them
* Remove an unnecessary block_in_place()
* Fix some test error messages that were changed by earlier fixes
* Expand some comments, fix typos
Co-authored-by: Marek <mail@marek.onl>
* Actually drop children of failed blocks
* Explain why we drop descendants of failed blocks
* Clarify a comment
* Wait for chain tip updates in a failing test on macOS
* Clean duplicate finalized blocks when the non-finalized state activates
* Send an error when receiving a duplicate finalized block
* Update checkpoint block behaviour, document its consensus rule
* Wait for chain tip changes in inbound_block_height_lookahead_limit test
* Wait for the genesis block to commit in the fake peer set mempool tests
* Disable unreliable mempool verification check in the send transaction test
* Appease rustfmt
* Use clear_finalized_block_queue() everywhere that blocks are dropped
* Document how Finalized and NonFinalized clones are different
* sends non-finalized blocks to the block write task
* passes ZebraDb to commit_new_chain, commit_block, and no_duplicates_in_finalized_chain instead of FinalizedState
* Update zebra-state/src/service/write.rs
Co-authored-by: teor <teor@riseup.net>
* updates comments, renames send_process_queued, other minor cleanup
* update assert_block_can_be_validated comment
* removes `mem` field from StateService
* removes `disk` field from StateService and updates block_iter to use `ZebraDb` instead of the finalized state
* updates tests that use the disk to use read_service.db instead
* moves best_tip to a read fn and returns finalized & non-finalized states from setup instead of the state service
* changes `contextual_validity` to get the network from the finalized_state instead of another param
* swaps out StateService with FinalizedState and NonFinalizedState in tests
* adds NotReadyToBeCommitted error and returns it from validate_and_commit when a blocks parent hash is not in any chain
* removes NonFinalizedWriteCmd and calls, moves update_latest_channels above rsp_tx.send
* makes parent_errors_map an indexmap
* clears non-finalized block queue when the receiver is dropped and when the StateService is being dropped
* sends non-finalized blocks to the block write task
* passes ZebraDb to commit_new_chain, commit_block, and no_duplicates_in_finalized_chain instead of FinalizedState
* updates comments, renames send_process_queued, other minor cleanup
* Update zebra-state/src/service/write.rs
Co-authored-by: teor <teor@riseup.net>
* update assert_block_can_be_validated comment
* removes `mem` field from StateService
* removes `disk` field from StateService and updates block_iter to use `ZebraDb` instead of the finalized state
* updates tests that use the disk to use read_service.db instead
* moves best_tip to a read fn and returns finalized & non-finalized states from setup instead of the state service
* changes `contextual_validity` to get the network from the finalized_state instead of another param
* swaps out StateService with FinalizedState and NonFinalizedState in tests
* adds NotReadyToBeCommitted error and returns it from validate_and_commit when a blocks parent hash is not in any chain
* removes NonFinalizedWriteCmd and calls, moves update_latest_channels above rsp_tx.send
* makes parent_errors_map an indexmap
* clears non-finalized block queue when the receiver is dropped and when the StateService is being dropped
* removes duplicate field definitions on StateService that were a result of a bad merge
* update NotReadyToBeCommitted error message
* Appear rustfmt
* Fix doc links
* Rename a function to initial_contextual_validity()
* Do error tasks on Err, and success tasks on Ok
* Simplify parent_error_map truncation
* Rewrite best_tip() to use tip()
* Rename latest_mem() to latest_non_finalized_state()
```sh
fastmod latest_mem latest_non_finalized_state zebra*
cargo fmt --all
```
* Simplify latest_non_finalized_state() using a new WatchReceiver API
* Expand some error messages
* Send the result after updating the channels, and document why
* wait for chain_tip_update before cancelling download in mempool_cancel_mined
* adds `sent_non_finalized_block_hashes` field to StateService
* adds batched sent_hash insertions and checks sent hashes in queue_and_commit_non_finalized before adding a block to the queue
* check that the `curr_buf` in SentHashes is not empty before pushing it to the `sent_bufs`
* Apply suggestions from code review
Co-authored-by: teor <teor@riseup.net>
* Fix rustfmt
* Check for finalized block heights using zs_contains()
* adds known_utxos field to SentHashes
* updates comment on SentHashes.add method
* Apply suggestions from code review
Co-authored-by: teor <teor@riseup.net>
* return early when there's a duplicate hash in QueuedBlocks.queue instead of panicking
* Make finalized UTXOs near the final checkpoint available for full block verification
* Replace a checkpoint height literal with the actual config
* Update mainnet and testnet checkpoints - 7 October 2022
* Fix some state service init arguments
* Allow more lookahead in the downloader, but less lookahead in the syncer
* Add the latest config to the tests, and fix the latest config check
* Increase the number of finalized blocks checked for non-finalized block UTXO spends
* fix(log): reduce verbose logs for block commits (#5348)
* Remove some verbose block write channel logs
* Only warn about tracing endpoint if the address is actually set
* Use CloneError instead of formatting a non-cloneable error
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Increase block verify timeout
* Work around a known block timeout bug by using a shorter timeout
Co-authored-by: teor <teor@riseup.net>
Co-authored-by: Marek <mail@marek.onl>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-10-11 12:25:45 -07:00
|
|
|
|
|
|
|
|
|
let max_checkpoint_height = if config.checkpoint_sync {
|
|
|
|
|
list.max_height()
|
|
|
|
|
} else {
|
|
|
|
|
list.min_height_in_range(network.mandatory_checkpoint_height()..)
|
|
|
|
|
.expect("hardcoded checkpoint list extends past canopy activation")
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
(list, max_checkpoint_height)
|
|
|
|
|
}
|
2023-02-20 21:30:29 -08:00
|
|
|
|
|
|
|
|
|
/// The background task handles for `zebra-consensus` verifier initialization.
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct BackgroundTaskHandles {
|
|
|
|
|
/// A handle to the state checkpoint verify task.
|
|
|
|
|
/// Finishes when all the checkpoints are verified, or when the state tip is reached.
|
|
|
|
|
pub state_checkpoint_verify_handle: JoinHandle<()>,
|
|
|
|
|
}
|