Skip to content

Commit

Permalink
Merge branch 'osmo-v27/0.50.10' into chore/update-changelog-v27
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddyMc authored Oct 18, 2024
2 parents 703277f + 2c466dc commit ebc92cf
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 260 deletions.
2 changes: 1 addition & 1 deletion tests/integration/staking/keeper/determinstic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func TestGRPCValidatorDelegations(t *testing.T) {
ValidatorAddr: validator.OperatorAddress,
}

testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.ValidatorDelegations, 17484, false)
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.ValidatorDelegations, 14475, false)
}

func TestGRPCValidatorUnbondingDelegations(t *testing.T) {
Expand Down
13 changes: 13 additions & 0 deletions x/bank/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ func (k BaseSendKeeper) InputOutputCoins(ctx context.Context, input types.Input,
return err
}

for _, out := range outputs {
outAddress, err := k.ak.AddressCodec().StringToBytes(out.Address)
if err != nil {
return err
}

if err := k.BlockBeforeSend(ctx, inAddress, outAddress, out.Coins); err != nil {
return err
}

k.TrackBeforeSend(ctx, inAddress, outAddress, out.Coins)
}

err = k.subUnlockedCoins(ctx, inAddress, input.Coins)
if err != nil {
return err
Expand Down
69 changes: 69 additions & 0 deletions x/bank/keeper/supply_offset_old.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package keeper

import (
"context"
"fmt"

"cosmossdk.io/math"
"cosmossdk.io/store/prefix"

"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/x/bank/types"
)

// NOTE: All these functions should only be used in the v27 migration
// this file should be removed completely after the migration

// GetSupplyOffset retrieves the SupplyOffset from store for a specific denom using the pre v26 (old) key
// TODO: Remove after v27 migration
func (k BaseViewKeeper) GetSupplyOffsetOld(ctx context.Context, denom string) math.Int {
store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
supplyOffsetStore := prefix.NewStore(store, types.SupplyOffsetKeyOld)

bz := supplyOffsetStore.Get([]byte(denom))
if bz == nil {
return math.NewInt(0)
}

var amount math.Int
err := amount.Unmarshal(bz)
if err != nil {
panic(fmt.Errorf("unable to unmarshal supply offset value %v", err))
}

return amount
}

// RemoveOldSupplyOffset removes the old supply offset key
// TODO: Remove after v27 migration
func (k BaseViewKeeper) RemoveOldSupplyOffset(ctx context.Context, denom string) {
store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
supplyOffsetStore := prefix.NewStore(store, types.SupplyOffsetKeyOld)

supplyOffsetStore.Delete([]byte(denom))
}

// setSupplyOffsetOld sets the supply offset for the given denom using the pre v26 (old) key
// TODO: Remove after v27 migration
func (k BaseKeeper) setSupplyOffsetOld(ctx context.Context, denom string, offsetAmount math.Int) {
intBytes, err := offsetAmount.Marshal()
if err != nil {
panic(fmt.Errorf("unable to marshal amount value %v", err))
}

store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
supplyOffsetStore := prefix.NewStore(store, types.SupplyOffsetKeyOld)

// Bank invariants and IBC requires to remove zero coins.
if offsetAmount.IsZero() {
supplyOffsetStore.Delete([]byte(denom))
} else {
supplyOffsetStore.Set([]byte(denom), intBytes)
}
}

// AddSupplyOffsetOld adjusts the current supply offset of a denom by the inputted offsetAmount using the pre v26 (old) key
// TODO: Remove after v27 migration
func (k BaseKeeper) AddSupplyOffsetOld(ctx context.Context, denom string, offsetAmount math.Int) {
k.setSupplyOffsetOld(ctx, denom, k.GetSupplyOffsetOld(ctx, denom).Add(offsetAmount))
}
5 changes: 5 additions & 0 deletions x/bank/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ var (
// ParamsKey is the prefix for x/bank parameters
ParamsKey = collections.NewPrefix(5)

// SupplyOffKey is a Osmosis specific key that handles supply offsets
SupplyOffsetKey = collections.NewPrefix(88)

// SupplyOffKeyOld is a Osmosis specific key that handles supply offsets pre v0.50
// TODO: Remove in the v28 upgrade
SupplyOffsetKeyOld = []byte{0x88}
)

// BalanceValueCodec is a codec for encoding bank balances in a backwards compatible way.
Expand Down
14 changes: 0 additions & 14 deletions x/staking/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
abci "github.com/cometbft/cometbft/abci/types"

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)

Expand All @@ -21,18 +20,5 @@ func (k *Keeper) BeginBlocker(ctx context.Context) error {
func (k *Keeper) EndBlocker(ctx context.Context) ([]abci.ValidatorUpdate, error) {
defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyEndBlocker)

// TODO: Remove migration code and panic catch in the next upgrade
// Wrap the migration call in a function that can recover from panics
func() {
defer func() {
if r := recover(); r != nil {
k.Logger(sdk.UnwrapSDKContext(ctx)).Error("Panic in MigrateDelegationsByValidatorIndex", "recover", r)
}
}()

// Only migrate 10000 items per block to make the migration as fast as possible
k.MigrateDelegationsByValidatorIndex(sdk.UnwrapSDKContext(ctx), 10000)
}()

return k.BlockValidatorUpdates(ctx)
}
7 changes: 0 additions & 7 deletions x/staking/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"context"
"fmt"
"strings"

"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -109,12 +108,6 @@ func (k Querier) ValidatorDelegations(ctx context.Context, req *types.QueryValid
pageRes *query.PageResponse
)
pageRes, err = query.Paginate(delStore, req.Pagination, func(delAddr, value []byte) error {
// Check the store to see if there is a value stored under the key
key := store.Get(types.NextMigrateDelegationsByValidatorIndexKey)
if key != nil {
// Users will never see this error as if there is an error the function defaults to the legacy implementation below
return fmt.Errorf("store migration is not finished, try again later")
}
bz := store.Get(types.GetDelegationKey(delAddr, valAddr))

var delegation types.Delegation
Expand Down
86 changes: 0 additions & 86 deletions x/staking/keeper/validator_index.go

This file was deleted.

150 changes: 0 additions & 150 deletions x/staking/keeper/validator_index_test.go

This file was deleted.

Loading

0 comments on commit ebc92cf

Please sign in to comment.