Browse Source

blockchain/v2: allow setting nil switch, for CustomReactors()

<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺
v                               ✰  Thanks for creating a PR! ✰    
v    Before smashing the submit button please review the checkboxes.
v    If a checkbox is n/a - please still include it but + a little note why
☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >  -->

Fixes an issue reported in https://github.com/tendermint/tendermint/issues/4595#issuecomment-612667441.

Not sure if this is sufficient to fully remove the reactor, but it fixes the immediate problem.
______

For contributor use:

- [x] Wrote tests
- [x] ~Updated CHANGELOG_PENDING.md~
- [x] Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
- [x] ~Updated relevant documentation (`docs/`) and code comments~
- [x] Re-reviewed `Files changed` in the Github PR explorer
pull/4672/head
Erik Grinaker 4 years ago
committed by GitHub
parent
commit
fb35b474ad
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 5 deletions
  1. +5
    -5
      blockchain/v2/reactor.go
  2. +16
    -0
      blockchain/v2/reactor_test.go

+ 5
- 5
blockchain/v2/reactor.go View File

@ -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) {


+ 16
- 0
blockchain/v2/reactor_test.go View File

@ -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


Loading…
Cancel
Save