From 0989797fcf8ead140f08e374497b4e5fb08bde07 Mon Sep 17 00:00:00 2001 From: NganSM Date: Fri, 22 Mar 2024 14:07:28 +0700 Subject: [PATCH] consortium/v2: Change rules to choose best parent Current rule to choose best parent block does not take into consideration the justified block height of the canonical chain and new chain (if upcoming block has smaller height than that of canonical chain). This might lead to in-turn miner producing block that cannot be inserted into canonical chain because it does not satisfy all the conditions for a reorg. --- consensus/consortium/v2/consortium.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/consensus/consortium/v2/consortium.go b/consensus/consortium/v2/consortium.go index eb7588280b..e154229b64 100644 --- a/consensus/consortium/v2/consortium.go +++ b/consensus/consortium/v2/consortium.go @@ -1171,9 +1171,14 @@ func (c *Consortium) GetBestParentBlock(chain *core.BlockChain) (*types.Block, b // Miner can create an inturn block which helps the chain to have // greater diffculty if snap.supposeValidator() == signer { - if !snap.IsRecentlySigned(signer) { + oldJustifiedBlockNumber, _ := c.GetJustifiedBlock(chain, currentBlock.NumberU64(), currentBlock.Hash()) + newJustifiedBlockNumber, _ := c.GetJustifiedBlock(chain, prevBlock.NumberU64(), prevBlock.Hash()) + // TODO: the case in which oldJustifiedBlockNumber - 1 == newJustifiedBlockNumber and the upcoming + // block is justified is not considered here + if !snap.IsRecentlySigned(signer) && oldJustifiedBlockNumber <= newJustifiedBlockNumber { return prevBlock, true } + return currentBlock, false } block = prevBlock