Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions ctxc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ const (
// maxHeadersServe is the maximum number of block headers to serve. This number
// is there to limit the number of disk lookups.
maxHeadersServe = 1024
// maxBodiesServe is the maximum number of block bodies to serve. This number
// is mostly there to limit the number of disk lookups. With 24KB block sizes
// nowadays, the practical limit will always be softResponseLimit.
maxBodiesServe = 1024

// maxReceiptsServe is the maximum number of block receipts to serve. This
// number is mostly there to limit the number of disk lookups. With block
// containing 200+ transactions nowadays, the practical limit will always
// be softResponseLimit.
maxReceiptsServe = 1024

// txChanSize is the size of channel listening to NewTxsEvent.
// The number is referenced from the size of tx pool.
Expand Down Expand Up @@ -741,11 +751,13 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
}
// Gather blocks until the fetch or network limits is reached
var (
hash common.Hash
bytes int
bodies []rlp.RawValue
hash common.Hash
bytes int
bodies []rlp.RawValue
lookups int
)
for bytes < softResponseLimit && len(bodies) < downloader.MaxBlockFetch {
for bytes < softResponseLimit && len(bodies) < downloader.MaxBlockFetch && lookups < 2*maxBodiesServe {
lookups++
// Retrieve the hash of the next block
if err := msgStream.Decode(&hash); err == rlp.EOL {
break
Expand Down Expand Up @@ -846,8 +858,10 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
hash common.Hash
bytes int
receipts []rlp.RawValue
lookups int
)
for bytes < softResponseLimit && len(receipts) < downloader.MaxReceiptFetch {
for bytes < softResponseLimit && len(receipts) < maxReceiptsServe && lookups < 2*maxReceiptsServe {
lookups++
// Retrieve the hash of the next block
if err := msgStream.Decode(&hash); err == rlp.EOL {
break
Expand Down