Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
fc3343b
first commit
rigelrozanski Apr 3, 2019
2ed7ec3
gaia cleanup
rigelrozanski Apr 4, 2019
fa8d51b
...
rigelrozanski Apr 4, 2019
78beb8b
Merge 'origin/develop' and working on module manager
rigelrozanski Apr 4, 2019
f3c84d2
Merge remote-tracking branch 'origin/develop' into rigel/genesis-gene…
rigelrozanski Apr 8, 2019
31e268a
staking multihooks
rigelrozanski Apr 8, 2019
f04fd65
missing module function return args
rigelrozanski Apr 8, 2019
b9fea80
bank module name constant
rigelrozanski Apr 8, 2019
53096ec
working, module interface for x/
rigelrozanski Apr 9, 2019
f89b67b
got this thing compiling
rigelrozanski Apr 9, 2019
fc2c20a
Merge remote-tracking branch 'origin/develop' into rigel/genesis-gene…
rigelrozanski Apr 9, 2019
f026bec
make test compiles and passes
rigelrozanski Apr 9, 2019
45d82f9
remove expanded simulation invariants
rigelrozanski Apr 9, 2019
3f4d0cf
genesis issue
rigelrozanski Apr 10, 2019
050317d
continued
rigelrozanski Apr 10, 2019
69a543e
continued
rigelrozanski Apr 10, 2019
95236c4
Merge remote-tracking branch 'origin/develop' into rigel/genesis-gene…
rigelrozanski Apr 10, 2019
03328ee
Merge remote-tracking branch 'origin/develop' into rigel/genesis-gene…
rigelrozanski Apr 10, 2019
9031e9d
register crisis routes thought mm
rigelrozanski Apr 10, 2019
480c10e
begin blocker to mm
rigelrozanski Apr 10, 2019
ef5ec28
end blocker to mm
rigelrozanski Apr 10, 2019
3c681a6
empty routes not initialized
rigelrozanski Apr 10, 2019
4ad51d2
move gaia initChainer sanity check to baseapp
rigelrozanski Apr 10, 2019
3620b2e
remove codecs from module manager
rigelrozanski Apr 10, 2019
62342b2
reorging genesis stuff
rigelrozanski Apr 10, 2019
6ce6260
Merge remote-tracking branch 'origin/develop' into rigel/genesis-gene…
rigelrozanski Apr 15, 2019
c8c3a08
module manager passed by reference/bugfixes from working last commit
rigelrozanski Apr 15, 2019
cd4d68f
move invariant checks from gaia to crisis
rigelrozanski Apr 15, 2019
2d95c57
typo
rigelrozanski Apr 15, 2019
a22a9f7
basic refactors cmd/gaia/init
rigelrozanski Apr 16, 2019
75a9a15
working
rigelrozanski Apr 16, 2019
631298e
MultiStakingHooks from types to x/staking/types
rigelrozanski Apr 17, 2019
a2cd3dc
default module manager order of operations from input modules
rigelrozanski Apr 17, 2019
26dae66
Merge branch 'rigel/genesis-generalization' into rigel/genesis-genera…
rigelrozanski Apr 17, 2019
1b805dd
working
rigelrozanski Apr 17, 2019
022498e
typo
rigelrozanski Apr 17, 2019
8e8345c
Merge branch 'rigel/genesis-generalization' into rigel/genesis-genera…
rigelrozanski Apr 17, 2019
2573df8
add AppModuleBasic
rigelrozanski Apr 17, 2019
9386263
moduleBasicManager / non-test code compiles
rigelrozanski Apr 17, 2019
a21406e
working attempting to get tests passing
rigelrozanski Apr 17, 2019
cf671d4
make test passes
rigelrozanski Apr 17, 2019
a2c8c28
sim random genesis fix
rigelrozanski Apr 18, 2019
c8a86bd
export bug
rigelrozanski Apr 18, 2019
cceb887
...
rigelrozanski Apr 18, 2019
a93c56a
genutil module
rigelrozanski Apr 19, 2019
da0a5f9
genutil working
rigelrozanski Apr 19, 2019
092aab3
Merge remote-tracking branch 'origin/develop' into rigel/genesis-gene…
rigelrozanski Apr 22, 2019
d2de398
Merge branch 'rigel/genesis-generalization' into rigel/genesis-genera…
rigelrozanski Apr 22, 2019
ec35f4d
Merge branch 'rigel/genesis-generalization2' into rigel/genesis-gener…
rigelrozanski Apr 22, 2019
4d36066
refactored - happy with non-testing code in cmd/
rigelrozanski Apr 23, 2019
add17c4
...
rigelrozanski Apr 23, 2019
93fa001
lint fixes
rigelrozanski Apr 23, 2019
c7fcefd
Merge branch 'rigel/genesis-generalization2' into rigel/genesis-gener…
rigelrozanski Apr 23, 2019
7977e7e
Merge remote-tracking branch 'origin/develop' into rigel/genesis-gene…
rigelrozanski Apr 26, 2019
62a2b69
Merge branch 'rigel/genesis-generalization' into rigel/genesis-genera…
rigelrozanski Apr 26, 2019
e2b257d
Merge branch 'rigel/genesis-generalization2' into rigel/genesis-gener…
rigelrozanski Apr 26, 2019
87ed491
comment improvement
rigelrozanski Apr 26, 2019
84a0167
Merge branch 'rigel/genesis-generalization' into rigel/genesis-genera…
rigelrozanski Apr 26, 2019
8054543
Merge branch 'rigel/genesis-generalization2' into rigel/genesis-gener…
rigelrozanski Apr 26, 2019
988da1b
cli test fix
rigelrozanski Apr 26, 2019
8fafc42
Merge branch 'rigel/genesis-generalization2' into rigel/genesis-gener…
rigelrozanski Apr 26, 2019
c8ed8ca
compile housing
rigelrozanski Apr 26, 2019
7e7fc06
working through compile errors
rigelrozanski Apr 27, 2019
b15175f
working gettin' compilin'
rigelrozanski Apr 28, 2019
1806ce1
non-test code compiles
rigelrozanski Apr 28, 2019
13840bd
Merge branch 'origin/master' into rigel/genesis-generalization
rigelrozanski Apr 29, 2019
f387889
Merge branch 'rigel/genesis-generalization' into rigel/genesis-genera…
rigelrozanski Apr 29, 2019
0c6d7e4
Merge branch 'rigel/genesis-generalization2' into rigel/genesis-gener…
rigelrozanski Apr 29, 2019
dca8f25
move testnet to its own module
rigelrozanski Apr 30, 2019
7e52f2d
reworking tests
rigelrozanski Apr 30, 2019
8008e48
bez staging PR 1 comments
rigelrozanski May 1, 2019
19e9edb
Merge branch 'rigel/genesis-generalization' into rigel/genesis-genera…
rigelrozanski May 1, 2019
d58b14d
Merge branch 'rigel/genesis-generalization2' into rigel/genesis-gener…
rigelrozanski May 1, 2019
1bd95b5
concise module function-of names
rigelrozanski May 1, 2019
bad6c13
Merge remote-tracking branch 'origin/master' into rigel/genesis-gener…
rigelrozanski May 1, 2019
62c7941
Merge remote-tracking branch 'origin/master' into rigel/genesis-gener…
rigelrozanski May 2, 2019
bfdc03a
moved all tests from genesis_test.go to other genutil tests
rigelrozanski May 2, 2019
5dc633b
genaccounts package, add genutil and genaccounts to app.go
rigelrozanski May 2, 2019
2b94f53
docs for genutil genaccounts
rigelrozanski May 2, 2019
b5bb13a
genaccounts iterate fn
rigelrozanski May 2, 2019
5a4cadf
non-test code with genaccounts/ now compiles
rigelrozanski May 2, 2019
0784d6a
working test compiling
rigelrozanski May 2, 2019
bc53079
Merge remote-tracking branch 'origin/master' into rigel/genesis-gener…
rigelrozanski May 3, 2019
56316cc
debugging tests
rigelrozanski May 4, 2019
b86f595
resolved all make test compile errors
rigelrozanski May 4, 2019
94fd81e
test debuggin
rigelrozanski May 6, 2019
1c4f39f
resolved all unit tests, introduced param module
rigelrozanski May 6, 2019
0f934a4
Merge remote-tracking branch 'origin/master' into rigel/genesis-gener…
rigelrozanski May 6, 2019
54b1dd3
cli-test compile fixes
rigelrozanski May 6, 2019
e051eca
staking initialization bug
rigelrozanski May 6, 2019
f760f46
Merge remote-tracking branch 'origin/master' into rigel/genesis-gener…
rigelrozanski May 8, 2019
1a8340b
code comment improvements, changelog entries
rigelrozanski May 8, 2019
8948d80
BasicGaiaApp -> ModuleBasics
rigelrozanski May 8, 2019
2053b83
highlevel explanation in types/module.go
rigelrozanski May 8, 2019
ebc7af9
Merge remote-tracking branch 'origin/master' into rigel/genesis-gener…
rigelrozanski May 8, 2019
44ff940
@alexanderbez comment revisions
rigelrozanski May 9, 2019
47d4817
@fedekunze PR comments
rigelrozanski May 9, 2019
aaed9ac
@alexanderbez PR comments (x2)
rigelrozanski May 9, 2019
1c2c4df
@cwgoes comments (minor updates)
rigelrozanski May 10, 2019
5a622b5
@fedekunze suggestions
rigelrozanski May 10, 2019
4196712
Merge remote-tracking branch 'origin/master' into rigel/genesis-gener…
rigelrozanski May 10, 2019
7e2b0d8
Merge remote-tracking branch 'origin/master' into rigel/genesis-gener…
rigelrozanski May 13, 2019
eb5f7a5
panic on init with multiple validator updates from different modules
rigelrozanski May 13, 2019
5c0aa05
initchain panic makes validate genesis fail
rigelrozanski May 13, 2019
a45a6f3
AppModuleGenesis seperation
rigelrozanski May 13, 2019
7563a16
test
rigelrozanski May 13, 2019
36a37a8
remove init panic logic in validate genesis replaced with TODO
rigelrozanski May 14, 2019
5c428b8
Merge remote-tracking branch 'origin/master' into rigel/genesis-gener…
rigelrozanski May 15, 2019
4528cf3
set maxprocs to match system's GOMAXPROCS
May 15, 2019
5349379
Update circleci
May 15, 2019
50dde98
Cap maxprocs in CI to 4
May 15, 2019
2bc901b
@alexanderbez recent comments addressed
rigelrozanski May 15, 2019
dc320a3
less blocks in twouble sims
rigelrozanski May 15, 2019
9bea7ee
runsim error output flag
rigelrozanski May 15, 2019
74a0042
-e on import_export as well
rigelrozanski May 15, 2019
e7f9c5a
error out
rigelrozanski May 15, 2019
6d9ddf1
Try to fix failures
May 15, 2019
9187c71
runsim
rigelrozanski May 16, 2019
7cee51a
Merge remote-tracking branch 'origin/alessio/runsim-default-maxprocs'…
rigelrozanski May 16, 2019
85be41a
Merge remote-tracking branch 'origin/master' into rigel/genesis-gener…
rigelrozanski May 16, 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
Prev Previous commit
Next Next commit
working through compile errors
  • Loading branch information
