示例#1
0
func randGenesisState(numValidators int, randPower bool, minPower int64) (*sm.State, []*types.PrivValidator) {
	db := dbm.NewMemDB()
	genDoc, privValidators := randGenesisDoc(numValidators, randPower, minPower)
	s0 := sm.MakeGenesisState(db, genDoc)
	s0.Save()
	return s0, privValidators
}
示例#2
0
func fixedConsensusState() *ConsensusState {
	stateDB := dbm.NewMemDB()
	state := sm.MakeGenesisStateFromFile(stateDB, config.GetString("genesis_file"))
	privValidatorFile := config.GetString("priv_validator_file")
	privValidator := types.LoadOrGenPrivValidator(privValidatorFile)
	return newConsensusState(state, privValidator, counter.NewCounterApplication(true))

}
示例#3
0
func simpleConsensusState(nValidators int) (*ConsensusState, []*validatorStub) {
	// Get State
	state, privVals := randGenesisState(nValidators, false, 10)

	// fmt.Println(state.Validators)

	vss := make([]*validatorStub, nValidators)

	// make consensus state for lead validator

	// Get BlockStore
	blockDB := dbm.NewMemDB()
	blockStore := bc.NewBlockStore(blockDB)

	// one for mempool, one for consensus
	app := example.NewCounterApplication(false)
	appCMem := app.Open()
	appCCon := app.Open()
	proxyAppCtxMem := proxy.NewLocalAppContext(appCMem)
	proxyAppCtxCon := proxy.NewLocalAppContext(appCCon)

	// Make Mempool
	mempool := mempl.NewMempool(proxyAppCtxMem)

	// Make ConsensusReactor
	cs := NewConsensusState(state, proxyAppCtxCon, blockStore, mempool)
	cs.SetPrivValidator(privVals[0])

	evsw := events.NewEventSwitch()
	cs.SetEventSwitch(evsw)
	evsw.Start()

	// start the transition routines
	//	cs.startRoutines()

	for i := 0; i < nValidators; i++ {
		vss[i] = NewValidatorStub(privVals[i])
	}
	// since cs1 starts at 1
	incrementHeight(vss[1:]...)

	return cs, vss
}
示例#4
0
func newConsensusState(state *sm.State, pv *types.PrivValidator, app tmsp.Application) *ConsensusState {
	// Get BlockStore
	blockDB := dbm.NewMemDB()
	blockStore := bc.NewBlockStore(blockDB)

	// one for mempool, one for consensus
	mtx := new(sync.Mutex)
	proxyAppConnMem := tmspcli.NewLocalClient(mtx, app)
	proxyAppConnCon := tmspcli.NewLocalClient(mtx, app)

	// Make Mempool
	mempool := mempl.NewMempool(config, proxyAppConnMem)

	// Make ConsensusReactor
	cs := NewConsensusState(config, state, proxyAppConnCon, blockStore, mempool)
	cs.SetPrivValidator(pv)

	evsw := events.NewEventSwitch()
	cs.SetEventSwitch(evsw)
	evsw.Start()
	return cs
}