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

Migrate genesis cmd #4471

Merged
merged 72 commits into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
e6f42f8
init following what's inside breaking CHANGELOGs
sabau Jun 3, 2019
9673144
Changelog
sabau Jun 3, 2019
46840e1
we skipped 0.35
sabau Jun 4, 2019
eb24889
Merge branch 'master' into sabau/4409-migrate-genesis
sabau Jun 6, 2019
04f1a2e
stash everything not compiling, skeleton
sabau Jun 11, 2019
0b74d51
statically working,
sabau Jun 12, 2019
3e44ddc
migration function, broke
sabau Jun 12, 2019
ae1dbbc
first version working
sabau Jun 12, 2019
5956387
need some extra eyes to check simulations
sabau Jun 12, 2019
eb01af2
Update 4409-migration-scrip
sabau Jun 12, 2019
4bc62b1
long life to the mapped functions
sabau Jun 12, 2019
ed420e3
Update contrib/export/v036/gov/types.go
sabau Jun 12, 2019
0446dd4
Update contrib/export/v036/migrate.go
sabau Jun 12, 2019
0c17580
verbose but safer version
sabau Jun 12, 2019
7ca5677
Merge remote-tracking branch 'origin/sabau/4409-migrate-genesis' into…
sabau Jun 12, 2019
8731735
missing flags
sabau Jun 12, 2019
9a4e31c
VoteOption and and ProposalType
sabau Jun 14, 2019
762b00e
use same tag as git
sabau Jun 15, 2019
36bc111
rename flags, print genesis instead of outputting into file
sabau Jun 15, 2019
1faa6e0
Merge branch 'sabau/4409-migrate-genesis' of github.com:cosmos/cosmos…
sabau Jun 15, 2019
c7f90a8
fix flag renaming, log fatals instead of panic
sabau Jun 15, 2019
f96e1bb
remove unused var
sabau Jun 15, 2019
c4d307e
fail if missing flags
sabau Jun 16, 2019
5d94dca
mandatory arguments become positionals
sabau Jun 16, 2019
e2f6fe9
Cleanup
alexanderbez Jun 18, 2019
3295563
Update contrib/export/types/types.go
sabau Jun 18, 2019
9709380
cleanup and add make command
sabau Jun 18, 2019
2aea524
align docs
sabau Jun 18, 2019
c692a13
fix makefile
sabau Jun 19, 2019
b5da6d0
cleanup comments
sabau Jun 19, 2019
a708f52
cobra version for flags
sabau Jun 19, 2019
756a45d
Update contrib/export/main.go
sabau Jun 20, 2019
601d007
move comment, remove unnecessary cobra check, fix makefile
sabau Jun 20, 2019
a16c3b3
override time and chain-id with optional flags
sabau Jun 20, 2019
02ead07
Cleanup export command
alexanderbez Jun 20, 2019
2a9fa3c
remove source flag, add new flags to doc
sabau Jun 20, 2019
ee652a3
docs, add flag on both examples
sabau Jun 20, 2019
9f3fdd4
More cleanup
alexanderbez Jun 20, 2019
58fa889
Update pending log entry
alexanderbez Jun 20, 2019
e354f93
functions helps, but still simulation fails
sabau Jun 21, 2019
9a8ebac
Merge remote-tracking branch 'origin/sabau/4409-migrate-genesis' into…
sabau Jun 21, 2019
9a1d4d1
double codec, types from 034 fixed, registered types,
sabau Jun 21, 2019
fca4757
fixed both problems with old and new prefixes, double codec actually …
sabau Jun 24, 2019
7cd5379
remove debugging assignment
sabau Jun 24, 2019
abfd8fa
add step by step guide to export and migrate
sabau Jun 25, 2019
bf9453a
practical example from scratch, genesis from github does not match wi…
sabau Jun 25, 2019
9163645
support versions in between in 0.33.x migration script
sabau Jun 25, 2019
ef1ca22
explicit double migration example
sabau Jun 25, 2019
497afc4
make migrate root command for now
sabau Jun 25, 2019
004bcc9
rename export to migrate
sabau Jun 25, 2019
212791e
cleanup README
sabau Jun 25, 2019
f915ea1
remove unnecessary unmarshal/marshal on each module
sabau Jun 25, 2019
f2f0dc6
add testnet genesis and cci check
sabau Jun 25, 2019
1bea87b
build and run migrate
sabau Jun 25, 2019
32fc8e8
move types to legacy and governance migration function too
sabau Jun 26, 2019
0980d2d
Update contrib/migrate/v036/migrate.go
sabau Jun 27, 2019
891d4a3
remove CCI check
sabau Jun 28, 2019
b8b4cdf
Merge remote-tracking branch 'origin/sabau/4409-migrate-genesis' into…
sabau Jun 28, 2019
4a7df4a
mvoe command out of contrib inside genutil
sabau Jun 28, 2019
9a61bae
Merge branch 'master' into sabau/4409-migrate-genesis
sabau Jun 28, 2019
791e174
standardize command
sabau Jun 28, 2019
4f37798
remove unused function from 034 types
sabau Jun 28, 2019
799115b
remove deprecated makefile target, align docs
sabau Jun 28, 2019
daeb260
Merge branch 'master' into sabau/4409-migrate-genesis
sabau Jul 1, 2019
31326bf
add some tests on new command
sabau Jul 1, 2019
247b487
Update x/genutil/legacy/v036/migrate_test.go
sabau Jul 1, 2019
ee27266
simplify emptyGenesis body
sabau Jul 1, 2019
0671983
Merge remote-tracking branch 'origin/sabau/4409-migrate-genesis' into…
sabau Jul 1, 2019
77f2117
remove test on parameters length
sabau Jul 1, 2019
04a94ae
cobra command description replace binary with ServerName
sabau Jul 1, 2019
f9d8ea0
Merge branch 'master' into sabau/4409-migrate-genesis
alexanderbez Jul 2, 2019
e191e4d
Cleanup
alexanderbez Jul 2, 2019
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
1 change: 1 addition & 0 deletions .pending/features/sdk/4409-migration-scrip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4409 Implement an export tool to migrate exported state from v0.34.x to v0.36
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

def process_raw_genesis(genesis, parsed_args):
# update genesis with breaking changes
genesis['consensus_params']['block'] = genesis['consensus_params']['block_size']
del genesis['consensus_params']['block_size']
if 'block_size' in genesis['consensus_params']:
genesis['consensus_params']['block'] = genesis['consensus_params']['block_size']
del genesis['consensus_params']['block_size']

genesis['app_state']['crisis'] = {
'constant_fee': {
Expand Down
8 changes: 8 additions & 0 deletions docs/clients/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ Light-clients enable users to interact with your application without having to d

- [Command-Line interface for SDK-based blockchain](./cli.md)
- [Service provider doc](./service-providers.md)

sabau marked this conversation as resolved.
Show resolved Hide resolved
## Genesis upgrade

If you need to upgrade your node you could export the genesis and migrate it to the new version through this script:

```bash
<appbinary> migrate v0.36 genesis_0_34.json [--time "2019-04-22T17:00:11Z"] [--chain-id test] > ~/.gaiad/genesis.json
```
87 changes: 87 additions & 0 deletions x/genutil/client/cli/migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package cli

import (
"fmt"
"github.com/cosmos/cosmos-sdk/server"
"strings"
"time"

"github.com/spf13/cobra"
"github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/codec"
extypes "github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/cosmos/cosmos-sdk/x/genutil/legacy/v036"
)

var migrationMap = extypes.MigrationMap{
"v0.36": v036.Migrate,
}

const (
flagGenesisTime = "genesis-time"
flagChainId = "chain-id"
)

func MigrateGenesisCmd(_ *server.Context, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "migrate [target-version] [genesis-file]",
Short: "Migrate genesis to a specified target version",
Long: strings.TrimSpace(`Migrate the source genesis into the target version and print to STDOUT.

Example:
[binary] migrate v0.36 /path/to/genesis.json --chain-id=cosmoshub-3 --genesis-time=2019-04-22T17:00:00Z
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
`),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
target := args[0]
importGenesis := args[1]

genDoc, err := types.GenesisDocFromFile(importGenesis)
if err != nil {
return err
}

var initialState extypes.AppMap
cdc.MustUnmarshalJSON(genDoc.AppState, &initialState)

if migrationMap[target] == nil {
return fmt.Errorf("unknown migration function version: %s", target)
}

newGenState := migrationMap[target](initialState, cdc)
genDoc.AppState = cdc.MustMarshalJSON(newGenState)

genesisTime := cmd.Flag(flagGenesisTime).Value.String()
if genesisTime != "" {
var t time.Time

err := t.UnmarshalText([]byte(genesisTime))
if err != nil {
return err
}

genDoc.GenesisTime = t
}

chainId := cmd.Flag(flagChainId).Value.String()
if chainId != "" {
genDoc.ChainID = chainId
}

out, err := cdc.MarshalJSONIndent(genDoc, "", " ")
if err != nil {
return err
}

fmt.Println(string(out))
return nil

},
}

cmd.Flags().String(flagGenesisTime, "", "Override genesis_time with this flag")
cmd.Flags().String(flagChainId, "", "Override chain_id with this flag")

return cmd
}
26 changes: 26 additions & 0 deletions x/genutil/legacy/v036/migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package v036

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/genutil"
v034gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v034"
v036gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v036"
)

// Migrate migrates exported state from v0.34 to a v0.36 genesis state.
func Migrate(appState genutil.AppMap, cdc *codec.Codec) genutil.AppMap {
v034Codec := codec.New()
codec.RegisterCrypto(v034Codec)
v036Codec := codec.New()
codec.RegisterCrypto(v036Codec)

if appState[v034gov.ModuleName] != nil {
var govState v034gov.GenesisState
v034gov.RegisterCodec(v034Codec)
v034Codec.MustUnmarshalJSON(appState[v034gov.ModuleName], &govState)
v036gov.RegisterCodec(v036Codec)
delete(appState, v034gov.ModuleName) // Drop old key, in case it changed name
appState[v036gov.ModuleName] = v036Codec.MustMarshalJSON(v036gov.MigrateGovernance(govState))
}
return appState
}
15 changes: 15 additions & 0 deletions x/genutil/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package genutil

import (
"encoding/json"
"github.com/cosmos/cosmos-sdk/codec"
)

type (
// AppMap map modules names with their json raw representation
AppMap map[string]json.RawMessage
// MigrationCallback converts a genesis map from the previous version to the targeted one
MigrationCallback func(AppMap, *codec.Codec) AppMap
// MigrationMap defines a mapping from a version to a MigrationCallback
MigrationMap map[string]MigrationCallback
)
Loading