Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add height in exported genesis #7089

Merged
merged 70 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
7b56ee3
Add height in exported genesis
amaury1093 Aug 18, 2020
167cc8b
+1
amaury1093 Aug 18, 2020
e17275c
Add test
amaury1093 Aug 19, 2020
ef1e6f0
Merge branch 'master' into am-7018-export-height
amaury1093 Aug 19, 2020
64e828b
Refactor ctx in setupApp
amaury1093 Aug 19, 2020
a04a42c
Use amino in export
amaury1093 Aug 20, 2020
a619220
Merge branch 'master' into am-7018-export-height
amaury1093 Aug 20, 2020
2c7ef98
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 21, 2020
1749ca8
Use tmjson
amaury1093 Aug 21, 2020
2b1cec3
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 24, 2020
facab0e
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 24, 2020
a4ac0fc
Add custom initialVersion (set to 0 for now)
amaury1093 Aug 24, 2020
6a9e6bc
Add comment
amaury1093 Aug 24, 2020
a04b438
Add mount in initChainer
amaury1093 Aug 25, 2020
bf549ec
app.LastBlockheight
amaury1093 Aug 25, 2020
86162b3
Merge branch 'master' into am-7018-export-height
amaury1093 Aug 25, 2020
fb99bb3
InitializeAndSeal in InitChain?
amaury1093 Aug 25, 2020
bf9d606
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 25, 2020
405c921
Merge branch 'master' into am-7018-export-height
alexanderbez Aug 26, 2020
270c323
Revert create store with initial version
amaury1093 Aug 26, 2020
5df1626
Update to latest iavl
amaury1093 Aug 26, 2020
9d16e9e
Check height in test
amaury1093 Aug 26, 2020
af9e5dc
Merge branch 'master' into am-7018-export-height
amaury1093 Aug 26, 2020
9274552
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 27, 2020
5dfa955
Make it work
amaury1093 Aug 27, 2020
4aa9bcc
Add more tests
amaury1093 Aug 27, 2020
bcbb243
Rename interface
amaury1093 Aug 27, 2020
7fdab5d
Use struct isntead of 6 args
amaury1093 Aug 27, 2020
6839081
Fix lint
amaury1093 Aug 27, 2020
0b82fec
Remove stray fmt
amaury1093 Aug 27, 2020
ca6b7c1
Revert go mod/sum
amaury1093 Aug 27, 2020
7f0b573
Install iavl rc3
amaury1093 Aug 27, 2020
4c858a5
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 28, 2020
76c7a12
Update comments
amaury1093 Aug 28, 2020
b80e01b
Merge branch 'master' into am-7018-export-height
jackzampolin Aug 28, 2020
eb65bd1
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Aug 31, 2020
10bc9e6
Add fee in network
amaury1093 Aug 31, 2020
314f0a3
Merge branch 'am-7018-export-height' of ssh://github.com/cosmos/cosmo…
amaury1093 Aug 31, 2020
255aaa7
Typo
amaury1093 Aug 31, 2020
f6216f6
Fix logic in commit
amaury1093 Aug 31, 2020
1f1b602
Fix tests
amaury1093 Aug 31, 2020
789842a
Only set initial version on > 1
amaury1093 Aug 31, 2020
fac4d5e
Genesis block num = 1
amaury1093 Aug 31, 2020
b532d0d
Fresh chain, genesis block = 0
amaury1093 Aug 31, 2020
6ab3cf9
Merge branch 'master' into am-7018-export-height
amaury1093 Aug 31, 2020
54b0a97
Add comments
amaury1093 Aug 31, 2020
e62a650
Merge branch 'master' into am-7018-export-height
amaury1093 Sep 1, 2020
c95c075
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Sep 1, 2020
dbc92b7
Revert Mutable/ImmutableTree
amaury1093 Sep 1, 2020
e238ebe
Allow for zero height
amaury1093 Sep 1, 2020
b8ba3e2
Fix restart
amaury1093 Sep 1, 2020
57485ee
Add comments
amaury1093 Sep 1, 2020
7c6ba4d
Add comments, fix test
amaury1093 Sep 1, 2020
ecd6d7a
Merge branch 'master' into am-7018-export-height
amaury1093 Sep 1, 2020
66a0dc8
Fix remaining one test
amaury1093 Sep 1, 2020
f7cd6d2
Add panic test
amaury1093 Sep 1, 2020
af26c5b
Update comment
amaury1093 Sep 1, 2020
5c5b3eb
Merge branch 'master' into am-7018-export-height
alexanderbez Sep 1, 2020
31d2986
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Sep 2, 2020
57c1f9f
Add test for --height
amaury1093 Sep 2, 2020
2b28235
Merge branch 'am-7018-export-height' of ssh://github.com/cosmos/cosmo…
amaury1093 Sep 2, 2020
aeec99f
No cast
amaury1093 Sep 2, 2020
c2d41b5
Add check that genesis file exists
amaury1093 Sep 2, 2020
d7f4353
Remove duplicate imports
amaury1093 Sep 2, 2020
5940b66
Merge branch 'master' into am-7018-export-height
alexanderbez Sep 2, 2020
95365dc
Merge branch 'master' into am-7018-export-height
alexanderbez Sep 2, 2020
788fb8b
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-7…
amaury1093 Sep 2, 2020
6bf735c
Fail early
amaury1093 Sep 2, 2020
8712d04
Merge branch 'am-7018-export-height' of ssh://github.com/cosmos/cosmo…
amaury1093 Sep 2, 2020
abdfb85
Merge branch 'master' into am-7018-export-height
clevinson Sep 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion server/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com
forZeroHeight, _ := cmd.Flags().GetBool(flagForZeroHeight)
jailWhiteList, _ := cmd.Flags().GetStringSlice(flagJailWhitelist)

