eth, les: reject stale request (#19689)

* eth, les: reject stale request

* les: reuse local head number
This commit is contained in:
gary rong
2019-06-11 15:40:32 +08:00
committed by Péter Szilágyi
parent 3d3e83ecff
commit c0a034ec89
5 changed files with 90 additions and 2 deletions

View File

@ -698,6 +698,13 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
p.Log().Warn("Failed to retrieve header for code", "block", *number, "hash", request.BHash)
continue
}
// Refuse to search stale state data in the database since looking for
// a non-exist key is kind of expensive.
local := pm.blockchain.CurrentHeader().Number.Uint64()
if !pm.server.archiveMode && header.Number.Uint64()+core.TriesInMemory <= local {
p.Log().Debug("Reject stale code request", "number", header.Number.Uint64(), "head", local)
continue
}
triedb := pm.blockchain.StateCache().TrieDB()
account, err := pm.getAccount(triedb, header.Root, common.BytesToHash(request.AccKey))
@ -852,6 +859,13 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
p.Log().Warn("Failed to retrieve header for proof", "block", *number, "hash", request.BHash)
continue
}
// Refuse to search stale state data in the database since looking for
// a non-exist key is kind of expensive.
local := pm.blockchain.CurrentHeader().Number.Uint64()
if !pm.server.archiveMode && header.Number.Uint64()+core.TriesInMemory <= local {
p.Log().Debug("Reject stale trie request", "number", header.Number.Uint64(), "head", local)
continue
}
root = header.Root
}
// Open the account or storage trie for the request