diff --git a/blockchain/v2/reactor.go b/blockchain/v2/reactor.go index 88ec6268d..ff89ee94c 100644 --- a/blockchain/v2/reactor.go +++ b/blockchain/v2/reactor.go @@ -187,12 +187,12 @@ func NewBlockchainReactor( // SetSwitch implements Reactor interface. func (r *BlockchainReactor) SetSwitch(sw *p2p.Switch) { - if sw == nil { - panic("set nil switch") - } - r.Switch = sw - r.io = newSwitchIo(sw) + if sw != nil { + r.io = newSwitchIo(sw) + } else { + r.io = nil + } } func (r *BlockchainReactor) setMaxPeerHeight(height int64) { diff --git a/blockchain/v2/reactor_test.go b/blockchain/v2/reactor_test.go index 0b5f0b388..10b1d23df 100644 --- a/blockchain/v2/reactor_test.go +++ b/blockchain/v2/reactor_test.go @@ -411,6 +411,22 @@ func TestReactorHelperMode(t *testing.T) { } } +func TestReactorSetSwitchNil(t *testing.T) { + config := cfg.ResetTestRoot("blockchain_reactor_v2_test") + defer os.RemoveAll(config.RootDir) + genDoc, privVals := randGenesisDoc(config.ChainID(), 1, false, 30) + + reactor := newTestReactor(testReactorParams{ + logger: log.TestingLogger(), + genDoc: genDoc, + privVals: privVals, + }) + reactor.SetSwitch(nil) + + assert.Nil(t, reactor.Switch) + assert.Nil(t, reactor.io) +} + //---------------------------------------------- // utility funcs