Skip to content

Commit

Permalink
Merge branch 'master' into sunny/sortabledecbytes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Dec 5, 2019
2 parents 3a65426 + 0300a6f commit 0c8eb18
Show file tree
Hide file tree
Showing 33 changed files with 933 additions and 543 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ upgrade via: `sudo rm -rf /Library/Developer/CommandLineTools; xcode-select --in
correct version via: `pkgutil --pkg-info=com.apple.pkg.CLTools_Executables`.
* (keys) [\#5097](https://github.com/cosmos/cosmos-sdk/pull/5097) New `keys migrate` command to assist users migrate their keys
to the new keyring.
* (keys) [\#5366](https://github.com/cosmos/cosmos-sdk/pull/5366) `keys list` now accepts a `--list-names` option to list key names only, whilst the `keys delete`
command can delete multiple keys by passing their names as arguments. The aforementioned commands can then be piped together, e.g.
`appcli keys list -n | xargs appcli keys delete`
* (modules) [\#4233](https://github.com/cosmos/cosmos-sdk/pull/4233) Add upgrade module that coordinates software upgrades of live chains.
* [\#4486](https://github.com/cosmos/cosmos-sdk/issues/4486) Introduce new `PeriodicVestingAccount` vesting account type
that allows for arbitrary vesting periods.
Expand Down Expand Up @@ -172,12 +175,15 @@ generalized genesis accounts through the `GenesisAccount` interface.
* (simulation) [\#4824](https://github.com/cosmos/cosmos-sdk/issues/4824) PrintAllInvariants flag will print all failed invariants
* (simulation) [\#4490](https://github.com/cosmos/cosmos-sdk/issues/4490) add `InitialBlockHeight` flag to resume a simulation from a given block
* Support exporting the simulation stats to a given JSON file
* (simulation) [\#4847](https://github.com/cosmos/cosmos-sdk/issues/4847), [\#4838](https://github.com/cosmos/cosmos-sdk/pull/4838) `SimApp` and simulation refactors
* (simulation) [\#4847](https://github.com/cosmos/cosmos-sdk/issues/4847), [\#4838](https://github.com/cosmos/cosmos-sdk/pull/4838) and [\#4869](https://github.com/cosmos/cosmos-sdk/pull/4869) `SimApp` and simulation refactors:
* Implement `SimulationManager` for executing modules' simulation functionalities in a modularized way
* Add `RegisterStoreDecoders` to the `SimulationManager` for decoding each module's types
* Add `GenerateGenesisStates` to the `SimulationManager` to generate a randomized `GenState` for each module
* Add `RandomizedParams` to the `SimulationManager` that registers each modules' parameters `Content` to simulate
`ParamChangeProposal`s
* Add `RandomizedParams` to the `SimulationManager` that registers each modules' parameters in order to
simulate `ParamChangeProposal`s' `Content`s
* Add `WeightedOperations` to the `SimulationManager` that define simulation operations (modules' `Msg`s) with their
respective weights (i.e chance of being simulated).
* Add `ProposalContents` to the `SimulationManager` to register each module's governance proposal `Content`s.
* (simulation) [\#4893](https://github.com/cosmos/cosmos-sdk/issues/4893) Change SimApp keepers to be public and add getter functions for keys and codec
* (simulation) [\#4906](https://github.com/cosmos/cosmos-sdk/issues/4906) Add simulation `Config` struct that wraps simulation flags
* (simulation) [\#4935](https://github.com/cosmos/cosmos-sdk/issues/4935) Update simulation to reflect a proper `ABCI` application without bypassing `BaseApp` semantics
Expand Down
44 changes: 23 additions & 21 deletions client/keys/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,61 @@ const (

func deleteKeyCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "delete <name>",
Short: "Delete the given key",
Long: `Delete a key from the store.
Use: "delete <name>...",
Short: "Delete the given keys",
Long: `Delete keys from the Keybase backend.
Note that removing offline or ledger keys will remove
only the public key references stored locally, i.e.
private keys stored in a ledger device cannot be deleted with the CLI.
`,
RunE: runDeleteCmd,
Args: cobra.ExactArgs(1),
Args: cobra.MinimumNArgs(1),
}

cmd.Flags().BoolP(flagYes, "y", false,
"Skip confirmation prompt when deleting offline or ledger key references")
cmd.Flags().BoolP(flagForce, "f", false,
"Remove the key unconditionally without asking for the passphrase")
"Remove the key unconditionally without asking for the passphrase. Deprecated.")
return cmd
}

