Skip to content

Commit

Permalink
Adds an unused lockbox_input_value() fn for checking the expected i…
Browse files Browse the repository at this point in the history
…nput value by a certain block height.
  • Loading branch information
arya2 committed Jul 17, 2024
1 parent 014ff8c commit 78b45de
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion zebra-consensus/src/block/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ pub fn miner_fees_are_valid(
.map_err(|_| SubsidyError::SumOverflow)?;

let should_allow_unclaimed_subsidy =
NetworkUpgrade::current(network, height) <= NetworkUpgrade::Nu5;
NetworkUpgrade::current(network, height) < NetworkUpgrade::Nu6;

if if should_allow_unclaimed_subsidy {
left > right
Expand Down
2 changes: 1 addition & 1 deletion zebra-consensus/src/block/subsidy/funding_streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn funding_stream_values(
let range = FUNDING_STREAM_HEIGHT_RANGES.get(&network.kind()).unwrap();
if range.contains(&height) {
let block_subsidy = block_subsidy(height, network)?;
let funding_stream_numerators = if current_network_upgrade <= Nu5 {
let funding_stream_numerators = if current_network_upgrade < Nu6 {
PRE_NU6_FUNDING_STREAM_RECEIVER_NUMERATORS.iter()
} else {
POST_NU6_FUNDING_STREAM_RECEIVER_NUMERATORS.iter()
Expand Down
39 changes: 38 additions & 1 deletion zebra-consensus/src/block/subsidy/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use std::collections::HashSet;
use zebra_chain::{
amount::{Amount, Error, NonNegative},
block::{Height, HeightDiff},
parameters::{Network, NetworkUpgrade::*},
parameters::{
Network,
NetworkUpgrade::{self, *},
},
transaction::Transaction,
};

Expand Down Expand Up @@ -108,6 +111,40 @@ pub fn miner_subsidy(height: Height, network: &Network) -> Result<Amount<NonNega
block_subsidy(height, network)? - total_funding_stream_amount?
}

/// Lockbox funding stream total input value for a block height.
///
/// Assumes a constant funding stream amount per block.
// TODO: Cache the lockbox value balance in zebra-state (will be required for tracking lockbox
// value balance after ZSF ZIPs or after a ZIP for spending from the deferred pool)
#[allow(dead_code)]
fn lockbox_input_value(network: &Network, height: Height) -> Amount<NonNegative> {
let Some(nu6_activation_height) = NetworkUpgrade::Nu6.activation_height(network) else {
return Amount::zero();
};

let &deferred_amount_per_block = funding_stream_values(nu6_activation_height, network)
.expect("we always expect a funding stream hashmap response even if empty")
.get(&FundingStreamReceiver::Deferred)
.expect("we expect a lockbox funding stream after NU5");

let funding_stream_height_range = FUNDING_STREAM_HEIGHT_RANGES
.get(&network.kind())
.expect("must have funding stream height range on all networks");

// `min(height, last_height_with_deferred_pool_contribution) - (nu6_activation_height - 1)`,
// funding stream height range end bound is not incremented since it's an exclusive end bound
let num_blocks_with_lockbox_output = height
.next()
.expect("should be a valid height")
.min(funding_stream_height_range.end)
- nu6_activation_height;

(deferred_amount_per_block
* u64::try_from(num_blocks_with_lockbox_output)
.expect("num blocks with lockbox funding stream should fit in u64"))
.expect("lockbox input value should fit in Amount")
}

/// Returns all output amounts in `Transaction`.
pub fn output_amounts(transaction: &Transaction) -> HashSet<Amount<NonNegative>> {
transaction
Expand Down

0 comments on commit 78b45de

Please sign in to comment.