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

Commit

Permalink
Merge pull request #72 from binance-chain/release/0.30.1-binance.3
Browse files Browse the repository at this point in the history
Release/0.30.1 binance.3
  • Loading branch information
ackratos authored Apr 9, 2019
2 parents 14ae0f7 + efd486b commit 685fb83
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
8 changes: 5 additions & 3 deletions blockchain/state_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

type StatePool struct {
cmn.BaseService
keysPerRequest int64

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

func NewStatePool(requestsCh chan<- StateRequest, errorsCh chan<- peerError) *StatePool {
func NewStatePool(requestsCh chan<- StateRequest, errorsCh chan<- peerError, keysPerRequest int64) *StatePool {
sp := &StatePool{
keysPerRequest: keysPerRequest,
peers: make(map[p2p.ID]*spPeer),
chunks: make(map[int64][][]byte),
requests: make(map[string]*StateRequest),
Expand Down Expand Up @@ -179,8 +181,8 @@ func (pool *StatePool) sendRequest() {
if endIndexForThisPeer > pool.totalKeys {
endIndexForThisPeer = pool.totalKeys
}
for startIdx := int64(peerIdx) * pool.step; startIdx < endIndexForThisPeer; startIdx += keysPerRequest {
endIndex := startIdx + keysPerRequest
for startIdx := int64(peerIdx) * pool.step; startIdx < endIndexForThisPeer; startIdx += pool.keysPerRequest {
endIndex := startIdx + pool.keysPerRequest
if endIndex > endIndexForThisPeer {
endIndex = endIndexForThisPeer
}
Expand Down
4 changes: 2 additions & 2 deletions blockchain/state_reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const (
// TODO: REVIEW before final merge
bcStateResponseMessagePrefixSize = 8
bcStateResponseMessageFieldKeySize = 2
keysPerRequest = 5000 // response should be around 500KB per request
maxStateMsgSize = types.MaxStateSizeBytes +
bcStateResponseMessagePrefixSize +
bcStateResponseMessageFieldKeySize
Expand Down Expand Up @@ -73,6 +72,7 @@ func NewStateReactor(stateDB dbm.DB, app proxy.AppConnState, config *cfg.Config)
pool := NewStatePool(
requestsCh,
errorsCh,
int64(config.P2P.KeysPerRequest),
)

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

chunksToWrite := make([][]byte, 0, bcSR.pool.totalKeys)
for startIdx := int64(0); startIdx < bcSR.pool.totalKeys; startIdx += keysPerRequest {
for startIdx := int64(0); startIdx < bcSR.pool.totalKeys; startIdx += bcSR.pool.keysPerRequest {
if chunks, ok := bcSR.pool.chunks[startIdx]; ok {
for _, chunk := range chunks {
chunksToWrite = append(chunksToWrite, chunk)
Expand Down
12 changes: 12 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,21 @@ type P2PConfig struct {
// Maximum size of a message packet payload, in bytes
MaxPacketMsgPayloadSize int `mapstructure:"max_packet_msg_payload_size"`

// Maximum num of keys a state sync request ask for
KeysPerRequest int `mapstructure:"keys_per_request"`

// Rate at which packets can be sent, in bytes/second
SendRate int64 `mapstructure:"send_rate"`

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

// Interval to send pings
PingInterval time.Duration `mapstructure:"ping_interval"`

// Maximum wait time for pongs
PongTimeout time.Duration `mapstructure:"pong_timeout"`

// Set true to enable the peer-exchange reactor
PexReactor bool `mapstructure:"pex"`

Expand Down Expand Up @@ -468,8 +477,11 @@ func DefaultP2PConfig() *P2PConfig {
MaxNumOutboundPeers: 10,
FlushThrottleTimeout: 10 * time.Millisecond,
MaxPacketMsgPayloadSize: 1024 * 1024, // 1 MB
KeysPerRequest: 2500, // would be around 250K for account node
SendRate: 50 * 1024 * 1024, // 50 MB/s
RecvRate: 50 * 1024 * 1024, // 50 MB/s
PingInterval: 60 * time.Second,
PongTimeout: 45 * time.Second,
PexReactor: true,
SeedMode: false,
AllowDuplicateIP: false,
Expand Down
9 changes: 9 additions & 0 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,21 @@ flush_throttle_timeout = "{{ .P2P.FlushThrottleTimeout }}"
# Maximum size of a message packet payload, in bytes
max_packet_msg_payload_size = {{ .P2P.MaxPacketMsgPayloadSize }}
# Maximum num of keys a state sync request ask for
keys_per_request = {{ .P2P.KeysPerRequest }}
# Rate at which packets can be sent, in bytes/second
send_rate = {{ .P2P.SendRate }}
# Rate at which packets can be received, in bytes/second
recv_rate = {{ .P2P.RecvRate }}
# Interval to send pings
ping_interval = "{{ .P2P.PingInterval }}"
# Maximum wait time for pongs
pong_timeout = "{{ .P2P.PongTimeout }}"
# Set true to enable the peer-exchange reactor
pex = {{ .P2P.PexReactor }}
Expand Down
7 changes: 6 additions & 1 deletion libs/db/go_level_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/errors"
"github.com/syndtr/goleveldb/leveldb/filter"
"github.com/syndtr/goleveldb/leveldb/iterator"
"github.com/syndtr/goleveldb/leveldb/opt"

Expand All @@ -28,7 +29,11 @@ type GoLevelDB struct {
}

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

func NewGoLevelDBWithOpts(name string, dir string, o *opt.Options) (*GoLevelDB, error) {
Expand Down
2 changes: 2 additions & 0 deletions p2p/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func MConnConfig(cfg *config.P2PConfig) conn.MConnConfig {
mConfig.SendRate = cfg.SendRate
mConfig.RecvRate = cfg.RecvRate
mConfig.MaxPacketMsgPayloadSize = cfg.MaxPacketMsgPayloadSize
mConfig.PingInterval = cfg.PingInterval
mConfig.PongTimeout = cfg.PongTimeout
return mConfig
}

Expand Down

0 comments on commit 685fb83

Please sign in to comment.