Skip to content

Commit

Permalink
Add support for processing ZSA orchard_shielded_data in zebra_state
Browse files Browse the repository at this point in the history
  • Loading branch information
dmidem committed Oct 30, 2024
1 parent 6b22fba commit ab9a2b5
Showing 1 changed file with 43 additions and 16 deletions.
59 changes: 43 additions & 16 deletions zebra-state/src/service/non_finalized_state/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1492,21 +1492,23 @@ impl Chain {
.zip(transaction_hashes.iter().cloned())
.enumerate()
{
let (
inputs,
outputs,
joinsplit_data,
sapling_shielded_data_per_spend_anchor,
sapling_shielded_data_shared_anchor,
orchard_shielded_data,
) = match transaction.deref() {
let transaction_data = match transaction.deref() {
V4 {
inputs,
outputs,
joinsplit_data,
sapling_shielded_data,
..
} => (inputs, outputs, joinsplit_data, sapling_shielded_data, &None, &None),
} => (
inputs,
outputs,
joinsplit_data,
sapling_shielded_data,
&None,
&None,
#[cfg(feature ="tx-v6")]
&None
),
V5 {
inputs,
outputs,
Expand All @@ -1520,28 +1522,51 @@ impl Chain {
&None,
sapling_shielded_data,
orchard_shielded_data,
#[cfg(feature ="tx-v6")]
&None,
),
#[cfg(feature ="tx-v6")]
V6 {
inputs,
outputs,
sapling_shielded_data,
orchard_shielded_data: _,
orchard_shielded_data,
..
} => (
inputs,
outputs,
&None,
&None,
sapling_shielded_data,
// FIXME: support V6 shielded data?
&None, //orchard_shielded_data,
&None,
orchard_shielded_data,
),
V1 { .. } | V2 { .. } | V3 { .. } => unreachable!(
"older transaction versions only exist in finalized blocks, because of the mandatory canopy checkpoint",
),
};

#[cfg(not(feature = "tx-v6"))]
let (
inputs,
outputs,
joinsplit_data,
sapling_shielded_data_per_spend_anchor,
sapling_shielded_data_shared_anchor,
orchard_shielded_data_vanilla,
) = transaction_data;

#[cfg(feature = "tx-v6")]
let (
inputs,
outputs,
joinsplit_data,
sapling_shielded_data_per_spend_anchor,
sapling_shielded_data_shared_anchor,
orchard_shielded_data_vanilla,
orchard_shielded_data_zsa,
) = transaction_data;

// add key `transaction.hash` and value `(height, tx_index)` to `tx_loc_by_hash`
let transaction_location = TransactionLocation::from_usize(height, transaction_index);
let prior_pair = self
Expand All @@ -1561,7 +1586,9 @@ impl Chain {
self.update_chain_tip_with(joinsplit_data)?;
self.update_chain_tip_with(sapling_shielded_data_per_spend_anchor)?;
self.update_chain_tip_with(sapling_shielded_data_shared_anchor)?;
self.update_chain_tip_with(orchard_shielded_data)?;
self.update_chain_tip_with(orchard_shielded_data_vanilla)?;
#[cfg(feature = "tx-v6")]
self.update_chain_tip_with(orchard_shielded_data_zsa)?;
}

// update the chain value pool balances
Expand Down Expand Up @@ -2049,11 +2076,11 @@ where
}
}

impl UpdateWith<Option<orchard::ShieldedData<orchard::OrchardVanilla>>> for Chain {
impl<V: orchard::OrchardFlavorExt> UpdateWith<Option<orchard::ShieldedData<V>>> for Chain {
#[instrument(skip(self, orchard_shielded_data))]
fn update_chain_tip_with(
&mut self,
orchard_shielded_data: &Option<orchard::ShieldedData<orchard::OrchardVanilla>>,
orchard_shielded_data: &Option<orchard::ShieldedData<V>>,
) -> Result<(), ValidateContextError> {
if let Some(orchard_shielded_data) = orchard_shielded_data {
// We do note commitment tree updates in parallel rayon threads.
Expand All @@ -2074,7 +2101,7 @@ impl UpdateWith<Option<orchard::ShieldedData<orchard::OrchardVanilla>>> for Chai
#[instrument(skip(self, orchard_shielded_data))]
fn revert_chain_with(
&mut self,
orchard_shielded_data: &Option<orchard::ShieldedData<orchard::OrchardVanilla>>,
orchard_shielded_data: &Option<orchard::ShieldedData<V>>,
_position: RevertPosition,
) {
if let Some(orchard_shielded_data) = orchard_shielded_data {
Expand Down

0 comments on commit ab9a2b5

Please sign in to comment.