Skip to content

Commit

Permalink
Merege PR #177: Enable using an orchestor account without balance a g…
Browse files Browse the repository at this point in the history
…entx

* Enable using an orchestor account without balance a gentx

* Fix testnet go.mod

* Update module/cmd/gravity/cmd/gentx.go

Co-authored-by: Jack Zampolin <[email protected]>
  • Loading branch information
zmanian and jackzampolin authored Sep 1, 2021
1 parent 45ea15a commit 860103c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
35 changes: 32 additions & 3 deletions module/cmd/gravity/cmd/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankexported "github.com/cosmos/cosmos-sdk/x/bank/exported"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
Expand All @@ -40,7 +41,7 @@ import (
)

// GenTxCmd builds the application's gentx command.
func GenTxCmd(mbm module.BasicManager, txEncCfg client.TxEncodingConfig, genBalIterator types.GenesisBalancesIterator, defaultNodeHome string) *cobra.Command {
func GenTxCmd(mbm module.BasicManager, txEncCfg client.TxEncodingConfig, genBalIterator types.GenesisBalancesIterator, genAccountIterator authtypes.GenesisAccountIterator, defaultNodeHome string) *cobra.Command {
ipDefault, _ := server.ExternalIP()
fsCreateValidator, defaultsDesc := cli.CreateValidatorMsgFlagSet(ipDefault)

Expand Down Expand Up @@ -149,9 +150,8 @@ $ %s gentx my-key-name 1000000stake 0x033030FEeBd93E3178487c35A9c8cA80874353C9 c
}

// validate orchestrator account in genesis and warn if not found
if err = genutil.ValidateAccountInGenesis(genesisState, genBalIterator, orchAddress, coins, cdc); err != nil {
if err = validateAccountPresentInGenesis(genesisState, genAccountIterator, orchAddress, coins, cdc); err != nil {
cmd.PrintErrf("orchestrator address not found in genesis file: %s\n", orchAddress)
return nil
}

txFactory := tx.NewFactoryCLI(clientCtx, cmd.Flags())
Expand Down Expand Up @@ -533,3 +533,32 @@ func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTx

return appGenTxs, persistentPeers, nil
}

func validateAccountPresentInGenesis(
appGenesisState map[string]json.RawMessage, genBalIterator authtypes.GenesisAccountIterator,
addr sdk.Address, coins sdk.Coins, cdc codec.Codec,
) error {

accountIsInGenesis := false

genBalIterator.IterateGenesisAccounts(cdc, appGenesisState,
func(acc authtypes.AccountI) (stop bool) {
accAddress := acc.GetAddress()

// ensure that account is in genesis
if accAddress.Equals(addr) {
// ensure account contains enough funds of default bond denom
accountIsInGenesis = true
return true
}

return false
},
)

if !accountIsInGenesis {
return fmt.Errorf("account %s does not have a balance in the genesis state", addr)
}

return nil
}
3 changes: 2 additions & 1 deletion module/cmd/gravity/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"github.com/cosmos/cosmos-sdk/x/auth/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
vestingcli "github.com/cosmos/cosmos-sdk/x/auth/vesting/client/cli"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
Expand Down Expand Up @@ -90,7 +91,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome),
CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
genutilcli.MigrateGenesisCmd(),
GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, authtypes.GenesisAccountIterator{}, app.DefaultNodeHome),
genutilcli.ValidateGenesisCmd(app.ModuleBasics),
AddGenesisAccountCmd(app.DefaultNodeHome),
tmcli.NewCompletionCmd(rootCmd, true),
Expand Down
4 changes: 2 additions & 2 deletions module/x/gravity/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func (k msgServer) SetDelegateKeys(c context.Context, msg *types.MsgDelegateKeys
if err = types.ValidateEthereumSignature(hash, msg.EthSignature, ethAddr); err != nil {
return nil, sdkerrors.Wrapf(
types.ErrDelegateKeys,
"failed to validate delegate keys signature for Ethereum address %X; %s",
ethAddr, err,
"failed to validate delegate keys signature for Ethereum address %X; %s ;%d",
ethAddr, err, nonce,
)
}

Expand Down
2 changes: 1 addition & 1 deletion testnet/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/peggyjv/gravity-bridge/module v0.0.0-00010101000000-000000000000
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/stretchr/testify v1.7.0
github.com/tendermint/tendermint v0.34.11
github.com/tendermint/tendermint v0.34.12
golang.org/x/net v0.0.0-20210610132358-84b48f89b13b // indirect
golang.org/x/sys v0.0.0-20210611083646-a4fc73990273 // indirect
gotest.tools/v3 v3.0.3 // indirect
Expand Down
7 changes: 4 additions & 3 deletions testnet/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ github.com/cosmos/iavl v0.15.0-rc5/go.mod h1:WqoPL9yPTQ85QBMT45OOUzPxG/U/JcJoN7u
github.com/cosmos/iavl v0.15.3/go.mod h1:OLjQiAQ4fGD2KDZooyJG9yz+p2ao2IAYSbke8mVvSA4=
github.com/cosmos/iavl v0.16.0 h1:ICIOB8xysirTX27GmVAaoeSpeozzgSu9d49w36xkVJA=
github.com/cosmos/iavl v0.16.0/go.mod h1:2A8O/Jz9YwtjqXMO0CjnnbTYEEaovE8jWcwrakH3PoE=
github.com/cosmos/ibc-go v1.0.0 h1:RtIRERSENyApp6WK7Germ3/wq8xvHxfsqfW/Xh+CJ2o=
github.com/cosmos/ibc-go v1.0.0/go.mod h1:2wHKQUa+BLJMEyN635KrHfmTTwSNHBtXcqdY8JWGuXA=
github.com/cosmos/ibc-go v1.0.1 h1:3g2e4lghZea6Yrvj5PBViZrHdcEbG6iq7eulq3vsmxk=
github.com/cosmos/ibc-go v1.0.1/go.mod h1:pfLnoW9yUdjSMw3rD0baIsqLBauVAlGFQ1zQ3HGK6J0=
github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4=
github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY=
github.com/cosmos/ledger-go v0.9.2 h1:Nnao/dLwaVTk1Q5U9THldpUMMXU94BOTWPddSmVB6pI=
Expand Down Expand Up @@ -823,8 +823,9 @@ github.com/tendermint/tendermint v0.34.0-rc4/go.mod h1:yotsojf2C1QBOw4dZrTcxbyxm
github.com/tendermint/tendermint v0.34.0-rc6/go.mod h1:ugzyZO5foutZImv0Iyx/gOFCX6mjJTgbLHTwi17VDVg=
github.com/tendermint/tendermint v0.34.0/go.mod h1:Aj3PIipBFSNO21r+Lq3TtzQ+uKESxkbA3yo/INM4QwQ=
github.com/tendermint/tendermint v0.34.10/go.mod h1:aeHL7alPh4uTBIJQ8mgFEE8VwJLXI1VD3rVOmH2Mcy0=
github.com/tendermint/tendermint v0.34.11 h1:q1Yh76oG4QbS07xhmIJh5iAE0fYpJ8P8YKYtjnWfJRY=
github.com/tendermint/tendermint v0.34.11/go.mod h1:aeHL7alPh4uTBIJQ8mgFEE8VwJLXI1VD3rVOmH2Mcy0=
github.com/tendermint/tendermint v0.34.12 h1:m+kUYNhONedhJfHmHG8lqsdZvbR5t6vmhaok1yXjpKg=
github.com/tendermint/tendermint v0.34.12/go.mod h1:aeHL7alPh4uTBIJQ8mgFEE8VwJLXI1VD3rVOmH2Mcy0=
github.com/tendermint/tm-db v0.6.2/go.mod h1:GYtQ67SUvATOcoY8/+x6ylk8Qo02BQyLrAs+yAcLvGI=
github.com/tendermint/tm-db v0.6.3/go.mod h1:lfA1dL9/Y/Y8wwyPp2NMLyn5P5Ptr/gvDFNWtrCWSf8=
github.com/tendermint/tm-db v0.6.4 h1:3N2jlnYQkXNQclQwd/eKV/NzlqPlfK21cpRRIx80XXQ=
Expand Down

0 comments on commit 860103c

Please sign in to comment.