From d05b0828683bcb79b2bf38d5a16ead441ae0a041 Mon Sep 17 00:00:00 2001 From: "bin.lv" Date: Tue, 14 Jan 2020 10:37:35 +0800 Subject: [PATCH] M: fetcher.go: optimize bodyFilter in function 'func (f *Fetcher) loop()' --- eth/fetcher/fetcher.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/eth/fetcher/fetcher.go b/eth/fetcher/fetcher.go index 28c532d9bd..859071a40d 100644 --- a/eth/fetcher/fetcher.go +++ b/eth/fetcher/fetcher.go @@ -515,14 +515,18 @@ func (f *Fetcher) loop() { blocks := []*types.Block{} for i := 0; i < len(task.transactions) && i < len(task.uncles); i++ { + var txnHash, uncleHash common.Hash // Match up a body to any possible completion request matched := false for hash, announce := range f.completing { if f.queued[hash] == nil { - txnHash := types.DeriveSha(types.Transactions(task.transactions[i])) - uncleHash := types.CalcUncleHash(task.uncles[i]) - + if txnHash == (common.Hash{}) { + txnHash = types.DeriveSha(types.Transactions(task.transactions[i])) + } + if uncleHash == (common.Hash{}) { + uncleHash = types.CalcUncleHash(task.uncles[i]) + } if txnHash == announce.header.TxHash && uncleHash == announce.header.UncleHash && announce.origin == task.peer { // Mark the body matched, reassemble if still unknown matched = true