Skip to content

Commit

Permalink
fix(dpos): fixed an issue of CheckBlockContext
Browse files Browse the repository at this point in the history
  • Loading branch information
RainFallsSilent committed Jan 1, 2025
1 parent 64ed9d5 commit 6d62f4b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion blockchain/blockvalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,20 @@ func (b *BlockChain) CheckBlockContext(block *Block, prevNode *BlockNode) error
if block.Height >= b.chainParams.DPoSConfiguration.RecordSponsorStartHeight {
lastBlock, err := b.GetDposBlockByHash(*prevNode.Hash)
if err != nil {
return errors.New("get last block failed")
// try get block from cache
lastBlockInCache, ok := b.blockCache[*prevNode.Hash]
if !ok {
return errors.New("get last block failed")
}
lastConfirmInCache, ok := b.confirmCache[*prevNode.Hash]
if !ok {
return errors.New("get last block confirm failed")
}
lastBlock = &DposBlock{
Block: lastBlockInCache,
HaveConfirm: lastConfirmInCache != nil,
Confirm: lastConfirmInCache,
}
}

if lastBlock.Confirm == nil && recordSponsorExist {
Expand Down

0 comments on commit 6d62f4b

Please sign in to comment.