Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yutianwu committed Sep 26, 2021
1 parent 4a84cfd commit 065e69e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 6 additions & 3 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,15 +886,18 @@ func (p *Parlia) Seal(chain consensus.ChainHeaderReader, block *types.Block, res
}

func (p *Parlia) shouldWaitForCurrentBlockProcess(chain consensus.ChainHeaderReader, header *types.Header, snap *Snapshot) bool {
if snap.inturn(p.val) {
return false
}

highestVerifiedHeader := chain.GetHighestVerifiedHeader()
if highestVerifiedHeader == nil || highestVerifiedHeader.Number == nil {
if highestVerifiedHeader == nil {
return false
}

if !snap.inturn(p.val) && header.Number.Cmp(highestVerifiedHeader.Number) == 0 {
if header.ParentHash == highestVerifiedHeader.ParentHash && header.Difficulty.Cmp(highestVerifiedHeader.Difficulty) < 0 {
return true
}

return false
}

Expand Down
10 changes: 9 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2001,7 +2001,15 @@ func (bc *BlockChain) updateHighestVerifiedHeader(header *types.Header) {
return
}
currentHeader := bc.highestVerifiedHeader.Load().(*types.Header)
if currentHeader == nil || currentHeader.Number == nil || currentHeader.Number.Cmp(header.Number) < 0 {
if currentHeader == nil {
bc.highestVerifiedHeader.Store(types.CopyHeader(header))
return
}

newTD := big.NewInt(0).Add(bc.GetTdByHash(header.ParentHash), header.Difficulty)
oldTD := big.NewInt(0).Add(bc.GetTdByHash(currentHeader.ParentHash), currentHeader.Difficulty)

if newTD.Cmp(oldTD) > 0 {
bc.highestVerifiedHeader.Store(types.CopyHeader(header))
return
}
Expand Down

0 comments on commit 065e69e

Please sign in to comment.