Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Only calculate tree route during finalization when there are multiple…
Browse files Browse the repository at this point in the history
… leaves (#14067) (#14069)

* Only calculate tree route when there are multiple leaves

* Update client/service/src/client/client.rs



---------

Co-authored-by: Sebastian Kunert <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
  • Loading branch information
3 people authored May 3, 2023
1 parent 6d71741 commit bca8a29
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions client/service/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,19 +936,24 @@ where
return Err(sp_blockchain::Error::NotInFinalizedChain)
}

let route_from_best =
sp_blockchain::tree_route(self.backend.blockchain(), best_block, block)?;

// if the block is not a direct ancestor of the current best chain,
// then some other block is the common ancestor.
if route_from_best.common_block().hash != block {
// NOTE: we're setting the finalized block as best block, this might
// be slightly inaccurate since we might have a "better" block
// further along this chain, but since best chain selection logic is
// plugable we cannot make a better choice here. usages that need
// an accurate "best" block need to go through `SelectChain`
// instead.
operation.op.mark_head(block)?;
// If there is only one leaf, best block is guaranteed to be
// a descendant of the new finalized block. If not,
// we need to check.
if self.backend.blockchain().leaves()?.len() > 1 {
let route_from_best =
sp_blockchain::tree_route(self.backend.blockchain(), best_block, block)?;

// if the block is not a direct ancestor of the current best chain,
// then some other block is the common ancestor.
if route_from_best.common_block().hash != block {
// NOTE: we're setting the finalized block as best block, this might
// be slightly inaccurate since we might have a "better" block
// further along this chain, but since best chain selection logic is
// plugable we cannot make a better choice here. usages that need
// an accurate "best" block need to go through `SelectChain`
// instead.
operation.op.mark_head(block)?;
}
}

let enacted = route_from_finalized.enacted();
Expand Down

0 comments on commit bca8a29

Please sign in to comment.