diff --git a/PENDING.md b/PENDING.md index 5d6a7e82d..05dd59ee0 100644 --- a/PENDING.md +++ b/PENDING.md @@ -58,6 +58,7 @@ BUG FIXES * [\#2921](https://github.com/cosmos/cosmos-sdk/issues/2921) Fix `keys delete` inability to delete offline and ledger keys. * Gaia + * [\#3003](https://github.com/cosmos/cosmos-sdk/issues/3003) CollectStdTxs() must validate DelegatorAddr against genesis accounts. * SDK * \#2967 Change ordering of `mint.BeginBlocker` and `distr.BeginBlocker`, recalculate inflation each block diff --git a/cmd/gaia/app/genesis.go b/cmd/gaia/app/genesis.go index d81d7d987..44cb9d2ee 100644 --- a/cmd/gaia/app/genesis.go +++ b/cmd/gaia/app/genesis.go @@ -213,8 +213,7 @@ func CollectStdTxs(cdc *codec.Codec, moniker string, genTxsDir string, genDoc tm addrMap := make(map[string]GenesisAccount, len(appState.Accounts)) for i := 0; i < len(appState.Accounts); i++ { acc := appState.Accounts[i] - strAddr := string(acc.Address) - addrMap[strAddr] = acc + addrMap[acc.Address.String()] = acc } // addresses and IPs (and port) validator server info @@ -254,20 +253,30 @@ func CollectStdTxs(cdc *codec.Codec, moniker string, genTxsDir string, genDoc tm "each genesis transaction must provide a single genesis message") } - // validate the validator address and funds against the accounts in the state msg := msgs[0].(stake.MsgCreateValidator) - addr := string(sdk.AccAddress(msg.ValidatorAddr)) - acc, ok := addrMap[addr] + // validate delegator and validator addresses and funds against the accounts in the state + delAddr := msg.DelegatorAddr.String() + valAddr := sdk.AccAddress(msg.ValidatorAddr).String() - if !ok { + delAcc, delOk := addrMap[delAddr] + _, valOk := addrMap[valAddr] + + accsNotInGenesis := []string{} + if !delOk { + accsNotInGenesis = append(accsNotInGenesis, delAddr) + } + if !valOk { + accsNotInGenesis = append(accsNotInGenesis, valAddr) + } + if len(accsNotInGenesis) != 0 { return appGenTxs, persistentPeers, fmt.Errorf( - "account %v not in genesis.json: %+v", addr, addrMap) + "account(s) %v not in genesis.json: %+v", strings.Join(accsNotInGenesis, " "), addrMap) } - if acc.Coins.AmountOf(msg.Delegation.Denom).LT(msg.Delegation.Amount) { + if delAcc.Coins.AmountOf(msg.Delegation.Denom).LT(msg.Delegation.Amount) { return appGenTxs, persistentPeers, fmt.Errorf( "insufficient fund for delegation %v: %v < %v", - acc.Address, acc.Coins.AmountOf(msg.Delegation.Denom), msg.Delegation.Amount, + delAcc.Address, delAcc.Coins.AmountOf(msg.Delegation.Denom), msg.Delegation.Amount, ) }