This commit is contained in:
Ethan Buchman 2018-05-31 22:18:17 -04:00
parent 485b4a0c6f
commit 7606b7595f
5 changed files with 13 additions and 11 deletions

View File

@ -2,7 +2,6 @@ package consensus
import ( import (
"bytes" "bytes"
"encoding/json"
"fmt" "fmt"
"hash/crc32" "hash/crc32"
"io" "io"
@ -197,20 +196,20 @@ type Handshaker struct {
stateDB dbm.DB stateDB dbm.DB
initialState sm.State initialState sm.State
store sm.BlockStore store sm.BlockStore
appState json.RawMessage genDoc *types.GenesisDoc
logger log.Logger logger log.Logger
nBlocks int // number of blocks applied to the state nBlocks int // number of blocks applied to the state
} }
func NewHandshaker(stateDB dbm.DB, state sm.State, func NewHandshaker(stateDB dbm.DB, state sm.State,
store sm.BlockStore, appState json.RawMessage) *Handshaker { store sm.BlockStore, genDoc *types.GenesisDoc) *Handshaker {
return &Handshaker{ return &Handshaker{
stateDB: stateDB, stateDB: stateDB,
initialState: state, initialState: state,
store: store, store: store,
appState: appState, genDoc: genDoc,
logger: log.NewNopLogger(), logger: log.NewNopLogger(),
nBlocks: 0, nBlocks: 0,
} }
@ -269,8 +268,11 @@ func (h *Handshaker) ReplayBlocks(state sm.State, appHash []byte, appBlockHeight
if appBlockHeight == 0 { if appBlockHeight == 0 {
validators := types.TM2PB.Validators(state.Validators) validators := types.TM2PB.Validators(state.Validators)
req := abci.RequestInitChain{ req := abci.RequestInitChain{
Validators: validators, Time: h.genDoc.GenesisTime.Unix(), // TODO
AppStateBytes: h.appState, ChainId: h.genDoc.ChainID,
ConsensusParams: types.TM2PB.ConsensusParams(h.genDoc.ConsensusParams),
Validators: validators,
AppStateBytes: h.genDoc.AppStateJSON,
} }
_, err := proxyApp.Consensus().InitChainSync(req) _, err := proxyApp.Consensus().InitChainSync(req)
if err != nil { if err != nil {

View File

@ -299,7 +299,7 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo
// Create proxyAppConn connection (consensus, mempool, query) // Create proxyAppConn connection (consensus, mempool, query)
clientCreator := proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()) clientCreator := proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir())
proxyApp := proxy.NewAppConns(clientCreator, proxyApp := proxy.NewAppConns(clientCreator,
NewHandshaker(stateDB, state, blockStore, gdoc.AppState())) NewHandshaker(stateDB, state, blockStore, gdoc))
err = proxyApp.Start() err = proxyApp.Start()
if err != nil { if err != nil {
cmn.Exit(cmn.Fmt("Error starting proxy app conns: %v", err)) cmn.Exit(cmn.Fmt("Error starting proxy app conns: %v", err))

View File

@ -52,7 +52,7 @@ func WALWithNBlocks(numBlocks int) (data []byte, err error) {
return nil, errors.Wrap(err, "failed to make genesis state") return nil, errors.Wrap(err, "failed to make genesis state")
} }
blockStore := bc.NewBlockStore(blockStoreDB) blockStore := bc.NewBlockStore(blockStoreDB)
handshaker := NewHandshaker(stateDB, state, blockStore, genDoc.AppState()) handshaker := NewHandshaker(stateDB, state, blockStore, genDoc)
proxyApp := proxy.NewAppConns(proxy.NewLocalClientCreator(app), handshaker) proxyApp := proxy.NewAppConns(proxy.NewLocalClientCreator(app), handshaker)
proxyApp.SetLogger(logger.With("module", "proxy")) proxyApp.SetLogger(logger.With("module", "proxy"))
if err := proxyApp.Start(); err != nil { if err := proxyApp.Start(); err != nil {

View File

@ -159,7 +159,7 @@ func NewNode(config *cfg.Config,
// and sync tendermint and the app by performing a handshake // and sync tendermint and the app by performing a handshake
// and replaying any necessary blocks // and replaying any necessary blocks
consensusLogger := logger.With("module", "consensus") consensusLogger := logger.With("module", "consensus")
handshaker := cs.NewHandshaker(stateDB, state, blockStore, genDoc.AppState()) handshaker := cs.NewHandshaker(stateDB, state, blockStore, genDoc)
handshaker.SetLogger(consensusLogger) handshaker.SetLogger(consensusLogger)
proxyApp := proxy.NewAppConns(clientCreator, handshaker) proxyApp := proxy.NewAppConns(clientCreator, handshaker)
proxyApp.SetLogger(logger.With("module", "proxy")) proxyApp.SetLogger(logger.With("module", "proxy"))

View File

@ -57,8 +57,8 @@ func (tm2pb) Validators(vals *ValidatorSet) []types.Validator {
return validators return validators
} }
func (tm2pb) ConsensusParams(params *ConsensusParams) types.ConsensusParams { func (tm2pb) ConsensusParams(params *ConsensusParams) *types.ConsensusParams {
return types.ConsensusParams{ return &types.ConsensusParams{
BlockSize: &types.BlockSize{ BlockSize: &types.BlockSize{
MaxBytes: int32(params.BlockSize.MaxBytes), MaxBytes: int32(params.BlockSize.MaxBytes),