Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include Amount in Complete Unbonding/Redelegation Events #5597

Merged
merged 6 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
23 changes: 17 additions & 6 deletions x/staking/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,14 +660,16 @@ func (k Keeper) Undelegate(
return completionTime, nil
}

// CompleteUnbonding completes the unbonding of all mature entries in the
// retrieved unbonding delegation object.
func (k Keeper) CompleteUnbonding(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
// CompleteUnbondingWithAmount completes the unbonding of all mature entries in
// the retrieved unbonding delegation object and returns the total unbonding
// balance or an error upon failure.
func (k Keeper) CompleteUnbondingWithAmount(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (sdk.Coins, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Introducing a new function instead of replacing the old as we want to get this into the next 0.37 and 0.38 point releases.

ubd, found := k.GetUnbondingDelegation(ctx, delAddr, valAddr)
if !found {
return types.ErrNoUnbondingDelegation
return nil, types.ErrNoUnbondingDelegation
}

balances := sdk.NewCoins()
ctxTime := ctx.BlockHeader().Time

// loop through all the entries and complete unbonding mature entries
Expand All @@ -682,8 +684,10 @@ func (k Keeper) CompleteUnbonding(ctx sdk.Context, delAddr sdk.AccAddress, valAd
amt := sdk.NewCoins(sdk.NewCoin(k.GetParams(ctx).BondDenom, entry.Balance))
err := k.supplyKeeper.UndelegateCoinsFromModuleToAccount(ctx, types.NotBondedPoolName, ubd.DelegatorAddress, amt)
if err != nil {
return err
return nil, err
}

balances = balances.Add(amt...)
}
}
}
Expand All @@ -695,7 +699,14 @@ func (k Keeper) CompleteUnbonding(ctx sdk.Context, delAddr sdk.AccAddress, valAd
k.SetUnbondingDelegation(ctx, ubd)
}

return nil
return balances, nil
}

// CompleteUnbonding performs the same logic as CompleteUnbondingWithAmount except
// it does not return the total unbonding amount.
func (k Keeper) CompleteUnbonding(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
_, err := k.CompleteUnbondingWithAmount(ctx, delAddr, valAddr)
return err
}

// begin unbonding / redelegation; create a redelegation record
Expand Down
3 changes: 2 additions & 1 deletion x/staking/keeper/val_state_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ func (k Keeper) BlockValidatorUpdates(ctx sdk.Context) []abci.ValidatorUpdate {
// Remove all mature unbonding delegations from the ubd queue.
matureUnbonds := k.DequeueAllMatureUBDQueue(ctx, ctx.BlockHeader().Time)
for _, dvPair := range matureUnbonds {
err := k.CompleteUnbonding(ctx, dvPair.DelegatorAddress, dvPair.ValidatorAddress)
balances, err := k.CompleteUnbondingWithAmount(ctx, dvPair.DelegatorAddress, dvPair.ValidatorAddress)
if err != nil {
continue
}

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeCompleteUnbonding,
sdk.NewAttribute(sdk.AttributeKeyAmount, balances.String()),
sdk.NewAttribute(types.AttributeKeyValidator, dvPair.ValidatorAddress.String()),
sdk.NewAttribute(types.AttributeKeyDelegator, dvPair.DelegatorAddress.String()),
),
Expand Down
25 changes: 13 additions & 12 deletions x/staking/spec/07_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ The staking module emits the following events:

## EndBlocker

| Type | Attribute Key | Attribute Value |
|-----------------------|-----------------------|-----------------------|
| complete_unbonding | validator | {validatorAddress} |
| complete_unbonding | delegator | {delegatorAddress} |
| complete_redelegation | source_validator | {srcValidatorAddress} |
| complete_redelegation | destination_validator | {dstValidatorAddress} |
| complete_redelegation | delegator | {delegatorAddress} |
| Type | Attribute Key | Attribute Value |
| --------------------- | --------------------- | ---------------------- |
| complete_unbonding | amount | {totalUnbondingAmount} |
| complete_unbonding | validator | {validatorAddress} |
| complete_unbonding | delegator | {delegatorAddress} |
| complete_redelegation | source_validator | {srcValidatorAddress} |
| complete_redelegation | destination_validator | {dstValidatorAddress} |
| complete_redelegation | delegator | {delegatorAddress} |

## Handlers

### MsgCreateValidator

| Type | Attribute Key | Attribute Value |
|------------------|---------------|--------------------|
| ---------------- | ------------- | ------------------ |
| create_validator | validator | {validatorAddress} |
| create_validator | amount | {delegationAmount} |
| message | module | staking |
Expand All @@ -31,7 +32,7 @@ The staking module emits the following events:
### MsgEditValidator

| Type | Attribute Key | Attribute Value |
|----------------|---------------------|---------------------|
| -------------- | ------------------- | ------------------- |
| edit_validator | commission_rate | {commissionRate} |
| edit_validator | min_self_delegation | {minSelfDelegation} |
| message | module | staking |
Expand All @@ -41,7 +42,7 @@ The staking module emits the following events:
### MsgDelegate

| Type | Attribute Key | Attribute Value |
|----------|---------------|--------------------|
| -------- | ------------- | ------------------ |
| delegate | validator | {validatorAddress} |
| delegate | amount | {delegationAmount} |
| message | module | staking |
Expand All @@ -51,7 +52,7 @@ The staking module emits the following events:
### MsgUndelegate

| Type | Attribute Key | Attribute Value |
|---------|---------------------|--------------------|
| ------- | ------------------- | ------------------ |
| unbond | validator | {validatorAddress} |
| unbond | amount | {unbondAmount} |
| unbond | completion_time [0] | {completionTime} |
Expand All @@ -64,7 +65,7 @@ The staking module emits the following events:
### MsgBeginRedelegate

| Type | Attribute Key | Attribute Value |
|------------|-----------------------|-----------------------|
| ---------- | --------------------- | --------------------- |
| redelegate | source_validator | {srcValidatorAddress} |
| redelegate | destination_validator | {dstValidatorAddress} |
| redelegate | amount | {unbondAmount} |
Expand Down