Skip to content

Commit

Permalink
Replace the Chain.history_tree field with a lookup method and remove …
Browse files Browse the repository at this point in the history
…redundant code
  • Loading branch information
teor2345 committed Feb 9, 2023
1 parent 50e6ef7 commit 09e5148
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 219 deletions.
8 changes: 3 additions & 5 deletions zebra-state/src/service/non_finalized_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::{

use zebra_chain::{
block::{self, Block},
history_tree::HistoryTree,
parameters::Network,
sprout, transparent,
};
Expand Down Expand Up @@ -156,7 +155,7 @@ impl NonFinalizedState {
let parent_hash = prepared.block.header.previous_block_hash;
let (height, hash) = (prepared.height, prepared.hash);

let parent_chain = self.parent_chain(parent_hash, finalized_state.history_tree())?;
let parent_chain = self.parent_chain(parent_hash)?;

// If the block is invalid, return the error,
// and drop the cloned parent Arc, or newly created chain fork.
Expand Down Expand Up @@ -281,7 +280,7 @@ impl NonFinalizedState {
// Clone function arguments for different threads
let block = contextual.block.clone();
let network = new_chain.network();
let history_tree = new_chain.history_tree.clone();
let history_tree = new_chain.history_tree_at_tip();

let block2 = contextual.block.clone();
let height = contextual.height;
Expand Down Expand Up @@ -470,7 +469,6 @@ impl NonFinalizedState {
fn parent_chain(
&mut self,
parent_hash: block::Hash,
history_tree: Arc<HistoryTree>,
) -> Result<Arc<Chain>, ValidateContextError> {
match self.find_chain(|chain| chain.non_finalized_tip_hash() == parent_hash) {
// Clone the existing Arc<Chain> in the non-finalized state
Expand All @@ -482,7 +480,7 @@ impl NonFinalizedState {
let fork_chain = self
.chain_set
.iter()
.find_map(|chain| chain.fork(parent_hash, history_tree.clone()).transpose())
.find_map(|chain| chain.fork(parent_hash).transpose())
.transpose()?
.ok_or(ValidateContextError::NotReadyToBeCommitted)?;

Expand Down
Loading

0 comments on commit 09e5148

Please sign in to comment.