func runDeleteCmd(cmd *cobra.Command, args []string) error {
name := args[0]
buf := bufio.NewReader(cmd.InOrStdin())

kb, err := NewKeyringFromHomeFlag(buf)
if err != nil {
return err
}

info, err := kb.Get(name)
if err != nil {
return err
}
for _, name := range args {
info, err := kb.Get(name)
if err != nil {
return err
}

if info.GetType() == keys.TypeLedger || info.GetType() == keys.TypeOffline {
// confirm deletion, unless -y is passed
if !viper.GetBool(flagYes) {
if err := confirmDeletion(buf); err != nil {
if info.GetType() == keys.TypeLedger || info.GetType() == keys.TypeOffline {
// confirm deletion, unless -y is passed
if !viper.GetBool(flagYes) {
if err := confirmDeletion(buf); err != nil {
return err
}
}

if err := kb.Delete(name, "", true); err != nil {
return err
}
cmd.PrintErrln("Public key reference deleted")
return nil
}

// old password and skip flag arguments are ignored
if err := kb.Delete(name, "", true); err != nil {
return err
}
cmd.PrintErrln("Public key reference deleted")
return nil
cmd.PrintErrln("Key deleted forever (uh oh!)")
}

// old password and skip flag arguments are ignored
if err := kb.Delete(name, "", true); err != nil {
return err
}
cmd.PrintErrln("Key deleted forever (uh oh!)")
return nil
}

Expand Down
21 changes: 18 additions & 3 deletions client/keys/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package keys

import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/cosmos/cosmos-sdk/client/flags"
)

const flagListNames = "list-names"

func listKeysCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Expand All @@ -15,18 +18,30 @@ along with their associated name and address.`,
RunE: runListCmd,
}
cmd.Flags().Bool(flags.FlagIndentResponse, false, "Add indent to JSON response")
cmd.Flags().BoolP(flagListNames, "n", false, "List names only")
return cmd
}

func runListCmd(cmd *cobra.Command, args []string) error {
func runListCmd(cmd *cobra.Command, _ []string) error {
kb, err := NewKeyringFromHomeFlag(cmd.InOrStdin())
if err != nil {
return err
}

infos, err := kb.List()
if err == nil {
if err != nil {
return err
}

if !viper.GetBool(flagListNames) {
printInfos(infos)
return nil
}

cmd.SetOut(cmd.OutOrStdout())
for _, info := range infos {
cmd.Println(info.GetName())
}
return err

return nil
}
9 changes: 9 additions & 0 deletions client/keys/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,19 @@ func Test_runListCmd(t *testing.T) {
if runningUnattended {
mockIn.Reset("testpass1\ntestpass1\n")
}
viper.Set(flagListNames, false)
viper.Set(flags.FlagHome, tt.kbDir)
if err := runListCmd(tt.args.cmd, tt.args.args); (err != nil) != tt.wantErr {
t.Errorf("runListCmd() error = %v, wantErr %v", err, tt.wantErr)
}

if runningUnattended {
mockIn.Reset("testpass1\ntestpass1\n")
}
viper.Set(flagListNames, true)
if err := runListCmd(tt.args.cmd, tt.args.args); (err != nil) != tt.wantErr {
t.Errorf("runListCmd() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
13 changes: 7 additions & 6 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ func NewSimApp(
bank.NewAppModule(app.BankKeeper, app.AccountKeeper),
crisis.NewAppModule(&app.CrisisKeeper),
supply.NewAppModule(app.SupplyKeeper, app.AccountKeeper),
gov.NewAppModule(app.GovKeeper, app.SupplyKeeper),
gov.NewAppModule(app.GovKeeper, app.AccountKeeper, app.SupplyKeeper),
mint.NewAppModule(app.MintKeeper),
distr.NewAppModule(app.DistrKeeper, app.SupplyKeeper),
slashing.NewAppModule(app.SlashingKeeper, app.StakingKeeper),
slashing.NewAppModule(app.SlashingKeeper, app.AccountKeeper, app.StakingKeeper),
distr.NewAppModule(app.DistrKeeper, app.AccountKeeper, app.SupplyKeeper, app.StakingKeeper),
staking.NewAppModule(app.StakingKeeper, app.AccountKeeper, app.SupplyKeeper),
upgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
Expand Down Expand Up @@ -260,11 +260,12 @@ func NewSimApp(
auth.NewAppModule(app.AccountKeeper),
bank.NewAppModule(app.BankKeeper, app.AccountKeeper),
supply.NewAppModule(app.SupplyKeeper, app.AccountKeeper),
gov.NewAppModule(app.GovKeeper, app.SupplyKeeper),
gov.NewAppModule(app.GovKeeper, app.AccountKeeper, app.SupplyKeeper),
mint.NewAppModule(app.MintKeeper),
distr.NewAppModule(app.DistrKeeper, app.SupplyKeeper),
staking.NewAppModule(app.StakingKeeper, app.AccountKeeper, app.SupplyKeeper),
slashing.NewAppModule(app.SlashingKeeper, app.StakingKeeper),
distr.NewAppModule(app.DistrKeeper, app.AccountKeeper, app.SupplyKeeper, app.StakingKeeper),
slashing.NewAppModule(app.SlashingKeeper, app.AccountKeeper, app.StakingKeeper),
params.NewAppModule(), // NOTE: only used for simulation to generate randomized param change proposals
)

app.sm.RegisterStoreDecoders()
Expand Down
21 changes: 2 additions & 19 deletions simapp/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,6 @@ package simapp

// Simulation parameter constants
const (
StakePerAccount = "stake_per_account"
InitiallyBondedValidators = "initially_bonded_validators"
OpWeightDeductFee = "op_weight_deduct_fee"
OpWeightMsgSend = "op_weight_msg_send"
OpWeightMsgMultiSend = "op_weight_msg_multisend"
OpWeightMsgSetWithdrawAddress = "op_weight_msg_set_withdraw_address"
OpWeightMsgWithdrawDelegationReward = "op_weight_msg_withdraw_delegation_reward"
OpWeightMsgWithdrawValidatorCommission = "op_weight_msg_withdraw_validator_commission"
OpWeightSubmitTextProposal = "op_weight_submit_text_proposal"
OpWeightSubmitCommunitySpendProposal = "op_weight_submit_community_spend_proposal"
OpWeightSubmitParamChangeProposal = "op_weight_submit_param_change_proposal"
OpWeightMsgDeposit = "op_weight_msg_deposit"
OpWeightMsgVote = "op_weight_msg_vote"
OpWeightMsgCreateValidator = "op_weight_msg_create_validator"
OpWeightMsgEditValidator = "op_weight_msg_edit_validator"
OpWeightMsgDelegate = "op_weight_msg_delegate"
OpWeightMsgUndelegate = "op_weight_msg_undelegate"
OpWeightMsgBeginRedelegate = "op_weight_msg_begin_redelegate"
OpWeightMsgUnjail = "op_weight_msg_unjail"
StakePerAccount = "stake_per_account"
InitiallyBondedValidators = "initially_bonded_validators"
)
19 changes: 19 additions & 0 deletions simapp/params/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Package params defines the simulation parameters in the simapp.
It contains the default weights used for each transaction used on the module's
simulation. These weights define the chance for a transaction to be simulated at
any gived operation.
You can repace the default values for the weights by providing a params.json
file with the weights defined for each of the transaction operations:
{
"op_weight_msg_send": 60,
"op_weight_msg_delegate": 100,
}
In the example above, the `MsgSend` has 60% chance to be simulated, while the
`MsgDelegate` will always be simulated.
*/
package params
22 changes: 22 additions & 0 deletions simapp/params/weights.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package params

// Default simulation operation weights for messages and gov proposals
const (
DefaultWeightMsgSend int = 100
DefaultWeightMsgMultiSend int = 10
DefaultWeightMsgSetWithdrawAddress int = 50
DefaultWeightMsgWithdrawDelegationReward int = 50
DefaultWeightMsgWithdrawValidatorCommission int = 50
DefaultWeightMsgDeposit int = 100
DefaultWeightMsgVote int = 67
DefaultWeightMsgUnjail int = 100
DefaultWeightMsgCreateValidator int = 100
DefaultWeightMsgEditValidator int = 5
DefaultWeightMsgDelegate int = 100
DefaultWeightMsgUndelegate int = 100
DefaultWeightMsgBeginRedelegate int = 100

DefaultWeightCommunitySpendProposal int = 5
DefaultWeightTextProposal int = 5
DefaultWeightParamChangeProposal int = 5
)
6 changes: 4 additions & 2 deletions simapp/sim_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func BenchmarkFullAppSimulation(b *testing.B) {
// TODO: parameterize numbers, save for a later PR
_, simParams, simErr := simulation.SimulateFromSeed(
b, os.Stdout, app.BaseApp, AppStateFn(app.Codec(), app.sm),
testAndRunTxs(app, config), app.ModuleAccountAddrs(), config,
SimulationOperations(app, app.Codec(), config),
app.ModuleAccountAddrs(), config,
)

// export state and params before the simulation error is checked
Expand Down Expand Up @@ -86,7 +87,8 @@ func BenchmarkInvariants(b *testing.B) {
// 2. Run parameterized simulation (w/o invariants)
_, simParams, simErr := simulation.SimulateFromSeed(
b, ioutil.Discard, app.BaseApp, AppStateFn(app.Codec(), app.sm),
testAndRunTxs(app, config), app.ModuleAccountAddrs(), config,
SimulationOperations(app, app.Codec(), config),
app.ModuleAccountAddrs(), config,
)

// export state and params before the simulation error is checked
Expand Down
Loading

0 comments on commit 0c8eb18

Please sign in to comment.