Browse Source

move app ver check into HandShake step, rollback default gen app version, and set kvstore/e2e app ver to 0

pull/8068/head
jay tseng 3 years ago
parent
commit
db7fcf80cd
No known key found for this signature in database GPG Key ID: 5A9D3063305E6427
9 changed files with 19 additions and 25 deletions
  1. +1
    -1
      abci/example/kvstore/kvstore.go
  2. +1
    -3
      config/toml.go
  3. +8
    -1
      internal/consensus/replay.go
  4. +1
    -1
      internal/consensus/replay_file.go
  5. +4
    -4
      internal/consensus/replay_test.go
  6. +1
    -12
      node/node.go
  7. +1
    -1
      node/node_test.go
  8. +1
    -1
      test/e2e/app/app.go
  9. +1
    -1
      types/params.go

+ 1
- 1
abci/example/kvstore/kvstore.go View File

@ -24,7 +24,7 @@ var (
stateKey = []byte("stateKey") stateKey = []byte("stateKey")
kvPairPrefixKey = []byte("kvPairKey:") kvPairPrefixKey = []byte("kvPairKey:")
ProtocolVersion uint64 = 0x1
ProtocolVersion uint64 = 0x0
) )
type State struct { type State struct {


+ 1
- 3
config/toml.go View File

@ -612,9 +612,7 @@ var testGenesisFmt = `{
"ed25519" "ed25519"
] ]
}, },
"version": {
"app_version": "1"
}
"version": {}
}, },
"validators": [ "validators": [
{ {


+ 8
- 1
internal/consensus/replay.go View File

@ -238,7 +238,7 @@ func (h *Handshaker) NBlocks() int {
} }
// TODO: retry the handshake/replay if it fails ? // TODO: retry the handshake/replay if it fails ?
func (h *Handshaker) Handshake(ctx context.Context, appClient abciclient.Client) error {
func (h *Handshaker) Handshake(ctx context.Context, appClient abciclient.Client, genDocAppVer uint64) error {
// Handshake is done via ABCI Info on the query conn. // Handshake is done via ABCI Info on the query conn.
res, err := appClient.Info(ctx, proxy.RequestInfo) res, err := appClient.Info(ctx, proxy.RequestInfo)
@ -259,6 +259,13 @@ func (h *Handshaker) Handshake(ctx context.Context, appClient abciclient.Client)
"protocol-version", res.AppVersion, "protocol-version", res.AppVersion,
) )
// Check app version is matched with the genesis file.
if res.AppVersion != genDocAppVer {
return fmt.Errorf("client app version (%d) is not matched with the genesis file (%d)",
res.AppVersion,
genDocAppVer)
}
// Only set the version if there is no existing state. // Only set the version if there is no existing state.
if h.initialState.LastBlockHeight == 0 { if h.initialState.LastBlockHeight == 0 {
h.initialState.Version.Consensus.App = res.AppVersion h.initialState.Version.Consensus.App = res.AppVersion


+ 1
- 1
internal/consensus/replay_file.go View File

@ -343,7 +343,7 @@ func newConsensusStateForReplay(
handshaker := NewHandshaker(logger, stateStore, state, blockStore, eventBus, gdoc) handshaker := NewHandshaker(logger, stateStore, state, blockStore, eventBus, gdoc)
if err = handshaker.Handshake(ctx, proxyApp); err != nil {
if err = handshaker.Handshake(ctx, proxyApp, gdoc.ConsensusParams.Version.AppVersion); err != nil {
return nil, err return nil, err
} }


+ 4
- 4
internal/consensus/replay_test.go View File

@ -782,7 +782,7 @@ func testHandshakeReplay(
require.NotNil(t, proxyApp) require.NotNil(t, proxyApp)
t.Cleanup(func() { cancel(); proxyApp.Wait() }) t.Cleanup(func() { cancel(); proxyApp.Wait() })
err = handshaker.Handshake(ctx, proxyApp)
err = handshaker.Handshake(ctx, proxyApp, genDoc.ConsensusParams.Version.AppVersion)
if expectError { if expectError {
require.Error(t, err) require.Error(t, err)
return return
@ -995,7 +995,7 @@ func TestHandshakePanicsIfAppReturnsWrongAppHash(t *testing.T) {
assert.Panics(t, func() { assert.Panics(t, func() {
h := NewHandshaker(logger, stateStore, state, store, eventBus, genDoc) h := NewHandshaker(logger, stateStore, state, store, eventBus, genDoc)
if err = h.Handshake(ctx, proxyApp); err != nil {
if err = h.Handshake(ctx, proxyApp, genDoc.ConsensusParams.Version.AppVersion); err != nil {
t.Log(err) t.Log(err)
} }
}) })
@ -1015,7 +1015,7 @@ func TestHandshakePanicsIfAppReturnsWrongAppHash(t *testing.T) {
assert.Panics(t, func() { assert.Panics(t, func() {
h := NewHandshaker(logger, stateStore, state, store, eventBus, genDoc) h := NewHandshaker(logger, stateStore, state, store, eventBus, genDoc)
if err = h.Handshake(ctx, proxyApp); err != nil {
if err = h.Handshake(ctx, proxyApp, genDoc.ConsensusParams.Version.AppVersion); err != nil {
t.Log(err) t.Log(err)
} }
}) })
@ -1270,7 +1270,7 @@ func TestHandshakeUpdatesValidators(t *testing.T) {
proxyApp := proxy.New(client, logger, proxy.NopMetrics()) proxyApp := proxy.New(client, logger, proxy.NopMetrics())
require.NoError(t, proxyApp.Start(ctx), "Error starting proxy app connections") require.NoError(t, proxyApp.Start(ctx), "Error starting proxy app connections")
require.NoError(t, handshaker.Handshake(ctx, proxyApp), "error on abci handshake")
require.NoError(t, handshaker.Handshake(ctx, proxyApp, genDoc.ConsensusParams.Version.AppVersion), "error on abci handshake")
// reload the state, check the validator set was updated // reload the state, check the validator set was updated
state, err = stateStore.Load() state, err = stateStore.Load()


+ 1
- 12
node/node.go View File

@ -164,17 +164,6 @@ func makeNode(
return nil, fmt.Errorf("error starting proxy app connections: %w", err) return nil, fmt.Errorf("error starting proxy app connections: %w", err)
} }
// Check app version is matched with the genesis file.
appInfo, err := proxyApp.Info(ctx, abci.RequestInfo{Version: ""})
if err != nil {
return nil, fmt.Errorf("error query app info: %w", err)
}
if appInfo.AppVersion != genDoc.ConsensusParams.Version.AppVersion {
return nil, fmt.Errorf("error client app version (%d) is not matched with the genesis file (%d)",
appInfo.AppVersion,
genDoc.ConsensusParams.Version.AppVersion)
}
// EventBus and IndexerService must be started before the handshake because // EventBus and IndexerService must be started before the handshake because
// we might need to index the txs of the replayed block as this might not have happened // we might need to index the txs of the replayed block as this might not have happened
// when the node stopped last time (i.e. the node stopped or crashed after it saved the block // when the node stopped last time (i.e. the node stopped or crashed after it saved the block
@ -238,7 +227,7 @@ func makeNode(
if err := consensus.NewHandshaker( if err := consensus.NewHandshaker(
logger.With("module", "handshaker"), logger.With("module", "handshaker"),
stateStore, state, blockStore, eventBus, genDoc, stateStore, state, blockStore, eventBus, genDoc,
).Handshake(ctx, proxyApp); err != nil {
).Handshake(ctx, proxyApp, genDoc.ConsensusParams.Version.AppVersion); err != nil {
return nil, combineCloseError(err, makeCloser(closers)) return nil, combineCloseError(err, makeCloser(closers))
} }


+ 1
- 1
node/node_test.go View File

@ -798,7 +798,7 @@ func TestNodeAppVersionNotMatched(t *testing.T) {
require.Error(t, err) require.Error(t, err)
require.Equal(t, require.Equal(t,
fmt.Sprintf("error client app version (%d) is not matched with the genesis file (%d)",
fmt.Sprintf("error=\"client app version (%d) is not matched with the genesis file (%d)\" closerError=\"\"",
kvstore.ProtocolVersion, kvstore.ProtocolVersion,
genesisDoc.ConsensusParams.Version.AppVersion), genesisDoc.ConsensusParams.Version.AppVersion),
err.Error()) err.Error())


+ 1
- 1
test/e2e/app/app.go View File

@ -105,7 +105,7 @@ func (app *Application) Info(req abci.RequestInfo) abci.ResponseInfo {
return abci.ResponseInfo{ return abci.ResponseInfo{
Version: version.ABCIVersion, Version: version.ABCIVersion,
AppVersion: 1,
AppVersion: 0,
LastBlockHeight: int64(app.state.Height), LastBlockHeight: int64(app.state.Height),
LastBlockAppHash: app.state.Hash, LastBlockAppHash: app.state.Hash,
} }


+ 1
- 1
types/params.go View File

@ -123,7 +123,7 @@ func DefaultValidatorParams() ValidatorParams {
func DefaultVersionParams() VersionParams { func DefaultVersionParams() VersionParams {
return VersionParams{ return VersionParams{
AppVersion: 1,
AppVersion: 0,
} }
} }


Loading…
Cancel
Save