Skip to content

Commit

Permalink
eth/fetcher: fix re-queue failed bug;
Browse files Browse the repository at this point in the history
  • Loading branch information
galaio committed Feb 6, 2023
1 parent c9bd677 commit 04b01da
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions eth/fetcher/block_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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:
Expand Down

0 comments on commit 04b01da

Please sign in to comment.