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

feat: make inflation share weight a decimal #190

Merged
merged 24 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a173d03
chore: make inflation-share-weight a LegacyDec
shifty11 May 22, 2024
8748d2c
fix: tests
shifty11 May 22, 2024
bd5d92f
fix: tests
shifty11 May 22, 2024
5df9f8a
fix: tests
shifty11 May 22, 2024
e8ecb42
fix: SplitInflation logic
shifty11 May 22, 2024
2b7e8d9
fix: tests
shifty11 May 22, 2024
6463063
feat: add migration for inflation-share-weight
shifty11 May 22, 2024
2cad9e6
refactor: rename v1.4 bundles types
shifty11 May 22, 2024
d3be301
fix: migration
shifty11 May 22, 2024
57cefb8
fix: test
shifty11 May 22, 2024
64bcc0b
Merge branch 'main' into rapha/make-inflation-share-weight-a-decimal
shifty11 May 23, 2024
deda791
chore: make totalInflationShareWeight a LegacyDec
shifty11 May 23, 2024
b901740
refactor: use only LegacyDec in keeper_suite_inflation_splitting_test.go
shifty11 May 23, 2024
3711a12
test: add more tests
shifty11 May 27, 2024
1102580
Merge branch 'main' into rapha/make-inflation-share-weight-a-decimal
shifty11 May 27, 2024
9678625
test: fix tests
shifty11 May 27, 2024
3e15eec
test: add second pool for some inflation-splitting tests
shifty11 May 29, 2024
09ef37b
test: check if inflation is correctly split across pools
mbreithecker May 31, 2024
c43f66d
chore: format
mbreithecker May 31, 2024
ea82ac0
chore: adjust migration + add event
mbreithecker May 31, 2024
c05d017
chore: update changelog
mbreithecker May 31, 2024
7359e08
Merge branch 'main' into rapha/make-inflation-share-weight-a-decimal
shifty11 Jun 3, 2024
e26b187
test: move resetting of team allocation to DeferCleanup
shifty11 Jun 3, 2024
5f514d9
chore: sync main
mbreithecker Jun 4, 2024
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
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
89 changes: 87 additions & 2 deletions app/upgrades/v1_5/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import (
"context"
"fmt"

"github.com/KYVENetwork/chain/app/upgrades/v1_5/v1_4_bundles_types"
"github.com/KYVENetwork/chain/app/upgrades/v1_5/v1_4_pool_types"
pooltypes "github.com/KYVENetwork/chain/x/pool/types"

"cosmossdk.io/math"

storetypes "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/types"

"github.com/KYVENetwork/chain/app/upgrades/v1_5/v1_4_types"
"github.com/KYVENetwork/chain/x/bundles/keeper"
bundlestypes "github.com/KYVENetwork/chain/x/bundles/types"
poolkeeper "github.com/KYVENetwork/chain/x/pool/keeper"
Expand All @@ -32,6 +35,10 @@ func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator,
return nil, err
}

if err := migrateInflationShareWeight(sdkCtx, poolKeeper, storeKeys, cdc); err != nil {
return nil, err
}

// TODO: migrate gov params

// TODO: migrate fundings
Expand Down Expand Up @@ -60,7 +67,7 @@ func migrateStorageCosts(sdkCtx sdk.Context, bundlesKeeper keeper.Keeper, poolKe

// Copy storage cost from old params to new params
// The storage cost of all storage providers will be the same after this migration
oldParams := v1_4_types.GetParams(sdkCtx, bundlesStoreKey, cdc)
oldParams := v1_4_bundles_types.GetParams(sdkCtx, bundlesStoreKey, cdc)
shifty11 marked this conversation as resolved.
Show resolved Hide resolved
newParams := bundlestypes.Params{
UploadTimeout: oldParams.UploadTimeout,
StorageCosts: []bundlestypes.StorageCost{
Expand All @@ -75,3 +82,81 @@ func migrateStorageCosts(sdkCtx sdk.Context, bundlesKeeper keeper.Keeper, poolKe
bundlesKeeper.SetParams(sdkCtx, newParams)
return nil
}

func migrateInflationShareWeight(sdkCtx sdk.Context, poolKeeper *poolkeeper.Keeper, storeKeys []storetypes.StoreKey, cdc codec.Codec) error {
var poolStoreKey storetypes.StoreKey
for _, k := range storeKeys {
if k.Name() == "pool" {
poolStoreKey = k
break
}
}
if poolStoreKey == nil {
return fmt.Errorf("store key not found: pool")
}

pools := v1_4_pool_types.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,
})
}
return nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v1_4_types
package v1_4_bundles_types

import (
storeTypes "cosmossdk.io/store/types"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions app/upgrades/v1_5/v1_4_pool_types/getters_pool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package v1_4_pool_types

import (
"cosmossdk.io/store/prefix"
storetypes "cosmossdk.io/store/types"
"github.com/KYVENetwork/chain/x/pool/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// 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
Loading