mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
les: fix variable name
This commit is contained in:
parent
09149afe26
commit
2b349f474a
3 changed files with 15 additions and 14 deletions
|
|
@ -528,7 +528,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
|||
origin = pm.blockchain.GetHeaderByNumber(query.Origin.Number)
|
||||
}
|
||||
if origin == nil {
|
||||
atomic.AddUint32(&p.invalidReq, 1)
|
||||
atomic.AddUint32(&p.invalidCount, 1)
|
||||
break
|
||||
}
|
||||
headers = append(headers, origin)
|
||||
|
|
@ -638,7 +638,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
|||
}
|
||||
number := rawdb.ReadHeaderNumber(pm.chainDb, hash)
|
||||
if number == nil {
|
||||
atomic.AddUint32(&p.invalidReq, 1)
|
||||
atomic.AddUint32(&p.invalidCount, 1)
|
||||
continue
|
||||
}
|
||||
if data := rawdb.ReadBodyRLP(pm.chainDb, hash, *number); len(data) != 0 {
|
||||
|
|
@ -698,7 +698,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
|||
number := rawdb.ReadHeaderNumber(pm.chainDb, request.BHash)
|
||||
if number == nil {
|
||||
p.Log().Warn("Failed to retrieve block num for code", "hash", request.BHash)
|
||||
atomic.AddUint32(&p.invalidReq, 1)
|
||||
atomic.AddUint32(&p.invalidCount, 1)
|
||||
continue
|
||||
}
|
||||
header := rawdb.ReadHeader(pm.chainDb, request.BHash, *number)
|
||||
|
|
@ -711,7 +711,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
|||
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)
|
||||
atomic.AddUint32(&p.invalidReq, 1)
|
||||
atomic.AddUint32(&p.invalidCount, 1)
|
||||
continue
|
||||
}
|
||||
triedb := pm.blockchain.StateCache().TrieDB()
|
||||
|
|
@ -719,7 +719,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
|||
account, err := pm.getAccount(triedb, header.Root, common.BytesToHash(request.AccKey))
|
||||
if err != nil {
|
||||
p.Log().Warn("Failed to retrieve account for code", "block", header.Number, "hash", header.Hash(), "account", common.BytesToHash(request.AccKey), "err", err)
|
||||
atomic.AddUint32(&p.invalidReq, 1)
|
||||
atomic.AddUint32(&p.invalidCount, 1)
|
||||
continue
|
||||
}
|
||||
code, err := triedb.Node(common.BytesToHash(account.CodeHash))
|
||||
|
|
@ -788,7 +788,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
|||
var results types.Receipts
|
||||
number := rawdb.ReadHeaderNumber(pm.chainDb, hash)
|
||||
if number == nil {
|
||||
atomic.AddUint32(&p.invalidReq, 1)
|
||||
atomic.AddUint32(&p.invalidCount, 1)
|
||||
continue
|
||||
}
|
||||
results = rawdb.ReadRawReceipts(pm.chainDb, hash, *number)
|
||||
|
|
@ -866,7 +866,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
|||
|
||||
if number = rawdb.ReadHeaderNumber(pm.chainDb, request.BHash); number == nil {
|
||||
p.Log().Warn("Failed to retrieve block num for proof", "hash", request.BHash)
|
||||
atomic.AddUint32(&p.invalidReq, 1)
|
||||
atomic.AddUint32(&p.invalidCount, 1)
|
||||
continue
|
||||
}
|
||||
if header = rawdb.ReadHeader(pm.chainDb, request.BHash, *number); header == nil {
|
||||
|
|
@ -878,7 +878,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
|||
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)
|
||||
atomic.AddUint32(&p.invalidReq, 1)
|
||||
atomic.AddUint32(&p.invalidCount, 1)
|
||||
continue
|
||||
}
|
||||
root = header.Root
|
||||
|
|
@ -903,7 +903,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
|||
account, err := pm.getAccount(statedb.TrieDB(), root, common.BytesToHash(request.AccKey))
|
||||
if err != nil {
|
||||
p.Log().Warn("Failed to retrieve account for proof", "block", header.Number, "hash", header.Hash(), "account", common.BytesToHash(request.AccKey), "err", err)
|
||||
atomic.AddUint32(&p.invalidReq, 1)
|
||||
atomic.AddUint32(&p.invalidCount, 1)
|
||||
continue
|
||||
}
|
||||
trie, err = statedb.OpenStorageTrie(common.BytesToHash(request.AccKey), account.Root)
|
||||
|
|
@ -1152,7 +1152,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
|||
}
|
||||
// If the client has made too much invalid request(e.g. request a non-exist data),
|
||||
// reject them to prevent SPAM attack.
|
||||
if atomic.LoadUint32(&p.invalidReq) > maxRequestErrors {
|
||||
if atomic.LoadUint32(&p.invalidCount) > maxRequestErrors {
|
||||
return errTooManyInvalidRequest
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -597,9 +597,10 @@ func TestStopResumeLes3(t *testing.T) {
|
|||
expBuf := testBufLimit
|
||||
var reqID uint64
|
||||
|
||||
header := pm.blockchain.CurrentHeader()
|
||||
req := func() {
|
||||
reqID++
|
||||
sendRequest(peer.app, GetBlockHeadersMsg, reqID, testCost, &getBlockHeadersData{Origin: hashOrNumber{Hash: common.Hash{1}}, Amount: 1})
|
||||
sendRequest(peer.app, GetBlockHeadersMsg, reqID, testCost, &getBlockHeadersData{Origin: hashOrNumber{Hash: header.Hash()}, Amount: 1})
|
||||
}
|
||||
|
||||
for i := 1; i <= 5; i++ {
|
||||
|
|
@ -607,8 +608,8 @@ func TestStopResumeLes3(t *testing.T) {
|
|||
for expBuf >= testCost {
|
||||
req()
|
||||
expBuf -= testCost
|
||||
if err := expectResponse(peer.app, BlockHeadersMsg, reqID, expBuf, nil); err != nil {
|
||||
t.Errorf("expected response and failed: %v", err)
|
||||
if err := expectResponse(peer.app, BlockHeadersMsg, reqID, expBuf, []*types.Header{header}); err != nil {
|
||||
t.Fatalf("expected response and failed: %v", err)
|
||||
}
|
||||
}
|
||||
// send some more requests in excess and expect a single StopMsg
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ type peer struct {
|
|||
// RequestProcessed is called
|
||||
responseLock sync.Mutex
|
||||
responseCount uint64
|
||||
invalidReq uint32
|
||||
invalidCount uint32
|
||||
|
||||
poolEntry *poolEntry
|
||||
hasBlock func(common.Hash, uint64, bool) bool
|
||||
|
|
|
|||
Loading…
Reference in a new issue