appState, validators, cp, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailWhiteList)
appState, validators, appHeight, cp, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailWhiteList)
if err != nil {
return fmt.Errorf("error exporting state: %v", err)
}
Expand All @@ -76,6 +76,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com

doc.AppState = appState
doc.Validators = validators
doc.InitialHeight = appHeight + 1
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
doc.ConsensusParams = &tmproto.ConsensusParams{
Block: tmproto.BlockParams{
MaxBytes: cp.Block.MaxBytes,
Expand Down
75 changes: 55 additions & 20 deletions server/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (
"path"
"testing"

"github.com/spf13/cobra"
"github.com/stretchr/testify/require"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"

Expand All @@ -29,6 +31,57 @@ func TestExportCmd_ConsensusParams(t *testing.T) {
tempDir, clean := testutil.NewTestCaseDir(t)
defer clean()

_, ctx, genDoc, cmd := setupApp(t, tempDir)

output := &bytes.Buffer{}
cmd.SetOut(output)
cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)})
require.NoError(t, cmd.ExecuteContext(ctx))

var exportedGenDoc tmtypes.GenesisDoc
err := json.Unmarshal(output.Bytes(), &exportedGenDoc)
if err != nil {
t.Fatalf("error unmarshaling exported genesis doc: %s", err)
}

require.Equal(t, genDoc.ConsensusParams.Block.TimeIotaMs, exportedGenDoc.ConsensusParams.Block.TimeIotaMs)
require.Equal(t, simapp.DefaultConsensusParams.Block.MaxBytes, exportedGenDoc.ConsensusParams.Block.MaxBytes)
require.Equal(t, simapp.DefaultConsensusParams.Block.MaxGas, exportedGenDoc.ConsensusParams.Block.MaxGas)

require.Equal(t, simapp.DefaultConsensusParams.Evidence.MaxAgeDuration, exportedGenDoc.ConsensusParams.Evidence.MaxAgeDuration)
require.Equal(t, simapp.DefaultConsensusParams.Evidence.MaxAgeNumBlocks, exportedGenDoc.ConsensusParams.Evidence.MaxAgeNumBlocks)
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved

require.Equal(t, simapp.DefaultConsensusParams.Validator.PubKeyTypes, exportedGenDoc.ConsensusParams.Validator.PubKeyTypes)
}

