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 premature abort during blocks processing for raft #881

Merged
merged 5 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,12 @@ func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*ty
// If the chain is terminating, stop processing blocks
if atomic.LoadInt32(&bc.procInterrupt) == 1 {
log.Debug("Premature abort during blocks processing")
// QUORUM
if bc.chainConfig.Istanbul == nil && bc.chainConfig.Clique == nil {
// Only returns an error for raft mode
zzy96 marked this conversation as resolved.
Show resolved Hide resolved
return i, events, coalescedLogs, ErrAbortBlocksProcessing
}
// END QUORUM
break
}
// If the header is a banned one, straight out abort
Expand Down
3 changes: 3 additions & 0 deletions core/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ var (
// ErrNonceTooHigh is returned if the nonce of a transaction is higher than the
// next one expected based on the local chain.
ErrNonceTooHigh = errors.New("nonce too high")

// ErrAbortBlocksProcessing is returned if bc.insertChain is interrupted under raft mode
ErrAbortBlocksProcessing = errors.New("abort during blocks processing")
)
13 changes: 11 additions & 2 deletions raft/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,11 @@ func (pm *ProtocolManager) eventLoop() {
headBlockHash := pm.blockchain.CurrentBlock().Hash()
log.Warn("not applying already-applied block", "block hash", block.Hash(), "parent", block.ParentHash(), "head", headBlockHash)
} else {
pm.applyNewChainHead(&block)
if !pm.applyNewChainHead(&block) {
// return false only if insert chain is interrupted
// stop eventloop
return
}
}

case raftpb.EntryConfChange:
Expand Down Expand Up @@ -869,7 +873,7 @@ func blockExtendsChain(block *types.Block, chain *core.BlockChain) bool {
return block.ParentHash() == chain.CurrentBlock().Hash()
}

func (pm *ProtocolManager) applyNewChainHead(block *types.Block) {
func (pm *ProtocolManager) applyNewChainHead(block *types.Block) bool {
if !blockExtendsChain(block, pm.blockchain) {
headBlock := pm.blockchain.CurrentBlock()

Expand All @@ -890,11 +894,16 @@ func (pm *ProtocolManager) applyNewChainHead(block *types.Block) {
_, err := pm.blockchain.InsertChain([]*types.Block{block})

if err != nil {
if err == core.ErrAbortBlocksProcessing {
log.Error(fmt.Sprintf("failed to extend chain: %s", err.Error()))
return false
}
panic(fmt.Sprintf("failed to extend chain: %s", err.Error()))
}

log.EmitCheckpoint(log.BlockCreated, "block", fmt.Sprintf("%x", block.Hash()))
}
return true
}

// Sets new appliedIndex in-memory, *and* writes this appliedIndex to LevelDB.
Expand Down