Skip to content

Commit

Permalink
fix pbss snapshot issue
Browse files Browse the repository at this point in the history
  • Loading branch information
krish-nr committed Sep 24, 2024
1 parent e3170ae commit 651bba6
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"sync/atomic"
"time"

"golang.org/x/exp/slices"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/lru"
"github.com/ethereum/go-ethereum/common/mclock"
Expand All @@ -50,7 +52,6 @@ import (
"github.com/ethereum/go-ethereum/triedb"
"github.com/ethereum/go-ethereum/triedb/hashdb"
"github.com/ethereum/go-ethereum/triedb/pathdb"
"golang.org/x/exp/slices"
)

var (
Expand Down Expand Up @@ -396,6 +397,22 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
// Make sure the state associated with the block is available, or log out
// if there is no available state, waiting for state sync.
head := bc.CurrentBlock()

//fix pbss snapshot if needed
if bc.triedb.Scheme() == rawdb.PathScheme {
log.Info("pbss snapshot validation")
currentSafe := bc.CurrentSafeBlock()
currentFinalize := bc.CurrentFinalBlock()

if currentSafe.Number.Uint64() > head.Number.Uint64() || currentFinalize.Number.Uint64() > head.Number.Uint64() {
log.Info("current unsafe is behind safe, reset")
bc.hc.SetHead(head.Number.Uint64(), nil, createDelFn(bc))
//想办法
bc.SetSafe(head)
bc.SetFinalized(head)
}
}

if !bc.NoTries() && !bc.HasState(head.Root) {
if head.Number.Uint64() == 0 {
// The genesis state is missing, which is only possible in the path-based
Expand Down

0 comments on commit 651bba6

Please sign in to comment.