aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-06-09 18:00:41 +0800
committerFelix Lange <fjl@twurst.com>2015-06-09 23:06:31 +0800
commit41b2008a669a8454ae19f783eb2dcd967e8752cf (patch)
tree6f5113c5bd1d2f8c2bb25c069ca30ad623928a87 /eth
parent7aefe123e98240ad4df440a8d1be4446744c8ca2 (diff)
downloaddexon-41b2008a669a8454ae19f783eb2dcd967e8752cf.tar.gz
dexon-41b2008a669a8454ae19f783eb2dcd967e8752cf.tar.zst
dexon-41b2008a669a8454ae19f783eb2dcd967e8752cf.zip
eth: limit number of sent blocks based on message size
If blocks get larger, sending 256 at once can make messages large enough to exceed the low-level write timeout.
Diffstat (limited to 'eth')
-rw-r--r--eth/handler.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/eth/handler.go b/eth/handler.go
index f2027c3c6..a67d956fb 100644
--- a/eth/handler.go
+++ b/eth/handler.go
@@ -18,6 +18,11 @@ import (
"github.com/ethereum/go-ethereum/rlp"
)
+// This is the target maximum size of returned blocks for the
+// getBlocks message. The reply message may exceed it
+// if a single block is larger than the limit.
+const maxBlockRespSize = 2 * 1024 * 1024
+
func errResp(code errCode, format string, v ...interface{}) error {
return fmt.Errorf("%v - %v", code, fmt.Sprintf(format, v...))
}
@@ -246,7 +251,10 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
if _, err := msgStream.List(); err != nil {
return err
}
- var i int
+ var (
+ i int
+ totalsize common.StorageSize
+ )
for {
i++
var hash common.Hash
@@ -260,8 +268,9 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
block := self.chainman.GetBlock(hash)
if block != nil {
blocks = append(blocks, block)
+ totalsize += block.Size()
}
- if i == downloader.MaxBlockFetch {
+ if i == downloader.MaxBlockFetch || totalsize > maxBlockRespSize {
break
}
}