From 04b01daf089bc018ba368bac28546184bbe04684 Mon Sep 17 00:00:00 2001 From: GalaIO Date: Mon, 6 Feb 2023 21:57:21 +0800 Subject: [PATCH] eth/fetcher: fix re-queue failed bug; --- eth/fetcher/block_fetcher.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/eth/fetcher/block_fetcher.go b/eth/fetcher/block_fetcher.go index 027ac16044..27ca30435f 100644 --- a/eth/fetcher/block_fetcher.go +++ b/eth/fetcher/block_fetcher.go @@ -430,18 +430,24 @@ func (f *BlockFetcher) loop() { case op := <-f.requeue: // Re-queue blocks that have not been written due to fork block competition - number := int64(0) - hash := "" + var ( + number uint64 + hash common.Hash + ) if op.header != nil { - number = op.header.Number.Int64() - hash = op.header.Hash().String() + number = op.header.Number.Uint64() + hash = op.header.Hash() } else if op.block != nil { - number = op.block.Number().Int64() - hash = op.block.Hash().String() + number = op.block.Number().Uint64() + hash = op.block.Hash() } log.Info("Re-queue blocks", "number", number, "hash", hash) - f.enqueue(op.origin, op.header, op.block) + // force enqueue, and continue later + f.queue.Push(op, -int64(number)) + if f.queueChangeHook != nil { + f.queueChangeHook(hash, true) + } case op := <-f.inject: // A direct block insertion was requested, try and fill any pending gaps @@ -842,7 +848,6 @@ func (f *BlockFetcher) importHeaders(op *blockOrHeaderInject) { log.Debug("Importing propagated header", "peer", peer, "number", header.Number, "hash", hash) go func() { - defer func() { f.done <- hash }() // If the parent's unknown, abort insertion parent := f.getHeader(header.ParentHash) if parent == nil { @@ -851,6 +856,8 @@ func (f *BlockFetcher) importHeaders(op *blockOrHeaderInject) { f.requeue <- op return } + defer func() { f.done <- hash }() + // Validate the header and if something went wrong, drop the peer if err := f.verifyHeader(header); err != nil && err != consensus.ErrFutureBlock { log.Debug("Propagated header verification failed", "peer", peer, "number", header.Number, "hash", hash, "err", err) @@ -880,8 +887,6 @@ func (f *BlockFetcher) importBlocks(op *blockOrHeaderInject) { // Run the import on a new thread log.Debug("Importing propagated block", "peer", peer, "number", block.Number(), "hash", hash) go func() { - defer func() { f.done <- hash }() - // If the parent's unknown, abort insertion parent := f.getBlock(block.ParentHash()) if parent == nil { @@ -890,6 +895,8 @@ func (f *BlockFetcher) importBlocks(op *blockOrHeaderInject) { f.requeue <- op return } + defer func() { f.done <- hash }() + // Quickly validate the header and propagate the block if it passes switch err := f.verifyHeader(block.Header()); err { case nil: