-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Genesis port script v0.34.0 #4023
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
0d88bc9
genesis port script
9aa7005
add command
e20d778
various fixes
4c549f2
works
fedekunze 62bca4d
cleanup and move to script
fedekunze f6887b0
typo
fedekunze 8915f47
check args
fedekunze 1dab733
rename files and fix scripts
fedekunze ddec599
command to run
fedekunze 4d726bc
address comments from review
fedekunze 5e4f838
use flags
fedekunze 2c99fb9
changelog
fedekunze d88b6d2
Update .pending/improvements/gaia/4018-create-genesis-
cwgoes 2f3012a
update value and validation test
fedekunze 39d7ce0
Merge branch 'fedekunze/4018-genesis-scritp' of https://github.com/co…
fedekunze 9df1f1b
add chain-id
fedekunze 50c58c6
Merge branch 'release/v0.34.0' into fedekunze/4018-genesis-scritp
alexanderbez b55d40a
New python script
31952f1
delete go files
fedekunze 4a3b178
numbers to strings
fedekunze 9c6a515
add crisis constant fee
fedekunze afe9952
Exit with error on stderr
6e01099
Refactoring, slightly more modular design
1b56d64
Fix indentation
34a9b36
Remove unnecessary variable
0fd205c
Minor reformatting
alexanderbez 1581756
Minor reformatting
alexanderbez c4de703
Rename file
alexanderbez 5c85697
Update contrib/export/v0.33.x-to-v0.34.0.py
cwgoes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| package export | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "time" | ||
|
|
||
| app "github.com/cosmos/cosmos-sdk/cmd/gaia/app" | ||
| "github.com/cosmos/cosmos-sdk/codec" | ||
| tmtypes "github.com/tendermint/tendermint/types" | ||
| ) | ||
|
|
||
| // GenesisFile defines the Gaia genesis format | ||
| type GenesisFile struct { | ||
| GenesisTime string `json:"genesis_time"` | ||
| ChainID string `json:"chain_id"` | ||
| ConsensusParams *tmtypes.ConsensusParams `json:"consensus_params"` | ||
alexanderbez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| AppHash string `json:"app_hash"` | ||
| AppState app.GenesisState `json:"app_state"` | ||
| } | ||
|
|
||
| // NewGenesisFile builds a default GenesisDoc and creates a GenesisFile from it | ||
| func NewGenesisFile(cdc *codec.Codec, path string) (GenesisFile, error) { | ||
|
|
||
| genDoc, err := importGenesis(path) | ||
| if err != nil { | ||
| return GenesisFile{}, err | ||
| } | ||
|
|
||
| var appState app.GenesisState | ||
| if genDoc.AppState == nil { | ||
| appState = app.GenesisState{} | ||
| } else { | ||
| if err = cdc.UnmarshalJSON(genDoc.AppState, &appState); err != nil { | ||
| return GenesisFile{}, err | ||
| } | ||
| } | ||
|
|
||
| return GenesisFile{ | ||
| GenesisTime: genDoc.GenesisTime.String(), | ||
| ChainID: genDoc.ChainID, | ||
| ConsensusParams: genDoc.ConsensusParams, | ||
| AppHash: genDoc.AppHash.String(), | ||
| AppState: appState, | ||
| }, nil | ||
| } | ||
|
|
||
| // ValidateInputs validates each of the parameters used by | ||
fedekunze marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| func ValidateInputs(path, chainID, genesisTime string) error { | ||
| if chainID = strings.Trim(chainID, " "); chainID == "" { | ||
fedekunze marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return fmt.Errorf("chain-id cannot be blank") | ||
| } | ||
| _, err := time.Parse(time.RFC3339, genesisTime) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if ext := filepath.Ext(path); ext != ".json" { | ||
| return fmt.Errorf("%s is not a JSON file", path) | ||
| } | ||
|
|
||
| if _, err = os.Stat(path); err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // importGenesis imports genesis from JSON and completes missing fields | ||
| func importGenesis(path string) (genDoc *tmtypes.GenesisDoc, err error) { | ||
| genDoc, err = tmtypes.GenesisDocFromFile(path) | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| err = genDoc.ValidateAndComplete() | ||
| if err != nil { | ||
| return | ||
| } | ||
| return | ||
| } | ||
|
|
||
| func defaultGenesisDoc(chainID string) (tmtypes.GenesisDoc, error) { | ||
fedekunze marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| genDoc := tmtypes.GenesisDoc{ | ||
| ChainID: chainID, | ||
| } | ||
| err := (&genDoc).ValidateAndComplete() | ||
| if err != nil { | ||
| return genDoc, err | ||
| } | ||
| return genDoc, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package export | ||
alexanderbez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "io/ioutil" | ||
| "os" | ||
| "testing" | ||
|
|
||
| app "github.com/cosmos/cosmos-sdk/cmd/gaia/app" | ||
| "github.com/stretchr/testify/require" | ||
| tmtypes "github.com/tendermint/tendermint/types" | ||
| ) | ||
|
|
||
| var ( | ||
| path = "./genesis.json" | ||
| chainID = "cosmos-zone" | ||
| genesisTime = "2019-02-11T12:00:00Z" | ||
| ) | ||
|
|
||
| func TestNewGenesisFile(t *testing.T) { | ||
| cdc := app.MakeCodec() | ||
| genDoc, err := defaultGenesisDoc(chainID) | ||
| require.NoError(t, err) | ||
|
|
||
| output, err := cdc.MarshalJSONIndent(genDoc, "", " ") | ||
| require.NoError(t, err) | ||
|
|
||
| err = ioutil.WriteFile(path, output, 0644) | ||
| require.NoError(t, err) | ||
|
|
||
| genesisFile, err := NewGenesisFile(cdc, path) | ||
| require.NoError(t, err) | ||
| require.NotEqual(t, GenesisFile{}, genesisFile) | ||
| os.Remove(path) | ||
| } | ||
|
|
||
| func TestDefaultGenesisDoc(t *testing.T) { | ||
| expectedGenDoc := tmtypes.GenesisDoc{ChainID: chainID} | ||
| genDoc, err := defaultGenesisDoc(chainID) | ||
| require.NoError(t, err) | ||
| require.NotEqual(t, expectedGenDoc, genDoc) | ||
|
|
||
| genDoc, err = defaultGenesisDoc("") | ||
| require.Error(t, err) | ||
| } | ||
|
|
||
| func TestImportGenesis(t *testing.T) { | ||
| genesis := tmtypes.GenesisDoc{ChainID: chainID} | ||
|
|
||
| output, err := json.Marshal(genesis) | ||
| require.NoError(t, err) | ||
|
|
||
| err = ioutil.WriteFile(path, output, 0644) | ||
| require.NoError(t, err) | ||
|
|
||
| genDoc, err := importGenesis(path) | ||
| require.NoError(t, err) | ||
| require.NotEqual(t, genesis, genDoc) | ||
| os.Remove(path) | ||
|
|
||
| // should fail with invalid genesis | ||
| genesis = tmtypes.GenesisDoc{} | ||
| output, err = json.Marshal(genesis) | ||
| require.NoError(t, err) | ||
|
|
||
| err = ioutil.WriteFile(path, output, 0644) | ||
| require.NoError(t, err) | ||
|
|
||
| genDoc, err = importGenesis(path) | ||
| require.Error(t, err) | ||
| os.Remove(path) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package main | ||
alexanderbez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
|
|
||
| app "github.com/cosmos/cosmos-sdk/cmd/gaia/app" | ||
| "github.com/cosmos/cosmos-sdk/scripts/export" | ||
| ) | ||
|
|
||
| // Command: go run main.go [path_to_old_genesis.json] [chain-id] [genesis-start-time] > [path_to_new_genesis.json] | ||
| func main() { | ||
| cdc := app.MakeCodec() | ||
|
|
||
| args := os.Args[1:] | ||
fedekunze marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if len(args) != 3 { | ||
| panic(fmt.Errorf("please provide path, chain-id and genesis time")) | ||
| } | ||
|
|
||
| pathToGenesis := args[0] | ||
| chainID := args[1] | ||
| genesisTime := args[2] | ||
|
|
||
| err := export.ValidateInputs(pathToGenesis, chainID, genesisTime) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| genesis, err := export.NewGenesisFile(cdc, pathToGenesis) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| genesis.ChainID = strings.Trim(chainID, " ") | ||
fedekunze marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| genesis.GenesisTime = genesisTime | ||
|
|
||
| // proposal #1 updates | ||
| genesis.AppState.MintData.Params.BlocksPerYear = 4855015 | ||
|
|
||
| // proposal #2 updates | ||
| genesis.ConsensusParams.Block.MaxGas = 200000 | ||
alexanderbez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| genesis.ConsensusParams.Block.MaxBytes = 2000000 | ||
|
|
||
| // enable transfers | ||
| genesis.AppState.BankData.SendEnabled = true | ||
| genesis.AppState.DistrData.WithdrawAddrEnabled = true | ||
|
|
||
| err = app.GaiaValidateGenesisState(genesis.AppState) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| genesisJSON, err := cdc.MarshalJSONIndent(genesis, "", " ") | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| fmt.Println(string(genesisJSON)) | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.