Skip to content

Commit

Permalink
Merge branch 'main' into troy/multiple-coins-local-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
troykessler committed Jun 4, 2024
2 parents 768a401 + 64930b6 commit ec39d19
Show file tree
Hide file tree
Showing 67 changed files with 54,601 additions and 662 deletions.
2 changes: 2 additions & 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 All @@ -38,6 +39,7 @@ An '!' indicates a state machine breaking change.

### Bug Fixes

- [#192](https://github.com/KYVENetwork/chain/pull/192) fix: Cosmos-SDK & IBC swagger-code generation.
- (`x/query`) [#159](https://github.com/KYVENetwork/chain/pull/159) Add pool params back to kyve params query.
- (`x/query`) [#160](https://github.com/KYVENetwork/chain/pull/160) Add funders back to pool query.
- [#163](https://github.com/KYVENetwork/chain/pull/163) Add back swagger UI for KYVE and Cosmos REST queries.
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ proto-format:

proto-gen:
@echo "🤖 Generating code from protobuf..."
@docker run --rm --volume "$(PWD)":/workspace --workdir /workspace \
@docker run --rm \
--volume "$(PWD)":/workspace `# Mount this repo as workspace` \
--volume "$$(go list -m -f '{{.Dir}}' github.com/cosmos/cosmos-sdk)":/cosmos-sdk:ro `# Mount cosmos-sdk from installed go modules` \
--volume "$$(go list -m -f '{{.Dir}}' github.com/cosmos/ibc-go/v8)":/ibc:ro `# Mount ibc-go from installed go modules` \
--workdir /workspace \
kyve-proto sh ./proto/generate.sh
@echo "✅ Completed code generation!"

Expand Down
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ func New(
app.appCodec,
app.GetStoreKeys(),
app.BundlesKeeper,
app.DelegationKeeper,
app.FundersKeeper,
app.StakersKeeper,
app.PoolKeeper,
),
)
Expand Down
228 changes: 197 additions & 31 deletions app/upgrades/v1_5/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,30 @@ import (
"context"
"fmt"

poolKeeper "github.com/KYVENetwork/chain/x/pool/keeper"
poolTypes "github.com/KYVENetwork/chain/x/pool/types"

"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"
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"
fundersKeeper "github.com/KYVENetwork/chain/x/funders/keeper"
funderTypes "github.com/KYVENetwork/chain/x/funders/types"
fundersTypes "github.com/KYVENetwork/chain/x/funders/types"
globalTypes "github.com/KYVENetwork/chain/x/global/types"
stakersKeeper "github.com/KYVENetwork/chain/x/stakers/keeper"
stakersTypes "github.com/KYVENetwork/chain/x/stakers/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"
bundlesKeeper "github.com/KYVENetwork/chain/x/bundles/keeper"
bundlesTypes "github.com/KYVENetwork/chain/x/bundles/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand All @@ -22,56 +37,207 @@ const (
UpgradeName = "v1.5.0"
)

func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator, cdc codec.Codec, storeKeys []storetypes.StoreKey, bundlesKeeper keeper.Keeper, poolKeeper *poolkeeper.Keeper) upgradetypes.UpgradeHandler {
func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator, cdc codec.Codec, storeKeys []storetypes.StoreKey, bundlesKeeper bundlesKeeper.Keeper, delegationKeeper delegationKeeper.Keeper, fundersKeeper fundersKeeper.Keeper, stakersKeeper *stakersKeeper.Keeper, poolKeeper *poolKeeper.Keeper) upgradetypes.UpgradeHandler {
return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
logger := sdkCtx.Logger().With("upgrade", UpgradeName)
logger.Info(fmt.Sprintf("performing upgrade %v", UpgradeName))

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

// TODO: migrate gov params
// TODO emit events if necessary

// migrate fundings
MigrateFundersModule(sdkCtx, cdc, MustGetStoreKey(storeKeys, fundersTypes.StoreKey), fundersKeeper)

// TODO: migrate fundings
// migrate delegations
migrateDelegationModule(sdkCtx, cdc, MustGetStoreKey(storeKeys, delegationTypes.StoreKey), delegationKeeper)

// TODO: migrate delegation outstanding rewards
// migrate stakers
migrateStakersModule(sdkCtx, cdc, MustGetStoreKey(storeKeys, stakersTypes.StoreKey), stakersKeeper)

// TODO: migrate network fee and whitelist weights
// migrate bundles
migrateBundlesModule(sdkCtx, cdc, MustGetStoreKey(storeKeys, bundlesTypes.StoreKey), bundlesKeeper)

// TODO: migrate MaxVotingPowerPerPool in pool params
// migrate pool
migrateMaxVotingPowerInPool(sdkCtx, cdc, MustGetStoreKey(storeKeys, poolTypes.StoreKey), *poolKeeper)
migrateInflationShareWeight(sdkCtx, cdc, MustGetStoreKey(storeKeys, poolTypes.StoreKey), poolKeeper)

return mm.RunMigrations(ctx, configurator, fromVM)
}
}

func migrateStorageCosts(sdkCtx sdk.Context, bundlesKeeper keeper.Keeper, poolKeeper *poolkeeper.Keeper, storeKeys []storetypes.StoreKey, cdc codec.Codec) error {
var bundlesStoreKey storetypes.StoreKey
func MustGetStoreKey(storeKeys []storetypes.StoreKey, storeName string) storetypes.StoreKey {
for _, k := range storeKeys {
if k.Name() == "bundles" {
bundlesStoreKey = k
break
if k.Name() == storeName {
return k
}
}
if bundlesStoreKey == nil {
return fmt.Errorf("store key not found: bundles")

panic(fmt.Sprintf("failed to find store key: %s", fundersTypes.StoreKey))
}

func MigrateFundersModule(sdkCtx sdk.Context, cdc codec.Codec, fundersStoreKey storetypes.StoreKey, fundersKeeper fundersKeeper.Keeper) {
// migrate params
// TODO: define final prices and initial whitelisted coins
oldParams := funders.GetParams(sdkCtx, cdc, fundersStoreKey)
fundersKeeper.SetParams(sdkCtx, fundersTypes.Params{
CoinWhitelist: []*fundersTypes.WhitelistCoinEntry{
{
CoinDenom: globalTypes.Denom,
MinFundingAmount: oldParams.MinFundingAmount,
MinFundingAmountPerBundle: oldParams.MinFundingAmountPerBundle,
CoinWeight: math.LegacyMustNewDecFromStr("0.06"),
},
},
MinFundingMultiple: oldParams.MinFundingMultiple,
})

// migrate fundings
oldFundings := funders.GetAllFundings(sdkCtx, cdc, fundersStoreKey)
for _, f := range oldFundings {
fundersKeeper.SetFunding(sdkCtx, &funderTypes.Funding{
FunderAddress: f.FunderAddress,
PoolId: f.PoolId,
Amounts: sdk.NewCoins(sdk.NewInt64Coin(globalTypes.Denom, int64(f.Amount))),
AmountsPerBundle: sdk.NewCoins(sdk.NewInt64Coin(globalTypes.Denom, int64(f.AmountPerBundle))),
TotalFunded: sdk.NewCoins(sdk.NewInt64Coin(globalTypes.Denom, int64(f.TotalFunded))),
})
}
}

func migrateDelegationModule(sdkCtx sdk.Context, cdc codec.Codec, delegationStoreKey storetypes.StoreKey, delegationKeeper delegationKeeper.Keeper) {
// migrate delegation entries
oldDelegationEntries := delegation.GetAllDelegationEntries(sdkCtx, cdc, delegationStoreKey)
for _, d := range oldDelegationEntries {
delegationKeeper.SetDelegationEntry(sdkCtx, delegationTypes.DelegationEntry{
Staker: d.Staker,
KIndex: d.KIndex,
Value: sdk.NewDecCoins(sdk.NewDecCoinFromDec(globalTypes.Denom, d.Value)),
})
}

// migrate delegation data
oldDelegationData := delegation.GetAllDelegationData(sdkCtx, cdc, delegationStoreKey)
for _, d := range oldDelegationData {
delegationKeeper.SetDelegationData(sdkCtx, delegationTypes.DelegationData{
Staker: d.Staker,
CurrentRewards: sdk.NewCoins(sdk.NewInt64Coin(globalTypes.Denom, int64(d.CurrentRewards))),
TotalDelegation: d.TotalDelegation,
LatestIndexK: d.LatestIndexK,
DelegatorCount: d.DelegatorCount,
LatestIndexWasUndelegation: d.LatestIndexWasUndelegation,
})
}
}

func migrateStakersModule(sdkCtx sdk.Context, cdc codec.Codec, stakersStoreKey storetypes.StoreKey, stakersKeeper *stakersKeeper.Keeper) {
// migrate stakers
oldStakers := stakers.GetAllStakers(sdkCtx, cdc, stakersStoreKey)
for _, s := range oldStakers {
stakersKeeper.Migration_SetStaker(sdkCtx, stakersTypes.Staker{
Address: s.Address,
Commission: s.Commission,
Moniker: s.Moniker,
Website: s.Website,
Identity: s.Identity,
SecurityContact: s.SecurityContact,
Details: s.Details,
CommissionRewards: sdk.NewCoins(sdk.NewInt64Coin(globalTypes.Denom, int64(s.CommissionRewards))),
})
}
}

func migrateBundlesModule(sdkCtx sdk.Context, cdc codec.Codec, bundlesStoreKey storetypes.StoreKey, bundlesKeeper bundlesKeeper.Keeper) {
oldParams := bundles.GetParams(sdkCtx, cdc, bundlesStoreKey)

// 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)
newParams := bundlestypes.Params{
// TODO: define final storage cost prices
bundlesKeeper.SetParams(sdkCtx, bundlesTypes.Params{
UploadTimeout: oldParams.UploadTimeout,
StorageCosts: []bundlestypes.StorageCost{
// TODO: define value for storage provider id 1 and 2
{StorageProviderId: 1, Cost: math.LegacyMustNewDecFromStr("0.00")},
{StorageProviderId: 2, Cost: math.LegacyMustNewDecFromStr("0.00")},
StorageCosts: []bundlesTypes.StorageCost{
// Arweave: https://arweave.net/price/1048576 -> 699 winston/byte * 40 USD/AR * 1.5 / 10**12
{StorageProviderId: 1, Cost: math.LegacyMustNewDecFromStr("0.000000004194")},
// Irys: https://node1.bundlr.network/price/1048576 -> 1048 winston/byte * 40 USD/AR * 1.5 / 10**12
{StorageProviderId: 2, Cost: math.LegacyMustNewDecFromStr("0.000000006288")},
// KYVE Storage Provider: zero since it is free to use for testnet participants
{StorageProviderId: 3, Cost: math.LegacyMustNewDecFromStr("0.00")},
},
NetworkFee: oldParams.NetworkFee,
MaxPoints: oldParams.MaxPoints,
}
})
}

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

bundlesKeeper.SetParams(sdkCtx, newParams)
return nil
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,
})
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v1_4_types
package bundles

import (
storeTypes "cosmossdk.io/store/types"
Expand All @@ -8,7 +8,7 @@ import (
)

// GetParams returns the current x/bundles module parameters.
func GetParams(ctx sdk.Context, storeKey storeTypes.StoreKey, cdc codec.Codec) (params Params) {
func GetParams(ctx sdk.Context, cdc codec.Codec, storeKey storeTypes.StoreKey) (params Params) {
store := ctx.KVStore(storeKey)

bz := store.Get(types.ParamsPrefix)
Expand Down

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

Loading

0 comments on commit ec39d19

Please sign in to comment.