Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 685fb83

Browse files
authored
Merge pull request #72 from binance-chain/release/0.30.1-binance.3
Release/0.30.1 binance.3
2 parents 14ae0f7 + efd486b commit 685fb83

6 files changed

Lines changed: 36 additions & 6 deletions

File tree

blockchain/state_pool.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
type StatePool struct {
3131
cmn.BaseService
32+
keysPerRequest int64
3233

3334
mtx sync.Mutex
3435
height int64 // the height in first state status response we received
@@ -55,8 +56,9 @@ type StatePool struct {
5556
errorsCh chan<- peerError
5657
}
5758

58-
func NewStatePool(requestsCh chan<- StateRequest, errorsCh chan<- peerError) *StatePool {
59+
func NewStatePool(requestsCh chan<- StateRequest, errorsCh chan<- peerError, keysPerRequest int64) *StatePool {
5960
sp := &StatePool{
61+
keysPerRequest: keysPerRequest,
6062
peers: make(map[p2p.ID]*spPeer),
6163
chunks: make(map[int64][][]byte),
6264
requests: make(map[string]*StateRequest),
@@ -179,8 +181,8 @@ func (pool *StatePool) sendRequest() {
179181
if endIndexForThisPeer > pool.totalKeys {
180182
endIndexForThisPeer = pool.totalKeys
181183
}
182-
for startIdx := int64(peerIdx) * pool.step; startIdx < endIndexForThisPeer; startIdx += keysPerRequest {
183-
endIndex := startIdx + keysPerRequest
184+
for startIdx := int64(peerIdx) * pool.step; startIdx < endIndexForThisPeer; startIdx += pool.keysPerRequest {
185+
endIndex := startIdx + pool.keysPerRequest
184186
if endIndex > endIndexForThisPeer {
185187
endIndex = endIndexForThisPeer
186188
}

blockchain/state_reactor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ const (
3636
// TODO: REVIEW before final merge
3737
bcStateResponseMessagePrefixSize = 8
3838
bcStateResponseMessageFieldKeySize = 2
39-
keysPerRequest = 5000 // response should be around 500KB per request
4039
maxStateMsgSize = types.MaxStateSizeBytes +
4140
bcStateResponseMessagePrefixSize +
4241
bcStateResponseMessageFieldKeySize
@@ -73,6 +72,7 @@ func NewStateReactor(stateDB dbm.DB, app proxy.AppConnState, config *cfg.Config)
7372
pool := NewStatePool(
7473
requestsCh,
7574
errorsCh,
75+
int64(config.P2P.KeysPerRequest),
7676
)
7777

7878
bcSR := &StateReactor{
@@ -228,7 +228,7 @@ func (bcSR *StateReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte) {
228228
bcSR.quitCh <- struct{}{}
229229

230230
chunksToWrite := make([][]byte, 0, bcSR.pool.totalKeys)
231-
for startIdx := int64(0); startIdx < bcSR.pool.totalKeys; startIdx += keysPerRequest {
231+
for startIdx := int64(0); startIdx < bcSR.pool.totalKeys; startIdx += bcSR.pool.keysPerRequest {
232232
if chunks, ok := bcSR.pool.chunks[startIdx]; ok {
233233
for _, chunk := range chunks {
234234
chunksToWrite = append(chunksToWrite, chunk)

config/config.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,21 @@ type P2PConfig struct {
422422
// Maximum size of a message packet payload, in bytes
423423
MaxPacketMsgPayloadSize int `mapstructure:"max_packet_msg_payload_size"`
424424

425+
// Maximum num of keys a state sync request ask for
426+
KeysPerRequest int `mapstructure:"keys_per_request"`
427+
425428
// Rate at which packets can be sent, in bytes/second
426429
SendRate int64 `mapstructure:"send_rate"`
427430

428431
// Rate at which packets can be received, in bytes/second
429432
RecvRate int64 `mapstructure:"recv_rate"`
430433

434+
// Interval to send pings
435+
PingInterval time.Duration `mapstructure:"ping_interval"`
436+
437+
// Maximum wait time for pongs
438+
PongTimeout time.Duration `mapstructure:"pong_timeout"`
439+
431440
// Set true to enable the peer-exchange reactor
432441
PexReactor bool `mapstructure:"pex"`
433442

@@ -468,8 +477,11 @@ func DefaultP2PConfig() *P2PConfig {
468477
MaxNumOutboundPeers: 10,
469478
FlushThrottleTimeout: 10 * time.Millisecond,
470479
MaxPacketMsgPayloadSize: 1024 * 1024, // 1 MB
480+
KeysPerRequest: 2500, // would be around 250K for account node
471481
SendRate: 50 * 1024 * 1024, // 50 MB/s
472482
RecvRate: 50 * 1024 * 1024, // 50 MB/s
483+
PingInterval: 60 * time.Second,
484+
PongTimeout: 45 * time.Second,
473485
PexReactor: true,
474486
SeedMode: false,
475487
AllowDuplicateIP: false,

config/toml.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,21 @@ flush_throttle_timeout = "{{ .P2P.FlushThrottleTimeout }}"
217217
# Maximum size of a message packet payload, in bytes
218218
max_packet_msg_payload_size = {{ .P2P.MaxPacketMsgPayloadSize }}
219219
220+
# Maximum num of keys a state sync request ask for
221+
keys_per_request = {{ .P2P.KeysPerRequest }}
222+
220223
# Rate at which packets can be sent, in bytes/second
221224
send_rate = {{ .P2P.SendRate }}
222225
223226
# Rate at which packets can be received, in bytes/second
224227
recv_rate = {{ .P2P.RecvRate }}
225228
229+
# Interval to send pings
230+
ping_interval = "{{ .P2P.PingInterval }}"
231+
232+
# Maximum wait time for pongs
233+
pong_timeout = "{{ .P2P.PongTimeout }}"
234+
226235
# Set true to enable the peer-exchange reactor
227236
pex = {{ .P2P.PexReactor }}
228237

libs/db/go_level_db.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/syndtr/goleveldb/leveldb"
99
"github.com/syndtr/goleveldb/leveldb/errors"
10+
"github.com/syndtr/goleveldb/leveldb/filter"
1011
"github.com/syndtr/goleveldb/leveldb/iterator"
1112
"github.com/syndtr/goleveldb/leveldb/opt"
1213

@@ -28,7 +29,11 @@ type GoLevelDB struct {
2829
}
2930

3031
func NewGoLevelDB(name string, dir string) (*GoLevelDB, error) {
31-
return NewGoLevelDBWithOpts(name, dir, nil)
32+
var defaultOptions = &opt.Options{OpenFilesCacheCapacity: 1024,
33+
BlockCacheCapacity: 2 * opt.GiB,
34+
WriteBuffer: 768 / 4 * opt.MiB, // Two of these are used internally
35+
Filter: filter.NewBloomFilter(10)}
36+
return NewGoLevelDBWithOpts(name, dir, defaultOptions)
3237
}
3338

3439
func NewGoLevelDBWithOpts(name string, dir string, o *opt.Options) (*GoLevelDB, error) {

p2p/switch.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ func MConnConfig(cfg *config.P2PConfig) conn.MConnConfig {
3737
mConfig.SendRate = cfg.SendRate
3838
mConfig.RecvRate = cfg.RecvRate
3939
mConfig.MaxPacketMsgPayloadSize = cfg.MaxPacketMsgPayloadSize
40+
mConfig.PingInterval = cfg.PingInterval
41+
mConfig.PongTimeout = cfg.PongTimeout
4042
return mConfig
4143
}
4244

0 commit comments

Comments
 (0)