Skip to content

Commit

Permalink
feat: make inflation share weight a decimal (#190)
Browse files Browse the repository at this point in the history
Co-authored-by: mbreithecker <m@breithecker.de>
  • Loading branch information
shifty11 and mbreithecker authored Jun 4, 2024
1 parent 6bbd4d8 commit 64930b6
Show file tree
Hide file tree
Showing 50 changed files with 3,042 additions and 607 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ An '!' indicates a state machine breaking change.

### Improvements

- ! (`x/pool`) [#190](https://github.com/KYVENetwork/chain/pull/190) Make inflation-share-weight a decimal.
- [#182](https://github.com/KYVENetwork/chain/pull/182) Make release builds reproducible.
- ! [#183](https://github.com/KYVENetwork/chain/pull/183) Only charge coins which are whitelisted.
- ! (deps) [#174](https://github.com/KYVENetwork/chain/pull/174) Add mainnet KYVE image to interchain tests.
Expand Down
71 changes: 69 additions & 2 deletions app/upgrades/v1_5/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/KYVENetwork/chain/app/upgrades/v1_5/v1_4_types/bundles"
"github.com/KYVENetwork/chain/app/upgrades/v1_5/v1_4_types/delegation"
"github.com/KYVENetwork/chain/app/upgrades/v1_5/v1_4_types/funders"
"github.com/KYVENetwork/chain/app/upgrades/v1_5/v1_4_types/pool"
v1_4_pool "github.com/KYVENetwork/chain/app/upgrades/v1_5/v1_4_types/pool"
"github.com/KYVENetwork/chain/app/upgrades/v1_5/v1_4_types/stakers"
delegationKeeper "github.com/KYVENetwork/chain/x/delegation/keeper"
delegationTypes "github.com/KYVENetwork/chain/x/delegation/types"
Expand Down Expand Up @@ -60,6 +60,7 @@ func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator,

// migrate pool
migrateMaxVotingPowerInPool(sdkCtx, cdc, MustGetStoreKey(storeKeys, poolTypes.StoreKey), *poolKeeper)
migrateInflationShareWeight(sdkCtx, cdc, MustGetStoreKey(storeKeys, poolTypes.StoreKey), poolKeeper)

return mm.RunMigrations(ctx, configurator, fromVM)
}
Expand Down Expand Up @@ -166,11 +167,77 @@ func migrateBundlesModule(sdkCtx sdk.Context, cdc codec.Codec, bundlesStoreKey s
}

func migrateMaxVotingPowerInPool(sdkCtx sdk.Context, cdc codec.Codec, poolStoreKey storetypes.StoreKey, poolKeeper poolKeeper.Keeper) {
oldParams := pool.GetParams(sdkCtx, cdc, poolStoreKey)
oldParams := v1_4_pool.GetParams(sdkCtx, cdc, poolStoreKey)

poolKeeper.SetParams(sdkCtx, poolTypes.Params{
ProtocolInflationShare: oldParams.ProtocolInflationShare,
PoolInflationPayoutRate: oldParams.PoolInflationPayoutRate,
MaxVotingPowerPerPool: math.LegacyMustNewDecFromStr("0.5"),
})
}

func migrateInflationShareWeight(sdkCtx sdk.Context, cdc codec.Codec, poolStoreKey storetypes.StoreKey, poolKeeper *poolKeeper.Keeper) {
pools := v1_4_pool.GetAllPools(sdkCtx, poolStoreKey, cdc)
for _, pool := range pools {
var newPool poolTypes.Pool

var protocol *poolTypes.Protocol
if pool.Protocol != nil {
protocol = &poolTypes.Protocol{
Version: pool.Protocol.Version,
Binaries: pool.Protocol.Binaries,
LastUpgrade: pool.Protocol.LastUpgrade,
}
}
var upgradePlan *poolTypes.UpgradePlan
if pool.UpgradePlan != nil {
upgradePlan = &poolTypes.UpgradePlan{
Version: pool.UpgradePlan.Version,
Binaries: pool.UpgradePlan.Binaries,
ScheduledAt: pool.UpgradePlan.ScheduledAt,
Duration: pool.UpgradePlan.Duration,
}
}

newPool = poolTypes.Pool{
Id: pool.Id,
Name: pool.Name,
Runtime: pool.Runtime,
Logo: pool.Logo,
Config: pool.Config,
StartKey: pool.StartKey,
CurrentKey: pool.CurrentKey,
CurrentSummary: pool.CurrentSummary,
CurrentIndex: pool.CurrentIndex,
TotalBundles: pool.TotalBundles,
UploadInterval: pool.UploadInterval,
// Currently all pools have int64(1_000_000) as inflation_share weight.
// Set this to 1 as we now support decimals
InflationShareWeight: math.LegacyMustNewDecFromStr("1"),
MinDelegation: pool.MinDelegation,
MaxBundleSize: pool.MaxBundleSize,
Disabled: pool.Disabled,
Protocol: protocol,
UpgradePlan: upgradePlan,
CurrentStorageProviderId: pool.CurrentStorageProviderId,
CurrentCompressionId: pool.CurrentCompressionId,
EndKey: pool.EndKey,
}
poolKeeper.SetPool(sdkCtx, newPool)

_ = sdkCtx.EventManager().EmitTypedEvent(&poolTypes.EventPoolUpdated{
Id: pool.Id,
RawUpdateString: "{\"inflation_share_weight\":\"1.0\"}",
Name: pool.Name,
Runtime: pool.Runtime,
Logo: pool.Logo,
Config: pool.Config,
UploadInterval: pool.UploadInterval,
InflationShareWeight: math.LegacyMustNewDecFromStr("1"),
MinDelegation: pool.MinDelegation,
MaxBundleSize: pool.MaxBundleSize,
StorageProviderId: pool.CurrentStorageProviderId,
CompressionId: pool.CurrentCompressionId,
})
}
}
17 changes: 17 additions & 0 deletions app/upgrades/v1_5/v1_4_types/pool/getters_pool.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pool

import (
"cosmossdk.io/store/prefix"
storeTypes "cosmossdk.io/store/types"
"github.com/KYVENetwork/chain/x/pool/types"
"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -16,3 +17,19 @@ func GetParams(ctx sdk.Context, cdc codec.Codec, storeKey storeTypes.StoreKey) (

return
}

// GetAllPools returns all pools
func GetAllPools(ctx sdk.Context, storeKey storeTypes.StoreKey, cdc codec.Codec) (list []Pool) {
store := prefix.NewStore(ctx.KVStore(storeKey), types.PoolKey)
iterator := storeTypes.KVStorePrefixIterator(store, []byte{})

defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
var val Pool
cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}

return
}
Loading

0 comments on commit 64930b6

Please sign in to comment.