From 16168d762313a9d4c2af4c30cfc3e172c3291145 Mon Sep 17 00:00:00 2001 From: Marek Date: Sun, 4 Aug 2024 00:29:09 +0200 Subject: [PATCH] Store Sprout trees with cached roots (#8741) Zebra's database expects all stored trees to have their roots cached in them. --- .../src/service/finalized_state/zebra_db/arbitrary.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/zebra-state/src/service/finalized_state/zebra_db/arbitrary.rs b/zebra-state/src/service/finalized_state/zebra_db/arbitrary.rs index 8a83a2894c5..bbe0e026d8c 100644 --- a/zebra-state/src/service/finalized_state/zebra_db/arbitrary.rs +++ b/zebra-state/src/service/finalized_state/zebra_db/arbitrary.rs @@ -49,14 +49,15 @@ impl ZebraDb { let sapling_anchors = self.db().cf_handle("sapling_anchors").unwrap(); let orchard_anchors = self.db().cf_handle("orchard_anchors").unwrap(); + let sprout_tree = sprout::tree::NoteCommitmentTree::default(); + // Calculate the root so we pass the tree with a cached root to the database. We need to do + // that because the database checks if the tree has a cached root. + sprout_tree.root(); + for transaction in block.transactions.iter() { // Sprout for joinsplit in transaction.sprout_groth16_joinsplits() { - batch.zs_insert( - &sprout_anchors, - joinsplit.anchor, - sprout::tree::NoteCommitmentTree::default(), - ); + batch.zs_insert(&sprout_anchors, joinsplit.anchor, sprout_tree.clone()); } // Sapling