func TestExportCmd_Height(t *testing.T) {
tempDir, clean := testutil.NewTestCaseDir(t)
defer clean()

app, ctx, _, cmd := setupApp(t, tempDir)

// Fast forward to block 3.
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 2}})
app.Commit()
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 3}})
app.Commit()

output := &bytes.Buffer{}
cmd.SetOut(output)
cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)})
require.NoError(t, cmd.ExecuteContext(ctx))

var exportedGenDoc tmtypes.GenesisDoc
err := json.Unmarshal(output.Bytes(), &exportedGenDoc)
if err != nil {
t.Fatalf("error unmarshaling exported genesis doc: %s", err)
}

require.Equal(t, int64(4), exportedGenDoc.InitialHeight)
}

func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *tmtypes.GenesisDoc, *cobra.Command) {

err := createConfigFolder(tempDir)
if err != nil {
t.Fatalf("error creating config folder: %s", err)
Expand Down Expand Up @@ -56,33 +109,15 @@ func TestExportCmd_ConsensusParams(t *testing.T) {
app.Commit()

cmd := ExportCmd(
func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, b bool, strings []string) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error) {
func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, b bool, strings []string) (json.RawMessage, []tmtypes.GenesisValidator, int64, *abci.ConsensusParams, error) {
return app.ExportAppStateAndValidators(true, []string{})
}, tempDir)

ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
ctx = context.WithValue(ctx, ServerContextKey, serverCtx)

output := &bytes.Buffer{}
cmd.SetOut(output)
cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)})
require.NoError(t, cmd.ExecuteContext(ctx))

var exportedGenDoc tmtypes.GenesisDoc
err = json.Unmarshal(output.Bytes(), &exportedGenDoc)
if err != nil {
t.Fatalf("error unmarshaling exported genesis doc: %s", err)
}

require.Equal(t, genDoc.ConsensusParams.Block.TimeIotaMs, exportedGenDoc.ConsensusParams.Block.TimeIotaMs)
require.Equal(t, simapp.DefaultConsensusParams.Block.MaxBytes, exportedGenDoc.ConsensusParams.Block.MaxBytes)
require.Equal(t, simapp.DefaultConsensusParams.Block.MaxGas, exportedGenDoc.ConsensusParams.Block.MaxGas)

require.Equal(t, simapp.DefaultConsensusParams.Evidence.MaxAgeDuration, exportedGenDoc.ConsensusParams.Evidence.MaxAgeDuration)
require.Equal(t, simapp.DefaultConsensusParams.Evidence.MaxAgeNumBlocks, exportedGenDoc.ConsensusParams.Evidence.MaxAgeNumBlocks)

require.Equal(t, simapp.DefaultConsensusParams.Validator.PubKeyTypes, exportedGenDoc.ConsensusParams.Validator.PubKeyTypes)
return app, ctx, genDoc, cmd
}

func createConfigFolder(dir string) error {
Expand Down
2 changes: 1 addition & 1 deletion server/types/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ type (

// AppExporter is a function that dumps all app state to
// JSON-serializable structure and returns the current validator set.
AppExporter func(log.Logger, dbm.DB, io.Writer, int64, bool, []string) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error)
AppExporter func(log.Logger, dbm.DB, io.Writer, int64, bool, []string) (json.RawMessage, []tmtypes.GenesisValidator, int64, *abci.ConsensusParams, error)
)
2 changes: 1 addition & 1 deletion simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestSimAppExport(t *testing.T) {

// Making a new app object with the db, so that initchain hasn't been called
app2 := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig())
_, _, _, err = app2.ExportAppStateAndValidators(false, []string{})
_, _, _, _, err = app2.ExportAppStateAndValidators(false, []string{})
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}

