mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-13 10:21:37 +00:00
eth/protocols/eth: remove useless checks in the eth protocol handler
This commit is contained in:
parent
b2490e3f20
commit
fb1ce79543
3 changed files with 13 additions and 15 deletions
|
|
@ -218,7 +218,8 @@ func (p *Peer) dispatcher() {
|
|||
// Stop tracking the request
|
||||
delete(pending, cancelOp.id)
|
||||
|
||||
// Not sure if the request is about the receipt, but remove it anyway
|
||||
// Not sure if the request is about the receipt, but remove it anyway.
|
||||
// TODO(rjl493456442, bosul): investigate whether we can avoid leaking peer fields here.
|
||||
p.receiptBufferLock.Lock()
|
||||
delete(p.receiptBuffer, cancelOp.id)
|
||||
p.receiptBufferLock.Unlock()
|
||||
|
|
|
|||
|
|
@ -35,6 +35,10 @@ const (
|
|||
// softResponseLimit is the target maximum size of replies to data retrievals.
|
||||
softResponseLimit = 2 * 1024 * 1024
|
||||
|
||||
// maxPacketSize is the devp2p message size limit commonly enforced by clients.
|
||||
// Any packet exceeding this limit must be rejected.
|
||||
maxPacketSize = 10 * 1024 * 1024
|
||||
|
||||
// maxHeadersServe is the maximum number of block headers to serve. This number
|
||||
// is there to limit the number of disk lookups.
|
||||
maxHeadersServe = 1024
|
||||
|
|
@ -49,8 +53,6 @@ const (
|
|||
// containing 200+ transactions nowadays, the practical limit will always
|
||||
// be softResponseLimit.
|
||||
maxReceiptsServe = 1024
|
||||
|
||||
maxPacketSize = 10 * 1024 * 1024
|
||||
)
|
||||
|
||||
// Handler is a callback to invoke from an outside runner after the boilerplate
|
||||
|
|
|
|||
|
|
@ -286,9 +286,8 @@ func ServiceGetReceiptsQuery68(chain *core.BlockChain, query GetReceiptsRequest)
|
|||
bytes int
|
||||
receipts []rlp.RawValue
|
||||
)
|
||||
for lookups, hash := range query {
|
||||
if bytes >= softResponseLimit || len(receipts) >= maxReceiptsServe ||
|
||||
lookups >= 2*maxReceiptsServe {
|
||||
for _, hash := range query {
|
||||
if bytes >= softResponseLimit || len(receipts) >= maxReceiptsServe {
|
||||
break
|
||||
}
|
||||
// Retrieve the requested block's receipts
|
||||
|
|
@ -323,9 +322,8 @@ func serviceGetReceiptsQuery69(chain *core.BlockChain, query GetReceiptsRequest)
|
|||
bytes int
|
||||
receipts []rlp.RawValue
|
||||
)
|
||||
for lookups, hash := range query {
|
||||
if bytes >= softResponseLimit || len(receipts) >= maxReceiptsServe ||
|
||||
lookups >= 2*maxReceiptsServe {
|
||||
for _, hash := range query {
|
||||
if bytes >= softResponseLimit || len(receipts) >= maxReceiptsServe {
|
||||
break
|
||||
}
|
||||
// Retrieve the requested block's receipts
|
||||
|
|
@ -362,13 +360,10 @@ func serviceGetReceiptsQuery70(chain *core.BlockChain, query GetReceiptsRequest,
|
|||
receipts []rlp.RawValue
|
||||
lastBlockIncomplete bool
|
||||
)
|
||||
|
||||
for lookups, hash := range query {
|
||||
if bytes >= softResponseLimit || len(receipts) >= maxReceiptsServe ||
|
||||
lookups >= 2*maxReceiptsServe {
|
||||
for i, hash := range query {
|
||||
if bytes >= softResponseLimit || len(receipts) >= maxReceiptsServe {
|
||||
break
|
||||
}
|
||||
|
||||
results := chain.GetReceiptsRLP(hash)
|
||||
if results == nil {
|
||||
if header := chain.GetHeaderByHash(hash); header == nil || header.ReceiptHash != types.EmptyRootHash {
|
||||
|
|
@ -387,7 +382,7 @@ func serviceGetReceiptsQuery70(chain *core.BlockChain, query GetReceiptsRequest,
|
|||
}
|
||||
}
|
||||
|
||||
if firstBlockReceiptIndex > 0 && lookups == 0 {
|
||||
if firstBlockReceiptIndex > 0 && i == 0 {
|
||||
results, lastBlockIncomplete = trimReceiptsRLP(results, int(firstBlockReceiptIndex), maxPacketSize)
|
||||
} else if bytes+len(results) > maxPacketSize {
|
||||
results, lastBlockIncomplete = trimReceiptsRLP(results, 0, maxPacketSize-bytes)
|
||||
|
|
|
|||
Loading…
Reference in a new issue