Browse Source

check client app version when construct the node

pull/8068/head
jay tseng 3 years ago
parent
commit
d159498c0e
No known key found for this signature in database GPG Key ID: 5A9D3063305E6427
4 changed files with 65 additions and 0 deletions
  1. +2
    -0
      internal/consensus/state.go
  2. +4
    -0
      internal/state/rollback.go
  3. +11
    -0
      node/node.go
  4. +48
    -0
      node/node_test.go

+ 2
- 0
internal/consensus/state.go View File

@ -1381,6 +1381,8 @@ func (cs *State) createProposalBlock(ctx context.Context) (block *types.Block, b
proposerAddr := cs.privValidatorPubKey.Address()
cs.logger.Debug("cs.state %w", cs.state)
return cs.blockExec.CreateProposalBlock(ctx, cs.Height, cs.state, commit, proposerAddr, votes)
}


+ 4
- 0
internal/state/rollback.go View File

@ -57,6 +57,8 @@ func Rollback(bs BlockStore, ss Store) (int64, []byte, error) {
return -1, nil, err
}
fmt.Printf("previousParams version %d", previousParams.Version.AppVersion)
valChangeHeight := invalidState.LastHeightValidatorsChanged
// this can only happen if the validator set changed since the last block
if valChangeHeight > rollbackHeight {
@ -98,6 +100,8 @@ func Rollback(bs BlockStore, ss Store) (int64, []byte, error) {
AppHash: latestBlock.Header.AppHash,
}
fmt.Printf("rollback state %w", rolledBackState)
// persist the new state. This overrides the invalid one. NOTE: this will also
// persist the validator set and consensus params over the existing structures,
// but both should be the same


+ 11
- 0
node/node.go View File

@ -164,6 +164,17 @@ func makeNode(
return nil, fmt.Errorf("error starting proxy app connections: %w", err)
}
// Check app version is match with the genesis file.
appInfo, err := proxyApp.Query().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
// 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


+ 48
- 0
node/node_test.go View File

@ -754,3 +754,51 @@ func loadStatefromGenesis(ctx context.Context, t *testing.T) sm.State {
return state
}
func TestNodeAppVersionNotMatched(t *testing.T) {
cfg, err := config.ResetTestRoot(t.TempDir(), "node_node_test")
require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir)
ctx, bcancel := context.WithCancel(context.Background())
defer bcancel()
// Construct the node params
nodeKey, err := types.LoadOrGenNodeKey(cfg.NodeKeyFile())
require.NoError(t, err)
pval, err := makeDefaultPrivval(cfg)
require.NoError(t, err)
logger := log.NewNopLogger()
appClient, _ := proxy.DefaultClientCreator(logger, cfg.ProxyApp, cfg.ABCI, cfg.DBDir())
genesisDoc, err := types.GenesisDocFromFile(cfg.GenesisFile())
require.NoError(t, err)
genesisDoc.ConsensusParams.Version.AppVersion = 2
genesisDocProvider := func() (*types.GenesisDoc, error) {
return genesisDoc, nil
}
// Create node
_, err = makeNode(
ctx,
cfg,
pval,
nodeKey,
appClient,
genesisDocProvider,
config.DefaultDBProvider,
logger,
)
require.Error(t, err)
require.Equal(t,
fmt.Sprintf("error client app version (%d) is not matched with the genesis file (%d)",
kvstore.ProtocolVersion,
genesisDoc.ConsensusParams.Version.AppVersion),
err.Error())
}

Loading…
Cancel
Save