Expand Down
6 changes: 3 additions & 3 deletions simapp/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
// file.
func (app *SimApp) ExportAppStateAndValidators(
forZeroHeight bool, jailWhiteList []string,
) (appState json.RawMessage, validators []tmtypes.GenesisValidator, cp *abci.ConsensusParams, err error) {
) (appState json.RawMessage, validators []tmtypes.GenesisValidator, height int64, cp *abci.ConsensusParams, err error) {

// as if they could withdraw from the start of the next block
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
Expand All @@ -31,11 +31,11 @@ func (app *SimApp) ExportAppStateAndValidators(
genState := app.mm.ExportGenesis(ctx, app.appCodec)
appState, err = json.MarshalIndent(genState, "", " ")
if err != nil {
return nil, nil, nil, err
return nil, nil, 0, nil, err
}

validators = staking.WriteValidators(ctx, app.StakingKeeper)
return appState, validators, app.BaseApp.GetConsensusParams(ctx), nil
return appState, validators, app.LastBlockHeight(), app.BaseApp.GetConsensusParams(ctx), nil
}

// prepare for fresh start at zero height
Expand Down
4 changes: 2 additions & 2 deletions simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestAppImportExport(t *testing.T) {

fmt.Printf("exporting genesis...\n")

appState, _, consensusParams, err := app.ExportAppStateAndValidators(false, []string{})
appState, _, _, consensusParams, err := app.ExportAppStateAndValidators(false, []string{})
require.NoError(t, err)

fmt.Printf("importing genesis...\n")
Expand Down Expand Up @@ -216,7 +216,7 @@ func TestAppSimulationAfterImport(t *testing.T) {

fmt.Printf("exporting genesis...\n")

appState, _, _, err := app.ExportAppStateAndValidators(true, []string{})
appState, _, _, _, err := app.ExportAppStateAndValidators(true, []string{})
require.NoError(t, err)

fmt.Printf("importing genesis...\n")
Expand Down
4 changes: 2 additions & 2 deletions simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty

func exportAppStateAndTMValidators(
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailWhiteList []string,
) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error) {
) (json.RawMessage, []tmtypes.GenesisValidator, int64, *abci.ConsensusParams, error) {
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved

encCfg := simapp.MakeEncodingConfig() // Ideally, we would reuse the one created by NewRootCmd.
encCfg.Marshaler = codec.NewProtoCodec(encCfg.InterfaceRegistry)
Expand All @@ -201,7 +201,7 @@ func exportAppStateAndTMValidators(
simApp = simapp.NewSimApp(logger, db, traceStore, false, map[int64]bool{}, "", uint(1), encCfg)

if err := simApp.LoadHeight(height); err != nil {
return nil, nil, nil, err
return nil, nil, 0, nil, err
}
} else {
simApp = simapp.NewSimApp(logger, db, traceStore, true, map[int64]bool{}, "", uint(1), encCfg)
Expand Down
2 changes: 1 addition & 1 deletion simapp/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type App interface {
// Exports the state of the application for a genesis file.
ExportAppStateAndValidators(
forZeroHeight bool, jailWhiteList []string,
) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error)
) (json.RawMessage, []tmtypes.GenesisValidator, int64, *abci.ConsensusParams, error)

// All the registered module account addreses.
ModuleAccountAddrs() map[string]bool
Expand Down
2 changes: 1 addition & 1 deletion simapp/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func CheckExportSimulation(
) error {
if config.ExportStatePath != "" {
fmt.Println("exporting app state...")
appState, _, _, err := app.ExportAppStateAndValidators(false, nil)
appState, _, _, _, err := app.ExportAppStateAndValidators(false, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion x/genutil/client/cli/validate_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func ValidateGenesisCmd(mbm module.BasicManager, txEncCfg client.TxEncodingConfi
}

var genState map[string]json.RawMessage
if err = cdc.UnmarshalJSON(genDoc.AppState, &genState); err != nil {
if err = json.Unmarshal(genDoc.AppState, &genState); err != nil {
return fmt.Errorf("error unmarshalling genesis doc %s: %s", genesis, err.Error())
}

Expand Down