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

Commit bca8a29

Browse files
chevdorskunertbkchr
authored
Only calculate tree route during finalization when there are multiple leaves (#14067) (#14069)
* Only calculate tree route when there are multiple leaves * Update client/service/src/client/client.rs --------- Co-authored-by: Sebastian Kunert <skunert49@gmail.com> Co-authored-by: Bastian Köcher <git@kchr.de>
1 parent 6d71741 commit bca8a29

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

client/service/src/client/client.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -936,19 +936,24 @@ where
936936
return Err(sp_blockchain::Error::NotInFinalizedChain)
937937
}
938938

939-
let route_from_best =
940-
sp_blockchain::tree_route(self.backend.blockchain(), best_block, block)?;
941-
942-
// if the block is not a direct ancestor of the current best chain,
943-
// then some other block is the common ancestor.
944-
if route_from_best.common_block().hash != block {
945-
// NOTE: we're setting the finalized block as best block, this might
946-
// be slightly inaccurate since we might have a "better" block
947-
// further along this chain, but since best chain selection logic is
948-
// plugable we cannot make a better choice here. usages that need
949-
// an accurate "best" block need to go through `SelectChain`
950-
// instead.
951-
operation.op.mark_head(block)?;
939+
// If there is only one leaf, best block is guaranteed to be
940+
// a descendant of the new finalized block. If not,
941+
// we need to check.
942+
if self.backend.blockchain().leaves()?.len() > 1 {
943+
let route_from_best =
944+
sp_blockchain::tree_route(self.backend.blockchain(), best_block, block)?;
945+
946+
// if the block is not a direct ancestor of the current best chain,
947+
// then some other block is the common ancestor.
948+
if route_from_best.common_block().hash != block {
949+
// NOTE: we're setting the finalized block as best block, this might
950+
// be slightly inaccurate since we might have a "better" block
951+
// further along this chain, but since best chain selection logic is
952+
// plugable we cannot make a better choice here. usages that need
953+
// an accurate "best" block need to go through `SelectChain`
954+
// instead.
955+
operation.op.mark_head(block)?;
956+
}
952957
}
953958

954959
let enacted = route_from_finalized.enacted();

0 commit comments

Comments
 (0)