Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix pbss snapshot inconsistency with engine-sync enabled when starting #189

Merged
merged 4 commits into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 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 @@ -398,6 +399,31 @@ 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.Debug("pbss snapshot validation")
currentSafe := bc.CurrentSafeBlock()
currentFinalize := bc.CurrentFinalBlock()

// Check if either safe or finalized block is ahead of the head block
if currentSafe != nil && currentFinalize != nil {
if currentSafe.Number.Uint64() > head.Number.Uint64() || currentFinalize.Number.Uint64() > head.Number.Uint64() {
log.Info("current unsafe is behind safe, reset")
bc.HeaderChainForceSetHead(head.Number.Uint64())

// Update the safe and finalized block conditionally
if currentSafe.Number.Uint64() > head.Number.Uint64() {
bc.SetSafe(head)
}
if currentFinalize.Number.Uint64() > head.Number.Uint64() {
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
Loading