Disable view change optionally

-disable_view_change flag controls the behavior.  Default is enable view
change.
pull/913/head
Eugene Kim 6 years ago
parent edc5e66bec
commit f5d1ddcce1
  1. 7
      cmd/harmony/main.go
  2. 13
      consensus/consensus.go
  3. 3
      consensus/view_change.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}

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

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

Loading…
Cancel
Save