Browse Source

consensus: fix tests

pull/484/head
Ethan Buchman 8 years ago
parent
commit
92bafa7ecd
9 changed files with 84 additions and 86 deletions
  1. +3
    -6
      consensus/byzantine_test.go
  2. +33
    -17
      consensus/common_test.go
  3. +4
    -5
      consensus/height_vote_set_test.go
  4. +1
    -2
      consensus/mempool_test.go
  5. +3
    -5
      consensus/reactor_test.go
  6. +18
    -22
      consensus/replay_test.go
  7. +2
    -9
      consensus/state.go
  8. +14
    -15
      consensus/state_test.go
  9. +6
    -5
      p2p/switch.go

+ 3
- 6
consensus/byzantine_test.go View File

@ -5,9 +5,6 @@ import (
"testing"
"time"
"github.com/spf13/viper"
"github.com/tendermint/tendermint/config/tendermint_test"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types"
. "github.com/tendermint/tmlibs/common"
@ -15,7 +12,7 @@ import (
)
func init() {
config = tendermint_test.ResetConfig("consensus_byzantine_test")
config = ResetConfig("consensus_byzantine_test")
}
//----------------------------------------------
@ -36,7 +33,7 @@ func TestByzantine(t *testing.T) {
switches := make([]*p2p.Switch, N)
for i := 0; i < N; i++ {
switches[i] = p2p.NewSwitch(viper.New())
switches[i] = p2p.NewSwitch(config.P2P)
}
reactors := make([]p2p.Reactor, N)
@ -80,7 +77,7 @@ func TestByzantine(t *testing.T) {
reactors[i] = conRI
}
p2p.MakeConnectedSwitches(N, func(i int, s *p2p.Switch) *p2p.Switch {
p2p.MakeConnectedSwitches(config.P2P, N, func(i int, s *p2p.Switch) *p2p.Switch {
// ignore new switch s, we already made ours
switches[i].AddReactor("CONSENSUS", reactors[i])
return switches[i]


+ 33
- 17
consensus/common_test.go View File

@ -11,11 +11,10 @@ import (
"testing"
"time"
"github.com/spf13/viper"
abcicli "github.com/tendermint/abci/client"
abci "github.com/tendermint/abci/types"
bc "github.com/tendermint/tendermint/blockchain"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/config/tendermint_test"
mempl "github.com/tendermint/tendermint/mempool"
"github.com/tendermint/tendermint/p2p"
@ -29,7 +28,7 @@ import (
)
// genesis, chain_id, priv_val
var config *viper.Viper // NOTE: must be reset for each _test.go file
var config *NodeConfig // NOTE: must be reset for each _test.go file
var ensureTimeout = time.Duration(2)
func ensureDir(dir string, mode os.FileMode) {
@ -38,6 +37,23 @@ func ensureDir(dir string, mode os.FileMode) {
}
}
type NodeConfig struct {
cfg.Config `mapstructure:",squash"`
P2P *p2p.Config `mapstructure:"p2p"`
Mempool *mempl.Config `mapstructure:"mempool"`
Consensus *Config `mapstructure:"consensus"`
}
// TODO: This is the same as NodeConfig. Should we move the configs to types (?)
func ResetConfig(name string) *NodeConfig {
viperConfig := tendermint_test.ResetConfig(name)
config := new(NodeConfig)
if err := viperConfig.Unmarshal(config); err != nil {
panic(err)
}
return config
}
//-------------------------------------------------------------------------------
// validator stub (a dummy consensus peer we control)
@ -66,7 +82,7 @@ func (vs *validatorStub) signVote(voteType byte, hash []byte, header types.PartS
Type: voteType,
BlockID: types.BlockID{hash, header},
}
err := vs.PrivValidator.SignVote(config.GetString("chain_id"), vote)
err := vs.PrivValidator.SignVote(config.ChainID, vote)
return vote, err
}
@ -117,7 +133,7 @@ func decideProposal(cs1 *ConsensusState, vs *validatorStub, height, round int) (
// Make proposal
polRound, polBlockID := cs1.Votes.POLInfo()
proposal = types.NewProposal(height, round, blockParts.Header(), polRound, polBlockID)
if err := vs.SignProposal(config.GetString("chain_id"), proposal); err != nil {
if err := vs.SignProposal(config.ChainID, proposal); err != nil {
panic(err)
}
return
@ -235,7 +251,7 @@ func newConsensusState(state *sm.State, pv *types.PrivValidator, app abci.Applic
return newConsensusStateWithConfig(config, state, pv, app)
}
func newConsensusStateWithConfig(thisConfig *viper.Viper, state *sm.State, pv *types.PrivValidator, app abci.Application) *ConsensusState {
func newConsensusStateWithConfig(thisConfig *NodeConfig, state *sm.State, pv *types.PrivValidator, app abci.Application) *ConsensusState {
// Get BlockStore
blockDB := dbm.NewMemDB()
blockStore := bc.NewBlockStore(blockDB)
@ -246,10 +262,10 @@ func newConsensusStateWithConfig(thisConfig *viper.Viper, state *sm.State, pv *t
proxyAppConnCon := abcicli.NewLocalClient(mtx, app)
// Make Mempool
mempool := mempl.NewMempool(thisConfig, proxyAppConnMem)
mempool := mempl.NewMempool(thisConfig.Mempool, proxyAppConnMem)
// Make ConsensusReactor
cs := NewConsensusState(thisConfig, state, proxyAppConnCon, blockStore, mempool)
cs := NewConsensusState(thisConfig.Consensus, state, proxyAppConnCon, blockStore, mempool)
cs.SetPrivValidator(pv)
evsw := types.NewEventSwitch()
@ -258,8 +274,8 @@ func newConsensusStateWithConfig(thisConfig *viper.Viper, state *sm.State, pv *t
return cs
}
func loadPrivValidator(conf *viper.Viper) *types.PrivValidator {
privValidatorFile := conf.GetString("priv_validator_file")
func loadPrivValidator(config *NodeConfig) *types.PrivValidator {
privValidatorFile := config.PrivValidatorFile
ensureDir(path.Dir(privValidatorFile), 0700)
privValidator := types.LoadOrGenPrivValidator(privValidatorFile)
privValidator.Reset()
@ -268,7 +284,7 @@ func loadPrivValidator(conf *viper.Viper) *types.PrivValidator {
func fixedConsensusState() *ConsensusState {
stateDB := dbm.NewMemDB()
state := sm.MakeGenesisStateFromFile(stateDB, config.GetString("genesis_file"))
state := sm.MakeGenesisStateFromFile(stateDB, config.GenesisFile)
privValidator := loadPrivValidator(config)
cs := newConsensusState(state, privValidator, counter.NewCounterApplication(true))
return cs
@ -276,7 +292,7 @@ func fixedConsensusState() *ConsensusState {
func fixedConsensusStateDummy() *ConsensusState {
stateDB := dbm.NewMemDB()
state := sm.MakeGenesisStateFromFile(stateDB, config.GetString("genesis_file"))
state := sm.MakeGenesisStateFromFile(stateDB, config.GenesisFile)
privValidator := loadPrivValidator(config)
cs := newConsensusState(state, privValidator, dummy.NewDummyApplication())
return cs
@ -321,8 +337,8 @@ func randConsensusNet(nValidators int, testName string, tickerFunc func() Timeou
db := dbm.NewMemDB() // each state needs its own db
state := sm.MakeGenesisState(db, genDoc)
state.Save()
thisConfig := tendermint_test.ResetConfig(Fmt("%s_%d", testName, i))
ensureDir(path.Dir(thisConfig.GetString("cs_wal_file")), 0700) // dir for wal
thisConfig := ResetConfig(Fmt("%s_%d", testName, i))
ensureDir(path.Dir(thisConfig.Consensus.WalFile), 0700) // dir for wal
css[i] = newConsensusStateWithConfig(thisConfig, state, privVals[i], appFunc())
css[i].SetTimeoutTicker(tickerFunc())
}
@ -337,8 +353,8 @@ func randConsensusNetWithPeers(nValidators, nPeers int, testName string, tickerF
db := dbm.NewMemDB() // each state needs its own db
state := sm.MakeGenesisState(db, genDoc)
state.Save()
thisConfig := tendermint_test.ResetConfig(Fmt("%s_%d", testName, i))
ensureDir(path.Dir(thisConfig.GetString("cs_wal_file")), 0700) // dir for wal
thisConfig := ResetConfig(Fmt("%s_%d", testName, i))
ensureDir(path.Dir(thisConfig.Consensus.WalFile), 0700) // dir for wal
var privVal *types.PrivValidator
if i < nValidators {
privVal = privVals[i]
@ -381,7 +397,7 @@ func randGenesisDoc(numValidators int, randPower bool, minPower int64) (*types.G
sort.Sort(types.PrivValidatorsByAddress(privValidators))
return &types.GenesisDoc{
GenesisTime: time.Now(),
ChainID: config.GetString("chain_id"),
ChainID: config.ChainID,
Validators: validators,
}, privValidators
}


+ 4
- 5
consensus/height_vote_set_test.go View File

@ -3,19 +3,18 @@ package consensus
import (
"testing"
. "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tendermint/config/tendermint_test"
"github.com/tendermint/tendermint/types"
. "github.com/tendermint/tmlibs/common"
)
func init() {
config = tendermint_test.ResetConfig("consensus_height_vote_set_test")
config = ResetConfig("consensus_height_vote_set_test")
}
func TestPeerCatchupRounds(t *testing.T) {
valSet, privVals := types.RandValidatorSet(10, 1)
hvs := NewHeightVoteSet(config.GetString("chain_id"), 1, valSet)
hvs := NewHeightVoteSet(config.ChainID, 1, valSet)
vote999_0 := makeVoteHR(t, 1, 999, privVals, 0)
added, err := hvs.AddVote(vote999_0, "peer1")
@ -52,7 +51,7 @@ func makeVoteHR(t *testing.T, height, round int, privVals []*types.PrivValidator
Type: types.VoteTypePrecommit,
BlockID: types.BlockID{[]byte("fakehash"), types.PartSetHeader{}},
}
chainID := config.GetString("chain_id")
chainID := config.ChainID
err := privVal.SignVote(chainID, vote)
if err != nil {
panic(Fmt("Error signing vote: %v", err))


+ 1
- 2
consensus/mempool_test.go View File

@ -6,14 +6,13 @@ import (
"time"
abci "github.com/tendermint/abci/types"
"github.com/tendermint/tendermint/config/tendermint_test"
"github.com/tendermint/tendermint/types"
. "github.com/tendermint/tmlibs/common"
)
func init() {
config = tendermint_test.ResetConfig("consensus_mempool_test")
config = ResetConfig("consensus_mempool_test")
}
func TestTxConcurrentWithCommit(t *testing.T) {


+ 3
- 5
consensus/reactor_test.go View File

@ -6,8 +6,6 @@ import (
"testing"
"time"
"github.com/tendermint/tendermint/config/tendermint_test"
"github.com/tendermint/abci/example/dummy"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types"
@ -15,7 +13,7 @@ import (
)
func init() {
config = tendermint_test.ResetConfig("consensus_reactor_test")
config = ResetConfig("consensus_reactor_test")
}
//----------------------------------------------
@ -41,7 +39,7 @@ func startConsensusNet(t *testing.T, css []*ConsensusState, N int, subscribeEven
}
}
// make connected switches and start all reactors
p2p.MakeConnectedSwitches(N, func(i int, s *p2p.Switch) *p2p.Switch {
p2p.MakeConnectedSwitches(config.P2P, N, func(i int, s *p2p.Switch) *p2p.Switch {
s.AddReactor("CONSENSUS", reactors[i])
return s
}, p2p.Connect2Switches)
@ -236,7 +234,7 @@ func TestReactorWithTimeoutCommit(t *testing.T) {
css := randConsensusNet(N, "consensus_reactor_with_timeout_commit_test", newMockTickerFunc(false), newCounter)
// override default SkipTimeoutCommit == true for tests
for i := 0; i < N; i++ {
css[i].timeoutParams.SkipTimeoutCommit = false
css[i].config.SkipTimeoutCommit = false
}
reactors, eventChans := startConsensusNet(t, css, N-1, false)


+ 18
- 22
consensus/replay_test.go View File

@ -12,12 +12,9 @@ import (
"testing"
"time"
"github.com/spf13/viper"
"github.com/tendermint/abci/example/dummy"
"github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire"
"github.com/tendermint/tendermint/config/tendermint_test"
"github.com/tendermint/tendermint/proxy"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types"
@ -26,7 +23,7 @@ import (
)
func init() {
config = tendermint_test.ResetConfig("consensus_replay_test")
config = ResetConfig("consensus_replay_test")
}
// These tests ensure we can always recover from failure at any part of the consensus process.
@ -136,7 +133,7 @@ func waitForBlock(newBlockCh chan interface{}, thisCase *testCase, i int) {
func runReplayTest(t *testing.T, cs *ConsensusState, walFile string, newBlockCh chan interface{},
thisCase *testCase, i int) {
cs.config.Set("cs_wal_file", walFile)
cs.config.WalFile = walFile
started, err := cs.Start()
if err != nil {
t.Fatalf("Cannot start consensus: %v", err)
@ -309,7 +306,7 @@ func TestHandshakeReplayNone(t *testing.T) {
// Make some blocks. Start a fresh app and apply nBlocks blocks. Then restart the app and sync it up with the remaining blocks
func testHandshakeReplay(t *testing.T, nBlocks int, mode uint) {
config := tendermint_test.ResetConfig("proxy_test_")
config := ResetConfig("proxy_test_")
// copy the many_blocks file
walBody, err := cmn.ReadFile(path.Join(data_dir, "many_blocks.cswal"))
@ -317,10 +314,10 @@ func testHandshakeReplay(t *testing.T, nBlocks int, mode uint) {
t.Fatal(err)
}
walFile := writeWAL(string(walBody))
config.Set("cs_wal_file", walFile)
config.Consensus.WalFile = walFile
privVal := types.LoadPrivValidator(config.GetString("priv_validator_file"))
testPartSize = config.GetInt("block_part_size")
privVal := types.LoadPrivValidator(config.PrivValidatorFile)
testPartSize = config.Consensus.BlockPartSize
wal, err := NewWAL(walFile, false)
if err != nil {
@ -339,19 +336,19 @@ func testHandshakeReplay(t *testing.T, nBlocks int, mode uint) {
latestAppHash := buildTMStateFromChain(config, state, chain, mode)
// make a new client creator
dummyApp := dummy.NewPersistentDummyApplication(path.Join(config.GetString("db_dir"), "2"))
dummyApp := dummy.NewPersistentDummyApplication(path.Join(config.DBDir, "2"))
clientCreator2 := proxy.NewLocalClientCreator(dummyApp)
if nBlocks > 0 {
// run nBlocks against a new client to build up the app state.
// use a throwaway tendermint state
proxyApp := proxy.NewAppConns(config, clientCreator2, nil)
proxyApp := proxy.NewAppConns(clientCreator2, nil)
state, _ := stateAndStore(config, privVal.PubKey)
buildAppStateFromChain(proxyApp, state, chain, nBlocks, mode)
}
// now start the app using the handshake - it should sync
handshaker := NewHandshaker(config, state, store)
proxyApp := proxy.NewAppConns(config, clientCreator2, handshaker)
handshaker := NewHandshaker(state, store)
proxyApp := proxy.NewAppConns(clientCreator2, handshaker)
if _, err := proxyApp.Start(); err != nil {
t.Fatalf("Error starting proxy app connections: %v", err)
}
@ -418,10 +415,10 @@ func buildAppStateFromChain(proxyApp proxy.AppConns,
}
func buildTMStateFromChain(config *viper.Viper, state *sm.State, chain []*types.Block, mode uint) []byte {
func buildTMStateFromChain(config *NodeConfig, state *sm.State, chain []*types.Block, mode uint) []byte {
// run the whole chain against this client to build up the tendermint state
clientCreator := proxy.NewLocalClientCreator(dummy.NewPersistentDummyApplication(path.Join(config.GetString("db_dir"), "1")))
proxyApp := proxy.NewAppConns(config, clientCreator, nil) // sm.NewHandshaker(config, state, store, ReplayLastBlock))
clientCreator := proxy.NewLocalClientCreator(dummy.NewPersistentDummyApplication(path.Join(config.DBDir, "1")))
proxyApp := proxy.NewAppConns(clientCreator, nil) // sm.NewHandshaker(config, state, store, ReplayLastBlock))
if _, err := proxyApp.Start(); err != nil {
panic(err)
}
@ -615,10 +612,9 @@ func makeBlockchain(t *testing.T, chainID string, nBlocks int, privVal *types.Pr
}
// fresh state and mock store
func stateAndStore(config *viper.Viper, pubKey crypto.PubKey) (*sm.State, *mockBlockStore) {
func stateAndStore(config *NodeConfig, pubKey crypto.PubKey) (*sm.State, *mockBlockStore) {
stateDB := dbm.NewMemDB()
state := sm.MakeGenesisStateFromFile(stateDB, config.GetString("genesis_file"))
state := sm.MakeGenesisStateFromFile(stateDB, config.GenesisFile())
store := NewMockBlockStore(config)
return state, store
}
@ -627,13 +623,13 @@ func stateAndStore(config *viper.Viper, pubKey crypto.PubKey) (*sm.State, *mockB
// mock block store
type mockBlockStore struct {
config *viper.Viper
config *NodeConfig
chain []*types.Block
commits []*types.Commit
}
// TODO: NewBlockStore(db.NewMemDB) ...
func NewMockBlockStore(config *viper.Viper) *mockBlockStore {
func NewMockBlockStore(config *NodeConfig) *mockBlockStore {
return &mockBlockStore{config, nil, nil}
}
@ -642,7 +638,7 @@ func (bs *mockBlockStore) LoadBlock(height int) *types.Block { return bs.chain[h
func (bs *mockBlockStore) LoadBlockMeta(height int) *types.BlockMeta {
block := bs.chain[height-1]
return &types.BlockMeta{
BlockID: types.BlockID{block.Hash(), block.MakePartSet(bs.config.GetInt("block_part_size")).Header()},
BlockID: types.BlockID{block.Hash(), block.MakePartSet(bs.config.Consensus.BlockPartSize).Header()},
Header: block.Header,
}
}


+ 2
- 9
consensus/state.go View File

@ -46,8 +46,6 @@ type Config struct {
// TODO: This probably shouldn't be exposed but it makes it
// easy to write tests for the wal/replay
BlockPartSize int `mapstructure:"block_part_size"`
chainID string
}
func NewDefaultConfig(rootDir string) *Config {
@ -81,10 +79,6 @@ func NewTestConfig(rootDir string) *Config {
return config
}
func (cfg *Config) SetChainID(chainID string) {
cfg.chainID = chainID
}
// Wait this long for a proposal
func (cfg *Config) Propose(round int) time.Duration {
return time.Duration(cfg.TimeoutPropose+cfg.TimeoutProposeDelta*round) * time.Millisecond
@ -302,7 +296,6 @@ type ConsensusState struct {
}
func NewConsensusState(config *Config, state *sm.State, proxyAppConn proxy.AppConnConsensus, blockStore types.BlockStore, mempool types.Mempool) *ConsensusState {
config.chainID = state.ChainID // Set ChainID
cs := &ConsensusState{
config: config,
proxyAppConn: proxyAppConn,
@ -558,7 +551,7 @@ func (cs *ConsensusState) reconstructLastCommit(state *sm.State) {
return
}
seenCommit := cs.blockStore.LoadSeenCommit(state.LastBlockHeight)
lastPrecommits := types.NewVoteSet(cs.config.chainID, state.LastBlockHeight, seenCommit.Round(), types.VoteTypePrecommit, state.LastValidators)
lastPrecommits := types.NewVoteSet(cs.state.ChainID, state.LastBlockHeight, seenCommit.Round(), types.VoteTypePrecommit, state.LastValidators)
for _, precommit := range seenCommit.Precommits {
if precommit == nil {
continue
@ -629,7 +622,7 @@ func (cs *ConsensusState) updateToState(state *sm.State) {
cs.LockedRound = 0
cs.LockedBlock = nil
cs.LockedBlockParts = nil
cs.Votes = NewHeightVoteSet(cs.config.chainID, height, validators)
cs.Votes = NewHeightVoteSet(state.ChainID, height, validators)
cs.CommitRound = -1
cs.LastCommit = lastPrecommits
cs.LastValidators = state.LastValidators


+ 14
- 15
consensus/state_test.go View File

@ -6,17 +6,16 @@ import (
"testing"
"time"
"github.com/tendermint/tendermint/config/tendermint_test"
"github.com/tendermint/tendermint/types"
. "github.com/tendermint/tmlibs/common"
)
func init() {
config = tendermint_test.ResetConfig("consensus_state_test")
config = ResetConfig("consensus_state_test")
}
func (tp *TimeoutParams) ensureProposeTimeout() time.Duration {
return time.Duration(tp.Propose0*2) * time.Millisecond
func (config *Config) ensureProposeTimeout() time.Duration {
return time.Duration(config.TimeoutPropose*2) * time.Millisecond
}
/*
@ -126,7 +125,7 @@ func TestEnterProposeNoPrivValidator(t *testing.T) {
startTestRound(cs, height, round)
// if we're not a validator, EnterPropose should timeout
ticker := time.NewTicker(cs.timeoutParams.ensureProposeTimeout())
ticker := time.NewTicker(cs.config.ensureProposeTimeout())
select {
case <-timeoutCh:
case <-ticker.C:
@ -167,7 +166,7 @@ func TestEnterProposeYesPrivValidator(t *testing.T) {
}
// if we're a validator, enterPropose should not timeout
ticker := time.NewTicker(cs.timeoutParams.ensureProposeTimeout())
ticker := time.NewTicker(cs.config.ensureProposeTimeout())
select {
case <-timeoutCh:
panic("Expected EnterPropose not to timeout")
@ -181,7 +180,7 @@ func TestBadProposal(t *testing.T) {
height, round := cs1.Height, cs1.Round
vs2 := vss[1]
partSize := config.GetInt("block_part_size")
partSize := config.Consensus.BlockPartSize
proposalCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringCompleteProposal(), 1)
voteCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringVote(), 1)
@ -201,7 +200,7 @@ func TestBadProposal(t *testing.T) {
propBlock.AppHash = stateHash
propBlockParts := propBlock.MakePartSet(partSize)
proposal := types.NewProposal(vs2.Height, round, propBlockParts.Header(), -1, types.BlockID{})
if err := vs2.SignProposal(config.GetString("chain_id"), proposal); err != nil {
if err := vs2.SignProposal(config.ChainID, proposal); err != nil {
t.Fatal("failed to sign bad proposal", err)
}
@ -328,7 +327,7 @@ func TestLockNoPOL(t *testing.T) {
vs2 := vss[1]
height := cs1.Height
partSize := config.GetInt("block_part_size")
partSize := config.Consensus.BlockPartSize
timeoutProposeCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutPropose(), 1)
timeoutWaitCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutWait(), 1)
@ -494,7 +493,7 @@ func TestLockPOLRelock(t *testing.T) {
cs1, vss := randConsensusState(4)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
partSize := config.GetInt("block_part_size")
partSize := config.Consensus.BlockPartSize
timeoutProposeCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutPropose(), 1)
timeoutWaitCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutWait(), 1)
@ -606,7 +605,7 @@ func TestLockPOLUnlock(t *testing.T) {
cs1, vss := randConsensusState(4)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
partSize := config.GetInt("block_part_size")
partSize := config.Consensus.BlockPartSize
proposalCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringCompleteProposal(), 1)
timeoutProposeCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutPropose(), 1)
@ -701,7 +700,7 @@ func TestLockPOLSafety1(t *testing.T) {
cs1, vss := randConsensusState(4)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
partSize := config.GetInt("block_part_size")
partSize := config.Consensus.BlockPartSize
proposalCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringCompleteProposal(), 1)
timeoutProposeCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutPropose(), 1)
@ -822,7 +821,7 @@ func TestLockPOLSafety2(t *testing.T) {
cs1, vss := randConsensusState(4)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
partSize := config.GetInt("block_part_size")
partSize := config.Consensus.BlockPartSize
proposalCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringCompleteProposal(), 1)
timeoutProposeCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutPropose(), 1)
@ -878,7 +877,7 @@ func TestLockPOLSafety2(t *testing.T) {
// in round 2 we see the polkad block from round 0
newProp := types.NewProposal(height, 2, propBlockParts0.Header(), 0, propBlockID1)
if err := vs3.SignProposal(config.GetString("chain_id"), newProp); err != nil {
if err := vs3.SignProposal(config.ChainID, newProp); err != nil {
t.Fatal(err)
}
cs1.SetProposalAndBlock(newProp, propBlock0, propBlockParts0, "some peer")
@ -997,7 +996,7 @@ func TestHalt1(t *testing.T) {
cs1, vss := randConsensusState(4)
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
partSize := config.GetInt("block_part_size")
partSize := config.Consensus.BlockPartSize
proposalCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringCompleteProposal(), 1)
timeoutWaitCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutWait(), 1)


+ 6
- 5
p2p/switch.go View File

@ -27,7 +27,7 @@ type Config struct {
PexReactor bool `mapstructure:"pex_reactor"`
MaxNumPeers int `mapstructure:"max_num_peers"`
Peer *PeerConfig `mapstructure:"peer"`
peer *PeerConfig // Not exposed
}
func NewDefaultConfig(rootDir string) *Config {
@ -36,7 +36,7 @@ func NewDefaultConfig(rootDir string) *Config {
AddrBookFile: rootDir + "/addrbook.json",
AddrBookStrict: true,
MaxNumPeers: 50,
Peer: DefaultPeerConfig(),
peer: DefaultPeerConfig(),
}
}
@ -103,6 +103,7 @@ var (
)
func NewSwitch(config *Config) *Switch {
config.peer = DefaultPeerConfig()
sw := &Switch{
config: config,
reactors: make(map[string]Reactor),
@ -228,7 +229,7 @@ func (sw *Switch) AddPeer(peer *Peer) error {
return err
}
if err := peer.HandshakeTimeout(sw.nodeInfo, time.Duration(sw.config.Peer.HandshakeTimeout*time.Second)); err != nil {
if err := peer.HandshakeTimeout(sw.nodeInfo, time.Duration(sw.config.peer.HandshakeTimeout*time.Second)); err != nil {
return err
}
@ -337,7 +338,7 @@ func (sw *Switch) DialPeerWithAddress(addr *NetAddress, persistent bool) (*Peer,
sw.dialing.Set(addr.IP.String(), addr)
defer sw.dialing.Delete(addr.IP.String())
peer, err := newOutboundPeerWithConfig(addr, sw.reactorsByCh, sw.chDescs, sw.StopPeerForError, sw.nodePrivKey, sw.config.Peer)
peer, err := newOutboundPeerWithConfig(addr, sw.reactorsByCh, sw.chDescs, sw.StopPeerForError, sw.nodePrivKey, sw.config.peer)
if err != nil {
log.Info("Failed dialing peer", "address", addr, "error", err)
return nil, err
@ -456,7 +457,7 @@ func (sw *Switch) listenerRoutine(l Listener) {
}
// New inbound connection!
err := sw.addPeerWithConnectionAndConfig(inConn, sw.config.Peer)
err := sw.addPeerWithConnectionAndConfig(inConn, sw.config.peer)
if err != nil {
log.Notice("Ignoring inbound connection: error while adding peer", "address", inConn.RemoteAddr().String(), "error", err)
continue


Loading…
Cancel
Save