diff --git a/config/config.go b/config/config.go deleted file mode 100644 index 21c6b81f8..000000000 --- a/config/config.go +++ /dev/null @@ -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) - } -} diff --git a/consensus/reactor.go b/consensus/reactor.go index b97a45a2d..98f6510dd 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -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, }, diff --git a/consensus/replay_test.go b/consensus/replay_test.go index 044bb96cc..d46f68cd1 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -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 { diff --git a/mempool/mempool.go b/mempool/mempool.go index 0fab674bf..6df62feee 100644 --- a/mempool/mempool.go +++ b/mempool/mempool.go @@ -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() { diff --git a/mempool/mempool_test.go b/mempool/mempool_test.go index 750f987da..a15496962 100644 --- a/mempool/mempool_test.go +++ b/mempool/mempool_test.go @@ -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)) } diff --git a/types/part_set.go b/types/part_set.go index c3e34cba3..bdf198d94 100644 --- a/types/part_set.go +++ b/types/part_set.go @@ -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 { diff --git a/types/tx.go b/types/tx.go index 63a7afad4..60699d534 100644 --- a/types/tx.go +++ b/types/tx.go @@ -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()