Browse Source

fixes from review

pull/205/head
Ethan Buchman 9 years ago
parent
commit
501c4e4bac
7 changed files with 6 additions and 131 deletions
  1. +0
    -117
      config/config.go
  2. +1
    -1
      consensus/reactor.go
  3. +0
    -2
      consensus/replay_test.go
  4. +3
    -3
      mempool/mempool.go
  5. +1
    -1
      mempool/mempool_test.go
  6. +0
    -6
      types/part_set.go
  7. +1
    -1
      types/tx.go

+ 0
- 117
config/config.go View File

@ -1,117 +0,0 @@
package config
import (
"github.com/naoina/toml"
"sync"
"time"
. "github.com/tendermint/go-common"
)
type Config interface {
Get(key string) interface{}
GetBool(key string) bool
GetFloat64(key string) float64
GetInt(key string) int
GetString(key string) string
GetStringMap(key string) map[string]interface{}
GetStringMapString(key string) map[string]string
GetStringSlice(key string) []string
GetTime(key string) time.Time
IsSet(key string) bool
Set(key string, value interface{})
}
type MapConfig struct {
required map[string]struct{} // blows up if trying to use before setting.
data map[string]interface{}
}
func ReadMapConfigFromFile(filePath string) (MapConfig, error) {
var configData = make(map[string]interface{})
fileBytes := MustReadFile(filePath)
err := toml.Unmarshal(fileBytes, configData)
if err != nil {
return MapConfig{}, err
}
return NewMapConfig(configData), nil
}
func NewMapConfig(data map[string]interface{}) MapConfig {
if data == nil {
data = make(map[string]interface{})
}
return MapConfig{
required: make(map[string]struct{}),
data: data,
}
}
func (cfg MapConfig) Get(key string) interface{} {
if _, ok := cfg.required[key]; ok {
PanicSanity(Fmt("config key %v is required but was not set.", key))
}
return cfg.data[key]
}
func (cfg MapConfig) GetBool(key string) bool { return cfg.Get(key).(bool) }
func (cfg MapConfig) GetFloat64(key string) float64 { return cfg.Get(key).(float64) }
func (cfg MapConfig) GetInt(key string) int { return cfg.Get(key).(int) }
func (cfg MapConfig) GetString(key string) string { return cfg.Get(key).(string) }
func (cfg MapConfig) GetStringMap(key string) map[string]interface{} {
return cfg.Get(key).(map[string]interface{})
}
func (cfg MapConfig) GetStringMapString(key string) map[string]string {
return cfg.Get(key).(map[string]string)
}
func (cfg MapConfig) GetStringSlice(key string) []string { return cfg.Get(key).([]string) }
func (cfg MapConfig) GetTime(key string) time.Time { return cfg.Get(key).(time.Time) }
func (cfg MapConfig) IsSet(key string) bool { _, ok := cfg.data[key]; return ok }
func (cfg MapConfig) Set(key string, value interface{}) {
delete(cfg.required, key)
cfg.data[key] = value
}
func (cfg MapConfig) SetDefault(key string, value interface{}) {
delete(cfg.required, key)
if cfg.IsSet(key) {
return
}
cfg.data[key] = value
}
func (cfg MapConfig) SetRequired(key string) {
if cfg.IsSet(key) {
return
}
cfg.required[key] = struct{}{}
}
//--------------------------------------------------------------------------------
// A little convenient hack to notify listeners upon config changes.
type Configurable func(Config)
var mtx sync.Mutex
var globalConfig Config
var confs []Configurable
func OnConfig(conf func(Config)) {
mtx.Lock()
defer mtx.Unlock()
confs = append(confs, conf)
if globalConfig != nil {
conf(globalConfig)
}
}
func ApplyConfig(config Config) {
mtx.Lock()
globalConfig = config
confsCopy := make([]Configurable, len(confs))
copy(confsCopy, confs)
mtx.Unlock()
for _, conf := range confsCopy {
conf(config)
}
}

+ 1
- 1
consensus/reactor.go View File

@ -92,7 +92,7 @@ func (conR *ConsensusReactor) GetChannels() []*p2p.ChannelDescriptor {
},
&p2p.ChannelDescriptor{
ID: DataChannel, // maybe split between gossiping current block and catchup stuff
Priority: 200, // once we gossip the whole block there's nothing left to send until next height or round
Priority: 10, // once we gossip the whole block there's nothing left to send until next height or round
SendQueueCapacity: 100,
RecvBufferCapacity: 50 * 4096,
},


+ 0
- 2
consensus/replay_test.go View File

@ -80,8 +80,6 @@ func TestReplayCatchup(t *testing.T) {
// start timeout and receive routines
cs.startRoutines(0)
// cs.scheduleRound0(cs.Height)
// open wal and run catchup messages
openWAL(t, cs, name)
if err := cs.catchupReplay(cs.Height); err != nil {


+ 3
- 3
mempool/mempool.go View File

@ -201,12 +201,12 @@ func (mem *Mempool) Reap(maxTxs int) []types.Tx {
return txs
}
// maxTxs: 0 means uncapped, -1 means none
// maxTxs: -1 means uncapped, 0 means none
func (mem *Mempool) collectTxs(maxTxs int) []types.Tx {
if maxTxs == 0 {
maxTxs = mem.txs.Len()
} else if maxTxs < 0 {
return []types.Tx{}
} else if maxTxs < 0 {
maxTxs = mem.txs.Len()
}
txs := make([]types.Tx, 0, MinInt(mem.txs.Len(), maxTxs))
for e := mem.txs.Front(); e != nil && len(txs) < maxTxs; e = e.Next() {


+ 1
- 1
mempool/mempool_test.go View File

@ -48,7 +48,7 @@ func TestSerialReap(t *testing.T) {
}
reapCheck := func(exp int) {
txs := mempool.Reap(0)
txs := mempool.Reap(-1)
if len(txs) != exp {
t.Fatalf("Expected to reap %v txs but got %v", exp, len(txs))
}


+ 0
- 6
types/part_set.go View File

@ -231,12 +231,6 @@ func (ps *PartSet) GetReader() io.Reader {
PanicSanity("Cannot GetReader() on incomplete PartSet")
}
return NewPartSetReader(ps.parts)
buf := []byte{}
for _, part := range ps.parts {
buf = append(buf, part.Bytes...)
}
return bytes.NewReader(buf)
}
type PartSetReader struct {


+ 1
- 1
types/tx.go View File

@ -15,7 +15,7 @@ func (txs Txs) Hash() []byte {
case 0:
return nil
case 1:
return txs[0]
return merkle.SimpleHashFromBinary(txs[0])
default:
left := Txs(txs[:(len(txs)+1)/2]).Hash()
right := Txs(txs[(len(txs)+1)/2:]).Hash()


Loading…
Cancel
Save