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

staking msgServer.CancelUnbondingDelegation could possibly choose mismatching UnbondingDelegationEntry to cancel #12931

Closed
adu-crypto opened this issue Aug 16, 2022 · 11 comments · Fixed by #12967

Comments

@adu-crypto
Copy link
Contributor

Summary of Bug

this is an issue found in cronos latest simulation: crypto-org-chain/cronos#645.
Generally speaking, two UnbondingDelegationEntry could have the same CreationHeight, and the current unbond entry matching logic of msgServer.CancelUnbondingDelegation is ambiguous when dealing with this case.

Version

main and v0.46

Steps to Reproduce

refer to crypto-org-chain/cronos#645

@anilcse
Copy link
Collaborator

anilcse commented Aug 16, 2022

This we discussed internally with @gsk967 and possible solution can be:

  • Restrict user to cancel entire unbonding. The original implementation allowed user to cancel a part (can be full) of the unbonding. Like if there are 1000token unbonding, user can cancel 500tokens if they wish. If we have to match the amount, we should remove this flexibility

cc @gsk967

@anilcse
Copy link
Collaborator

anilcse commented Aug 16, 2022

We can update the docs now to clarify this behavior and introduce a breaking chage in next release which would allow delegator to either force cancel-ubd with exact amount or allow a partical cancellation of ubd.

@yihuang
Copy link
Collaborator

yihuang commented Aug 16, 2022

I think there are two issues here:

  1. currently, our simulation tests fail because of this, that probably can be fixed at the test case generation logic, maybe don't generate multiple unbonding requests at the same block?
  2. is current behavior expected or problematic?

@anilcse
Copy link
Collaborator

anilcse commented Aug 16, 2022

It is expected behavior as per the implementation. But best solution can be giving an option for the delegator to chose either to cancel-entire unbonding or partial. Which is not there atm. It's not that problematic afaik. Having multiple unbondings between same-validator and delegator combination sounds rare to me. imo, it's not critical, should address in next release.

  1. currently, our simulation tests fail because of this, that probably can be fixed at the test case generation logic, maybe don't generate multiple unbonding requests at the same block?

Yes, that should fix your simulations. You can consider multiple unbondings from different delegators<>validator combo if required.

@adu-crypto
Copy link
Contributor Author

I think the current behavior is misleading.
the root cause is that we don't have the unique identifier for UnbondingDelegationEntry, so the delegator could not correctly specify which unbonding entry to cancel.

@anilcse
Copy link
Collaborator

anilcse commented Aug 16, 2022

Yes, the fix for this can be either to consdier unbonding-entry input from user or match exact amount

@anilcse
Copy link
Collaborator

anilcse commented Aug 16, 2022

For better UX, I would advise for matching exact amount instead of asking user to input the ubd entry. If there are multiple entries of same amount, I don't see any problem in cancelling any one of them.

@alexanderbez
Copy link
Contributor

For better UX, I would advise for matching exact amount instead of asking user to input the ubd entry. If there are multiple entries of same amount, I don't see any problem in cancelling any one of them.

agreed.

mergify bot pushed a commit that referenced this issue Aug 17, 2022
…e` failure (#12933)

## Description


---
This is a temporary fix targeted at staking module simulation for #12931.
We should randomly choose the unbonding entry `CreationHeight`, and then fetch the first entry that matches the `CreationHeight` to make sure we can get the correct entry balance.
### 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/main/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/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/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)
@gsk967
Copy link
Contributor

gsk967 commented Aug 18, 2022

@anilcse @marbar3778 @alexanderbez

When delegator broadcast the multiple unbonding delegations msgs on same height, we are generating the multiple records with same creation_height and completion_time

instead of this way, can't we just update the balance and initial_balance to the existing unbonding delegation

Sample Query

simd q staking unbonding-delegations cosmos1huplz9naax6qe0g2pdaupjcmv4y0fxvhhkte73
pagination:
  next_key: null
  total: "0"
unbonding_responses:
- delegator_address: cosmos1huplz9naax6qe0g2pdaupjcmv4y0fxvhhkte73
  entries:
  - balance: "100"
    completion_time: "2022-09-08T10:35:22.277275812Z"
    creation_height: "110"
    initial_balance: "100"
  - balance: "20"
    completion_time: "2022-09-08T10:35:22.277275812Z"
    creation_height: "110"
    initial_balance: "20"
  - balance: "30"
    completion_time: "2022-09-08T10:35:22.277275812Z"
    creation_height: "110"
    initial_balance: "30"
  validator_address: cosmosvaloper16q08najdx3gu3gk5zyh4p7sa94knz4ukj5kclz

Solution:

// AddEntry - append entry to the unbonding delegation
func (ubd *UnbondingDelegation) AddEntry(creationHeight int64, minTime time.Time, balance math.Int) {
    // Check the entries exists with creation_height and complete_time
    var entryIndex int64 = -1 
    for index, ubdEntry := ranage ubd.Entries {
        if ubdEntry.CreationHeight == creationHeight && ubdEntry.CompletionTime.Equal(minTime){
            entryIndex = index
            break
        }
    }
    // entryIndex exists 
    if entryIndex != -1 {
        ubdEntry = ubd.Entries[entryIndex]
        ubdEntry.Balance =  ubdEntry.Balance.Add(balance)
        ubdEntry.InitialBalance =  ubdEntry.InitialBalance.Add(balance)

        // update the entry 
        ubd.Entries[entryIndex] = ubdEntry
    }else{
        // append the new unbond delegation entry 
        entry := NewUnbondingDelegationEntry(creationHeight, minTime, balance)
	    ubd.Entries = append(ubd.Entries, entry)
    }
}

@anilcse
Copy link
Collaborator

anilcse commented Aug 18, 2022

This would save us some storage too. Agree with this

@alexanderbez
Copy link
Contributor

@gsk967 I can't see why that wouldn't work. I think it makes sense. Let's do it!

mergify bot pushed a commit that referenced this issue Aug 18, 2022
…e` failure (#12933)

## Description

---
This is a temporary fix targeted at staking module simulation for #12931.
We should randomly choose the unbonding entry `CreationHeight`, and then fetch the first entry that matches the `CreationHeight` to make sure we can get the correct entry balance.
### 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/main/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/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/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)

(cherry picked from commit e130915)

# Conflicts:
#	go.work.sum
@gsk967 gsk967 mentioned this issue Aug 19, 2022
19 tasks
@mergify mergify bot closed this as completed in #12967 Aug 24, 2022
@mergify mergify bot closed this as completed in 81028cf Aug 24, 2022
Wryhder pushed a commit to Wryhder/cosmos-sdk that referenced this issue Oct 26, 2022
## Description
This pull request contains the fix regarding cancel unbonding delegations 

It will remove duplicate ubdEntries  which have same `creation_height`  and create new ubdEntry with updated `balance` and `initial_balance`

Closes: cosmos#12931 



---

### 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/main/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/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/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)
sampocs added a commit to iqlusioninc/cosmos-sdk that referenced this issue Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants