M: fetcher.go: optimize bodyFilter in function 'func (f *Fetcher) loop()'

This commit is contained in:
bin.lv 2020-01-14 10:37:35 +08:00
parent e9e69d6e29
commit d05b082868

View file

@ -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