diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 0249ad753..5b2c01230 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -113,6 +113,10 @@ var ( // dbDir is the database directory. dbDir = flag.String("db_dir", "", "blockchain database directory") + + // Disable view change. + disableViewChange = flag.Bool("disable_view_change", false, + "Do not propose view change (testing only)") ) func initSetup() { @@ -267,6 +271,9 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node { os.Exit(1) } currentConsensus.MinPeers = *minPeers + if *disableViewChange { + currentConsensus.DisableViewChangeForTestingOnly() + } // Current node. chainDBFactory := &shardchain.LDBFactory{RootDir: nodeConfig.DBDir} diff --git a/consensus/consensus.go b/consensus/consensus.go index 24b1cdd76..8e20efa4a 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -149,6 +149,9 @@ type Consensus struct { // Used to convey to the consensus main loop that block syncing has finished. syncReadyChan chan struct{} + + // If true, this consensus will not propose view change. + disableViewChange bool } // StakeInfoFinder returns the stake information finder instance this @@ -163,6 +166,16 @@ func (consensus *Consensus) SetStakeInfoFinder(stakeInfoFinder StakeInfoFinder) consensus.stakeInfoFinder = stakeInfoFinder } +// DisableViewChangeForTestingOnly makes the receiver not propose view +// changes when it should, e.g. leader timeout. +// +// As the name implies, this is intended for testing only, +// and should not be used on production network. +// This is also not part of the long-term consensus API and may go away later. +func (consensus *Consensus) DisableViewChangeForTestingOnly() { + consensus.disableViewChange = true +} + // BlocksSynchronized lets the main loop know that block synchronization finished // thus the blockchain is likely to be up to date. func (consensus *Consensus) BlocksSynchronized() { diff --git a/consensus/view_change.go b/consensus/view_change.go index 3968d2584..3a23da9ea 100644 --- a/consensus/view_change.go +++ b/consensus/view_change.go @@ -138,6 +138,9 @@ func createTimeout() map[string]*utils.Timeout { // startViewChange send a new view change func (consensus *Consensus) startViewChange(viewID uint32) { + if consensus.disableViewChange { + return + } for k := range consensus.consensusTimeout { if k != "viewchange" { consensus.consensusTimeout[k].Stop()