2022-03-17 15:59:46 -07:00
|
|
|
//! State [`tower::Service`] request types.
|
|
|
|
|
2022-04-20 11:27:00 -07:00
|
|
|
use std::{
|
|
|
|
collections::{HashMap, HashSet},
|
2023-06-21 09:58:11 -07:00
|
|
|
ops::{Deref, DerefMut, RangeInclusive},
|
2022-04-20 11:27:00 -07:00
|
|
|
sync::Arc,
|
|
|
|
};
|
state: introduce PreparedBlock, FinalizedBlock
This change introduces two new types:
- `PreparedBlock`, representing a block which has undergone semantic
validation and has been prepared for contextual validation;
- `FinalizedBlock`, representing a block which is ready to be finalized
immediately;
and changes the `Request::CommitBlock`,`Request::CommitFinalizedBlock`
variants to use these types instead of their previous fields.
This change solves the problem of passing data between semantic
validation and contextual validation, and cleans up the state code by
allowing it to pass around a bundle of data. Previously, the state code
just passed around an `Arc<Block>`, which forced it to needlessly
recompute block hashes and other data, and was incompatible with the
already-known but not-yet-implemented data transfer requirements, namely
passing in the Sprout and Sapling anchors computed during contextual
validation.
This commit propagates the `PreparedBlock` and `FinalizedBlock` types
through the state code but only uses their data opportunistically, e.g.,
changing .hash() computations to use the precomputed hash. In the
future, these structures can be extended to pass data through the
verification pipeline for reuse as appropriate. For instance, these
changes allow the sprout and sapling anchors to be propagated through
the state.
2020-11-21 01:16:14 -08:00
|
|
|
|
2020-09-09 17:59:58 -07:00
|
|
|
use zebra_chain::{
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
amount::{Amount, NegativeAllowed, NonNegative},
|
2020-09-09 17:59:58 -07:00
|
|
|
block::{self, Block},
|
2022-09-06 02:32:54 -07:00
|
|
|
history_tree::HistoryTree,
|
|
|
|
orchard,
|
|
|
|
parallel::tree::NoteCommitmentTrees,
|
|
|
|
sapling,
|
2022-05-12 00:00:12 -07:00
|
|
|
serialization::SerializationError,
|
2022-11-29 20:40:15 -08:00
|
|
|
sprout,
|
2023-09-03 15:18:41 -07:00
|
|
|
subtree::{NoteCommitmentSubtree, NoteCommitmentSubtreeIndex},
|
2022-11-29 20:40:15 -08:00
|
|
|
transaction::{self, UnminedTx},
|
2021-08-25 06:57:07 -07:00
|
|
|
transparent::{self, utxos_from_ordered_utxos},
|
|
|
|
value_balance::{ValueBalance, ValueBalanceError},
|
2020-09-09 17:59:58 -07:00
|
|
|
};
|
|
|
|
|
2022-09-13 17:35:37 -07:00
|
|
|
/// Allow *only* these unused imports, so that rustdoc link resolution
|
2022-04-08 15:42:05 -07:00
|
|
|
/// will work with inline links.
|
2020-09-09 17:59:58 -07:00
|
|
|
#[allow(unused_imports)]
|
2022-09-13 17:35:37 -07:00
|
|
|
use crate::{
|
|
|
|
constants::{MAX_FIND_BLOCK_HASHES_RESULTS, MAX_FIND_BLOCK_HEADERS_RESULTS_FOR_ZEBRA},
|
|
|
|
ReadResponse, Response,
|
|
|
|
};
|
2020-09-09 17:59:58 -07:00
|
|
|
|
|
|
|
/// Identify a block by hash or height.
|
|
|
|
///
|
|
|
|
/// This enum implements `From` for [`block::Hash`] and [`block::Height`],
|
|
|
|
/// so it can be created using `hash.into()` or `height.into()`.
|
2020-11-01 10:49:34 -08:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
2020-09-09 17:59:58 -07:00
|
|
|
pub enum HashOrHeight {
|
|
|
|
/// A block identified by hash.
|
|
|
|
Hash(block::Hash),
|
|
|
|
/// A block identified by height.
|
|
|
|
Height(block::Height),
|
|
|
|
}
|
|
|
|
|
2020-11-01 10:49:34 -08:00
|
|
|
impl HashOrHeight {
|
|
|
|
/// Unwrap the inner height or attempt to retrieve the height for a given
|
|
|
|
/// hash if one exists.
|
|
|
|
pub fn height_or_else<F>(self, op: F) -> Option<block::Height>
|
|
|
|
where
|
|
|
|
F: FnOnce(block::Hash) -> Option<block::Height>,
|
|
|
|
{
|
|
|
|
match self {
|
|
|
|
HashOrHeight::Hash(hash) => op(hash),
|
|
|
|
HashOrHeight::Height(height) => Some(height),
|
|
|
|
}
|
|
|
|
}
|
2023-02-06 17:25:34 -08:00
|
|
|
|
2023-02-14 00:52:58 -08:00
|
|
|
/// Unwrap the inner hash or attempt to retrieve the hash for a given
|
|
|
|
/// height if one exists.
|
|
|
|
///
|
|
|
|
/// # Consensus
|
|
|
|
///
|
|
|
|
/// In the non-finalized state, a height can have multiple valid hashes.
|
|
|
|
/// We typically use the hash that is currently on the best chain.
|
|
|
|
pub fn hash_or_else<F>(self, op: F) -> Option<block::Hash>
|
|
|
|
where
|
|
|
|
F: FnOnce(block::Height) -> Option<block::Hash>,
|
|
|
|
{
|
|
|
|
match self {
|
|
|
|
HashOrHeight::Hash(hash) => Some(hash),
|
|
|
|
HashOrHeight::Height(height) => op(height),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-06 17:25:34 -08:00
|
|
|
/// Returns the hash if this is a [`HashOrHeight::Hash`].
|
|
|
|
pub fn hash(&self) -> Option<block::Hash> {
|
|
|
|
if let HashOrHeight::Hash(hash) = self {
|
|
|
|
Some(*hash)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the height if this is a [`HashOrHeight::Height`].
|
|
|
|
pub fn height(&self) -> Option<block::Height> {
|
|
|
|
if let HashOrHeight::Height(height) = self {
|
|
|
|
Some(*height)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
2020-11-01 10:49:34 -08:00
|
|
|
}
|
|
|
|
|
2020-09-09 17:59:58 -07:00
|
|
|
impl From<block::Hash> for HashOrHeight {
|
|
|
|
fn from(hash: block::Hash) -> Self {
|
|
|
|
Self::Hash(hash)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<block::Height> for HashOrHeight {
|
2022-12-07 14:39:11 -08:00
|
|
|
fn from(height: block::Height) -> Self {
|
|
|
|
Self::Height(height)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<(block::Height, block::Hash)> for HashOrHeight {
|
|
|
|
fn from((_height, hash): (block::Height, block::Hash)) -> Self {
|
|
|
|
// Hash is more specific than height for the non-finalized state
|
|
|
|
hash.into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<(block::Hash, block::Height)> for HashOrHeight {
|
|
|
|
fn from((hash, _height): (block::Hash, block::Height)) -> Self {
|
|
|
|
hash.into()
|
2020-09-09 17:59:58 -07:00
|
|
|
}
|
|
|
|
}
|
2020-09-09 16:42:52 -07:00
|
|
|
|
2022-05-12 00:00:12 -07:00
|
|
|
impl std::str::FromStr for HashOrHeight {
|
|
|
|
type Err = SerializationError;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
s.parse()
|
|
|
|
.map(Self::Hash)
|
|
|
|
.or_else(|_| s.parse().map(Self::Height))
|
|
|
|
.map_err(|_| {
|
|
|
|
SerializationError::Parse("could not convert the input string to a hash or height")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
state: introduce PreparedBlock, FinalizedBlock
This change introduces two new types:
- `PreparedBlock`, representing a block which has undergone semantic
validation and has been prepared for contextual validation;
- `FinalizedBlock`, representing a block which is ready to be finalized
immediately;
and changes the `Request::CommitBlock`,`Request::CommitFinalizedBlock`
variants to use these types instead of their previous fields.
This change solves the problem of passing data between semantic
validation and contextual validation, and cleans up the state code by
allowing it to pass around a bundle of data. Previously, the state code
just passed around an `Arc<Block>`, which forced it to needlessly
recompute block hashes and other data, and was incompatible with the
already-known but not-yet-implemented data transfer requirements, namely
passing in the Sprout and Sapling anchors computed during contextual
validation.
This commit propagates the `PreparedBlock` and `FinalizedBlock` types
through the state code but only uses their data opportunistically, e.g.,
changing .hash() computations to use the precomputed hash. In the
future, these structures can be extended to pass data through the
verification pipeline for reuse as appropriate. For instance, these
changes allow the sprout and sapling anchors to be propagated through
the state.
2020-11-21 01:16:14 -08:00
|
|
|
/// A block which has undergone semantic validation and has been prepared for
|
|
|
|
/// contextual validation.
|
|
|
|
///
|
|
|
|
/// It is the constructor's responsibility to perform semantic validation and to
|
|
|
|
/// ensure that all fields are consistent.
|
|
|
|
///
|
|
|
|
/// This structure contains data from contextual validation, which is computed in
|
|
|
|
/// the *service caller*'s task, not inside the service call itself. This allows
|
|
|
|
/// moving work out of the single-threaded state service.
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
2023-06-01 05:29:03 -07:00
|
|
|
pub struct SemanticallyVerifiedBlock {
|
state: introduce PreparedBlock, FinalizedBlock
This change introduces two new types:
- `PreparedBlock`, representing a block which has undergone semantic
validation and has been prepared for contextual validation;
- `FinalizedBlock`, representing a block which is ready to be finalized
immediately;
and changes the `Request::CommitBlock`,`Request::CommitFinalizedBlock`
variants to use these types instead of their previous fields.
This change solves the problem of passing data between semantic
validation and contextual validation, and cleans up the state code by
allowing it to pass around a bundle of data. Previously, the state code
just passed around an `Arc<Block>`, which forced it to needlessly
recompute block hashes and other data, and was incompatible with the
already-known but not-yet-implemented data transfer requirements, namely
passing in the Sprout and Sapling anchors computed during contextual
validation.
This commit propagates the `PreparedBlock` and `FinalizedBlock` types
through the state code but only uses their data opportunistically, e.g.,
changing .hash() computations to use the precomputed hash. In the
future, these structures can be extended to pass data through the
verification pipeline for reuse as appropriate. For instance, these
changes allow the sprout and sapling anchors to be propagated through
the state.
2020-11-21 01:16:14 -08:00
|
|
|
/// The block to commit to the state.
|
|
|
|
pub block: Arc<Block>,
|
|
|
|
/// The hash of the block.
|
|
|
|
pub hash: block::Hash,
|
|
|
|
/// The height of the block.
|
|
|
|
pub height: block::Height,
|
|
|
|
/// New transparent outputs created in this block, indexed by
|
2022-06-02 08:07:35 -07:00
|
|
|
/// [`OutPoint`](transparent::OutPoint).
|
state: introduce PreparedBlock, FinalizedBlock
This change introduces two new types:
- `PreparedBlock`, representing a block which has undergone semantic
validation and has been prepared for contextual validation;
- `FinalizedBlock`, representing a block which is ready to be finalized
immediately;
and changes the `Request::CommitBlock`,`Request::CommitFinalizedBlock`
variants to use these types instead of their previous fields.
This change solves the problem of passing data between semantic
validation and contextual validation, and cleans up the state code by
allowing it to pass around a bundle of data. Previously, the state code
just passed around an `Arc<Block>`, which forced it to needlessly
recompute block hashes and other data, and was incompatible with the
already-known but not-yet-implemented data transfer requirements, namely
passing in the Sprout and Sapling anchors computed during contextual
validation.
This commit propagates the `PreparedBlock` and `FinalizedBlock` types
through the state code but only uses their data opportunistically, e.g.,
changing .hash() computations to use the precomputed hash. In the
future, these structures can be extended to pass data through the
verification pipeline for reuse as appropriate. For instance, these
changes allow the sprout and sapling anchors to be propagated through
the state.
2020-11-21 01:16:14 -08:00
|
|
|
///
|
2021-07-19 06:52:32 -07:00
|
|
|
/// Each output is tagged with its transaction index in the block.
|
|
|
|
/// (The outputs of earlier transactions in a block can be spent by later
|
|
|
|
/// transactions.)
|
|
|
|
///
|
state: introduce PreparedBlock, FinalizedBlock
This change introduces two new types:
- `PreparedBlock`, representing a block which has undergone semantic
validation and has been prepared for contextual validation;
- `FinalizedBlock`, representing a block which is ready to be finalized
immediately;
and changes the `Request::CommitBlock`,`Request::CommitFinalizedBlock`
variants to use these types instead of their previous fields.
This change solves the problem of passing data between semantic
validation and contextual validation, and cleans up the state code by
allowing it to pass around a bundle of data. Previously, the state code
just passed around an `Arc<Block>`, which forced it to needlessly
recompute block hashes and other data, and was incompatible with the
already-known but not-yet-implemented data transfer requirements, namely
passing in the Sprout and Sapling anchors computed during contextual
validation.
This commit propagates the `PreparedBlock` and `FinalizedBlock` types
through the state code but only uses their data opportunistically, e.g.,
changing .hash() computations to use the precomputed hash. In the
future, these structures can be extended to pass data through the
verification pipeline for reuse as appropriate. For instance, these
changes allow the sprout and sapling anchors to be propagated through
the state.
2020-11-21 01:16:14 -08:00
|
|
|
/// Note: although these transparent outputs are newly created, they may not
|
|
|
|
/// be unspent, since a later transaction in a block can spend outputs of an
|
|
|
|
/// earlier transaction.
|
2022-04-12 10:21:46 -07:00
|
|
|
///
|
|
|
|
/// This field can also contain unrelated outputs, which are ignored.
|
2021-07-19 06:52:32 -07:00
|
|
|
pub new_outputs: HashMap<transparent::OutPoint, transparent::OrderedUtxo>,
|
2021-08-30 17:55:39 -07:00
|
|
|
/// A precomputed list of the hashes of the transactions in this block,
|
|
|
|
/// in the same order as `block.transactions`.
|
2021-08-30 11:42:07 -07:00
|
|
|
pub transaction_hashes: Arc<[transaction::Hash]>,
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
/// This block's contribution to the deferred pool.
|
|
|
|
pub deferred_balance: Option<Amount<NonNegative>>,
|
state: introduce PreparedBlock, FinalizedBlock
This change introduces two new types:
- `PreparedBlock`, representing a block which has undergone semantic
validation and has been prepared for contextual validation;
- `FinalizedBlock`, representing a block which is ready to be finalized
immediately;
and changes the `Request::CommitBlock`,`Request::CommitFinalizedBlock`
variants to use these types instead of their previous fields.
This change solves the problem of passing data between semantic
validation and contextual validation, and cleans up the state code by
allowing it to pass around a bundle of data. Previously, the state code
just passed around an `Arc<Block>`, which forced it to needlessly
recompute block hashes and other data, and was incompatible with the
already-known but not-yet-implemented data transfer requirements, namely
passing in the Sprout and Sapling anchors computed during contextual
validation.
This commit propagates the `PreparedBlock` and `FinalizedBlock` types
through the state code but only uses their data opportunistically, e.g.,
changing .hash() computations to use the precomputed hash. In the
future, these structures can be extended to pass data through the
verification pipeline for reuse as appropriate. For instance, these
changes allow the sprout and sapling anchors to be propagated through
the state.
2020-11-21 01:16:14 -08:00
|
|
|
}
|
|
|
|
|
2023-06-21 09:58:11 -07:00
|
|
|
/// A block ready to be committed directly to the finalized state with
|
2023-07-04 14:29:41 -07:00
|
|
|
/// a small number of checks if compared with a `ContextuallyVerifiedBlock`.
|
2023-06-21 09:58:11 -07:00
|
|
|
///
|
|
|
|
/// This is exposed for use in checkpointing.
|
|
|
|
///
|
|
|
|
/// Note: The difference between a `CheckpointVerifiedBlock` and a `ContextuallyVerifiedBlock` is
|
|
|
|
/// that the `CheckpointVerifier` doesn't bind the transaction authorizing data to the
|
|
|
|
/// `ChainHistoryBlockTxAuthCommitmentHash`, but the `NonFinalizedState` and `FinalizedState` do.
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
|
|
pub struct CheckpointVerifiedBlock(pub(crate) SemanticallyVerifiedBlock);
|
|
|
|
|
2021-08-30 17:55:39 -07:00
|
|
|
// Some fields are pub(crate), so we can add whatever db-format-dependent
|
|
|
|
// precomputation we want here without leaking internal details.
|
|
|
|
|
2023-06-01 05:29:03 -07:00
|
|
|
/// 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.
|
2021-07-19 06:52:32 -07:00
|
|
|
///
|
2022-06-02 08:07:35 -07:00
|
|
|
/// Used by the state service and non-finalized `Chain`.
|
2023-06-01 05:29:03 -07:00
|
|
|
///
|
|
|
|
/// Note: The difference between a `CheckpointVerifiedBlock` and a `ContextuallyVerifiedBlock` is
|
|
|
|
/// that the `CheckpointVerifier` doesn't bind the transaction authorizing data to the
|
|
|
|
/// `ChainHistoryBlockTxAuthCommitmentHash`, but the `NonFinalizedState` and `FinalizedState` do.
|
2021-07-19 06:52:32 -07:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
2023-06-01 05:29:03 -07:00
|
|
|
pub struct ContextuallyVerifiedBlock {
|
2022-04-12 10:21:46 -07:00
|
|
|
/// The block to commit to the state.
|
2021-07-19 06:52:32 -07:00
|
|
|
pub(crate) block: Arc<Block>,
|
2022-04-12 10:21:46 -07:00
|
|
|
|
|
|
|
/// The hash of the block.
|
2021-07-19 06:52:32 -07:00
|
|
|
pub(crate) hash: block::Hash,
|
2022-04-12 10:21:46 -07:00
|
|
|
|
|
|
|
/// The height of the block.
|
2021-07-19 06:52:32 -07:00
|
|
|
pub(crate) height: block::Height,
|
2022-04-12 10:21:46 -07:00
|
|
|
|
|
|
|
/// New transparent outputs created in this block, indexed by
|
2022-06-02 08:07:35 -07:00
|
|
|
/// [`OutPoint`](transparent::OutPoint).
|
2022-04-12 10:21:46 -07:00
|
|
|
///
|
|
|
|
/// Note: although these transparent outputs are newly created, they may not
|
|
|
|
/// be unspent, since a later transaction in a block can spend outputs of an
|
|
|
|
/// earlier transaction.
|
|
|
|
///
|
|
|
|
/// This field can also contain unrelated outputs, which are ignored.
|
|
|
|
pub(crate) new_outputs: HashMap<transparent::OutPoint, transparent::OrderedUtxo>,
|
|
|
|
|
|
|
|
/// The outputs spent by this block, indexed by the [`transparent::Input`]'s
|
2022-06-02 08:07:35 -07:00
|
|
|
/// [`OutPoint`](transparent::OutPoint).
|
2022-04-12 10:21:46 -07:00
|
|
|
///
|
|
|
|
/// Note: these inputs can come from earlier transactions in this block,
|
|
|
|
/// or earlier blocks in the chain.
|
|
|
|
///
|
|
|
|
/// This field can also contain unrelated outputs, which are ignored.
|
|
|
|
pub(crate) spent_outputs: HashMap<transparent::OutPoint, transparent::OrderedUtxo>,
|
|
|
|
|
|
|
|
/// A precomputed list of the hashes of the transactions in this block,
|
|
|
|
/// in the same order as `block.transactions`.
|
2021-08-30 11:42:07 -07:00
|
|
|
pub(crate) transaction_hashes: Arc<[transaction::Hash]>,
|
2022-04-12 10:21:46 -07:00
|
|
|
|
2021-08-25 06:57:07 -07:00
|
|
|
/// The sum of the chain value pool changes of all transactions in this block.
|
|
|
|
pub(crate) chain_value_pool_change: ValueBalance<NegativeAllowed>,
|
2021-07-19 06:52:32 -07:00
|
|
|
}
|
|
|
|
|
2022-09-06 02:32:54 -07:00
|
|
|
/// Wraps note commitment trees and the history tree together.
|
2023-11-08 14:06:16 -08:00
|
|
|
///
|
|
|
|
/// The default instance represents the treestate that corresponds to the genesis block.
|
|
|
|
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
2022-09-06 02:32:54 -07:00
|
|
|
pub struct Treestate {
|
|
|
|
/// Note commitment trees.
|
|
|
|
pub note_commitment_trees: NoteCommitmentTrees,
|
|
|
|
/// History tree.
|
|
|
|
pub history_tree: Arc<HistoryTree>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Treestate {
|
|
|
|
pub fn new(
|
|
|
|
sprout: Arc<sprout::tree::NoteCommitmentTree>,
|
|
|
|
sapling: Arc<sapling::tree::NoteCommitmentTree>,
|
|
|
|
orchard: Arc<orchard::tree::NoteCommitmentTree>,
|
2023-09-03 15:18:41 -07:00
|
|
|
sapling_subtree: Option<NoteCommitmentSubtree<sapling::tree::Node>>,
|
|
|
|
orchard_subtree: Option<NoteCommitmentSubtree<orchard::tree::Node>>,
|
2022-09-06 02:32:54 -07:00
|
|
|
history_tree: Arc<HistoryTree>,
|
|
|
|
) -> Self {
|
|
|
|
Self {
|
|
|
|
note_commitment_trees: NoteCommitmentTrees {
|
|
|
|
sprout,
|
|
|
|
sapling,
|
2023-08-28 01:50:31 -07:00
|
|
|
sapling_subtree,
|
2022-09-06 02:32:54 -07:00
|
|
|
orchard,
|
2023-08-28 01:50:31 -07:00
|
|
|
orchard_subtree,
|
2022-09-06 02:32:54 -07:00
|
|
|
},
|
|
|
|
history_tree,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-27 01:58:14 -07:00
|
|
|
/// Contains a block ready to be committed.
|
|
|
|
///
|
|
|
|
/// Zebra's state service passes this `enum` over to the finalized state
|
|
|
|
/// when committing a block.
|
|
|
|
pub enum FinalizableBlock {
|
|
|
|
Checkpoint {
|
|
|
|
checkpoint_verified: CheckpointVerifiedBlock,
|
|
|
|
},
|
|
|
|
Contextual {
|
|
|
|
contextually_verified: ContextuallyVerifiedBlock,
|
|
|
|
treestate: Treestate,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-11-08 14:06:16 -08:00
|
|
|
/// Contains a block with all its associated data that the finalized state can commit to its
|
|
|
|
/// database.
|
|
|
|
///
|
|
|
|
/// Note that it's the constructor's responsibility to ensure that all data is valid and verified.
|
|
|
|
pub struct FinalizedBlock {
|
|
|
|
/// The block to commit to the state.
|
|
|
|
pub(super) block: Arc<Block>,
|
|
|
|
/// The hash of the block.
|
|
|
|
pub(super) hash: block::Hash,
|
|
|
|
/// The height of the block.
|
|
|
|
pub(super) height: block::Height,
|
|
|
|
/// New transparent outputs created in this block, indexed by
|
|
|
|
/// [`OutPoint`](transparent::OutPoint).
|
|
|
|
pub(super) new_outputs: HashMap<transparent::OutPoint, transparent::OrderedUtxo>,
|
|
|
|
/// A precomputed list of the hashes of the transactions in this block, in the same order as
|
|
|
|
/// `block.transactions`.
|
|
|
|
pub(super) transaction_hashes: Arc<[transaction::Hash]>,
|
|
|
|
/// The tresstate associated with the block.
|
|
|
|
pub(super) treestate: Treestate,
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
/// This block's contribution to the deferred pool.
|
|
|
|
pub(super) deferred_balance: Option<Amount<NonNegative>>,
|
2023-11-08 14:06:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl FinalizedBlock {
|
|
|
|
/// Constructs [`FinalizedBlock`] from [`CheckpointVerifiedBlock`] and its [`Treestate`].
|
|
|
|
pub fn from_checkpoint_verified(block: CheckpointVerifiedBlock, treestate: Treestate) -> Self {
|
|
|
|
Self::from_semantically_verified(SemanticallyVerifiedBlock::from(block), treestate)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Constructs [`FinalizedBlock`] from [`ContextuallyVerifiedBlock`] and its [`Treestate`].
|
|
|
|
pub fn from_contextually_verified(
|
|
|
|
block: ContextuallyVerifiedBlock,
|
|
|
|
treestate: Treestate,
|
|
|
|
) -> Self {
|
|
|
|
Self::from_semantically_verified(SemanticallyVerifiedBlock::from(block), treestate)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Constructs [`FinalizedBlock`] from [`SemanticallyVerifiedBlock`] and its [`Treestate`].
|
|
|
|
fn from_semantically_verified(block: SemanticallyVerifiedBlock, treestate: Treestate) -> Self {
|
|
|
|
Self {
|
|
|
|
block: block.block,
|
|
|
|
hash: block.hash,
|
|
|
|
height: block.height,
|
|
|
|
new_outputs: block.new_outputs,
|
|
|
|
transaction_hashes: block.transaction_hashes,
|
|
|
|
treestate,
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
deferred_balance: block.deferred_balance,
|
2023-11-08 14:06:16 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-27 01:58:14 -07:00
|
|
|
impl FinalizableBlock {
|
|
|
|
/// Create a new [`FinalizableBlock`] given a [`ContextuallyVerifiedBlock`].
|
2023-06-21 09:58:11 -07:00
|
|
|
pub fn new(contextually_verified: ContextuallyVerifiedBlock, treestate: Treestate) -> Self {
|
2023-06-27 01:58:14 -07:00
|
|
|
Self::Contextual {
|
|
|
|
contextually_verified,
|
|
|
|
treestate,
|
2022-09-06 02:32:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-27 01:58:14 -07:00
|
|
|
#[cfg(test)]
|
|
|
|
/// Extract a [`Block`] from a [`FinalizableBlock`] variant.
|
|
|
|
pub fn inner_block(&self) -> Arc<Block> {
|
|
|
|
match self {
|
|
|
|
FinalizableBlock::Checkpoint {
|
|
|
|
checkpoint_verified,
|
|
|
|
} => checkpoint_verified.block.clone(),
|
|
|
|
FinalizableBlock::Contextual {
|
|
|
|
contextually_verified,
|
|
|
|
..
|
|
|
|
} => contextually_verified.block.clone(),
|
|
|
|
}
|
2023-06-21 09:58:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-27 01:58:14 -07:00
|
|
|
impl From<CheckpointVerifiedBlock> for FinalizableBlock {
|
|
|
|
fn from(checkpoint_verified: CheckpointVerifiedBlock) -> Self {
|
|
|
|
Self::Checkpoint {
|
|
|
|
checkpoint_verified,
|
2023-06-21 09:58:11 -07:00
|
|
|
}
|
2022-09-06 02:32:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-27 01:58:14 -07:00
|
|
|
impl From<Arc<Block>> for FinalizableBlock {
|
|
|
|
fn from(block: Arc<Block>) -> Self {
|
|
|
|
Self::from(CheckpointVerifiedBlock::from(block))
|
2022-09-06 02:32:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-01 05:29:03 -07:00
|
|
|
impl From<&SemanticallyVerifiedBlock> for SemanticallyVerifiedBlock {
|
|
|
|
fn from(semantically_verified: &SemanticallyVerifiedBlock) -> Self {
|
|
|
|
semantically_verified.clone()
|
2021-08-25 06:57:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-30 17:55:39 -07:00
|
|
|
// Doing precomputation in these impls means that it will be done in
|
|
|
|
// the *service caller*'s task, not inside the service call itself.
|
|
|
|
// This allows moving work out of the single-threaded state service.
|
|
|
|
|
2023-06-01 05:29:03 -07:00
|
|
|
impl ContextuallyVerifiedBlock {
|
2022-06-02 08:07:35 -07:00
|
|
|
/// Create a block that's ready for non-finalized `Chain` contextual validation,
|
2023-06-01 05:29:03 -07:00
|
|
|
/// using a [`SemanticallyVerifiedBlock`] and the UTXOs it spends.
|
2021-08-25 06:57:07 -07:00
|
|
|
///
|
2023-06-01 05:29:03 -07:00
|
|
|
/// When combined, `semantically_verified.new_outputs` and `spent_utxos` must contain
|
2022-06-02 08:07:35 -07:00
|
|
|
/// the [`Utxo`](transparent::Utxo)s spent by every transparent input in this block,
|
2021-08-25 06:57:07 -07:00
|
|
|
/// including UTXOs created by earlier transactions in this block.
|
|
|
|
///
|
2023-06-01 05:29:03 -07:00
|
|
|
/// Note: a [`ContextuallyVerifiedBlock`] isn't actually contextually valid until
|
2023-05-30 19:38:56 -07:00
|
|
|
/// [`Chain::push()`](crate::service::non_finalized_state::Chain::push) returns success.
|
2021-08-25 06:57:07 -07:00
|
|
|
pub fn with_block_and_spent_utxos(
|
2023-06-01 05:29:03 -07:00
|
|
|
semantically_verified: SemanticallyVerifiedBlock,
|
2022-04-12 10:21:46 -07:00
|
|
|
mut spent_outputs: HashMap<transparent::OutPoint, transparent::OrderedUtxo>,
|
2021-08-25 06:57:07 -07:00
|
|
|
) -> Result<Self, ValueBalanceError> {
|
2023-06-01 05:29:03 -07:00
|
|
|
let SemanticallyVerifiedBlock {
|
2021-08-25 06:57:07 -07:00
|
|
|
block,
|
|
|
|
hash,
|
|
|
|
height,
|
|
|
|
new_outputs,
|
|
|
|
transaction_hashes,
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
deferred_balance,
|
2023-06-01 05:29:03 -07:00
|
|
|
} = semantically_verified;
|
2021-08-25 06:57:07 -07:00
|
|
|
|
|
|
|
// This is redundant for the non-finalized state,
|
|
|
|
// but useful to make some tests pass more easily.
|
2022-04-12 10:21:46 -07:00
|
|
|
//
|
|
|
|
// TODO: fix the tests, and stop adding unrelated outputs.
|
|
|
|
spent_outputs.extend(new_outputs.clone());
|
2021-08-25 06:57:07 -07:00
|
|
|
|
|
|
|
Ok(Self {
|
|
|
|
block: block.clone(),
|
|
|
|
hash,
|
|
|
|
height,
|
2022-04-12 10:21:46 -07:00
|
|
|
new_outputs,
|
|
|
|
spent_outputs: spent_outputs.clone(),
|
2021-08-25 06:57:07 -07:00
|
|
|
transaction_hashes,
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
chain_value_pool_change: block.chain_value_pool_change(
|
|
|
|
&utxos_from_ordered_utxos(spent_outputs),
|
|
|
|
deferred_balance,
|
|
|
|
)?,
|
2021-08-25 06:57:07 -07:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
impl CheckpointVerifiedBlock {
|
|
|
|
/// Creates a [`CheckpointVerifiedBlock`] from [`Block`] with optional deferred balance and
|
|
|
|
/// optional pre-computed hash.
|
|
|
|
pub fn new(
|
|
|
|
block: Arc<Block>,
|
|
|
|
hash: Option<block::Hash>,
|
|
|
|
deferred_balance: Option<Amount<NonNegative>>,
|
|
|
|
) -> Self {
|
|
|
|
let mut block = Self::with_hash(block.clone(), hash.unwrap_or(block.hash()));
|
|
|
|
block.deferred_balance = deferred_balance;
|
|
|
|
block
|
|
|
|
}
|
|
|
|
/// Creates a block that's ready to be committed to the finalized state,
|
|
|
|
/// using a precalculated [`block::Hash`].
|
|
|
|
///
|
|
|
|
/// Note: a [`CheckpointVerifiedBlock`] isn't actually finalized
|
|
|
|
/// until [`Request::CommitCheckpointVerifiedBlock`] returns success.
|
|
|
|
pub fn with_hash(block: Arc<Block>, hash: block::Hash) -> Self {
|
|
|
|
Self(SemanticallyVerifiedBlock::with_hash(block, hash))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-21 09:58:11 -07:00
|
|
|
impl SemanticallyVerifiedBlock {
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
/// Creates [`SemanticallyVerifiedBlock`] from [`Block`] and [`block::Hash`].
|
|
|
|
pub fn with_hash(block: Arc<Block>, hash: block::Hash) -> Self {
|
2022-03-09 15:34:50 -08:00
|
|
|
let height = block
|
|
|
|
.coinbase_height()
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
.expect("semantically verified block should have a coinbase height");
|
2021-08-30 11:42:07 -07:00
|
|
|
let transaction_hashes: Arc<[_]> = block.transactions.iter().map(|tx| tx.hash()).collect();
|
2023-06-19 15:48:59 -07:00
|
|
|
let new_outputs = transparent::new_ordered_outputs(&block, &transaction_hashes);
|
2020-11-23 12:02:57 -08:00
|
|
|
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
Self {
|
2020-11-23 12:02:57 -08:00
|
|
|
block,
|
|
|
|
hash,
|
2021-03-21 19:20:44 -07:00
|
|
|
height,
|
2020-11-23 12:02:57 -08:00
|
|
|
new_outputs,
|
2020-11-24 19:55:15 -08:00
|
|
|
transaction_hashes,
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
deferred_balance: None,
|
2020-11-23 12:02:57 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
/// Sets the deferred balance in the block.
|
|
|
|
pub fn with_deferred_balance(mut self, deferred_balance: Option<Amount<NonNegative>>) -> Self {
|
|
|
|
self.deferred_balance = deferred_balance;
|
|
|
|
self
|
2023-06-21 09:58:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-01 05:29:03 -07:00
|
|
|
impl From<Arc<Block>> for CheckpointVerifiedBlock {
|
2021-08-30 17:55:39 -07:00
|
|
|
fn from(block: Arc<Block>) -> Self {
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
CheckpointVerifiedBlock(SemanticallyVerifiedBlock::from(block))
|
2021-08-30 17:55:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-21 09:58:11 -07:00
|
|
|
impl From<Arc<Block>> for SemanticallyVerifiedBlock {
|
|
|
|
fn from(block: Arc<Block>) -> Self {
|
|
|
|
let hash = block.hash();
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
let height = block
|
|
|
|
.coinbase_height()
|
|
|
|
.expect("semantically verified block should have a coinbase height");
|
|
|
|
let transaction_hashes: Arc<[_]> = block.transactions.iter().map(|tx| tx.hash()).collect();
|
|
|
|
let new_outputs = transparent::new_ordered_outputs(&block, &transaction_hashes);
|
2023-06-21 09:58:11 -07:00
|
|
|
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
Self {
|
2021-07-19 06:52:32 -07:00
|
|
|
block,
|
|
|
|
hash,
|
|
|
|
height,
|
|
|
|
new_outputs,
|
|
|
|
transaction_hashes,
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
deferred_balance: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-12 10:21:46 -07:00
|
|
|
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
impl From<ContextuallyVerifiedBlock> for SemanticallyVerifiedBlock {
|
|
|
|
fn from(valid: ContextuallyVerifiedBlock) -> Self {
|
state: introduce PreparedBlock, FinalizedBlock
This change introduces two new types:
- `PreparedBlock`, representing a block which has undergone semantic
validation and has been prepared for contextual validation;
- `FinalizedBlock`, representing a block which is ready to be finalized
immediately;
and changes the `Request::CommitBlock`,`Request::CommitFinalizedBlock`
variants to use these types instead of their previous fields.
This change solves the problem of passing data between semantic
validation and contextual validation, and cleans up the state code by
allowing it to pass around a bundle of data. Previously, the state code
just passed around an `Arc<Block>`, which forced it to needlessly
recompute block hashes and other data, and was incompatible with the
already-known but not-yet-implemented data transfer requirements, namely
passing in the Sprout and Sapling anchors computed during contextual
validation.
This commit propagates the `PreparedBlock` and `FinalizedBlock` types
through the state code but only uses their data opportunistically, e.g.,
changing .hash() computations to use the precomputed hash. In the
future, these structures can be extended to pass data through the
verification pipeline for reuse as appropriate. For instance, these
changes allow the sprout and sapling anchors to be propagated through
the state.
2020-11-21 01:16:14 -08:00
|
|
|
Self {
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
block: valid.block,
|
|
|
|
hash: valid.hash,
|
|
|
|
height: valid.height,
|
|
|
|
new_outputs: valid.new_outputs,
|
|
|
|
transaction_hashes: valid.transaction_hashes,
|
|
|
|
deferred_balance: Some(
|
|
|
|
valid
|
|
|
|
.chain_value_pool_change
|
|
|
|
.deferred_amount()
|
|
|
|
.constrain::<NonNegative>()
|
|
|
|
.expect("deferred balance in a block must me non-negative"),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<FinalizedBlock> for SemanticallyVerifiedBlock {
|
|
|
|
fn from(finalized: FinalizedBlock) -> Self {
|
|
|
|
Self {
|
|
|
|
block: finalized.block,
|
|
|
|
hash: finalized.hash,
|
|
|
|
height: finalized.height,
|
|
|
|
new_outputs: finalized.new_outputs,
|
|
|
|
transaction_hashes: finalized.transaction_hashes,
|
|
|
|
deferred_balance: finalized.deferred_balance,
|
state: introduce PreparedBlock, FinalizedBlock
This change introduces two new types:
- `PreparedBlock`, representing a block which has undergone semantic
validation and has been prepared for contextual validation;
- `FinalizedBlock`, representing a block which is ready to be finalized
immediately;
and changes the `Request::CommitBlock`,`Request::CommitFinalizedBlock`
variants to use these types instead of their previous fields.
This change solves the problem of passing data between semantic
validation and contextual validation, and cleans up the state code by
allowing it to pass around a bundle of data. Previously, the state code
just passed around an `Arc<Block>`, which forced it to needlessly
recompute block hashes and other data, and was incompatible with the
already-known but not-yet-implemented data transfer requirements, namely
passing in the Sprout and Sapling anchors computed during contextual
validation.
This commit propagates the `PreparedBlock` and `FinalizedBlock` types
through the state code but only uses their data opportunistically, e.g.,
changing .hash() computations to use the precomputed hash. In the
future, these structures can be extended to pass data through the
verification pipeline for reuse as appropriate. For instance, these
changes allow the sprout and sapling anchors to be propagated through
the state.
2020-11-21 01:16:14 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-27 01:58:14 -07:00
|
|
|
impl From<CheckpointVerifiedBlock> for SemanticallyVerifiedBlock {
|
|
|
|
fn from(checkpoint_verified: CheckpointVerifiedBlock) -> Self {
|
|
|
|
checkpoint_verified.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-21 09:58:11 -07:00
|
|
|
impl Deref for CheckpointVerifiedBlock {
|
|
|
|
type Target = SemanticallyVerifiedBlock;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl DerefMut for CheckpointVerifiedBlock {
|
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
&mut self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-09 16:42:52 -07:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
2022-06-02 08:07:35 -07:00
|
|
|
/// A query about or modification to the chain state, via the
|
|
|
|
/// [`StateService`](crate::service::StateService).
|
2020-09-09 16:42:52 -07:00
|
|
|
pub enum Request {
|
2023-07-04 14:29:41 -07:00
|
|
|
/// Performs contextual validation of the given semantically verified block,
|
|
|
|
/// committing it to the state if successful.
|
2020-09-09 17:59:58 -07:00
|
|
|
///
|
2023-07-04 14:29:41 -07:00
|
|
|
/// This request can be made out-of-order; the state service will queue it
|
|
|
|
/// until its parent is ready.
|
2020-09-09 17:59:58 -07:00
|
|
|
///
|
2020-11-12 11:43:17 -08:00
|
|
|
/// Returns [`Response::Committed`] with the hash of the block when it is
|
|
|
|
/// committed to the state, or an error if the block fails contextual
|
|
|
|
/// validation or has already been committed to the state.
|
|
|
|
///
|
|
|
|
/// This request cannot be cancelled once submitted; dropping the response
|
|
|
|
/// future will have no effect on whether it is eventually processed. A
|
|
|
|
/// request to commit a block which has been queued internally but not yet
|
|
|
|
/// committed will fail the older request and replace it with the newer request.
|
2021-06-18 10:43:05 -07:00
|
|
|
///
|
|
|
|
/// # Correctness
|
|
|
|
///
|
|
|
|
/// Block commit requests should be wrapped in a timeout, so that
|
|
|
|
/// out-of-order and invalid requests do not hang indefinitely. See the [`crate`]
|
|
|
|
/// documentation for details.
|
2023-06-01 05:29:03 -07:00
|
|
|
CommitSemanticallyVerifiedBlock(SemanticallyVerifiedBlock),
|
2020-09-09 17:59:58 -07:00
|
|
|
|
2023-07-04 14:29:41 -07:00
|
|
|
/// Commit a checkpointed block to the state, skipping most but not all
|
|
|
|
/// contextual validation.
|
2020-11-12 11:43:17 -08:00
|
|
|
///
|
2023-07-04 14:29:41 -07:00
|
|
|
/// This is exposed for use in checkpointing, which produces checkpoint vefified
|
|
|
|
/// blocks. This request can be made out-of-order; the state service will queue
|
|
|
|
/// it until its parent is ready.
|
2020-09-09 17:59:58 -07:00
|
|
|
///
|
2020-11-12 11:43:17 -08:00
|
|
|
/// Returns [`Response::Committed`] with the hash of the newly committed
|
|
|
|
/// block, or an error.
|
2020-09-09 17:59:58 -07:00
|
|
|
///
|
2020-11-12 11:43:17 -08:00
|
|
|
/// This request cannot be cancelled once submitted; dropping the response
|
|
|
|
/// future will have no effect on whether it is eventually processed.
|
2022-09-28 09:09:56 -07:00
|
|
|
/// Duplicate requests will replace the older duplicate, and return an error
|
|
|
|
/// in its response future.
|
|
|
|
///
|
|
|
|
/// # Note
|
|
|
|
///
|
2023-07-04 14:29:41 -07:00
|
|
|
/// [`SemanticallyVerifiedBlock`], [`ContextuallyVerifiedBlock`] and
|
|
|
|
/// [`CheckpointVerifiedBlock`] are an internal Zebra implementation detail.
|
|
|
|
/// There is no difference between these blocks on the Zcash network, or in Zebra's
|
2022-09-28 09:09:56 -07:00
|
|
|
/// network or syncer implementations.
|
|
|
|
///
|
|
|
|
/// # Consensus
|
|
|
|
///
|
|
|
|
/// Checkpointing is allowed under the Zcash "social consensus" rules.
|
|
|
|
/// Zebra checkpoints both settled network upgrades, and blocks past the rollback limit.
|
|
|
|
/// (By the time Zebra release is tagged, its final checkpoint is typically hours or days old.)
|
|
|
|
///
|
|
|
|
/// > 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.
|
|
|
|
/// > ...
|
|
|
|
/// > A full validator MAY impose a limit on the number of blocks it will “roll back”
|
|
|
|
/// > when switching from one best valid block chain to another that is not a descendent.
|
|
|
|
/// > For `zcashd` and `zebra` this limit is 100 blocks.
|
|
|
|
///
|
|
|
|
/// <https://zips.z.cash/protocol/protocol.pdf#blockchain>
|
2021-06-18 10:43:05 -07:00
|
|
|
///
|
|
|
|
/// # Correctness
|
|
|
|
///
|
|
|
|
/// Block commit requests should be wrapped in a timeout, so that
|
|
|
|
/// out-of-order and invalid requests do not hang indefinitely. See the [`crate`]
|
|
|
|
/// documentation for details.
|
2023-06-01 05:29:03 -07:00
|
|
|
CommitCheckpointVerifiedBlock(CheckpointVerifiedBlock),
|
2020-09-09 17:59:58 -07:00
|
|
|
|
2020-11-16 12:50:57 -08:00
|
|
|
/// Computes the depth in the current best chain of the block identified by the given hash.
|
2020-09-09 17:59:58 -07:00
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
2020-11-16 12:50:57 -08:00
|
|
|
/// * [`Response::Depth(Some(depth))`](Response::Depth) if the block is in the best chain;
|
2020-09-09 17:59:58 -07:00
|
|
|
/// * [`Response::Depth(None)`](Response::Depth) otherwise.
|
|
|
|
Depth(block::Hash),
|
|
|
|
|
2022-09-13 17:35:37 -07:00
|
|
|
/// Returns [`Response::Tip(Option<(Height, block::Hash)>)`](Response::Tip)
|
|
|
|
/// with the current best chain tip.
|
2020-09-09 17:59:58 -07:00
|
|
|
Tip,
|
|
|
|
|
2020-11-16 12:50:57 -08:00
|
|
|
/// Computes a block locator object based on the current best chain.
|
2020-09-09 17:59:58 -07:00
|
|
|
///
|
|
|
|
/// Returns [`Response::BlockLocator`] with hashes starting
|
2020-11-16 12:50:57 -08:00
|
|
|
/// from the best chain tip, and following the chain of previous
|
|
|
|
/// hashes. The first hash is the best chain tip. The last hash is
|
|
|
|
/// the tip of the finalized portion of the state. Block locators
|
|
|
|
/// are not continuous - some intermediate hashes might be skipped.
|
|
|
|
///
|
|
|
|
/// If the state is empty, the block locator is also empty.
|
2020-09-09 17:59:58 -07:00
|
|
|
BlockLocator,
|
|
|
|
|
2020-11-16 12:50:57 -08:00
|
|
|
/// Looks up a transaction by hash in the current best chain.
|
2020-09-09 17:59:58 -07:00
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
2020-11-16 12:50:57 -08:00
|
|
|
/// * [`Response::Transaction(Some(Arc<Transaction>))`](Response::Transaction) if the transaction is in the best chain;
|
2020-09-09 17:59:58 -07:00
|
|
|
/// * [`Response::Transaction(None)`](Response::Transaction) otherwise.
|
|
|
|
Transaction(transaction::Hash),
|
|
|
|
|
2022-11-10 22:40:35 -08:00
|
|
|
/// Looks up a UTXO identified by the given [`OutPoint`](transparent::OutPoint),
|
|
|
|
/// returning `None` immediately if it is unknown.
|
|
|
|
///
|
|
|
|
/// Checks verified blocks in the finalized chain and the _best_ non-finalized chain.
|
|
|
|
UnspentBestChainUtxo(transparent::OutPoint),
|
|
|
|
|
2020-11-16 12:50:57 -08:00
|
|
|
/// Looks up a block by hash or height in the current best chain.
|
2020-09-09 17:59:58 -07:00
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
2020-11-16 12:50:57 -08:00
|
|
|
/// * [`Response::Block(Some(Arc<Block>))`](Response::Block) if the block is in the best chain;
|
|
|
|
/// * [`Response::Block(None)`](Response::Block) otherwise.
|
2020-09-09 17:59:58 -07:00
|
|
|
///
|
|
|
|
/// Note: the [`HashOrHeight`] can be constructed from a [`block::Hash`] or
|
|
|
|
/// [`block::Height`] using `.into()`.
|
|
|
|
Block(HashOrHeight),
|
2020-10-14 14:06:32 -07:00
|
|
|
|
2024-04-12 13:07:44 -07:00
|
|
|
/// Looks up a block header by hash or height in the current best chain.
|
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
|
|
|
/// [`Response::BlockHeader(block::Header)`](Response::BlockHeader).
|
|
|
|
///
|
|
|
|
/// Note: the [`HashOrHeight`] can be constructed from a [`block::Hash`] or
|
|
|
|
/// [`block::Height`] using `.into()`.
|
|
|
|
BlockHeader(HashOrHeight),
|
|
|
|
|
2022-09-15 21:13:26 -07:00
|
|
|
/// Request a UTXO identified by the given [`OutPoint`](transparent::OutPoint),
|
|
|
|
/// waiting until it becomes available if it is unknown.
|
|
|
|
///
|
|
|
|
/// Checks the finalized chain, all non-finalized chains, queued unverified blocks,
|
|
|
|
/// and any blocks that arrive at the state after the request future has been created.
|
2020-11-12 11:43:17 -08:00
|
|
|
///
|
|
|
|
/// This request is purely informational, and there are no guarantees about
|
state: introduce PreparedBlock, FinalizedBlock
This change introduces two new types:
- `PreparedBlock`, representing a block which has undergone semantic
validation and has been prepared for contextual validation;
- `FinalizedBlock`, representing a block which is ready to be finalized
immediately;
and changes the `Request::CommitBlock`,`Request::CommitFinalizedBlock`
variants to use these types instead of their previous fields.
This change solves the problem of passing data between semantic
validation and contextual validation, and cleans up the state code by
allowing it to pass around a bundle of data. Previously, the state code
just passed around an `Arc<Block>`, which forced it to needlessly
recompute block hashes and other data, and was incompatible with the
already-known but not-yet-implemented data transfer requirements, namely
passing in the Sprout and Sapling anchors computed during contextual
validation.
This commit propagates the `PreparedBlock` and `FinalizedBlock` types
through the state code but only uses their data opportunistically, e.g.,
changing .hash() computations to use the precomputed hash. In the
future, these structures can be extended to pass data through the
verification pipeline for reuse as appropriate. For instance, these
changes allow the sprout and sapling anchors to be propagated through
the state.
2020-11-21 01:16:14 -08:00
|
|
|
/// whether the UTXO remains unspent or is on the best chain, or any chain.
|
|
|
|
/// Its purpose is to allow asynchronous script verification.
|
2020-11-16 12:50:57 -08:00
|
|
|
///
|
2021-06-18 10:43:05 -07:00
|
|
|
/// # Correctness
|
|
|
|
///
|
|
|
|
/// UTXO requests should be wrapped in a timeout, so that
|
|
|
|
/// out-of-order and invalid requests do not hang indefinitely. See the [`crate`]
|
|
|
|
/// documentation for details.
|
2022-09-15 21:13:26 -07:00
|
|
|
///
|
|
|
|
/// Outdated requests are pruned on a regular basis.
|
2020-10-14 14:06:32 -07:00
|
|
|
AwaitUtxo(transparent::OutPoint),
|
2020-11-30 13:30:37 -08:00
|
|
|
|
|
|
|
/// Finds the first hash that's in the peer's `known_blocks` and the local best chain.
|
|
|
|
/// Returns a list of hashes that follow that intersection, from the best chain.
|
|
|
|
///
|
|
|
|
/// If there is no matching hash in the best chain, starts from the genesis hash.
|
|
|
|
///
|
|
|
|
/// Stops the list of hashes after:
|
|
|
|
/// * adding the best tip,
|
|
|
|
/// * adding the `stop` hash to the list, if it is in the best chain, or
|
|
|
|
/// * adding 500 hashes to the list.
|
|
|
|
///
|
|
|
|
/// Returns an empty list if the state is empty.
|
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
|
|
|
/// [`Response::BlockHashes(Vec<block::Hash>)`](Response::BlockHashes).
|
2022-05-30 13:12:11 -07:00
|
|
|
/// See <https://en.bitcoin.it/wiki/Protocol_documentation#getblocks>
|
2020-11-30 13:30:37 -08:00
|
|
|
FindBlockHashes {
|
|
|
|
/// Hashes of known blocks, ordered from highest height to lowest height.
|
|
|
|
known_blocks: Vec<block::Hash>,
|
|
|
|
/// Optionally, the last block hash to request.
|
|
|
|
stop: Option<block::Hash>,
|
|
|
|
},
|
|
|
|
|
|
|
|
/// Finds the first hash that's in the peer's `known_blocks` and the local best chain.
|
|
|
|
/// Returns a list of headers that follow that intersection, from the best chain.
|
|
|
|
///
|
|
|
|
/// If there is no matching hash in the best chain, starts from the genesis header.
|
|
|
|
///
|
|
|
|
/// Stops the list of headers after:
|
|
|
|
/// * adding the best tip,
|
|
|
|
/// * adding the header matching the `stop` hash to the list, if it is in the best chain, or
|
2022-09-13 17:35:37 -07:00
|
|
|
/// * adding [`MAX_FIND_BLOCK_HEADERS_RESULTS_FOR_ZEBRA`] headers to the list.
|
2020-11-30 13:30:37 -08:00
|
|
|
///
|
|
|
|
/// Returns an empty list if the state is empty.
|
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
|
|
|
/// [`Response::BlockHeaders(Vec<block::Header>)`](Response::BlockHeaders).
|
2022-05-30 13:12:11 -07:00
|
|
|
/// See <https://en.bitcoin.it/wiki/Protocol_documentation#getheaders>
|
2020-11-30 13:30:37 -08:00
|
|
|
FindBlockHeaders {
|
|
|
|
/// Hashes of known blocks, ordered from highest height to lowest height.
|
|
|
|
known_blocks: Vec<block::Hash>,
|
|
|
|
/// Optionally, the hash of the last header to request.
|
|
|
|
stop: Option<block::Hash>,
|
|
|
|
},
|
2022-11-29 20:40:15 -08:00
|
|
|
|
|
|
|
/// Contextually validates anchors and nullifiers of a transaction on the best chain
|
|
|
|
///
|
|
|
|
/// Returns [`Response::ValidBestChainTipNullifiersAndAnchors`]
|
|
|
|
CheckBestChainTipNullifiersAndAnchors(UnminedTx),
|
2023-01-11 15:39:51 -08:00
|
|
|
|
2023-01-27 13:46:51 -08:00
|
|
|
/// Calculates the median-time-past for the *next* block on the best chain.
|
|
|
|
///
|
|
|
|
/// Returns [`Response::BestChainNextMedianTimePast`] when successful.
|
|
|
|
BestChainNextMedianTimePast,
|
|
|
|
|
2023-02-20 21:30:29 -08:00
|
|
|
/// Looks up a block hash by height in the current best chain.
|
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
|
|
|
/// * [`Response::BlockHash(Some(hash))`](Response::BlockHash) if the block is in the best chain;
|
|
|
|
/// * [`Response::BlockHash(None)`](Response::BlockHash) otherwise.
|
|
|
|
BestChainBlockHash(block::Height),
|
|
|
|
|
2023-03-24 00:10:07 -07:00
|
|
|
/// Checks if a block is present anywhere in the state service.
|
|
|
|
/// Looks up `hash` in block queues as well as the finalized chain and all non-finalized chains.
|
|
|
|
///
|
|
|
|
/// Returns [`Response::KnownBlock(Some(Location))`](Response::KnownBlock) if the block is in the best state service.
|
|
|
|
/// Returns [`Response::KnownBlock(None)`](Response::KnownBlock) otherwise.
|
|
|
|
KnownBlock(block::Hash),
|
|
|
|
|
2023-01-11 15:39:51 -08:00
|
|
|
#[cfg(feature = "getblocktemplate-rpcs")]
|
|
|
|
/// Performs contextual validation of the given block, but does not commit it to the state.
|
|
|
|
///
|
|
|
|
/// Returns [`Response::ValidBlockProposal`] when successful.
|
|
|
|
/// See `[ReadRequest::CheckBlockProposalValidity]` for details.
|
2023-06-01 05:29:03 -07:00
|
|
|
CheckBlockProposalValidity(SemanticallyVerifiedBlock),
|
2020-09-09 16:42:52 -07:00
|
|
|
}
|
2022-03-17 15:59:46 -07:00
|
|
|
|
2022-09-16 12:03:56 -07:00
|
|
|
impl Request {
|
|
|
|
fn variant_name(&self) -> &'static str {
|
|
|
|
match self {
|
2023-06-01 05:29:03 -07:00
|
|
|
Request::CommitSemanticallyVerifiedBlock(_) => "commit_semantically_verified_block",
|
|
|
|
Request::CommitCheckpointVerifiedBlock(_) => "commit_checkpoint_verified_block",
|
|
|
|
|
2022-09-16 12:03:56 -07:00
|
|
|
Request::AwaitUtxo(_) => "await_utxo",
|
|
|
|
Request::Depth(_) => "depth",
|
|
|
|
Request::Tip => "tip",
|
|
|
|
Request::BlockLocator => "block_locator",
|
|
|
|
Request::Transaction(_) => "transaction",
|
2022-11-10 22:40:35 -08:00
|
|
|
Request::UnspentBestChainUtxo { .. } => "unspent_best_chain_utxo",
|
2022-09-16 12:03:56 -07:00
|
|
|
Request::Block(_) => "block",
|
2024-04-12 13:07:44 -07:00
|
|
|
Request::BlockHeader(_) => "block_header",
|
2022-09-16 12:03:56 -07:00
|
|
|
Request::FindBlockHashes { .. } => "find_block_hashes",
|
|
|
|
Request::FindBlockHeaders { .. } => "find_block_headers",
|
2022-11-29 20:40:15 -08:00
|
|
|
Request::CheckBestChainTipNullifiersAndAnchors(_) => {
|
|
|
|
"best_chain_tip_nullifiers_anchors"
|
|
|
|
}
|
2023-01-27 13:46:51 -08:00
|
|
|
Request::BestChainNextMedianTimePast => "best_chain_next_median_time_past",
|
2023-02-20 21:30:29 -08:00
|
|
|
Request::BestChainBlockHash(_) => "best_chain_block_hash",
|
2023-03-24 00:10:07 -07:00
|
|
|
Request::KnownBlock(_) => "known_block",
|
2023-01-11 15:39:51 -08:00
|
|
|
#[cfg(feature = "getblocktemplate-rpcs")]
|
|
|
|
Request::CheckBlockProposalValidity(_) => "check_block_proposal_validity",
|
2022-09-16 12:03:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Counts metric for StateService call
|
|
|
|
pub fn count_metric(&self) {
|
|
|
|
metrics::counter!(
|
|
|
|
"state.requests",
|
|
|
|
"service" => "state",
|
|
|
|
"type" => self.variant_name()
|
2024-01-01 17:26:54 -08:00
|
|
|
)
|
|
|
|
.increment(1);
|
2022-09-16 12:03:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-13 01:48:13 -07:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
2022-06-02 08:07:35 -07:00
|
|
|
/// A read-only query about the chain state, via the
|
|
|
|
/// [`ReadStateService`](crate::service::ReadStateService).
|
2022-03-17 15:59:46 -07:00
|
|
|
pub enum ReadRequest {
|
2022-09-13 17:35:37 -07:00
|
|
|
/// Returns [`ReadResponse::Tip(Option<(Height, block::Hash)>)`](ReadResponse::Tip)
|
|
|
|
/// with the current best chain tip.
|
|
|
|
Tip,
|
|
|
|
|
2024-08-16 12:54:44 -07:00
|
|
|
/// Returns [`ReadResponse::TipPoolValues(Option<(Height, block::Hash, ValueBalance)>)`](ReadResponse::TipPoolValues)
|
|
|
|
/// with the current best chain tip.
|
|
|
|
TipPoolValues,
|
|
|
|
|
2022-09-13 17:35:37 -07:00
|
|
|
/// Computes the depth in the current best chain of the block identified by the given hash.
|
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
|
|
|
/// * [`ReadResponse::Depth(Some(depth))`](ReadResponse::Depth) if the block is in the best chain;
|
|
|
|
/// * [`ReadResponse::Depth(None)`](ReadResponse::Depth) otherwise.
|
|
|
|
Depth(block::Hash),
|
|
|
|
|
2022-03-17 15:59:46 -07:00
|
|
|
/// Looks up a block by hash or height in the current best chain.
|
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
2022-09-13 17:35:37 -07:00
|
|
|
/// * [`ReadResponse::Block(Some(Arc<Block>))`](ReadResponse::Block) if the block is in the best chain;
|
|
|
|
/// * [`ReadResponse::Block(None)`](ReadResponse::Block) otherwise.
|
2022-03-17 15:59:46 -07:00
|
|
|
///
|
|
|
|
/// Note: the [`HashOrHeight`] can be constructed from a [`block::Hash`] or
|
|
|
|
/// [`block::Height`] using `.into()`.
|
|
|
|
Block(HashOrHeight),
|
|
|
|
|
2024-04-12 13:07:44 -07:00
|
|
|
/// Looks up a block header by hash or height in the current best chain.
|
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
|
|
|
/// [`Response::BlockHeader(block::Header)`](Response::BlockHeader).
|
|
|
|
///
|
|
|
|
/// Note: the [`HashOrHeight`] can be constructed from a [`block::Hash`] or
|
|
|
|
/// [`block::Height`] using `.into()`.
|
|
|
|
BlockHeader(HashOrHeight),
|
|
|
|
|
2022-03-17 15:59:46 -07:00
|
|
|
/// Looks up a transaction by hash in the current best chain.
|
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
2022-09-13 17:35:37 -07:00
|
|
|
/// * [`ReadResponse::Transaction(Some(Arc<Transaction>))`](ReadResponse::Transaction) if the transaction is in the best chain;
|
|
|
|
/// * [`ReadResponse::Transaction(None)`](ReadResponse::Transaction) otherwise.
|
2022-03-17 15:59:46 -07:00
|
|
|
Transaction(transaction::Hash),
|
2022-04-13 01:48:13 -07:00
|
|
|
|
2022-10-02 16:34:44 -07:00
|
|
|
/// Looks up the transaction IDs for a block, using a block hash or height.
|
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
|
|
|
/// * An ordered list of transaction hashes, or
|
|
|
|
/// * `None` if the block was not found.
|
|
|
|
///
|
|
|
|
/// Note: Each block has at least one transaction: the coinbase transaction.
|
|
|
|
///
|
|
|
|
/// Returned txids are in the order they appear in the block.
|
|
|
|
TransactionIdsForBlock(HashOrHeight),
|
|
|
|
|
2022-09-15 21:13:26 -07:00
|
|
|
/// Looks up a UTXO identified by the given [`OutPoint`](transparent::OutPoint),
|
|
|
|
/// returning `None` immediately if it is unknown.
|
|
|
|
///
|
|
|
|
/// Checks verified blocks in the finalized chain and the _best_ non-finalized chain.
|
2022-11-10 22:40:35 -08:00
|
|
|
UnspentBestChainUtxo(transparent::OutPoint),
|
2022-09-15 21:13:26 -07:00
|
|
|
|
|
|
|
/// Looks up a UTXO identified by the given [`OutPoint`](transparent::OutPoint),
|
|
|
|
/// returning `None` immediately if it is unknown.
|
|
|
|
///
|
|
|
|
/// Checks verified blocks in the finalized chain and _all_ non-finalized chains.
|
|
|
|
///
|
|
|
|
/// This request is purely informational, there is no guarantee that
|
|
|
|
/// the UTXO remains unspent in the best chain.
|
|
|
|
AnyChainUtxo(transparent::OutPoint),
|
|
|
|
|
2022-09-13 17:35:37 -07:00
|
|
|
/// Computes a block locator object based on the current best chain.
|
2022-04-21 13:19:26 -07:00
|
|
|
///
|
2022-09-13 17:35:37 -07:00
|
|
|
/// Returns [`ReadResponse::BlockLocator`] with hashes starting
|
|
|
|
/// from the best chain tip, and following the chain of previous
|
|
|
|
/// hashes. The first hash is the best chain tip. The last hash is
|
|
|
|
/// the tip of the finalized portion of the state. Block locators
|
|
|
|
/// are not continuous - some intermediate hashes might be skipped.
|
|
|
|
///
|
|
|
|
/// If the state is empty, the block locator is also empty.
|
|
|
|
BlockLocator,
|
|
|
|
|
|
|
|
/// Finds the first hash that's in the peer's `known_blocks` and the local best chain.
|
|
|
|
/// Returns a list of hashes that follow that intersection, from the best chain.
|
|
|
|
///
|
|
|
|
/// If there is no matching hash in the best chain, starts from the genesis hash.
|
|
|
|
///
|
|
|
|
/// Stops the list of hashes after:
|
|
|
|
/// * adding the best tip,
|
|
|
|
/// * adding the `stop` hash to the list, if it is in the best chain, or
|
|
|
|
/// * adding [`MAX_FIND_BLOCK_HASHES_RESULTS`] hashes to the list.
|
|
|
|
///
|
|
|
|
/// Returns an empty list if the state is empty.
|
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
|
|
|
/// [`ReadResponse::BlockHashes(Vec<block::Hash>)`](ReadResponse::BlockHashes).
|
|
|
|
/// See <https://en.bitcoin.it/wiki/Protocol_documentation#getblocks>
|
|
|
|
FindBlockHashes {
|
|
|
|
/// Hashes of known blocks, ordered from highest height to lowest height.
|
|
|
|
known_blocks: Vec<block::Hash>,
|
|
|
|
/// Optionally, the last block hash to request.
|
|
|
|
stop: Option<block::Hash>,
|
|
|
|
},
|
|
|
|
|
|
|
|
/// Finds the first hash that's in the peer's `known_blocks` and the local best chain.
|
|
|
|
/// Returns a list of headers that follow that intersection, from the best chain.
|
|
|
|
///
|
|
|
|
/// If there is no matching hash in the best chain, starts from the genesis header.
|
|
|
|
///
|
|
|
|
/// Stops the list of headers after:
|
|
|
|
/// * adding the best tip,
|
|
|
|
/// * adding the header matching the `stop` hash to the list, if it is in the best chain, or
|
|
|
|
/// * adding [`MAX_FIND_BLOCK_HEADERS_RESULTS_FOR_ZEBRA`] headers to the list.
|
|
|
|
///
|
|
|
|
/// Returns an empty list if the state is empty.
|
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
|
|
|
/// [`ReadResponse::BlockHeaders(Vec<block::Header>)`](ReadResponse::BlockHeaders).
|
|
|
|
/// See <https://en.bitcoin.it/wiki/Protocol_documentation#getheaders>
|
|
|
|
FindBlockHeaders {
|
|
|
|
/// Hashes of known blocks, ordered from highest height to lowest height.
|
|
|
|
known_blocks: Vec<block::Hash>,
|
|
|
|
/// Optionally, the hash of the last header to request.
|
|
|
|
stop: Option<block::Hash>,
|
|
|
|
},
|
2022-04-21 13:19:26 -07:00
|
|
|
|
2022-05-12 00:00:12 -07:00
|
|
|
/// Looks up a Sapling note commitment tree either by a hash or height.
|
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
|
|
|
/// * [`ReadResponse::SaplingTree(Some(Arc<NoteCommitmentTree>))`](crate::ReadResponse::SaplingTree)
|
|
|
|
/// if the corresponding block contains a Sapling note commitment tree.
|
|
|
|
/// * [`ReadResponse::SaplingTree(None)`](crate::ReadResponse::SaplingTree) otherwise.
|
|
|
|
SaplingTree(HashOrHeight),
|
|
|
|
|
|
|
|
/// Looks up an Orchard note commitment tree either by a hash or height.
|
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
|
|
|
/// * [`ReadResponse::OrchardTree(Some(Arc<NoteCommitmentTree>))`](crate::ReadResponse::OrchardTree)
|
|
|
|
/// if the corresponding block contains a Sapling note commitment tree.
|
|
|
|
/// * [`ReadResponse::OrchardTree(None)`](crate::ReadResponse::OrchardTree) otherwise.
|
|
|
|
OrchardTree(HashOrHeight),
|
|
|
|
|
2023-09-06 00:15:18 -07:00
|
|
|
/// Returns a list of Sapling note commitment subtrees by their indexes, starting at
|
|
|
|
/// `start_index`, and returning up to `limit` subtrees.
|
2023-09-03 15:18:41 -07:00
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
|
|
|
/// * [`ReadResponse::SaplingSubtree(BTreeMap<_, NoteCommitmentSubtreeData<_>>))`](crate::ReadResponse::SaplingSubtrees)
|
2023-09-06 00:15:18 -07:00
|
|
|
/// * An empty list if there is no subtree at `start_index`.
|
2023-09-03 15:18:41 -07:00
|
|
|
SaplingSubtrees {
|
|
|
|
/// The index of the first 2^16-leaf subtree to return.
|
|
|
|
start_index: NoteCommitmentSubtreeIndex,
|
|
|
|
/// The maximum number of subtree values to return.
|
|
|
|
limit: Option<NoteCommitmentSubtreeIndex>,
|
|
|
|
},
|
|
|
|
|
2023-09-06 00:15:18 -07:00
|
|
|
/// Returns a list of Orchard note commitment subtrees by their indexes, starting at
|
|
|
|
/// `start_index`, and returning up to `limit` subtrees.
|
2023-09-03 15:18:41 -07:00
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
|
|
|
/// * [`ReadResponse::OrchardSubtree(BTreeMap<_, NoteCommitmentSubtreeData<_>>))`](crate::ReadResponse::OrchardSubtrees)
|
2023-09-06 00:15:18 -07:00
|
|
|
/// * An empty list if there is no subtree at `start_index`.
|
2023-09-03 15:18:41 -07:00
|
|
|
OrchardSubtrees {
|
|
|
|
/// The index of the first 2^16-leaf subtree to return.
|
|
|
|
start_index: NoteCommitmentSubtreeIndex,
|
|
|
|
/// The maximum number of subtree values to return.
|
|
|
|
limit: Option<NoteCommitmentSubtreeIndex>,
|
|
|
|
},
|
|
|
|
|
2022-09-13 17:35:37 -07:00
|
|
|
/// Looks up the balance of a set of transparent addresses.
|
|
|
|
///
|
change: Track the balance of the deferred chain value pool (#8729)
* Addresses clippy lints
* checks network magic and returns early from `is_regtest()`
* Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into structs, splits them into pre/post NU6 funding streams, and adds them as a field on `testnet::Parameters`
* Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and conversion logic with constraints.
Minor refactors
* Empties recipients list
* Adds a comment on num_addresses calculation being invalid for configured Testnets, but that being okay since configured testnet parameters are checked when they're being built
* Documentation fixes, minor cleanup, renames a test, adds TODOs, and fixes test logic
* Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs and TODOs
* Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding streams, updates the `miner_fees_are_valid()` and `subsidy_is_valid()` functions to check that the deferred pool contribution is valid and that there are no unclaimed block subsidies after NU6 activation, and adds some TODOs
* adds `lockbox_input_value()` fn
* Adds TODOs for linking to relevant ZIPs and updating height ranges
* Adds `nu6_lockbox_funding_stream` acceptance test
* updates funding stream values test to check post-NU6 funding streams too, adds Mainnet/Testnet NU6 activation heights, fixes lints/compilation issue
* Reverts Mainnet/Testnet NU6 activation height definitions, updates `test_funding_stream_values()` to use a configured testnet with the post-NU6 Mainnet funding streams height range
* reverts unnecessary refactor
* appease clippy
* Adds a test for `lockbox_input_value()`
* Applies suggestions from code review
* Fixes potential panic
* Fixes bad merge
* Update zebra-chain/src/parameters/network_upgrade.rs
* Updates acceptance test to check that invalid blocks are rejected
* Checks that the original valid block template at height 2 is accepted as a block submission
* Reverts changes for coinbase should balance exactly ZIP
* Add `Deferred` to `ValueBalance`
* Update snapshots
* Unrelated: Revise docs
* Add TODOs
* Stop recalculating the block subsidy
* Track deferred balances
* Support heights below slow start shift in halvings
* Fix `CheckpointVerifiedBlock` conversion in tests
* Allow deserialization of legacy `ValueBalance`s
* Simplify docs
* Fix warnings raised by Clippy
* Fix warnings raised by `cargo fmt`
* Update zebra-chain/src/block.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Refactor docs around chain value pool changes
* updates test name
* Updates deferred pool funding stream name to "Lockbox", moves post-NU6 height ranges to constants, updates TODO
* Updates `get_block_subsidy()` RPC method to exclude lockbox funding stream from `fundingstreams` field
* Adds a TODO for updating `FundingStreamReceiver::name()` method docs
* Updates `FundingStreamRecipient::new()` to accept an iterator of items instead of an option of an iterator, updates a comment quoting the coinbase transaction balance consensus rule to note that the current code is inconsistent with the protocol spec, adds a TODO for updating the quote there once the protocol spec has been updated.
* Update zebra-consensus/src/checkpoint.rs
Co-authored-by: Arya <aryasolhi@gmail.com>
* Update docs for value balances
* Cleanup: Simplify getting info for FS receivers
* Avoid a panic when deserializing value balances
* Uses FPF Testnet address for post-NU6 testnet funding streams
* Updates the NU6 consensus branch id
* Update zebra-consensus/src/checkpoint.rs
* Bump the major database format version
* Add a database upgrade mark
* Fix tests after merge
* trigger GitHub actions
---------
Co-authored-by: Arya <aryasolhi@gmail.com>
Co-authored-by: Pili Guerra <mpguerra@users.noreply.github.com>
2024-08-05 13:30:47 -07:00
|
|
|
/// Returns an [`Amount`] with the total
|
2022-09-13 17:35:37 -07:00
|
|
|
/// balance of the set of addresses.
|
|
|
|
AddressBalance(HashSet<transparent::Address>),
|
|
|
|
|
2022-05-12 00:00:12 -07:00
|
|
|
/// Looks up transaction hashes that were sent or received from addresses,
|
2022-04-21 13:19:26 -07:00
|
|
|
/// in an inclusive blockchain height range.
|
2022-04-13 01:48:13 -07:00
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
2022-09-13 17:35:37 -07:00
|
|
|
/// * An ordered, unique map of transaction locations and hashes.
|
|
|
|
/// * An empty map if no transactions were found for the given arguments.
|
2022-04-13 01:48:13 -07:00
|
|
|
///
|
2022-04-21 13:19:26 -07:00
|
|
|
/// Returned txids are in the order they appear in blocks,
|
|
|
|
/// which ensures that they are topologically sorted
|
2022-04-13 01:48:13 -07:00
|
|
|
/// (i.e. parent txids will appear before child txids).
|
2022-04-21 13:19:26 -07:00
|
|
|
TransactionIdsByAddresses {
|
|
|
|
/// The requested addresses.
|
|
|
|
addresses: HashSet<transparent::Address>,
|
2022-04-20 11:27:00 -07:00
|
|
|
|
2022-04-21 13:19:26 -07:00
|
|
|
/// The blocks to be queried for transactions.
|
|
|
|
height_range: RangeInclusive<block::Height>,
|
|
|
|
},
|
2022-04-24 20:00:52 -07:00
|
|
|
|
|
|
|
/// Looks up utxos for the provided addresses.
|
|
|
|
///
|
|
|
|
/// Returns a type with found utxos and transaction information.
|
|
|
|
UtxosByAddresses(HashSet<transparent::Address>),
|
2022-10-20 23:01:29 -07:00
|
|
|
|
2022-11-29 20:40:15 -08:00
|
|
|
/// Contextually validates anchors and nullifiers of a transaction on the best chain
|
|
|
|
///
|
|
|
|
/// Returns [`ReadResponse::ValidBestChainTipNullifiersAndAnchors`].
|
|
|
|
CheckBestChainTipNullifiersAndAnchors(UnminedTx),
|
|
|
|
|
2023-01-27 13:46:51 -08:00
|
|
|
/// Calculates the median-time-past for the *next* block on the best chain.
|
|
|
|
///
|
|
|
|
/// Returns [`ReadResponse::BestChainNextMedianTimePast`] when successful.
|
|
|
|
BestChainNextMedianTimePast,
|
|
|
|
|
2022-10-20 23:01:29 -07:00
|
|
|
/// Looks up a block hash by height in the current best chain.
|
|
|
|
///
|
|
|
|
/// Returns
|
|
|
|
///
|
|
|
|
/// * [`ReadResponse::BlockHash(Some(hash))`](ReadResponse::BlockHash) if the block is in the best chain;
|
|
|
|
/// * [`ReadResponse::BlockHash(None)`](ReadResponse::BlockHash) otherwise.
|
|
|
|
BestChainBlockHash(block::Height),
|
2022-11-28 01:06:32 -08:00
|
|
|
|
|
|
|
#[cfg(feature = "getblocktemplate-rpcs")]
|
|
|
|
/// Get state information from the best block chain.
|
|
|
|
///
|
|
|
|
/// Returns [`ReadResponse::ChainInfo(info)`](ReadResponse::ChainInfo) where `info` is a
|
|
|
|
/// [`zebra-state::GetBlockTemplateChainInfo`](zebra-state::GetBlockTemplateChainInfo)` structure containing
|
|
|
|
/// best chain state information.
|
|
|
|
ChainInfo,
|
2022-12-08 11:56:14 -08:00
|
|
|
|
|
|
|
#[cfg(feature = "getblocktemplate-rpcs")]
|
|
|
|
/// Get the average solution rate in the best chain.
|
|
|
|
///
|
|
|
|
/// Returns [`ReadResponse::SolutionRate`]
|
|
|
|
SolutionRate {
|
2023-10-10 19:02:51 -07:00
|
|
|
/// The number of blocks to calculate the average difficulty for.
|
2022-12-08 11:56:14 -08:00
|
|
|
num_blocks: usize,
|
2023-10-10 19:02:51 -07:00
|
|
|
/// Optionally estimate the network solution rate at the time when this height was mined.
|
|
|
|
/// Otherwise, estimate at the current tip height.
|
2022-12-08 11:56:14 -08:00
|
|
|
height: Option<block::Height>,
|
|
|
|
},
|
2023-01-11 15:39:51 -08:00
|
|
|
|
|
|
|
#[cfg(feature = "getblocktemplate-rpcs")]
|
|
|
|
/// Performs contextual validation of the given block, but does not commit it to the state.
|
|
|
|
///
|
|
|
|
/// It is the caller's responsibility to perform semantic validation.
|
|
|
|
/// (The caller does not need to check proof of work for block proposals.)
|
|
|
|
///
|
|
|
|
/// Returns [`ReadResponse::ValidBlockProposal`] when successful, or an error if
|
|
|
|
/// the block fails contextual validation.
|
2023-06-01 05:29:03 -07:00
|
|
|
CheckBlockProposalValidity(SemanticallyVerifiedBlock),
|
2022-03-17 15:59:46 -07:00
|
|
|
}
|
2022-09-13 17:35:37 -07:00
|
|
|
|
2022-09-16 12:03:56 -07:00
|
|
|
impl ReadRequest {
|
|
|
|
fn variant_name(&self) -> &'static str {
|
|
|
|
match self {
|
|
|
|
ReadRequest::Tip => "tip",
|
2024-08-16 12:54:44 -07:00
|
|
|
ReadRequest::TipPoolValues => "tip_pool_values",
|
2022-09-16 12:03:56 -07:00
|
|
|
ReadRequest::Depth(_) => "depth",
|
|
|
|
ReadRequest::Block(_) => "block",
|
2024-04-12 13:07:44 -07:00
|
|
|
ReadRequest::BlockHeader(_) => "block_header",
|
2022-09-16 12:03:56 -07:00
|
|
|
ReadRequest::Transaction(_) => "transaction",
|
2022-10-02 16:34:44 -07:00
|
|
|
ReadRequest::TransactionIdsForBlock(_) => "transaction_ids_for_block",
|
2022-11-10 22:40:35 -08:00
|
|
|
ReadRequest::UnspentBestChainUtxo { .. } => "unspent_best_chain_utxo",
|
2022-09-16 12:03:56 -07:00
|
|
|
ReadRequest::AnyChainUtxo { .. } => "any_chain_utxo",
|
|
|
|
ReadRequest::BlockLocator => "block_locator",
|
|
|
|
ReadRequest::FindBlockHashes { .. } => "find_block_hashes",
|
|
|
|
ReadRequest::FindBlockHeaders { .. } => "find_block_headers",
|
|
|
|
ReadRequest::SaplingTree { .. } => "sapling_tree",
|
|
|
|
ReadRequest::OrchardTree { .. } => "orchard_tree",
|
2023-09-03 15:18:41 -07:00
|
|
|
ReadRequest::SaplingSubtrees { .. } => "sapling_subtrees",
|
|
|
|
ReadRequest::OrchardSubtrees { .. } => "orchard_subtrees",
|
2022-09-16 12:03:56 -07:00
|
|
|
ReadRequest::AddressBalance { .. } => "address_balance",
|
|
|
|
ReadRequest::TransactionIdsByAddresses { .. } => "transaction_ids_by_addesses",
|
|
|
|
ReadRequest::UtxosByAddresses(_) => "utxos_by_addesses",
|
2022-11-29 20:40:15 -08:00
|
|
|
ReadRequest::CheckBestChainTipNullifiersAndAnchors(_) => {
|
|
|
|
"best_chain_tip_nullifiers_anchors"
|
|
|
|
}
|
2023-01-27 13:46:51 -08:00
|
|
|
ReadRequest::BestChainNextMedianTimePast => "best_chain_next_median_time_past",
|
2022-10-20 23:01:29 -07:00
|
|
|
ReadRequest::BestChainBlockHash(_) => "best_chain_block_hash",
|
2022-11-28 01:06:32 -08:00
|
|
|
#[cfg(feature = "getblocktemplate-rpcs")]
|
|
|
|
ReadRequest::ChainInfo => "chain_info",
|
2022-12-08 11:56:14 -08:00
|
|
|
#[cfg(feature = "getblocktemplate-rpcs")]
|
|
|
|
ReadRequest::SolutionRate { .. } => "solution_rate",
|
2023-01-11 15:39:51 -08:00
|
|
|
#[cfg(feature = "getblocktemplate-rpcs")]
|
|
|
|
ReadRequest::CheckBlockProposalValidity(_) => "check_block_proposal_validity",
|
2022-09-16 12:03:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Counts metric for ReadStateService call
|
|
|
|
pub fn count_metric(&self) {
|
|
|
|
metrics::counter!(
|
|
|
|
"state.requests",
|
|
|
|
"service" => "read_state",
|
|
|
|
"type" => self.variant_name()
|
2024-01-01 17:26:54 -08:00
|
|
|
)
|
|
|
|
.increment(1);
|
2022-09-16 12:03:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-13 17:35:37 -07:00
|
|
|
/// Conversion from read-write [`Request`]s to read-only [`ReadRequest`]s.
|
|
|
|
///
|
|
|
|
/// Used to dispatch read requests concurrently from the [`StateService`](crate::service::StateService).
|
|
|
|
impl TryFrom<Request> for ReadRequest {
|
|
|
|
type Error = &'static str;
|
|
|
|
|
|
|
|
fn try_from(request: Request) -> Result<ReadRequest, Self::Error> {
|
|
|
|
match request {
|
|
|
|
Request::Tip => Ok(ReadRequest::Tip),
|
|
|
|
Request::Depth(hash) => Ok(ReadRequest::Depth(hash)),
|
2023-01-27 13:46:51 -08:00
|
|
|
Request::BestChainNextMedianTimePast => Ok(ReadRequest::BestChainNextMedianTimePast),
|
2023-02-20 21:30:29 -08:00
|
|
|
Request::BestChainBlockHash(hash) => Ok(ReadRequest::BestChainBlockHash(hash)),
|
2022-09-13 17:35:37 -07:00
|
|
|
|
|
|
|
Request::Block(hash_or_height) => Ok(ReadRequest::Block(hash_or_height)),
|
2024-04-12 13:07:44 -07:00
|
|
|
Request::BlockHeader(hash_or_height) => Ok(ReadRequest::BlockHeader(hash_or_height)),
|
2022-09-13 17:35:37 -07:00
|
|
|
Request::Transaction(tx_hash) => Ok(ReadRequest::Transaction(tx_hash)),
|
2022-11-10 22:40:35 -08:00
|
|
|
Request::UnspentBestChainUtxo(outpoint) => {
|
|
|
|
Ok(ReadRequest::UnspentBestChainUtxo(outpoint))
|
|
|
|
}
|
2022-09-13 17:35:37 -07:00
|
|
|
|
|
|
|
Request::BlockLocator => Ok(ReadRequest::BlockLocator),
|
|
|
|
Request::FindBlockHashes { known_blocks, stop } => {
|
|
|
|
Ok(ReadRequest::FindBlockHashes { known_blocks, stop })
|
|
|
|
}
|
|
|
|
Request::FindBlockHeaders { known_blocks, stop } => {
|
|
|
|
Ok(ReadRequest::FindBlockHeaders { known_blocks, stop })
|
|
|
|
}
|
|
|
|
|
2022-11-29 20:40:15 -08:00
|
|
|
Request::CheckBestChainTipNullifiersAndAnchors(tx) => {
|
|
|
|
Ok(ReadRequest::CheckBestChainTipNullifiersAndAnchors(tx))
|
|
|
|
}
|
|
|
|
|
2023-06-01 05:29:03 -07:00
|
|
|
Request::CommitSemanticallyVerifiedBlock(_)
|
|
|
|
| Request::CommitCheckpointVerifiedBlock(_) => Err("ReadService does not write blocks"),
|
2022-09-15 21:13:26 -07:00
|
|
|
|
2023-02-20 21:30:29 -08:00
|
|
|
Request::AwaitUtxo(_) => Err("ReadService does not track pending UTXOs. \
|
|
|
|
Manually convert the request to ReadRequest::AnyChainUtxo, \
|
|
|
|
and handle pending UTXOs"),
|
|
|
|
|
2023-03-24 00:10:07 -07:00
|
|
|
Request::KnownBlock(_) => Err("ReadService does not track queued blocks"),
|
|
|
|
|
2023-01-11 15:39:51 -08:00
|
|
|
#[cfg(feature = "getblocktemplate-rpcs")]
|
2023-06-01 05:29:03 -07:00
|
|
|
Request::CheckBlockProposalValidity(semantically_verified) => Ok(
|
|
|
|
ReadRequest::CheckBlockProposalValidity(semantically_verified),
|
|
|
|
),
|
2022-09-13 17:35:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|