diff --git a/chain/src/chain.rs b/chain/src/chain.rs index 59e2efcb5..52c7bb8d9 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -358,11 +358,15 @@ impl Chain { /// Sets the sumtree roots on a brand new block by applying the block on the /// current sumtree state. - pub fn set_sumtree_roots(&self, b: &mut Block) -> Result<(), Error> { + pub fn set_sumtree_roots(&self, b: &mut Block, is_fork: bool) -> Result<(), Error> { let mut sumtrees = self.sumtrees.write().unwrap(); + let store = self.store.clone(); let roots = sumtree::extending(&mut sumtrees, |extension| { // apply the block on the sumtrees and check the resulting root + if is_fork { + pipe::rewind_and_apply_fork(b, store, extension)?; + } extension.apply_block(b)?; extension.force_rollback(); Ok(extension.roots()) @@ -374,7 +378,7 @@ impl Chain { Ok(()) } - /// returs sumtree roots + /// Returns current sumtree roots pub fn get_sumtree_roots( &self, ) -> ( diff --git a/chain/src/pipe.rs b/chain/src/pipe.rs index 0ba3e9771..1c6804b1b 100644 --- a/chain/src/pipe.rs +++ b/chain/src/pipe.rs @@ -393,11 +393,11 @@ fn update_header_head(bh: &BlockHeader, ctx: &mut BlockContext) -> Result