Expand description
State contextual verification and storage code for Zebra.
§Correctness
Await UTXO and block commit requests should be wrapped in a timeout, because:
- await UTXO requests wait for a block containing that UTXO, and
- contextual verification and state updates wait for all previous blocks.
Otherwise, verification of out-of-order and invalid blocks can hang indefinitely.
Re-exports§
pub use config::check_and_delete_old_databases;
pub use config::check_and_delete_old_state_databases;
pub use config::database_format_version_on_disk;
pub use config::state_database_format_version_on_disk;
pub use config::Config;
pub use constants::state_database_format_version_in_code;
pub use constants::MAX_BLOCK_REORG_HEIGHT;
Modules§
- arbitrary
- Randomised data generation for state data.
- check
- Consensus critical contextual checks
- config
- Cached state configuration for Zebra.
- constants
- Constants that impact state behaviour.
- error 🔒
- Error types for Zebra’s state.
- request 🔒
- State [
tower::Service
] request types. - response 🔒
- State [
tower::Service
] response types. - service 🔒
- [
tower::Service
]s for Zebra’s cached chain state.
Structs§
- Chain
TipBlock - A chain tip block, with precalculated block data.
- Chain
TipChange - A chain tip change monitor.
- Chain
TipSender - A sender for changes to the non-finalized and finalized chain tips.
- Checkpoint
Verified Block - A block ready to be committed directly to the finalized state with
a small number of checks if compared with a
ContextuallyVerifiedBlock
. - Clone
Error - A wrapper for type erased errors that is itself clonable and implements the Error trait
- Commit
Semantically Verified Error - An error describing the reason a semantically verified block could not be committed to the state.
- Contextually
Verified Block - A contextually verified block, ready to be committed directly to the finalized state with no checks, if it becomes the root of the best non-finalized chain.
- Disk
Write Batch - Wrapper struct to ensure low-level database writes go through the correct API.
- Finalized
State - The finalized part of the chain state, stored in the db.
- GetBlock
Template Chain Info - A structure with the information needed from the state to build a
getblocktemplate
RPC response. - KV
- A formatting struct for raw key-value data
- Latest
Chain Tip - Efficient access to the state’s current best chain tip.
- MinedTx
- Information about a transaction in the best chain
- NonFinalized
State - The state of the chains in memory, including queued blocks.
- Output
Index - A transparent output’s index in its transaction.
- Output
Location - A transparent output’s location in the chain, by block height and transaction index.
- RawBytes
- Access database keys or values as raw bytes. Mainly for use in tests, runtime checks, or format compatibility code.
- Read
State Service - A read-only service for accessing Zebra’s cached blockchain state.
- Sapling
Scanned Database Entry - A database column family entry for a block scanned with a Sapling vieweing key.
- Sapling
Scanned Database Index - A database column family key for a block scanned with a Sapling vieweing key.
- Sapling
Scanned Result - Stores a scanning result.
- Semantically
Verified Block - A block which has undergone semantic validation and has been prepared for contextual validation.
- Transaction
Index - A transaction’s index in its block.
- Transaction
Location - A transaction’s location in the chain, by block height and transaction index.
- Typed
Column Family - A type-safe read-only column family reference.
- Watch
Receiver - Efficient access to state data via a [
tokio
] [watch::Receiver
] channel, while avoiding deadlocks. - Write
Typed Batch - A type-safe and drop-safe batch write to a column family.
- ZebraDb
- Wrapper struct to ensure high-level
zebra-state
database access goes through the correct API.
Enums§
- Hash
OrHeight - Identify a block by hash or height.
- Known
Block - An enum of block stores in the state where a block hash could be found.
- Read
Request - A read-only query about the chain state, via the
ReadStateService
. - Read
Response - A response to a read-only
ReadStateService
’sReadRequest
. - Request
- A query about or modification to the chain state, via the
StateService
. - Response
- A response to a
StateService
Request
. - Spend
- Identify a spend by a transparent outpoint or revealed nullifier.
- TipAction
- Actions that we can take in response to a
ChainTipChange
. - Validate
Context Error - An error describing why a block failed contextual validation.
Constants§
- CHAIN_
TIP_ UPDATE_ WAIT_ LIMIT - How long we wait for chain tip updates before skipping them.
- MAX_
ON_ DISK_ HEIGHT - The maximum value of an on-disk serialized
Height
.
Traits§
- Duplicate
Nullifier Error - Trait for creating the corresponding duplicate nullifier error from a nullifier.
- From
Disk - Helper type for reading types from disk as raw bytes.
- Into
Disk - Helper type for writing types to disk as raw bytes. Also used to convert key types to raw bytes for disk lookups.
- Read
Disk - Helper trait for retrieving and deserializing values from rocksdb column families.
- Write
Disk - Helper trait for inserting serialized typed (Key, Value) pairs into rocksdb.
Functions§
- init
- Initialize a state service from the provided
Config
. Returns a boxed state service, a read-only state service, and receivers for state chain tip updates. - init_
read_ only - Initialize a read state service from the provided
Config
. Returns a read-only state service, - init_
test - Returns a
StateService
with an ephemeralConfig
and a buffer with a single slot. - init_
test_ services - Initializes a state service with an ephemeral
Config
and a buffer with a single slot, then returns the read-write service, read-only service, and tip watch channels. - populated_
state - Initialize a state service with blocks, and return:
- spawn_
init - Calls
init
with the providedConfig
andNetwork
from a blocking task. Returns a [tokio::task::JoinHandle
] with a boxed state service, a read state service, and receivers for state chain tip updates. - spawn_
init_ read_ only - Calls
init_read_only
with the providedConfig
andNetwork
from a blocking task. Returns a [tokio::task::JoinHandle
] with a read state service and chain tip sender. - write_
database_ format_ version_ to_ disk - Writes
changed_version
to the on-disk database after the format is changed. (Or a new database is created.) - write_
state_ database_ format_ version_ to_ disk - Writes
changed_version
to the on-disk state database after the format is changed. (Or a new database is created.)
Type Aliases§
- BoxError
- A boxed
std::error::Error
. - Sapling
Scanning Key - The type used in Zebra to store Sapling scanning keys. It can represent a full viewing key or an individual viewing key.