rigelrozanski committed Apr 27, 2019
commit 7e7fc06ab0792b008aa0e2b106fd7d722854edb9
4 changes: 2 additions & 2 deletions cmd/gaia/cmd/gaiad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
genutil "github.com/cosmos/cosmos-sdk/x/genutil"
genutil "github.com/cosmos/cosmos-sdk/x/genutil/server/cli"
)

// gaiad custom flags
Expand Down Expand Up @@ -48,7 +48,7 @@ func main() {
rootCmd.AddCommand(genutil.CollectGenTxsCmd(ctx, cdc))
rootCmd.AddCommand(genutil.TestnetFilesCmd(ctx, cdc))
rootCmd.AddCommand(genutil.GenTxCmd(ctx, cdc))
rootCmd.AddCommand(genutil.AddGenesisAccountCmd(ctx, cdc))
rootCmd.AddCommand(genutil.AddGenesisAccountCmd(ctx, cdc)) // XXX pass in the mbm validate function
rootCmd.AddCommand(genutil.ValidateGenesisCmd(ctx, cdc))
rootCmd.AddCommand(client.NewCompletionCmd(rootCmd, true))

Expand Down
6 changes: 3 additions & 3 deletions types/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type AppModuleBasic interface {
Name() string
RegisterCodec(*codec.Codec)
DefaultGenesis() json.RawMessage
ValidateGenesis(json.RawMessage) error
ValidateGenesis(*codec.Codec, json.RawMessage) error
}

// collections of AppModuleBasic
Expand All @@ -47,9 +47,9 @@ func (mbm ModuleBasicManager) DefaultGenesis() map[string]json.RawMessage {
}

// Provided default genesis information for all modules
func (mbm ModuleBasicManager) ValidateGenesis(genesis map[string]json.RawMessage) error {
func (mbm ModuleBasicManager) ValidateGenesis(cdc *codec.Codec, genesis map[string]json.RawMessage) error {
for _, mb := range mbm {
if err := mb.ValidateGenesis(genesis[mb.Name()]); err != nil {
if err := mb.ValidateGenesis(cdc, genesis[mb.Name()]); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion x/auth/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (AppModuleBasic) DefaultGenesis() json.RawMessage {
}

// module validate genesis
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
func (AppModuleBasic) ValidateGenesis(_ *codec.Codec, bz json.RawMessage) error {
var data GenesisState
err := moduleCdc.UnmarshalJSON(bz, &data)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (AppModuleBasic) DefaultGenesis() json.RawMessage {
}

// module validate genesis
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
func (AppModuleBasic) ValidateGenesis(_ *codec.Codec, bz json.RawMessage) error {
var data GenesisState
err := moduleCdc.UnmarshalJSON(bz, &data)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/crisis/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (AppModuleBasic) DefaultGenesis() json.RawMessage {
}

// module validate genesis
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
func (AppModuleBasic) ValidateGenesis(_ *codec.Codec, bz json.RawMessage) error {
var data GenesisState
err := moduleCdc.UnmarshalJSON(bz, &data)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (AppModuleBasic) DefaultGenesis() json.RawMessage {
}

// module validate genesis
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
func (AppModuleBasic) ValidateGenesis(_ *codec.Codec, bz json.RawMessage) error {
var data GenesisState
err := ModuleCdc.UnmarshalJSON(bz, &data)
if err != nil {
Expand Down
44 changes: 35 additions & 9 deletions x/genutil/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ import (
"github.com/tendermint/tendermint/crypto"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/cmd/gaia/app" // XXX XXX
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I agree that it makes sense to separate out this logic, I am not entirely convinced it should be a module, especially since it imports two other modules directly. Do we expect this to be used frequently by SDK chains other than gaia, in exactly this form?

If not, I wonder if a better structure might be to abstract out most of the common functionality into a library (subpackage of types/ maybe) and call it from Gaia - then applications could import what they need.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a good pattern

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup see my further comment, once the further abstraction is concluded, this should be able to be used by other blockchain projects with custom genesis account types and create validator messages. Thus it's good and ought to be a module.

based on comments here: #4159 (comment) I perceive it to be unwise to move have elements outside of x/ depend on things from x/ (until the point that they are just using expected interfaces which is not yet the case) - so yeah I'm pretty fiercely certain this aint' belong in types/ - but yeah see that other thread

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"github.com/cosmos/cosmos-sdk/x/staking" // XXX XXX
"github.com/cosmos/cosmos-sdk/x/staking"
)

const flagGenTxDir = "gentx-dir"
Expand Down Expand Up @@ -73,12 +72,34 @@ func genAppStateFromConfig(cdc *codec.Codec, config *cfg.Config,
}

// create the app state
genesisState, err := GenesisStateFromGenDoc(cdc, genDoc)
appGenesisState, err := GenesisStateFromGenDoc(cdc, genDoc)
if err != nil {
return appState, err
}
var genesisState GenesisState
cdc.UnmarshalJSON(appGenesisState[moduleName], &genesisState)

// convert all the GenTxs to JSON
var appGenTxsBz []json.RawMessage
for _, genTx := range appGenTxs {
txBz, err := cdc.MarshalJSON(genTx)
if err != nil {
return appState, err
}
appGenTxsBz = append(appGenTxsBz, txBz)
}

genesisState.GenTxs = appGenTxsBz
genesisStateBz, err := cdc.MarshalJSON(genesisState)
if err != nil {
return appState, err
}

appGenesisState[moduleName] = genesisStateBz
appState, err = codec.MarshalJSONIndent(cdc, appGenesisState)
if err != nil {
return appState, err
}
genesisState.Module[moduleName] = appGenTxs // XXXXXXXXXXXXX XXX fix up
appState = codec.MarshalJSONIndent(cdc, genesisState)

genDoc.AppState = appState
err = ExportGenesisFile(&genDoc, config.GenesisFile())
Expand All @@ -98,14 +119,18 @@ func CollectStdTxs(cdc *codec.Codec, moniker string, genTxsDir string, genDoc tm

// prepare a map of all accounts in genesis state to then validate
// against the validators addresses
var appState app.GenesisState
var appState ExpectedAppGenesisState
if err := cdc.UnmarshalJSON(genDoc.AppState, &appState); err != nil {
return appGenTxs, persistentPeers, err
}
var genesisState GenesisState
if err := cdc.UnmarshalJSON(appState[moduleName], &genesisState); err != nil {
return appGenTxs, persistentPeers, err
}

addrMap := make(map[string]app.GenesisAccount, len(appState.Accounts))
for i := 0; i < len(appState.Accounts); i++ {
acc := appState.Accounts[i]
addrMap := make(map[string]GenesisAccount, len(genesisState.Accounts))
for i := 0; i < len(genesisState.Accounts); i++ {
acc := genesisState.Accounts[i]
addrMap[acc.Address.String()] = acc
}

Expand Down Expand Up @@ -145,6 +170,7 @@ func CollectStdTxs(cdc *codec.Codec, moniker string, genTxsDir string, genDoc tm
"each genesis transaction must provide a single genesis message")
}

// TODO abstract out staking reference here through the expected staking keeper
msg := msgs[0].(staking.MsgCreateValidator)
// validate delegator and validator addresses and funds against the accounts in the state
delAddr := msg.DelegatorAddress.String()
Expand Down
13 changes: 12 additions & 1 deletion x/genutil/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package genutil

import (
"encoding/json"

abci "github.com/tendermint/tendermint/abci/types"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -12,8 +14,17 @@ type StakingKeeper interface {
ApplyAndReturnValidatorSetUpdates(sdk.Context) (updates []abci.ValidatorUpdate)
}

// expected account keeper
type AccountKeeper interface {
NewAccount(sdk.Context, auth.Account)
SetAccount(sdk.Context, auth.Account)
IterateAccounts(ctx sdk.Context, process func(Account) (stop bool))
IterateAccounts(ctx sdk.Context, process func(auth.Account) (stop bool))
}

// The expected format of app genesis state
type ExpectedAppGenesisState map[string]json.RawMessage

// expected cosmos app
type CosmosApp interface {
NewDefaultGenesisState() ExpectedAppGenesisState
}
14 changes: 9 additions & 5 deletions x/genutil/export.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
package genutil

import (
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
)

func ExportGenesis(accountKeeper AccountKeeper) GenesisState {
// export genesis for all accounts
func ExportGenesis(ctx sdk.Context, accountKeeper AccountKeeper) GenesisState {

// iterate to get the accounts
accounts := []GenesisAccount{}
app.accountKeeper.IterateAccounts(ctx,
accountKeeper.IterateAccounts(ctx,
func(acc auth.Account) (stop bool) {
account := NewGenesisAccountI(acc)
account, err := NewGenesisAccountI(acc)
if err != nil {
panic(err)
}
accounts = append(accounts, account)
return false
},
)

var genesisState GenesisState
genesisState.GenesisAccounts = accounts
genesisState.Accounts = accounts
return genesisState
}
10 changes: 5 additions & 5 deletions x/genutil/genesis_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ func NewGenesisAccountI(acc auth.Account) (GenesisAccount, error) {
Sequence: acc.GetSequence(),
}

if err := gacc.Validate(); err != nil {
return gacc, err
}

vacc, ok := acc.(auth.VestingAccount)
if ok {
err := ValidateVestingAccount(vacc)
if err != nil {
return err
}

gacc.OriginalVesting = vacc.GetOriginalVesting()
gacc.DelegatedFree = vacc.GetDelegatedFree()
gacc.DelegatedVesting = vacc.GetDelegatedVesting()
Expand Down Expand Up @@ -115,6 +114,7 @@ func (ga *GenesisAccount) ToAccount() auth.Account {
//___________________________________
type GenesisAccounts []GenesisAccount

// genesis accounts contain an address
func (gaccs GenesisAccounts) Contains(acc sdk.AccAddress) bool {
for _, gacc := range gaccs {
if gacc.Address.Equals(acc) {
Expand Down
18 changes: 8 additions & 10 deletions x/genutil/genesis_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"sort"
"time"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/staking" // XXX XXX
"github.com/cosmos/cosmos-sdk/x/staking"
)

// State to Unmarshal
Expand All @@ -29,14 +30,11 @@ func (gs GenesisState) Sanitize() {
}

// validate genesis information
func ValidateGenesis(genesisState GenesisState) error {
func ValidateGenesis(cdc *codec.Codec, genesisState GenesisState) error {
if err := validateGenesisStateAccounts(genesisState.Accounts); err != nil {
return err
}
if err := validateGenTxs(genesisState.GenTxs); err != nil {
return err
}
return nil
return validateGenTxs(cdc, genesisState.GenTxs)
}

// validateGenesisStateAccounts performs validation of genesis accounts. It
Expand Down Expand Up @@ -74,21 +72,21 @@ func validateGenesisStateAccounts(accs []GenesisAccount) error {
}

// validate GenTx transactions
func validateGenTxs(genTxs []json.RawMessage) error {
func validateGenTxs(cdc *codec.Codec, genTxs []json.RawMessage) error {
for i, genTx := range genTxs {
var tx auth.StdTx
if err := cdc.UnmarshalJSON(genTx, &tx); err != nil {
return genesisState, err
return err
}

msgs := tx.GetMsgs()
if len(msgs) != 1 {
return genesisState, errors.New(
return errors.New(
"must provide genesis StdTx with exactly 1 CreateValidator message")
}

if _, ok := msgs[0].(staking.MsgCreateValidator); !ok {
return genesisState, fmt.Errorf(
return fmt.Errorf(
"Genesis transaction %v does not contain a MsgCreateValidator", i)
}
}
Expand Down
15 changes: 9 additions & 6 deletions x/genutil/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/common"

"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
Expand All @@ -29,15 +28,19 @@ var (
defaultMinSelfDelegation = "1"
)

func accountInGenesis(genesisState app.GenesisState, key sdk.AccAddress, coins sdk.Coins, cdc *codec.Codec) error {
func validateAccountInGenesis(appGenesisState ExpectedGenesisState, key sdk.AccAddress, coins sdk.Coins, cdc *codec.Codec) error {
accountIsInGenesis := false

// TODO refactor out bond denom to common state area
stakingDataBz := genesisState.Modules[staking.ModuleName]
stakingDataBz := appGenesisState[staking.ModuleName]
var stakingData staking.GenesisState
cdc.MustUnmarshalJSON(stakingDataBz, &stakingData)
bondDenom := stakingData.Params.BondDenom

genUtilDataBz := appGenesisState[staking.ModuleName]
var genesisState GenesisState
cdc.MustUnmarshalJSON(genUtilDataBz, &genesisState)

// Check if the account is in genesis
for _, acc := range genesisState.Accounts {
// Ensure that account is in genesis
Expand All @@ -55,11 +58,11 @@ func accountInGenesis(genesisState app.GenesisState, key sdk.AccAddress, coins s
}
}

if accountIsInGenesis {
return nil
if !accountIsInGenesis {
return fmt.Errorf("account %s in not in the app_state.accounts array of genesis.json", key)
}

return fmt.Errorf("account %s in not in the app_state.accounts array of genesis.json", key)
return nil
}

func makeOutputFilepath(rootDir, nodeID string) (string, error) {
Expand Down
6 changes: 3 additions & 3 deletions x/genutil/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
)

const ModuleName = "genutil"
const moduleName = "genutil"

// app module basics object
type AppModuleBasic struct{}
Expand All @@ -27,13 +27,13 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {}
func (AppModuleBasic) DefaultGenesis() json.RawMessage { return nil }

// module validate genesis
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
func (AppModuleBasic) ValidateGenesis(cdc *codec.Codec, bz json.RawMessage) error {
var data GenesisState
err := ModuleCdc.UnmarshalJSON(bz, &data)
if err != nil {
return err
}
return ValidateGenesis(data)
return ValidateGenesis(cdc, data)
}

//___________________________
Expand Down
3 changes: 2 additions & 1 deletion x/genutil/server/cli/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/x/genutil"
)

const flagGenTxDir = "gentx-dir"
Expand All @@ -26,7 +27,7 @@ func CollectGenTxsCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
config := ctx.Config
config.SetRoot(viper.GetString(cli.HomeFlag))
name := viper.GetString(client.FlagName)
nodeID, valPubKey, err := InitializeNodeValidatorFiles(config)
nodeID, valPubKey, err := genutil.InitializeNodeValidatorFiles(config)
if err != nil {
return err
}
Expand Down
Loading