Skip to content

Commit

Permalink
bugfix: If parentofParent is nil, return the parent.Difficulty
Browse files Browse the repository at this point in the history
This was observed during the hardfork recovery process, this ideally should never happen but we cannot crash the node if it did
  • Loading branch information
gameofpointers committed Oct 25, 2023
1 parent d8c64cf commit d6304db
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion consensus/blake3pow/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func (blake3pow *Blake3pow) CalcDifficulty(chain consensus.ChainHeaderReader, pa
}

parentOfParent := chain.GetHeaderByHash(parent.ParentHash())
if parentOfParent.Hash() == chain.Config().GenesisHash {
if parentOfParent == nil || parentOfParent.Hash() == chain.Config().GenesisHash {
return parent.Difficulty()
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/progpow/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func (progpow *Progpow) CalcDifficulty(chain consensus.ChainHeaderReader, parent
return parent.Difficulty()
}
parentOfParent := chain.GetHeaderByHash(parent.ParentHash())
if parentOfParent.Hash() == chain.Config().GenesisHash {
if parentOfParent == nil || parentOfParent.Hash() == chain.Config().GenesisHash {
return parent.Difficulty()
}

Expand Down

0 comments on commit d6304db

Please sign in to comment.