Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change: Track the balance of the deferred chain value pool #8729

Merged
merged 64 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
bf1278a
Addresses clippy lints
arya2 Jul 25, 2024
aa88979
checks network magic and returns early from `is_regtest()`
arya2 Jul 22, 2024
d9a53e6
Moves `subsidy.rs` to `zebra-chain`, refactors funding streams into …
arya2 Jul 23, 2024
124e249
Replaces Vec with HashMap, adds `ConfiguredFundingStreams` type and c…
arya2 Jul 24, 2024
cbf7ef3
Empties recipients list
arya2 Jul 24, 2024
54af589
Adds a comment on num_addresses calculation being invalid for configu…
arya2 Jul 24, 2024
db434c3
Documentation fixes, minor cleanup, renames a test, adds TODOs, and f…
arya2 Jul 24, 2024
7d7f606
Removes unnecessary `ParameterSubsidy` impl for &Network, adds docs a…
arya2 Jul 24, 2024
77a6f2c
Adds a "deferred" FundingStreamReceiver, adds a post-NU6 funding stre…
arya2 Jul 24, 2024
dbc7ca9
adds `lockbox_input_value()` fn
arya2 Jul 24, 2024
0f962c5
Adds TODOs for linking to relevant ZIPs and updating height ranges
arya2 Jul 24, 2024
9bca31f
Adds `nu6_lockbox_funding_stream` acceptance test
arya2 Jul 24, 2024
0d22b68
updates funding stream values test to check post-NU6 funding streams …
arya2 Jul 24, 2024
039c9a1
Reverts Mainnet/Testnet NU6 activation height definitions, updates `t…
arya2 Jul 24, 2024
2f14517
reverts unnecessary refactor
arya2 Jul 24, 2024
33a5545
appease clippy
arya2 Jul 24, 2024
1183d49
Adds a test for `lockbox_input_value()`
arya2 Jul 24, 2024
b523bf5
Applies suggestions from code review
arya2 Jul 25, 2024
7df2e28
Fixes potential panic
arya2 Jul 26, 2024
95378fd
Merge branch 'main' into deferred-pool
arya2 Jul 29, 2024
7173af7
Fixes bad merge
arya2 Jul 29, 2024
c6244e6
Update zebra-chain/src/parameters/network_upgrade.rs
arya2 Jul 29, 2024
166bc23
Updates acceptance test to check that invalid blocks are rejected
arya2 Jul 29, 2024
c113601
Checks that the original valid block template at height 2 is accepted…
arya2 Jul 29, 2024
4627c08
Reverts changes for coinbase should balance exactly ZIP
arya2 Jul 29, 2024
4d74245
Add `Deferred` to `ValueBalance`
upbqdn Jul 23, 2024
19f63b2
Update snapshots
upbqdn Jul 24, 2024
c54ef0c
Unrelated: Revise docs
upbqdn Jul 24, 2024
3a3f2ed
Add TODOs
upbqdn Jul 25, 2024
8f83b14
Stop recalculating the block subsidy
upbqdn Jul 28, 2024
5c470ef
Track deferred balances
upbqdn Jul 29, 2024
27177f2
Support heights below slow start shift in halvings
upbqdn Jul 29, 2024
99b761e
Fix `CheckpointVerifiedBlock` conversion in tests
upbqdn Jul 29, 2024
fbbd8d1
Allow deserialization of legacy `ValueBalance`s
upbqdn Jul 29, 2024
6aa2858
Merge branch 'main' into deferred-pool
mpguerra Jul 30, 2024
cbafe35
Simplify docs
upbqdn Jul 30, 2024
8074a13
Merge branch 'deferred-pool' into update-value-balance
upbqdn Jul 30, 2024
a0fd18a
Fix warnings raised by Clippy
upbqdn Jul 30, 2024
9c0c7ff
Fix warnings raised by `cargo fmt`
upbqdn Jul 30, 2024
0bdda3a
Update zebra-chain/src/block.rs
upbqdn Jul 30, 2024
a1b3ca6
Refactor docs around chain value pool changes
upbqdn Jul 31, 2024
c5e7dbe
Merge branch 'update-value-balance' of github.com:ZcashFoundation/zeb…
upbqdn Jul 31, 2024
b82f2be
Merge branch 'main' into deferred-pool
arya2 Jul 31, 2024
126fdab
updates test name
arya2 Aug 1, 2024
bf49432
Updates deferred pool funding stream name to "Lockbox", moves post-NU…
arya2 Aug 1, 2024
14fbfb4
Updates `get_block_subsidy()` RPC method to exclude lockbox funding s…
arya2 Aug 1, 2024
7987c76
Adds a TODO for updating `FundingStreamReceiver::name()` method docs
arya2 Aug 1, 2024
e5eaf38
Updates `FundingStreamRecipient::new()` to accept an iterator of item…
arya2 Aug 1, 2024
a813af8
Update zebra-consensus/src/checkpoint.rs
upbqdn Aug 1, 2024
16eeee4
Update docs for value balances
upbqdn Aug 1, 2024
f826113
Cleanup: Simplify getting info for FS receivers
upbqdn Aug 1, 2024
d7f3df9
Avoid a panic when deserializing value balances
upbqdn Aug 1, 2024
bcdb7f3
Merge branch 'deferred-pool' into update-value-balance
upbqdn Aug 1, 2024
8949301
Uses FPF Testnet address for post-NU6 testnet funding streams
arya2 Aug 1, 2024
cdb1684
Updates the NU6 consensus branch id
arya2 Aug 1, 2024
40da48d
Update zebra-consensus/src/checkpoint.rs
arya2 Aug 1, 2024
93160c5
Merge branch 'deferred-pool' into update-value-balance
upbqdn Aug 1, 2024
9620344
Merge branch 'update-value-balance' of github.com:ZcashFoundation/zeb…
upbqdn Aug 1, 2024
9cb40e4
Bump the major database format version
upbqdn Aug 1, 2024
b37f6b4
Add a database upgrade mark
upbqdn Aug 3, 2024
c378a25
Merge branch 'main' into update-value-balance
upbqdn Aug 3, 2024
ba5ecec
Fix tests after merge
upbqdn Aug 3, 2024
fd41ebe
Merge branch 'main' into update-value-balance
upbqdn Aug 3, 2024
64279cb
trigger GitHub actions
upbqdn Aug 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions zebra-chain/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{collections::HashMap, fmt, ops::Neg, sync::Arc};
use halo2::pasta::pallas;

use crate::{
amount::NegativeAllowed,
amount::{Amount, NegativeAllowed, NonNegative},
block::merkle::AuthDataRoot,
fmt::DisplayToDebug,
orchard,
Expand Down Expand Up @@ -205,34 +205,39 @@ impl Block {
.expect("number of transactions must fit u64")
}

/// Get the overall chain value pool change in this block,
/// the negative sum of the transaction value balances in this block.
/// Returns the overall chain value pool change in this block---the negative sum of the
/// transaction value balances in this block.
///
/// These are the changes in the transparent, sprout, sapling, and orchard
/// chain value pools, as a result of this block.
/// These are the changes in the transparent, Sprout, Sapling, Orchard, and
/// Deferred chain value pools, as a result of this block.
///
/// Positive values are added to the corresponding chain value pool.
/// Negative values are removed from the corresponding pool.
/// Positive values are added to the corresponding chain value pool and negative values are
/// removed from the corresponding pool.
///
/// <https://zebra.zfnd.org/dev/rfcs/0012-value-pools.html#definitions>
///
/// `utxos` must contain the [`transparent::Utxo`]s of every input in this block,
/// including UTXOs created by earlier transactions in this block.
/// (It can also contain unrelated UTXOs, which are ignored.)
/// The given `utxos` must contain the [`transparent::Utxo`]s of every input in this block,
/// including UTXOs created by earlier transactions in this block. It can also contain unrelated
/// UTXOs, which are ignored.
///
/// Note: the chain value pool has the opposite sign to the transaction
/// value pool.
/// Note that the chain value pool has the opposite sign to the transaction value pool.
pub fn chain_value_pool_change(
&self,
utxos: &HashMap<transparent::OutPoint, transparent::Utxo>,
deferred_balance: Option<Amount<NonNegative>>,
) -> Result<ValueBalance<NegativeAllowed>, ValueBalanceError> {
let transaction_value_balance_total = self
Ok(*self
.transactions
.iter()
.flat_map(|t| t.value_balance(utxos))
.sum::<Result<ValueBalance<NegativeAllowed>, _>>()?;

Ok(transaction_value_balance_total.neg())
.sum::<Result<ValueBalance<NegativeAllowed>, _>>()?
.neg()
.set_deferred_amount(
deferred_balance
.unwrap_or(Amount::zero())
.constrain::<NegativeAllowed>()
.map_err(ValueBalanceError::Deferred)?,
))
}

/// Compute the root of the authorizing data Merkle tree,
Expand Down
23 changes: 14 additions & 9 deletions zebra-chain/src/parameters/network/subsidy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,24 @@ pub enum FundingStreamReceiver {
}

impl FundingStreamReceiver {
/// The name for each funding stream receiver, as described in [ZIP-1014] and [`zcashd`].
/// Returns a human-readable name and a specification URL for the receiver, as described in
/// [ZIP-1014] and [`zcashd`].
///
/// [ZIP-1014]: https://zips.z.cash/zip-1014#abstract
/// [`zcashd`]: https://github.com/zcash/zcash/blob/3f09cfa00a3c90336580a127e0096d99e25a38d6/src/consensus/funding.cpp#L13-L32
// TODO: Update method documentation with a reference to https://zips.z.cash/draft-nuttycom-funding-allocation once its
// status is updated to 'Proposed'.
pub fn name(self) -> &'static str {
match self {
FundingStreamReceiver::Ecc => "Electric Coin Company",
FundingStreamReceiver::ZcashFoundation => "Zcash Foundation",
FundingStreamReceiver::MajorGrants => "Major Grants",
// TODO: Find out what this should be called and update the funding stream name.
FundingStreamReceiver::Deferred => "Lockbox",
}
pub fn info(&self) -> (&'static str, &'static str) {
(
match self {
FundingStreamReceiver::Ecc => "Electric Coin Company",
FundingStreamReceiver::ZcashFoundation => "Zcash Foundation",
FundingStreamReceiver::MajorGrants => "Major Grants",
// TODO: Find out what this should be called and update the funding stream name
FundingStreamReceiver::Deferred => "Lockbox",
},
FUNDING_STREAM_SPECIFICATION,
)
}
}

Expand All @@ -90,6 +94,7 @@ impl FundingStreamReceiver {
/// [7.10.1]: https://zips.z.cash/protocol/protocol.pdf#zip214fundingstreams
pub const FUNDING_STREAM_RECEIVER_DENOMINATOR: u64 = 100;

// TODO: Update the link for post-NU6 funding streams.
/// The specification for all current funding stream receivers, a URL that links to [ZIP-214].
///
/// [ZIP-214]: https://zips.z.cash/zip-0214
Expand Down
32 changes: 15 additions & 17 deletions zebra-chain/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1390,10 +1390,7 @@ impl Transaction {
.map(|shielded_data| &mut shielded_data.value_balance)
}

/// Get the value balances for this transaction,
/// using the transparent outputs spent in this transaction.
///
/// See `value_balance` for details.
/// Returns the value balances for this transaction using the provided transparent outputs.
pub(crate) fn value_balance_from_outputs(
&self,
outputs: &HashMap<transparent::OutPoint, transparent::Output>,
Expand All @@ -1404,25 +1401,26 @@ impl Transaction {
+ self.orchard_value_balance()
}

/// Get the value balances for this transaction.
/// These are the changes in the transaction value pool,
/// split up into transparent, sprout, sapling, and orchard values.
/// Returns the value balances for this transaction.
///
/// Calculated as the sum of the inputs and outputs from each pool,
/// or the sum of the value balances from each pool.
/// These are the changes in the transaction value pool, split up into transparent, Sprout,
/// Sapling, and Orchard values.
///
/// Positive values are added to this transaction's value pool,
/// and removed from the corresponding chain value pool.
/// Negative values are removed from this transaction,
/// and added to the corresponding pool.
/// Calculated as the sum of the inputs and outputs from each pool, or the sum of the value
/// balances from each pool.
///
/// Positive values are added to this transaction's value pool, and removed from the
/// corresponding chain value pool. Negative values are removed from this transaction, and added
/// to the corresponding pool.
///
/// <https://zebra.zfnd.org/dev/rfcs/0012-value-pools.html#definitions>
///
/// `utxos` must contain the utxos of every input in the transaction,
/// including UTXOs created by earlier transactions in this block.
/// `utxos` must contain the utxos of every input in the transaction, including UTXOs created by
/// earlier transactions in this block.
///
/// ## Note
///
/// Note: the chain value pool has the opposite sign to the transaction
/// value pool.
/// The chain value pool has the opposite sign to the transaction value pool.
pub fn value_balance(
&self,
utxos: &HashMap<transparent::OutPoint, transparent::Utxo>,
Expand Down
Loading
Loading