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 b5967ee commit 49b4c9a
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 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,43 @@ 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(nu5_activation_height) = NetworkUpgrade::Nu5.activation_height(network) else {
return Amount::zero();
};

// TODO: Use NU6 directly once it's been added.
let Some(nu6_activation_height) = NetworkUpgrade::Nu5
.next_upgrade()
.and_then(|nu6| 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");

let num_blocks_with_lockbox_output =
height.min(funding_stream_height_range.end) - nu5_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 49b4c9a

Please sign in to comment.