Skip to content

Commit

Permalink
fix: CUDOS delegations movement fix (#401)
Browse files Browse the repository at this point in the history
* fix

* Better fix
  • Loading branch information
MissingNO57 authored Oct 18, 2024
1 parent c0a610a commit 38dd028
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
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 @@ -2061,9 +2061,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() {
delegatedAmount := sourceDelegations.MustGet(validatorAddr)

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

0 comments on commit 38dd028

Please sign in to comment.