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 for panic 'failed to update current block' #4612

Merged
merged 1 commit into from
Jan 18, 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
29 changes: 10 additions & 19 deletions core/blockchain_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"sync/atomic"
"time"

"github.com/pkg/errors"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/common/prque"
Expand Down Expand Up @@ -66,7 +68,6 @@ import (
"github.com/harmony-one/harmony/staking/slash"
staking "github.com/harmony-one/harmony/staking/types"
lru "github.com/hashicorp/golang-lru"
"github.com/pkg/errors"
)

var (
Expand Down Expand Up @@ -1730,21 +1731,16 @@ func (bc *BlockChainImpl) insertChain(chain types.Blocks, verifyHeaders bool) (i
err = NewBlockValidator(bc).ValidateBody(block)
}
switch {
case err == ErrKnownBlock:
// Block and state both already known. However if the current block is below
// this number we did a rollback and we should reimport it nonetheless.
if bc.CurrentBlock().NumberU64() >= block.NumberU64() {
stats.ignored++
continue
}
case errors.Is(err, ErrKnownBlock):
return i, events, coalescedLogs, err

case err == consensus_engine.ErrFutureBlock:
return i, events, coalescedLogs, err

case err == consensus_engine.ErrUnknownAncestor:
case errors.Is(err, consensus_engine.ErrUnknownAncestor):
return i, events, coalescedLogs, err

case err == consensus_engine.ErrPrunedAncestor:
case errors.Is(err, consensus_engine.ErrPrunedAncestor):
// TODO: add fork choice mechanism
// Block competing with the canonical chain, store in the db, but don't process
// until the competitor TD goes above the canonical TD
Expand All @@ -1771,9 +1767,7 @@ func (bc *BlockChainImpl) insertChain(chain types.Blocks, verifyHeaders bool) (i
// Prune in case non-empty winner chain
if len(winner) > 0 {
// Import all the pruned blocks to make the state available
bc.chainmu.Unlock()
_, evs, logs, err := bc.insertChain(winner, true /* verifyHeaders */)
bc.chainmu.Lock()
events, coalescedLogs = evs, logs

if err != nil {
Expand Down Expand Up @@ -1908,10 +1902,10 @@ func (bc *BlockChainImpl) insertChain(chain types.Blocks, verifyHeaders bool) (i

// insertStats tracks and reports on block insertion.
type insertStats struct {
queued, processed, ignored int
usedGas uint64
lastIndex int
startTime mclock.AbsTime
queued, processed int
usedGas uint64
lastIndex int
startTime mclock.AbsTime
}

// statsReportLimit is the time limit during import and export after which we
Expand Down Expand Up @@ -1950,9 +1944,6 @@ func (st *insertStats) report(chain []*types.Block, index int, cache common.Stor
if st.queued > 0 {
context = context.Int("queued", st.queued)
}
if st.ignored > 0 {
context = context.Int("ignored", st.ignored)
}

logger := context.Logger()
logger.Info().Msg("Imported new chain segment")
Expand Down