les: reuse local head number

This commit is contained in:
rjl493456442 2019-06-11 15:15:23 +08:00
parent cd5003a1da
commit ec4d1d57cf

View file

@ -700,8 +700,9 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
} }
// Refuse to search stale state data in the database since looking for // Refuse to search stale state data in the database since looking for
// a non-exist key is kind of expensive. // a non-exist key is kind of expensive.
if !pm.server.archiveMode && header.Number.Uint64()+core.TriesInMemory <= pm.blockchain.CurrentHeader().Number.Uint64() { local := pm.blockchain.CurrentHeader().Number.Uint64()
p.Log().Debug("Reject stale code request", "number", header.Number.Uint64(), "head", 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 continue
} }
triedb := pm.blockchain.StateCache().TrieDB() triedb := pm.blockchain.StateCache().TrieDB()
@ -860,8 +861,9 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
} }
// Refuse to search stale state data in the database since looking for // Refuse to search stale state data in the database since looking for
// a non-exist key is kind of expensive. // a non-exist key is kind of expensive.
if !pm.server.archiveMode && header.Number.Uint64()+core.TriesInMemory <= pm.blockchain.CurrentHeader().Number.Uint64() { local := pm.blockchain.CurrentHeader().Number.Uint64()
p.Log().Debug("Reject stale trie request", "number", header.Number.Uint64(), "head", 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 continue
} }
root = header.Root root = header.Root