cosmos-sdk/simapp
Sai Kumar 5bde3686c4
feat: Cancel unbonding delegation entry (#10885)
## Description


Closes: #577

This pull request contains `Canceling unbonding delegation entry` and `delegate back to previous validator`

### `Msg` Service
```protobuf=
package cosmos.staking.v1beta1;

service Msg {
    // CancelUnbondingDelegation
    rpc CancelUnbondingDelegation(MsgCancelUnbondingDelegation) returns (MsgCancelUnbondingDelegationResponse);
}

// MsgCancelUnbondingDelegation
message MsgCancelUnbondingDelegation {
  option (gogoproto.equal)           = false;
  option (gogoproto.goproto_getters) = false;

  string                   delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
  string                   validator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
  cosmos.base.v1beta1.Coin amount            = 3 [(gogoproto.nullable) = false];
  // creation_height is the height which the unbonding took place.
  int64 creation_height = 4;
}

// MsgCancelUnbondingDelegationResponse
message MsgCancelUnbondingDelegationResponse{
}
```

### `Msg` Method Implementation
```go=
func (k msgServer) CancelUnbondingDelegation(goCtx context.Context, msg *types.MsgCancelUnbondingDelegation) (*types.MsgCancelUnbondingDelegationResponse, error) {
    /*
    // checking the unbonding delegation at creation_height 
         // get the unbonding delegations of delegatorAddress 
        if ubdEntry balance is equal to msg.Amount 
            remove the entry from ubd  
        else 
            update the specific entry with new balance
                
        if len(ubd.Entries) == 0 {
            k.RemoveUnbondingDelegation(ctx, ubd)
        } else {
            k.SetUnbondingDelegation(ctx, ubd)
        }
    */
    

    // update the delegation back to validator 
    // get validator
        validator, found := k.GetValidator(ctx, valAddr)
        if !found {
            return nil, types.ErrNoValidatorFound
        }

        // delegate the unbonding amount to validator back
        _, err = k.Keeper.Delegate(ctx, delegatorAddress, msg.Amount.Amount, types.Unbonding, validator, false)
        if err != nil {
            return nil, err
        }
    
    
        _, err := ms.Keeper.CancelUnbondingDelegation(ctx,delegatorAddress,validatorAddress,amount,creation_height)
        if err != nil {
            return nil, err 
        }


        return &types.MsgCancelUnbondingDelegationResponse{}, nil
}
```

#### `cli tx` Method
```bash=
simd tx staking cancel-unbond [validator-address] [amount] [creation_height] --from [user] --chain-id [chain-id]
Example: 
simd tx staking cancel-unbond cosmosvaloper1mqtyv4qux68r26mql2hjhgrvz72snjwpulq22m 100000stake 10280 --from test1 --chain-id test-chain
```

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2022-04-05 10:01:13 +00:00
..
helpers refactor: Change SignerData.SignerIndex to PubKey (#10692) 2021-12-08 11:43:15 +00:00
params feat: Cancel unbonding delegation entry (#10885) 2022-04-05 10:01:13 +00:00
simd revert: Revert "feat: staking config (#10988)" (#11446) 2022-03-24 12:26:25 +01:00
README.md docs: Improve markdownlint configuration (#11104) 2022-02-10 12:07:01 +00:00
app.go revert: Revert "feat: staking config (#10988)" (#11446) 2022-03-24 12:26:25 +01:00
app_test.go docs: improve RegisterMigration docs (#11225) 2022-02-18 12:42:47 +00:00
config.go feat(types): Deprecate the DBBackend variable in favor of new app-db-backend config entry (#11188) 2022-03-18 10:26:20 +01:00
encoding.go codecs: rename MakeCodecs rename and docs update (#8245) 2021-01-07 21:50:52 +00:00
export.go feat!: add error handling to staking hooks (#9571) 2021-06-30 10:13:07 +00:00
genesis.go x/authz: audit updates (#9042) 2021-05-06 18:23:48 +00:00
genesis_account.go x/auth: remove alias.go usage (#6440) 2020-06-17 14:42:27 -04:00
genesis_account_test.go Update tm pubkey references (#7102) 2020-08-28 16:02:38 +00:00
sim_bench_test.go simapp, types: fix benchmarks panics by honoring skip if set (#8763) 2021-03-03 03:54:14 -08:00
sim_test.go feat(authz)!: pruning expired authorizations (#10714) 2022-02-16 17:36:50 +00:00
state.go refactor: move from io/ioutil to io and os package (#10341) 2021-10-13 07:38:22 +00:00
test_helpers.go revert: Revert "feat: staking config (#10988)" (#11446) 2022-03-24 12:26:25 +01:00
types.go Add height in exported genesis (#7089) 2020-09-03 10:11:46 +00:00
utils.go feat(types): Deprecate the DBBackend variable in favor of new app-db-backend config entry (#11188) 2022-03-18 10:26:20 +01:00
utils_test.go codec: Rename codec and marshaler interfaces (#9226) 2021-04-29 10:46:22 +00:00

README.md

order
false

simapp

simapp is an application built using the Cosmos SDK for testing and educational purposes.

Running testnets with simd

If you want to spin up a quick testnet with your friends, you can follow these steps. Unless otherwise noted, every step must be done by everyone who wants to participate in this testnet.

  1. From the root directory of the Cosmos SDK repository, run $ make build. This will build the simd binary inside a new build directory. The following instructions are run from inside the build directory.

  2. If you've run simd before, you may need to reset your database before starting a new testnet. You can reset your database with the following command: $ ./simd unsafe-reset-all.

  3. $ ./simd init [moniker] --chain-id [chain-id]. This will initialize a new working directory at the default location ~/.simapp. You need to provide a "moniker" and a "chain id". These two names can be anything, but you will need to use the same "chain id" in the following steps.

  4. $ ./simd keys add [key_name]. This will create a new key, with a name of your choosing. Save the output of this command somewhere; you'll need the address generated here later.

  5. $ ./simd add-genesis-account [key_name] [amount], where key_name is the same key name as before; and amount is something like 10000000000000000000000000stake.

  6. $ ./simd gentx [key_name] [amount] --chain-id [chain-id]. This will create the genesis transaction for your new chain. Here amount should be at least 1000000000stake. If you provide too much or too little, you will encounter an error when starting your node.

  7. Now, one person needs to create the genesis file genesis.json using the genesis transactions from every participant, by gathering all the genesis transactions under config/gentx and then calling $ ./simd collect-gentxs. This will create a new genesis.json file that includes data from all the validators (we sometimes call it the "super genesis file" to distinguish it from single-validator genesis files).

  8. Once you've received the super genesis file, overwrite your original genesis.json file with the new super genesis.json.

  9. Modify your config/config.toml (in the simapp working directory) to include the other participants as persistent peers:

    # Comma separated list of nodes to keep persistent connections to
    persistent_peers = "[validator_address]@[ip_address]:[port],[validator_address]@[ip_address]:[port]"
    

    You can find validator_address by running $ ./simd tendermint show-node-id. The output will be the hex-encoded validator_address. The default port is 26656.

  10. Now you can start your nodes: $ ./simd start.

Now you have a small testnet that you can use to try out changes to the Cosmos SDK or Tendermint!

NOTE: Sometimes creating the network through the collect-gentxs will fail, and validators will start in a funny state (and then panic). If this happens, you can try to create and start the network first with a single validator and then add additional validators using a create-validator transaction.