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

fix: CUDOS delegations movement fix #401

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 9 additions & 5 deletions app/ordered_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,17 @@ func (om *OrderedMap[K, V]) Has(key K) bool {
func (om *OrderedMap[K, V]) Delete(key K) {
if _, exists := om.values[key]; exists {
delete(om.values, key)
// Remove key from slice
for i, k := range om.keys {
if k == key {
om.keys = append(om.keys[:i], om.keys[i+1:]...)
break
// Create a new slice to avoid modifying the original reference
newKeys := make([]K, 0, len(om.keys)-1)

// Remove the key from the keys slice
for _, k := range om.keys {
if k != key {
newKeys = append(newKeys, k)
}
}

om.keys = newKeys // Assign the newly created slice to om.keys
}
}

Expand Down
6 changes: 4 additions & 2 deletions app/upgrade_cudos.go
Original file line number Diff line number Diff line change
Expand Up @@ -2032,9 +2032,11 @@ func DoGenesisAccountMovements(genesisData *GenesisData, cudosCfg *CudosMergeCon

// Handle delegations movement
remainingAmountToMove := sdk.NewIntFromBigInt(accountMovement.Amount.BigInt())

if sourceDelegations, exists := genesisData.Delegations.Get(accountMovement.SourceAddress); exists {
for i := range sourceDelegations.Iterate() {
validatorAddr, delegatedAmount := i.Key, i.Value
// We iterate and delete from source array at the same time
for _, validatorAddr := range sourceDelegations.Keys() {
pbukva marked this conversation as resolved.
Show resolved Hide resolved
delegatedAmount := sourceDelegations.MustGet(validatorAddr)

if delegatedAmount.GTE(remainingAmountToMove) {
// Split delegation
Expand Down
Loading