1use std::{
13 collections::{BTreeMap, HashMap, HashSet},
14 ops::RangeBounds,
15 sync::Arc,
16};
17
18use chrono::{DateTime, Utc};
19use itertools::Itertools;
20
21use zebra_chain::{
22 amount::NonNegative,
23 block::{self, Block, Height},
24 orchard,
25 parallel::tree::NoteCommitmentTrees,
26 parameters::{Network, GENESIS_PREVIOUS_BLOCK_HASH},
27 primitives::byte_array::increment_big_endian,
28 sapling,
29 serialization::{CompactSizeMessage, TrustedPreallocate, ZcashSerialize as _},
30 transaction::{self, Transaction},
31 transparent,
32 value_balance::ValueBalance,
33};
34
35use crate::{
36 error::{BlockReadError, CommitCheckpointVerifiedError},
37 request::FinalizedBlock,
38 service::finalized_state::{
39 disk_db::{DiskDb, DiskWriteBatch, ReadDisk, WriteDisk},
40 disk_format::{
41 block::TransactionLocation,
42 transparent::{AddressBalanceLocationUpdates, OutputLocation},
43 },
44 zebra_db::{metrics::block_precommit_metrics, ZebraDb},
45 FromDisk, IntoDisk, RawBytes,
46 },
47 HashOrHeight,
48};
49
50#[cfg(feature = "indexer")]
51use crate::request::Spend;
52
53#[cfg(test)]
54mod tests;
55
56impl ZebraDb {
57 pub fn is_empty(&self) -> bool {
63 let hash_by_height = self.db.cf_handle("hash_by_height").unwrap();
64 self.db.zs_is_empty(&hash_by_height)
65 }
66
67 #[allow(clippy::unwrap_in_result)]
72 pub fn tip(&self) -> Option<(block::Height, block::Hash)> {
73 let hash_by_height = self.db.cf_handle("hash_by_height").unwrap();
74 self.db.zs_last_key_value(&hash_by_height)
75 }
76
77 #[allow(clippy::unwrap_in_result)]
79 pub fn contains_height(&self, height: block::Height) -> bool {
80 let hash_by_height = self.db.cf_handle("hash_by_height").unwrap();
81
82 self.db.zs_contains(&hash_by_height, &height)
83 }
84
85 #[allow(clippy::unwrap_in_result)]
87 pub fn hash(&self, height: block::Height) -> Option<block::Hash> {
88 let hash_by_height = self.db.cf_handle("hash_by_height").unwrap();
89 self.db.zs_get(&hash_by_height, &height)
90 }
91
92 #[allow(clippy::unwrap_in_result)]
94 pub fn contains_hash(&self, hash: block::Hash) -> bool {
95 let height_by_hash = self.db.cf_handle("height_by_hash").unwrap();
96
97 self.db.zs_contains(&height_by_hash, &hash)
98 }
99
100 #[allow(clippy::unwrap_in_result)]
102 pub fn height(&self, hash: block::Hash) -> Option<block::Height> {
103 let height_by_hash = self.db.cf_handle("height_by_hash").unwrap();
104 self.db.zs_get(&height_by_hash, &hash)
105 }
106
107 #[allow(dead_code)]
109 pub fn prev_block_hash_for_hash(&self, hash: block::Hash) -> Option<block::Hash> {
110 let height = self.height(hash)?;
111 let prev_height = height.previous().ok()?;
112
113 self.hash(prev_height)
114 }
115
116 #[allow(dead_code)]
118 pub fn prev_block_height_for_hash(&self, hash: block::Hash) -> Option<block::Height> {
119 let height = self.height(hash)?;
120
121 height.previous().ok()
122 }
123
124 #[allow(clippy::unwrap_in_result)]
129 pub fn block_header(&self, hash_or_height: HashOrHeight) -> Option<Arc<block::Header>> {
130 let block_header_by_height = self.db.cf_handle("block_header_by_height").unwrap();
132
133 let height = hash_or_height.height_or_else(|hash| self.height(hash))?;
134 let header = self.db.zs_get(&block_header_by_height, &height)?;
135
136 Some(header)
137 }
138
139 pub fn block(
143 &self,
144 hash_or_height: HashOrHeight,
145 ) -> Result<Option<Arc<Block>>, BlockReadError> {
146 Ok(self
147 .complete_block(hash_or_height, |header: &Arc<block::Header>| {
148 header.merkle_root
149 })?
150 .map(|(header, transactions)| {
151 Arc::new(Block {
152 header,
153 transactions,
154 })
155 }))
156 }
157
158 #[allow(clippy::unwrap_in_result)]
162 pub fn block_and_size(
163 &self,
164 hash_or_height: HashOrHeight,
165 ) -> Result<Option<(Arc<Block>, usize)>, BlockReadError> {
166 let Some((raw_header, raw_txs)) = self.raw_block(hash_or_height)? else {
167 return Ok(None);
168 };
169
170 let header = Arc::<block::Header>::from_bytes(raw_header.raw_bytes());
171 let txs: Vec<_> = raw_txs
172 .iter()
173 .map(|raw_tx| Arc::<Transaction>::from_bytes(raw_tx.raw_bytes()))
174 .collect();
175
176 let tx_count = CompactSizeMessage::try_from(txs.len())
181 .expect("must work for a previously serialized block");
182 let tx_raw = tx_count
183 .zcash_serialize_to_vec()
184 .expect("must work for a previously serialized block");
185 let size = raw_header.raw_bytes().len()
186 + raw_txs
187 .iter()
188 .map(|raw_tx| raw_tx.raw_bytes().len())
189 .sum::<usize>()
190 + tx_raw.len();
191
192 let block = Block {
193 header,
194 transactions: txs,
195 };
196 Ok(Some((Arc::new(block), size)))
197 }
198
199 fn raw_block(
201 &self,
202 hash_or_height: HashOrHeight,
203 ) -> Result<Option<(RawBytes, Vec<RawBytes>)>, BlockReadError> {
204 self.complete_block(hash_or_height, |header: &RawBytes| {
205 block::Header::from_bytes(header.raw_bytes()).merkle_root
206 })
207 }
208
209 #[allow(clippy::unwrap_in_result)]
216 fn complete_block<H: FromDisk, T: FromDisk>(
217 &self,
218 hash_or_height: HashOrHeight,
219 header_merkle_root: impl FnOnce(&H) -> block::merkle::Root,
220 ) -> Result<Option<(H, Vec<T>)>, BlockReadError> {
221 let Some(height) = hash_or_height.height_or_else(|hash| self.height(hash)) else {
222 return Ok(None);
223 };
224 let incomplete = |error| {
225 if self.db.is_read_only() {
228 Ok(None)
229 } else {
230 Err(error)
231 }
232 };
233 let headers = self.db.cf_handle("block_header_by_height").unwrap();
234 let header = match self.db.zs_get(&headers, &height) {
235 Some(header) => header,
236 None => {
237 #[cfg(test)]
238 tests::AFTER_MISSING_HEADER.with(|hook| {
239 if let Some(commit) = hook.borrow_mut().take() {
240 commit();
241 }
242 });
243 if !matches!(hash_or_height, HashOrHeight::Hash(_)) && !self.contains_height(height)
244 {
245 return Ok(None);
246 }
247 match self.db.zs_get(&headers, &height) {
249 Some(header) => header,
250 None => return incomplete(BlockReadError::CorruptBlock { height }),
251 }
252 }
253 };
254
255 let tx_by_loc = self.db.cf_handle("tx_by_loc").unwrap();
256 let hash_by_tx_loc = self.db.cf_handle("hash_by_tx_loc").unwrap();
257 let first = TransactionLocation::min_for_height(height).as_bytes();
258 let last = TransactionLocation::max_for_height(height).as_bytes();
259 let mut hashes = self
260 .db
261 .raw_iterator_cf_opt(&hash_by_tx_loc, Default::default());
262 hashes.seek_for_prev(last);
263 hashes.status().expect("unexpected database failure");
264 let Some(last_location) = hashes
265 .key()
266 .map(TransactionLocation::from_bytes)
267 .filter(|location| location.height == height)
268 else {
269 return incomplete(BlockReadError::CorruptBlock { height });
270 };
271 let expected_count = last_location.index.as_usize() + 1;
272
273 let mut upper_bound = Vec::with_capacity(last.len() + 1);
274 upper_bound.extend_from_slice(&last);
275 if increment_big_endian(&mut upper_bound) {
276 upper_bound.insert(0, 1);
277 }
278 let mut options = rocksdb::ReadOptions::default();
279 options.set_iterate_upper_bound(upper_bound);
280 let mut bodies = self.db.raw_iterator_cf_opt(&tx_by_loc, options);
281 bodies.seek(first);
282 let mut transactions = Vec::with_capacity(expected_count);
283 while let Some(key) = bodies.key().filter(|key| *key <= last.as_ref()) {
287 let location = TransactionLocation::from_bytes(key);
288 if location.index.as_usize() != transactions.len() {
289 return incomplete(BlockReadError::BlockBodyUnavailable { height });
290 }
291 if transactions.len() >= expected_count {
292 return incomplete(BlockReadError::CorruptBlock { height });
293 }
294 transactions.push(T::from_bytes(
295 bodies.value().expect("a valid iterator has a value"),
296 ));
297 bodies.next();
298 }
299 bodies.status().expect("unexpected database failure");
300 if transactions.len() != expected_count {
301 return incomplete(BlockReadError::BlockBodyUnavailable { height });
302 }
303
304 if self.db.is_read_only() {
305 hashes.seek(first);
308 hashes.status().expect("unexpected database failure");
309 if hashes.key() != Some(first.as_ref()) {
310 return Ok(None);
311 }
312 let mut remaining = expected_count;
313 let root: block::merkle::Root = std::iter::from_fn(|| {
314 if remaining == 0 {
315 return None;
316 }
317 let (key, value) = hashes.item()?;
318 if key > last.as_ref() {
319 return None;
320 }
321 let hash = transaction::Hash::from_bytes(value);
322 remaining -= 1;
323 if remaining > 0 {
324 hashes.next();
325 }
326 Some(hash)
327 })
328 .collect();
329 hashes.status().expect("unexpected database failure");
330 if remaining != 0 || root != header_merkle_root(&header) {
331 return Ok(None);
332 }
333 }
334
335 Ok(Some((header, transactions)))
336 }
337
338 #[allow(clippy::unwrap_in_result)]
341 pub fn sapling_tree_by_hash_or_height(
342 &self,
343 hash_or_height: HashOrHeight,
344 ) -> Option<Arc<sapling::tree::NoteCommitmentTree>> {
345 let height = hash_or_height.height_or_else(|hash| self.height(hash))?;
346
347 self.sapling_tree_by_height(&height)
348 }
349
350 #[allow(clippy::unwrap_in_result)]
353 pub fn orchard_tree_by_hash_or_height(
354 &self,
355 hash_or_height: HashOrHeight,
356 ) -> Option<Arc<orchard::tree::NoteCommitmentTree>> {
357 let height = hash_or_height.height_or_else(|hash| self.height(hash))?;
358
359 self.orchard_tree_by_height(&height)
360 }
361
362 #[allow(clippy::unwrap_in_result)]
365 pub fn ironwood_tree_by_hash_or_height(
366 &self,
367 hash_or_height: HashOrHeight,
368 ) -> Option<Arc<orchard::tree::NoteCommitmentTree>> {
369 let height = hash_or_height.height_or_else(|hash| self.height(hash))?;
370
371 self.ironwood_tree_by_height(&height)
372 }
373
374 pub fn finalized_tip_hash(&self) -> block::Hash {
378 self.tip()
379 .map(|(_, hash)| hash)
380 .unwrap_or(GENESIS_PREVIOUS_BLOCK_HASH)
382 }
383
384 pub fn finalized_tip_height(&self) -> Option<block::Height> {
386 self.tip().map(|(height, _)| height)
387 }
388
389 pub fn tip_block(&self) -> Result<Option<Arc<Block>>, BlockReadError> {
393 match self.tip() {
394 Some((height, _)) => self.block(height.into()),
395 None => Ok(None),
396 }
397 }
398
399 #[allow(clippy::unwrap_in_result)]
404 pub fn transaction(
405 &self,
406 hash: transaction::Hash,
407 ) -> Option<(Arc<Transaction>, Height, DateTime<Utc>)> {
408 let tx_by_loc = self.db.cf_handle("tx_by_loc").unwrap();
409
410 let transaction_location = self.transaction_location(hash)?;
411
412 let block_time = self
413 .block_header(transaction_location.height.into())
414 .map(|header| header.time);
415
416 self.db
417 .zs_get(&tx_by_loc, &transaction_location)
418 .and_then(|tx| block_time.map(|time| (tx, transaction_location.height, time)))
419 }
420
421 #[allow(clippy::unwrap_in_result)]
423 pub fn transactions_by_height(
424 &self,
425 height: Height,
426 ) -> impl Iterator<Item = (TransactionLocation, Transaction)> + '_ {
427 self.transactions_by_location_range(
428 TransactionLocation::min_for_height(height)
429 ..=TransactionLocation::max_for_height(height),
430 )
431 }
432
433 #[allow(clippy::unwrap_in_result)]
436 pub fn transactions_by_location_range<R>(
437 &self,
438 range: R,
439 ) -> impl Iterator<Item = (TransactionLocation, Transaction)> + '_
440 where
441 R: RangeBounds<TransactionLocation>,
442 {
443 let tx_by_loc = self.db.cf_handle("tx_by_loc").unwrap();
444 self.db.zs_forward_range_iter(tx_by_loc, range)
445 }
446
447 #[allow(clippy::unwrap_in_result)]
450 pub fn raw_transactions_by_location_range<R>(
451 &self,
452 range: R,
453 ) -> impl Iterator<Item = (TransactionLocation, RawBytes)> + '_
454 where
455 R: RangeBounds<TransactionLocation>,
456 {
457 let tx_by_loc = self.db.cf_handle("tx_by_loc").unwrap();
458 self.db.zs_forward_range_iter(tx_by_loc, range)
459 }
460
461 #[allow(clippy::unwrap_in_result)]
464 pub fn transaction_location(&self, hash: transaction::Hash) -> Option<TransactionLocation> {
465 let tx_loc_by_hash = self.db.cf_handle("tx_loc_by_hash").unwrap();
466 self.db.zs_get(&tx_loc_by_hash, &hash)
467 }
468
469 #[allow(clippy::unwrap_in_result)]
472 #[allow(dead_code)]
473 pub fn transaction_hash(&self, location: TransactionLocation) -> Option<transaction::Hash> {
474 let hash_by_tx_loc = self.db.cf_handle("hash_by_tx_loc").unwrap();
475 self.db.zs_get(&hash_by_tx_loc, &location)
476 }
477
478 #[cfg(feature = "indexer")]
481 pub fn spending_transaction_hash(&self, spend: &Spend) -> Option<transaction::Hash> {
482 let tx_loc = match spend {
483 Spend::OutPoint(outpoint) => self.spending_tx_loc(outpoint)?,
484 Spend::Sprout(nullifier) => self.sprout_revealing_tx_loc(nullifier)?,
485 Spend::Sapling(nullifier) => self.sapling_revealing_tx_loc(nullifier)?,
486 Spend::Orchard(nullifier) => self.orchard_revealing_tx_loc(nullifier)?,
487 Spend::Ironwood(nullifier) => self.ironwood_revealing_tx_loc(nullifier)?,
488 };
489
490 self.transaction_hash(tx_loc)
491 }
492
493 #[allow(clippy::unwrap_in_result)]
500 pub fn transaction_hashes_for_block(
501 &self,
502 hash_or_height: HashOrHeight,
503 ) -> Option<Arc<[transaction::Hash]>> {
504 let height = hash_or_height.height_or_else(|hash| self.height(hash))?;
506
507 let hash_by_tx_loc = self.db.cf_handle("hash_by_tx_loc").unwrap();
509
510 let mut transaction_hashes = Vec::new();
512
513 for tx_index in 0..=Transaction::max_allocation() {
514 let tx_loc = TransactionLocation::from_u64(height, tx_index);
515
516 if let Some(tx_hash) = self.db.zs_get(&hash_by_tx_loc, &tx_loc) {
517 transaction_hashes.push(tx_hash);
518 } else {
519 break;
520 }
521 }
522
523 Some(transaction_hashes.into())
524 }
525
526 #[allow(clippy::unwrap_in_result)]
541 pub(in super::super) fn write_block(
542 &mut self,
543 finalized: FinalizedBlock,
544 prev_note_commitment_trees: Option<NoteCommitmentTrees>,
545 network: &Network,
546 source: &str,
547 phase_timer: &mut Option<std::time::Instant>,
548 ) -> Result<block::Hash, CommitCheckpointVerifiedError> {
549 let tx_hash_indexes: HashMap<transaction::Hash, usize> = finalized
550 .transaction_hashes
551 .iter()
552 .enumerate()
553 .map(|(index, hash)| (*hash, index))
554 .collect();
555
556 let new_outputs_by_out_loc: BTreeMap<OutputLocation, transparent::Utxo> = finalized
562 .new_outputs
563 .iter()
564 .map(|(outpoint, ordered_utxo)| {
565 (
566 lookup_out_loc(finalized.height, outpoint, &tx_hash_indexes),
567 ordered_utxo.utxo.clone(),
568 )
569 })
570 .collect();
571
572 let spent_utxos: Vec<(transparent::OutPoint, OutputLocation, transparent::Utxo)> =
574 finalized
575 .block
576 .transactions
577 .iter()
578 .flat_map(|tx| tx.inputs().into_iter())
579 .flat_map(|input| input.outpoint())
580 .map(|outpoint| {
581 (
582 outpoint,
583 self.output_location(&outpoint).unwrap_or_else(|| {
586 lookup_out_loc(finalized.height, &outpoint, &tx_hash_indexes)
587 }),
588 self.utxo(&outpoint)
589 .map(|ordered_utxo| ordered_utxo.utxo)
590 .or_else(|| {
591 finalized
592 .new_outputs
593 .get(&outpoint)
594 .map(|ordered_utxo| ordered_utxo.utxo.clone())
595 })
596 .expect("already checked UTXO was in state or block"),
597 )
598 })
599 .collect();
600
601 let spent_utxos_by_outpoint: HashMap<transparent::OutPoint, transparent::Utxo> =
602 spent_utxos
603 .iter()
604 .map(|(outpoint, _output_loc, utxo)| (*outpoint, utxo.clone()))
605 .collect();
606
607 #[cfg(feature = "indexer")]
609 let out_loc_by_outpoint: HashMap<transparent::OutPoint, OutputLocation> = spent_utxos
610 .iter()
611 .map(|(outpoint, out_loc, _utxo)| (*outpoint, *out_loc))
612 .collect();
613 let spent_utxos_by_out_loc: BTreeMap<OutputLocation, transparent::Utxo> = spent_utxos
614 .into_iter()
615 .map(|(_outpoint, out_loc, utxo)| (out_loc, utxo))
616 .collect();
617 record_phase!(phase_timer, "checkpoint_spent_outputs");
618
619 let changed_addresses: HashSet<transparent::Address> = spent_utxos_by_out_loc
621 .values()
622 .chain(
623 finalized
624 .new_outputs
625 .values()
626 .map(|ordered_utxo| &ordered_utxo.utxo),
627 )
628 .filter_map(|utxo| utxo.output.address(network))
629 .unique()
630 .collect();
631
632 fn read_addr_locs<T, F: Fn(&transparent::Address) -> Option<T>>(
635 changed_addresses: HashSet<transparent::Address>,
636 f: F,
637 ) -> HashMap<transparent::Address, T> {
638 changed_addresses
639 .into_iter()
640 .filter_map(|address| Some((address, f(&address)?)))
641 .collect()
642 }
643
644 let address_balances: AddressBalanceLocationUpdates = if self.finished_format_upgrades() {
655 AddressBalanceLocationUpdates::Insert(read_addr_locs(changed_addresses, |addr| {
656 self.address_balance_location(addr)
657 }))
658 } else {
659 AddressBalanceLocationUpdates::Merge(read_addr_locs(changed_addresses, |addr| {
660 Some(self.address_balance_location(addr)?.into_new_change())
661 }))
662 };
663 record_phase!(phase_timer, "checkpoint_address_balances");
664
665 let mut batch = DiskWriteBatch::new();
666
667 batch.prepare_block_batch(
669 self,
670 network,
671 &finalized,
672 new_outputs_by_out_loc,
673 spent_utxos_by_outpoint,
674 spent_utxos_by_out_loc,
675 #[cfg(feature = "indexer")]
676 out_loc_by_outpoint,
677 address_balances,
678 self.finalized_value_pool(),
679 prev_note_commitment_trees,
680 )?;
681 record_phase!(phase_timer, "checkpoint_batch_build");
682
683 let batch_start = std::time::Instant::now();
685 if let Err(error) = self.db.write(batch) {
686 panic!("unexpected rocksdb error while writing block: {error}");
687 }
688 metrics::histogram!("zebra.state.rocksdb.batch_commit.duration_seconds")
689 .record(batch_start.elapsed().as_secs_f64());
690 record_phase!(phase_timer, "checkpoint_db_write");
691
692 tracing::trace!(?source, "committed block from");
693
694 Ok(finalized.hash)
695 }
696
697 pub fn write_batch(&self, batch: DiskWriteBatch) -> Result<(), rocksdb::Error> {
699 self.db.write(batch)
700 }
701}
702
703fn lookup_out_loc(
707 height: Height,
708 outpoint: &transparent::OutPoint,
709 tx_hash_indexes: &HashMap<transaction::Hash, usize>,
710) -> OutputLocation {
711 let tx_index = tx_hash_indexes
712 .get(&outpoint.hash)
713 .expect("already checked UTXO was in state or block");
714
715 let tx_loc = TransactionLocation::from_usize(height, *tx_index);
716
717 OutputLocation::from_outpoint(tx_loc, outpoint)
718}
719
720impl DiskWriteBatch {
721 #[allow(clippy::too_many_arguments)]
734 pub fn prepare_block_batch(
735 &mut self,
736 zebra_db: &ZebraDb,
737 network: &Network,
738 finalized: &FinalizedBlock,
739 new_outputs_by_out_loc: BTreeMap<OutputLocation, transparent::Utxo>,
740 spent_utxos_by_outpoint: HashMap<transparent::OutPoint, transparent::Utxo>,
741 spent_utxos_by_out_loc: BTreeMap<OutputLocation, transparent::Utxo>,
742 #[cfg(feature = "indexer")] out_loc_by_outpoint: HashMap<
743 transparent::OutPoint,
744 OutputLocation,
745 >,
746 address_balances: AddressBalanceLocationUpdates,
747 value_pool: ValueBalance<NonNegative>,
748 prev_note_commitment_trees: Option<NoteCommitmentTrees>,
749 ) -> Result<(), CommitCheckpointVerifiedError> {
750 let db = &zebra_db.db;
751
752 self.prepare_block_header_and_transaction_data_batch(db, finalized);
754
755 self.prepare_shielded_transaction_batch(zebra_db, finalized);
762 self.prepare_trees_batch(zebra_db, finalized, prev_note_commitment_trees);
763
764 if !finalized.height.is_min() {
774 self.prepare_transparent_transaction_batch(
776 zebra_db,
777 network,
778 finalized,
779 &new_outputs_by_out_loc,
780 &spent_utxos_by_outpoint,
781 &spent_utxos_by_out_loc,
782 #[cfg(feature = "indexer")]
783 &out_loc_by_outpoint,
784 address_balances,
785 );
786 }
787
788 self.prepare_chain_value_pools_batch(
790 zebra_db,
791 finalized,
792 spent_utxos_by_outpoint,
793 value_pool,
794 )?;
795
796 block_precommit_metrics(&finalized.block, finalized.hash, finalized.height);
798
799 Ok(())
800 }
801
802 #[allow(clippy::unwrap_in_result)]
805 pub fn prepare_block_header_and_transaction_data_batch(
806 &mut self,
807 db: &DiskDb,
808 finalized: &FinalizedBlock,
809 ) {
810 let block_header_by_height = db.cf_handle("block_header_by_height").unwrap();
812 let hash_by_height = db.cf_handle("hash_by_height").unwrap();
813 let height_by_hash = db.cf_handle("height_by_hash").unwrap();
814
815 let tx_by_loc = db.cf_handle("tx_by_loc").unwrap();
817 let hash_by_tx_loc = db.cf_handle("hash_by_tx_loc").unwrap();
818 let tx_loc_by_hash = db.cf_handle("tx_loc_by_hash").unwrap();
819
820 let FinalizedBlock {
821 block,
822 hash,
823 height,
824 transaction_hashes,
825 ..
826 } = finalized;
827
828 self.zs_insert(&block_header_by_height, height, &block.header);
830
831 self.zs_insert(&hash_by_height, height, hash);
833 self.zs_insert(&height_by_hash, hash, height);
834
835 for (transaction_index, (transaction, transaction_hash)) in block
836 .transactions
837 .iter()
838 .zip(transaction_hashes.iter())
839 .enumerate()
840 {
841 let transaction_location = TransactionLocation::from_usize(*height, transaction_index);
842
843 self.zs_insert(&tx_by_loc, transaction_location, transaction);
845
846 self.zs_insert(&hash_by_tx_loc, transaction_location, transaction_hash);
848 self.zs_insert(&tx_loc_by_hash, transaction_hash, transaction_location);
849 }
850 }
851}