// WALGenerateNBlocks generates a consensus WAL. It does this by spinning up a
// stripped down version of node (proxy app, event bus, consensus state) with a
// persistent kvstore application and special consensus wal instance
// (byteBufferWAL) and waits until numBlocks are created. If the node fails to produce given numBlocks, it returns an error.
WALGenerateNBlocks generates a consensus WAL. It does this by spinning up a
stripped down version of node (proxy app, event bus, consensus state) with a
persistent kvstore application and special consensus wal instance
(byteBufferWAL) and waits until numBlocks are created. If the node fails to produce given numBlocks, it returns an error.
// WALGenerateNBlocks generates a consensus WAL . It does this by spinning up a // stripped down version of node ( proxy app event bus consensus state ) with a // persistent kvstore application and special consensus wal instance // ( byteBufferWAL ) and waits until numBlocks are created . If the node fails to produce given numBlocks it returns an error .
func WALGenerateNBlocks(t *testing.T, wr io.Writer, numBlocks int) (err error) {
	config := getConfig(t)
	app := kvstore.NewPersistentKVStoreApplication(filepath.Join(config.DBDir(), "wal_generator"))
	logger := log.TestingLogger().With("wal_generator", "wal_generator")
	logger.Info("generating WAL (last height msg excluded)", "numBlocks", numBlocks)
	privValidatorKeyFile := config.PrivValidatorKeyFile()
	privValidatorStateFile := config.PrivValidatorStateFile()
	privValidator := privval.LoadOrGenFilePV(privValidatorKeyFile, privValidatorStateFile)
	genDoc, err := types.GenesisDocFromFile(config.GenesisFile())
	if err != nil {
		return errors.Wrap(err, "failed to read genesis file")
	}
	blockStoreDB := db.NewMemDB()
	stateDB := blockStoreDB
	state, err := sm.MakeGenesisState(genDoc)
	if err != nil {
		return errors.Wrap(err, "failed to make genesis state")
	}
	state.Version.Consensus.App = kvstore.ProtocolVersion
	sm.SaveState(stateDB, state)
	blockStore := store.NewBlockStore(blockStoreDB)
	proxyApp := proxy.NewAppConns(proxy.NewLocalClientCreator(app))
	proxyApp.SetLogger(logger.With("module", "proxy"))
	if err := proxyApp.Start(); err != nil {
		return errors.Wrap(err, "failed to start proxy app connections")
	}
	defer proxyApp.Stop()
	eventBus := types.NewEventBus()
	eventBus.SetLogger(logger.With("module", "events"))
	if err := eventBus.Start(); err != nil {
		return errors.Wrap(err, "failed to start event bus")
	}
	defer eventBus.Stop()
	mempool := mock.Mempool{}
	evpool := sm.MockEvidencePool{}
	blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyApp.Consensus(), mempool, evpool)
	consensusState := NewConsensusState(config.Consensus, state.Copy(), blockExec, blockStore, mempool, evpool)
	consensusState.SetLogger(logger)
	consensusState.SetEventBus(eventBus)
	if privValidator != nil {
		consensusState.SetPrivValidator(privValidator)
	}
	numBlocksWritten := make(chan struct{})
	wal := newByteBufferWAL(logger, NewWALEncoder(wr), int64(numBlocks), numBlocksWritten)
	wal.Write(EndHeightMessage{0})
	consensusState.wal = wal
	if err := consensusState.Start(); err != nil {
		return errors.Wrap(err, "failed to start consensus state")
	}
	select {
	case <-numBlocksWritten:
		consensusState.Stop()
		return nil
	case <-time.After(1 * time.Minute):
		consensusState.Stop()
		return fmt.Errorf("waited too long for tendermint to produce %d blocks (grep logs for `wal_generator`)", numBlocks)
	}
}
func WALGenerateNBlocks ( t * testing . T , wr io . Writer , numBlocks int ) ( err error ) { config := getConfig ( t ) app := kvstore . NewPersistentKVStoreApplication ( filepath . Join ( config . DBDir ( ) , " " ) ) logger := log . TestingLogger ( ) . With ( " " , " " ) logger . Info ( " " , " " , numBlocks ) privValidatorKeyFile := config . PrivValidatorKeyFile ( ) privValidatorStateFile := config . PrivValidatorStateFile ( ) privValidator := privval . LoadOrGenFilePV ( privValidatorKeyFile , privValidatorStateFile ) genDoc , err := types . GenesisDocFromFile ( config . GenesisFile ( ) ) if err != nil { return errors . Wrap ( err , " " ) } blockStoreDB := db . NewMemDB ( ) stateDB := blockStoreDB state , err := sm . MakeGenesisState ( genDoc ) if err != nil { return errors . Wrap ( err , " " ) } state . Version . Consensus . App = kvstore . ProtocolVersion sm . SaveState ( stateDB , state ) blockStore := store . NewBlockStore ( blockStoreDB ) proxyApp := proxy . NewAppConns ( proxy . NewLocalClientCreator ( app ) ) proxyApp . SetLogger ( logger . With ( " " , " " ) ) if err := proxyApp . Start ( ) ; err != nil { return errors . Wrap ( err , " " ) } defer proxyApp . Stop ( ) eventBus := types . NewEventBus ( ) eventBus . SetLogger ( logger . With ( " " , " " ) ) if err := eventBus . Start ( ) ; err != nil { return errors . Wrap ( err , " " ) } defer eventBus . Stop ( ) mempool := mock . Mempool { } evpool := sm . MockEvidencePool { } blockExec := sm . NewBlockExecutor ( stateDB , log . TestingLogger ( ) , proxyApp . Consensus ( ) , mempool , evpool ) consensusState := NewConsensusState ( config . Consensus , state . Copy ( ) , blockExec , blockStore , mempool , evpool ) consensusState . SetLogger ( logger ) consensusState . SetEventBus ( eventBus ) if privValidator != nil { consensusState . SetPrivValidator ( privValidator ) } numBlocksWritten := make ( chan struct { } ) wal := newByteBufferWAL ( logger , NewWALEncoder ( wr ) , int64 ( numBlocks ) , numBlocksWritten ) wal . Write ( EndHeightMessage { 0 } ) consensusState . wal = wal if err := consensusState . Start ( ) ; err != nil { return errors . Wrap ( err , " " ) } select { case <- numBlocksWritten : consensusState . Stop ( ) return nil case <- time . After ( 1 * time . Minute ) : consensusState . Stop ( ) return fmt . Errorf ( " " , numBlocks ) } }
WALGenerateNBlocks generates a consensus WAL.
WALGenerateNBlocks generates a consensus WAL .
///////////////////////////////////////////////////////////////////////////// // COPY PASTE FROM node.go WITH A FEW MODIFICATIONS // NOTE: we can't import node package because of circular dependency. // NOTE: we don't do handshake so need to set state.Version.Consensus.App directly. // END OF COPY PASTE ///////////////////////////////////////////////////////////////////////////// // set consensus wal to buffered WAL, which will write all incoming msgs to buffer // see wal.go#103