You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When restarting a node that previously crashed at a certain point, the loadLastState function may encounter a situation where head := GetHeadBlockHash(bc.db) is nil (head == (common.Hash{})) or currentBlock := bc.GetBlockByHash(head) is nil. This leads to an empty database or a missing head block, triggering a chain reset. However, during the reset process, specifically at if err := bc.SetHead(0); err != nil { ... } in the ResetWithGenesisBlock function in blockchain.go, causes a panic due to an unhandled nil return type:
panic: interface conversion: interface {} is nil, not *types.Block
After investigate, this panic error from :
// CurrentBlock retrieves the current head block of the canonical chain. The// block is retrieved from the blockchain's internal cache.func (bc*BlockChain) CurrentBlock() *types.Block {
returnbc.currentBlock.Load().(*types.Block)
}
// CurrentFastBlock retrieves the current fast-sync head block of the canonical// chain. The block is retrieved from the blockchain's internal cache.func (bc*BlockChain) CurrentFastBlock() *types.Block {
returnbc.currentFastBlock.Load().(*types.Block)
}
Issue Description
Summary
func (bc*BlockChain) SetHead(headuint64) error {
log.Warn("Rewinding blockchain", "target", head)
bc.mu.Lock()
deferbc.mu.Unlock()
...// Rewind the block chain, ensuring we don't end up with a stateless head blockifcurrentBlock:=bc.CurrentBlock(); currentBlock!=nil&¤tHeader.Number.Uint64() <currentBlock.NumberU64() {
bc.currentBlock.Store(bc.GetBlock(currentHeader.Hash(), currentHeader.Number.Uint64()))
}
...
When invoking the SetHead() method in blockchain.go , the application encounters a panic due to an unsafe type assertion in the CurrentBlock() method. Specifically, currentBlock.Load() returns nil, and the subsequent assertion to *types.Block fails, cause the panic.
Suggested Fix
Add a nil check for CurrentBlock() && CurrentFastBlock() in the blockchain.go to handle the nil return type gracefully and avoid the panic.
When restarting a node that previously crashed at a certain point, the
loadLastState
function may encounter a situation wherehead := GetHeadBlockHash(bc.db)
is nil (head == (common.Hash{})
) orcurrentBlock := bc.GetBlockByHash(head)
is nil. This leads to an empty database or a missing head block, triggering a chain reset. However, during the reset process, specifically atif err := bc.SetHead(0); err != nil { ... }
in theResetWithGenesisBlock
function inblockchain.go
, causes a panic due to an unhandled nil return type:After investigate, this panic error from :
Issue Description
Summary
When invoking the
SetHead()
method in blockchain.go , the application encounters a panic due to an unsafe type assertion in theCurrentBlock()
method. Specifically,currentBlock.Load()
returns nil, and the subsequent assertion to *types.Block fails, cause the panic.Suggested Fix
Add a nil check for
CurrentBlock()
&&CurrentFastBlock()
in theblockchain.go
to handle the nil return type gracefully and avoid the panic.The text was updated successfully, but these errors were encountered: