Skip to content

Commit

Permalink
pr fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaroms committed Oct 7, 2024
1 parent 4ea126e commit f331f5e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions x/pairing/keeper/unstaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/lavanet/lava/v3/utils"
epochstoragetypes "github.com/lavanet/lava/v3/x/epochstorage/types"
"github.com/lavanet/lava/v3/x/pairing/types"
)

Expand Down Expand Up @@ -62,22 +63,28 @@ func (k Keeper) UnstakeEntry(ctx sdk.Context, validator, chainID, creator, unsta
// distribute stake between other chains
metadata, err := k.epochStorageKeeper.GetMetadata(ctx, existingEntry.Address)
if err == nil {
total := amount.Amount
count := int64(len(metadata.Chains))

entries := []*epochstoragetypes.StakeEntry{}
for _, chain := range metadata.Chains {
entry, found := k.epochStorageKeeper.GetStakeEntryCurrent(ctx, chain, existingEntry.Address)
if !found {
if found {
entries = append(entries, &entry)
} else {
utils.LavaFormatError("did not find stake entry that exists in metadata", nil,
utils.LogAttr("provider", existingEntry.Address),
utils.LogAttr("chain", chain),
)
continue
}
}

total := amount.Amount
count := int64(len(entries))
for _, entry := range entries {
part := total.QuoRaw(count)
entry.Stake = entry.Stake.AddAmount(part)
total = total.Sub(part)
count--
k.epochStorageKeeper.SetStakeEntryCurrent(ctx, entry)
k.epochStorageKeeper.SetStakeEntryCurrent(ctx, *entry)
}
}
}
Expand Down

0 comments on commit f331f5e

Please sign in to comment.