Adds `issued_assets` fields on `ChainInner` and `ContextuallyValidatedBlock`

This commit is contained in:
Arya 2024-11-12 02:07:43 -05:00
parent c7116f33b1
commit bb62c67ba0
5 changed files with 28 additions and 8 deletions

View File

@ -103,8 +103,12 @@ impl ContextuallyVerifiedBlock {
.map(|outpoint| (outpoint, zero_utxo.clone()))
.collect();
ContextuallyVerifiedBlock::with_block_and_spent_utxos(block, zero_spent_utxos)
.expect("all UTXOs are provided with zero values")
ContextuallyVerifiedBlock::with_block_and_spent_utxos(
block,
zero_spent_utxos,
Default::default(),
)
.expect("all UTXOs are provided with zero values")
}
/// Create a [`ContextuallyVerifiedBlock`] from a [`Block`] or [`SemanticallyVerifiedBlock`],
@ -133,6 +137,7 @@ impl ContextuallyVerifiedBlock {
spent_outputs: new_outputs,
transaction_hashes,
chain_value_pool_change: ValueBalance::zero(),
issued_assets: Default::default(),
}
}
}

View File

@ -227,6 +227,10 @@ pub struct ContextuallyVerifiedBlock {
/// The sum of the chain value pool changes of all transactions in this block.
pub(crate) chain_value_pool_change: ValueBalance<NegativeAllowed>,
/// A partial map of `issued_assets` with entries for asset states that were updated in
/// this block.
pub(crate) issued_assets: IssuedAssets,
}
/// Wraps note commitment trees and the history tree together.
@ -431,6 +435,7 @@ impl ContextuallyVerifiedBlock {
pub fn with_block_and_spent_utxos(
semantically_verified: SemanticallyVerifiedBlock,
mut spent_outputs: HashMap<transparent::OutPoint, transparent::OrderedUtxo>,
issued_assets: IssuedAssets,
) -> Result<Self, ValueBalanceError> {
let SemanticallyVerifiedBlock {
block,
@ -459,6 +464,7 @@ impl ContextuallyVerifiedBlock {
&utxos_from_ordered_utxos(spent_outputs),
deferred_balance,
)?,
issued_assets,
})
}
}

View File

@ -325,7 +325,7 @@ impl NonFinalizedState {
finalized_state,
)?;
let _issued_assets =
let issued_assets =
check::issuance::valid_burns_and_issuance(finalized_state, &new_chain, &prepared)?;
// Reads from disk
@ -346,6 +346,8 @@ impl NonFinalizedState {
let contextual = ContextuallyVerifiedBlock::with_block_and_spent_utxos(
prepared.clone(),
spent_utxos.clone(),
// TODO: Refactor this into repeated `With::with()` calls, see http_request_compatibility module.
issued_assets,
)
.map_err(|value_balance_error| {
ValidateContextError::CalculateBlockChainValueChange {

View File

@ -177,6 +177,11 @@ pub struct ChainInner {
pub(crate) orchard_subtrees:
BTreeMap<NoteCommitmentSubtreeIndex, NoteCommitmentSubtreeData<orchard::tree::Node>>,
/// A partial map of `issued_assets` with entries for asset states that were updated in
/// this chain.
// TODO: Add reference to ZIP
pub(crate) issued_assets: HashMap<AssetBase, AssetState>,
// Nullifiers
//
/// The Sprout nullifiers revealed by `blocks`.
@ -240,6 +245,7 @@ impl Chain {
orchard_anchors_by_height: Default::default(),
orchard_trees_by_height: Default::default(),
orchard_subtrees: Default::default(),
issued_assets: Default::default(),
sprout_nullifiers: Default::default(),
sapling_nullifiers: Default::default(),
orchard_nullifiers: Default::default(),
@ -942,9 +948,8 @@ impl Chain {
/// Returns the Orchard issued asset state if one is present in
/// the chain for the provided asset base.
pub fn issued_asset(&self, _asset_base: &AssetBase) -> Option<AssetState> {
// self.orchard_issued_assets.get(asset_base).cloned()
None
pub fn issued_asset(&self, asset_base: &AssetBase) -> Option<AssetState> {
self.issued_assets.get(asset_base).cloned()
}
/// Adds the Orchard `tree` to the tree and anchor indexes at `height`.

View File

@ -52,6 +52,7 @@ fn push_genesis_chain() -> Result<()> {
ContextuallyVerifiedBlock::with_block_and_spent_utxos(
block,
only_chain.unspent_utxos(),
Default::default(),
)
.map_err(|e| (e, chain_values.clone()))
.expect("invalid block value pool change");
@ -148,6 +149,7 @@ fn forked_equals_pushed_genesis() -> Result<()> {
let block = ContextuallyVerifiedBlock::with_block_and_spent_utxos(
block,
partial_chain.unspent_utxos(),
Default::default()
)?;
partial_chain = partial_chain
.push(block)
@ -167,7 +169,7 @@ fn forked_equals_pushed_genesis() -> Result<()> {
for block in chain.iter().cloned() {
let block =
ContextuallyVerifiedBlock::with_block_and_spent_utxos(block, full_chain.unspent_utxos())?;
ContextuallyVerifiedBlock::with_block_and_spent_utxos(block, full_chain.unspent_utxos(), Default::default())?;
// Check some properties of the genesis block and don't push it to the chain.
if block.height == block::Height(0) {
@ -210,7 +212,7 @@ fn forked_equals_pushed_genesis() -> Result<()> {
// same original full chain.
for block in chain.iter().skip(fork_at_count).cloned() {
let block =
ContextuallyVerifiedBlock::with_block_and_spent_utxos(block, forked.unspent_utxos())?;
ContextuallyVerifiedBlock::with_block_and_spent_utxos(block, forked.unspent_utxos(), Default::default())?;
forked = forked.push(block).expect("forked chain push is valid");
}