diff --git a/consensus/replay_file.go b/consensus/replay_file.go index e4b9f0196..685eb71f2 100644 --- a/consensus/replay_file.go +++ b/consensus/replay_file.go @@ -298,13 +298,18 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo // Create proxyAppConn connection (consensus, mempool, query) clientCreator := proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()) - proxyApp := proxy.NewAppConns(clientCreator, - NewHandshaker(stateDB, state, blockStore, gdoc)) + proxyApp := proxy.NewAppConns(clientCreator) err = proxyApp.Start() if err != nil { cmn.Exit(fmt.Sprintf("Error starting proxy app conns: %v", err)) } + handshaker := NewHandshaker(stateDB, state, blockStore, gdoc) + err = handshaker.Handshake(proxyApp) + if err != nil { + cmn.Exit(fmt.Sprintf("Error on handshake: %v", err)) + } + eventBus := types.NewEventBus() if err := eventBus.Start(); err != nil { cmn.Exit(fmt.Sprintf("Failed to start event bus: %v", err)) diff --git a/consensus/replay_test.go b/consensus/replay_test.go index 44280f694..7a828da64 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -351,7 +351,7 @@ func testHandshakeReplay(t *testing.T, nBlocks int, mode uint) { if nBlocks > 0 { // run nBlocks against a new client to build up the app state. // use a throwaway tendermint state - proxyApp := proxy.NewAppConns(clientCreator2, nil) + proxyApp := proxy.NewAppConns(clientCreator2) stateDB, state, _ := stateAndStore(config, privVal.GetPubKey()) buildAppStateFromChain(proxyApp, stateDB, state, chain, nBlocks, mode) } @@ -359,11 +359,14 @@ func testHandshakeReplay(t *testing.T, nBlocks int, mode uint) { // now start the app using the handshake - it should sync genDoc, _ := sm.MakeGenesisDocFromFile(config.GenesisFile()) handshaker := NewHandshaker(stateDB, state, store, genDoc) - proxyApp := proxy.NewAppConns(clientCreator2, handshaker) + proxyApp := proxy.NewAppConns(clientCreator2) if err := proxyApp.Start(); err != nil { t.Fatalf("Error starting proxy app connections: %v", err) } defer proxyApp.Stop() + if err := handshaker.Handshake(proxyApp); err != nil { + t.Fatalf("Error on abci handshake: %v", err) + } // get the latest app hash from the app res, err := proxyApp.Query().InfoSync(abci.RequestInfo{Version: ""}) @@ -439,7 +442,7 @@ func buildAppStateFromChain(proxyApp proxy.AppConns, stateDB dbm.DB, func buildTMStateFromChain(config *cfg.Config, stateDB dbm.DB, state sm.State, chain []*types.Block, mode uint) sm.State { // run the whole chain against this client to build up the tendermint state clientCreator := proxy.NewLocalClientCreator(kvstore.NewPersistentKVStoreApplication(path.Join(config.DBDir(), "1"))) - proxyApp := proxy.NewAppConns(clientCreator, nil) // sm.NewHandshaker(config, state, store, ReplayLastBlock)) + proxyApp := proxy.NewAppConns(clientCreator) // sm.NewHandshaker(config, state, store, ReplayLastBlock)) if err := proxyApp.Start(); err != nil { panic(err) } @@ -643,11 +646,14 @@ func TestInitChainUpdateValidators(t *testing.T) { // now start the app using the handshake - it should sync genDoc, _ := sm.MakeGenesisDocFromFile(config.GenesisFile()) handshaker := NewHandshaker(stateDB, state, store, genDoc) - proxyApp := proxy.NewAppConns(clientCreator, handshaker) + proxyApp := proxy.NewAppConns(clientCreator) if err := proxyApp.Start(); err != nil { t.Fatalf("Error starting proxy app connections: %v", err) } defer proxyApp.Stop() + if err := handshaker.Handshake(proxyApp); err != nil { + t.Fatalf("Error on abci handshake: %v", err) + } // reload the state, check the validator set was updated state = sm.LoadState(stateDB) diff --git a/consensus/wal_generator.go b/consensus/wal_generator.go index 6d889aa6f..cdb667edf 100644 --- a/consensus/wal_generator.go +++ b/consensus/wal_generator.go @@ -52,13 +52,13 @@ func WALWithNBlocks(numBlocks int) (data []byte, err error) { return nil, errors.Wrap(err, "failed to make genesis state") } blockStore := bc.NewBlockStore(blockStoreDB) - handshaker := NewHandshaker(stateDB, state, blockStore, genDoc) - proxyApp := proxy.NewAppConns(proxy.NewLocalClientCreator(app), handshaker) + proxyApp := proxy.NewAppConns(proxy.NewLocalClientCreator(app)) proxyApp.SetLogger(logger.With("module", "proxy")) if err := proxyApp.Start(); err != nil { return nil, 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 { diff --git a/node/node.go b/node/node.go index 995d1c889..f3dcadf9c 100644 --- a/node/node.go +++ b/node/node.go @@ -190,18 +190,22 @@ func NewNode(config *cfg.Config, return nil, err } - // Create the proxyApp, which manages connections (consensus, mempool, query) - // and sync tendermint and the app by performing a handshake - // and replaying any necessary blocks - consensusLogger := logger.With("module", "consensus") - handshaker := cs.NewHandshaker(stateDB, state, blockStore, genDoc) - handshaker.SetLogger(consensusLogger) - proxyApp := proxy.NewAppConns(clientCreator, handshaker) + // Create the proxyApp and establish connections to the ABCI app (consensus, mempool, query). + proxyApp := proxy.NewAppConns(clientCreator) proxyApp.SetLogger(logger.With("module", "proxy")) if err := proxyApp.Start(); err != nil { return nil, fmt.Errorf("Error starting proxy app connections: %v", err) } + // Create the handshaker, which calls RequestInfo and replays any blocks + // as necessary to sync tendermint with the app. + consensusLogger := logger.With("module", "consensus") + handshaker := cs.NewHandshaker(stateDB, state, blockStore, genDoc) + handshaker.SetLogger(consensusLogger) + if err := handshaker.Handshake(proxyApp); err != nil { + return nil, fmt.Errorf("Error during handshake: %v", err) + } + // reload the state (it may have been updated by the handshake) state = sm.LoadState(stateDB) diff --git a/proxy/multi_app_conn.go b/proxy/multi_app_conn.go index 279fa42ee..b5897d8a5 100644 --- a/proxy/multi_app_conn.go +++ b/proxy/multi_app_conn.go @@ -17,26 +17,19 @@ type AppConns interface { Query() AppConnQuery } -func NewAppConns(clientCreator ClientCreator, handshaker Handshaker) AppConns { - return NewMultiAppConn(clientCreator, handshaker) +func NewAppConns(clientCreator ClientCreator) AppConns { + return NewMultiAppConn(clientCreator) } //----------------------------- // multiAppConn implements AppConns -type Handshaker interface { - Handshake(AppConns) error -} - // a multiAppConn is made of a few appConns (mempool, consensus, query) -// and manages their underlying abci clients, including the handshake -// which ensures the app and tendermint are synced. +// and manages their underlying abci clients // TODO: on app restart, clients must reboot together type multiAppConn struct { cmn.BaseService - handshaker Handshaker - mempoolConn *appConnMempool consensusConn *appConnConsensus queryConn *appConnQuery @@ -45,9 +38,8 @@ type multiAppConn struct { } // Make all necessary abci connections to the application -func NewMultiAppConn(clientCreator ClientCreator, handshaker Handshaker) *multiAppConn { +func NewMultiAppConn(clientCreator ClientCreator) *multiAppConn { multiAppConn := &multiAppConn{ - handshaker: handshaker, clientCreator: clientCreator, } multiAppConn.BaseService = *cmn.NewBaseService(nil, "multiAppConn", multiAppConn) @@ -103,10 +95,5 @@ func (app *multiAppConn) OnStart() error { } app.consensusConn = NewAppConnConsensus(concli) - // ensure app is synced to the latest state - if app.handshaker != nil { - return app.handshaker.Handshake(app) - } - return nil } diff --git a/state/execution_test.go b/state/execution_test.go index 02beeb9b7..e93c9bfd1 100644 --- a/state/execution_test.go +++ b/state/execution_test.go @@ -29,7 +29,7 @@ var ( func TestApplyBlock(t *testing.T) { cc := proxy.NewLocalClientCreator(kvstore.NewKVStoreApplication()) - proxyApp := proxy.NewAppConns(cc, nil) + proxyApp := proxy.NewAppConns(cc) err := proxyApp.Start() require.Nil(t, err) defer proxyApp.Stop() @@ -52,7 +52,7 @@ func TestApplyBlock(t *testing.T) { func TestBeginBlockValidators(t *testing.T) { app := &testApp{} cc := proxy.NewLocalClientCreator(app) - proxyApp := proxy.NewAppConns(cc, nil) + proxyApp := proxy.NewAppConns(cc) err := proxyApp.Start() require.Nil(t, err) defer proxyApp.Stop() @@ -105,7 +105,7 @@ func TestBeginBlockValidators(t *testing.T) { func TestBeginBlockByzantineValidators(t *testing.T) { app := &testApp{} cc := proxy.NewLocalClientCreator(app) - proxyApp := proxy.NewAppConns(cc, nil) + proxyApp := proxy.NewAppConns(cc) err := proxyApp.Start() require.Nil(t, err) defer proxyApp.Stop() @@ -239,7 +239,7 @@ func TestUpdateValidators(t *testing.T) { func TestEndBlockValidatorUpdates(t *testing.T) { app := &testApp{} cc := proxy.NewLocalClientCreator(app) - proxyApp := proxy.NewAppConns(cc, nil) + proxyApp := proxy.NewAppConns(cc) err := proxyApp.Start() require.Nil(t, err) defer proxyApp.Stop()