Merge pull request #913 from harmony-ek/disable_vc_again

Disable view change optionally
pull/914/head
Eugene Kim 6 years ago committed by GitHub
commit 444fc05ce1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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 is the database directory.
dbDir = flag.String("db_dir", "", "blockchain 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() { func initSetup() {
@ -267,6 +271,9 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node {
os.Exit(1) os.Exit(1)
} }
currentConsensus.MinPeers = *minPeers currentConsensus.MinPeers = *minPeers
if *disableViewChange {
currentConsensus.DisableViewChangeForTestingOnly()
}
// Current node. // Current node.
chainDBFactory := &shardchain.LDBFactory{RootDir: nodeConfig.DBDir} 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. // Used to convey to the consensus main loop that block syncing has finished.
syncReadyChan chan struct{} syncReadyChan chan struct{}
// If true, this consensus will not propose view change.
disableViewChange bool
} }
// StakeInfoFinder returns the stake information finder instance this // StakeInfoFinder returns the stake information finder instance this
@ -163,6 +166,16 @@ func (consensus *Consensus) SetStakeInfoFinder(stakeInfoFinder StakeInfoFinder)
consensus.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 // BlocksSynchronized lets the main loop know that block synchronization finished
// thus the blockchain is likely to be up to date. // thus the blockchain is likely to be up to date.
func (consensus *Consensus) BlocksSynchronized() { func (consensus *Consensus) BlocksSynchronized() {

@ -138,6 +138,9 @@ func createTimeout() map[string]*utils.Timeout {
// startViewChange send a new view change // startViewChange send a new view change
func (consensus *Consensus) startViewChange(viewID uint32) { func (consensus *Consensus) startViewChange(viewID uint32) {
if consensus.disableViewChange {
return
}
for k := range consensus.consensusTimeout { for k := range consensus.consensusTimeout {
if k != "viewchange" { if k != "viewchange" {
consensus.consensusTimeout[k].Stop() consensus.consensusTimeout[k].Stop()

Loading…
Cancel
Save