From f187c356c261cd74df846e0049246c9a5f8c4da6 Mon Sep 17 00:00:00 2001 From: Dmitry K Date: Thu, 30 Jan 2025 15:44:28 -0800 Subject: [PATCH 1/2] v0.0.12 --- app/upgrades.go | 4 +- app/upgrades/types.go | 6 +++ app/upgrades/v0.0.12.go | 114 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 app/upgrades/v0.0.12.go diff --git a/app/upgrades.go b/app/upgrades.go index df4543c99..a0a8eaaff 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -11,9 +11,7 @@ import ( // The chain upgrade can be scheduled AFTER the new version (with upgrade strategy implemented) is released, // so `cosmovisor` can automatically pull the binary from GitHub. var allUpgrades = []upgrades.Upgrade{ - upgrades.Upgrade_0_0_4, - upgrades.Upgrade_0_0_10, - upgrades.Upgrade_0_0_11, + upgrades.Upgrade_0_0_12, } // setUpgrades sets upgrade handlers for all upgrades and executes KVStore migration if an upgrade plan file exists. diff --git a/app/upgrades/types.go b/app/upgrades/types.go index 3bba73629..e87346c7e 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -16,8 +16,14 @@ import ( const ( // The default PNF/DAO address in the genesis file for Alpha TestNet. Used to create new authz authorizations. AlphaTestNetPnfAddress = "pokt1r6ja6rz6rpae58njfrsgs5n5sp3r36r2q9j04h" + // Authority address. Defaults to gov module address. Used to create new authz authorizations. + // DEV_NOTE: Use `keepers.UpgradeKeeper.Authority(ctx, &upgradetypes.QueryAuthorityRequest{})` to query the authority + // address for the current network. Keeping this variable for historical upgrades. AlphaTestNetAuthorityAddress = "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t" + + // The default PNF/DAO address in the genesis file for Beta TestNet. Used to create new authz authorizations. + BetaTestNetPnfAddress = "pokt1f0c9y7mahf2ya8tymy8g4rr75ezh3pkklu4c3e" ) // Upgrade represents a protocol upgrade in code. diff --git a/app/upgrades/v0.0.12.go b/app/upgrades/v0.0.12.go new file mode 100644 index 000000000..5d124f73e --- /dev/null +++ b/app/upgrades/v0.0.12.go @@ -0,0 +1,114 @@ +package upgrades + +import ( + "context" + + "cosmossdk.io/math" + storetypes "cosmossdk.io/store/types" + upgradetypes "cosmossdk.io/x/upgrade/types" + cosmosTypes "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/pokt-network/poktroll/app/keepers" + servicetypes "github.com/pokt-network/poktroll/x/service/types" + suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" +) + +// Upgrade_0_0_12 is the upgrade handler for v0.0.12 upgrade. +// - Before: v0.0.11 +// - After: v0.0.12 + +// This upgrade introduces a type change to RevSharePercent from float32 to uint64, which is introduced as a separate +// protobuf field. As a result, we expect existing on-chain data to switch to default value. +// Investigate the impact of this change on existing on-chain data. +// +// TODO_IN_THIS_PR: decide if we need a proper module migration. + +// TODO_IN_THIS_PR: WIP. Using this diff as a starting point: https://github.com/pokt-network/poktroll/compare/v0.0.11...feat/proof-endblocker +// TODO_IN_THIS_PR: Wait for https://github.com/pokt-network/poktroll/pull/1042 +var Upgrade_0_0_12 = Upgrade{ + PlanName: "v0.0.12", + CreateUpgradeHandler: func(mm *module.Manager, + keepers *keepers.Keepers, + configurator module.Configurator, + ) upgradetypes.UpgradeHandler { + // Adds new parameters using ignite's config.yml as a reference. Assuming we don't need any other parameters. + applyNewParameters := func(ctx context.Context) (err error) { + logger := cosmosTypes.UnwrapSDKContext(ctx).Logger() + logger.Info("Starting parameter updates for v0.0.12") + + // Add supplier module staking_fee per `config.yml`. The min stake is set to 1000000 upokt, but we avoid + // GetParams() to avoid potential protobuf issues and all networks have the same value (no need to read). + // Validate with: `poktrolld q supplier params --node=https://testnet-validated-validator-rpc.poktroll.com/` + supplierParams := suppliertypes.Params{ + MinStake: &cosmosTypes.Coin{ + Denom: "upokt", + Amount: math.NewInt(1000000), + }, + StakingFee: &cosmosTypes.Coin{ + Denom: "upokt", + // TODO_IN_THIS_PR: 100upokt a good value? + Amount: math.NewInt(100), + }, + } + + // ALL parameters must be present when setting params. + err = keepers.SupplierKeeper.SetParams(ctx, supplierParams) + if err != nil { + logger.Error("Failed to set supplier params", "error", err) + return err + } + logger.Info("Successfully updated supplier params", "new_params", supplierParams) + + // Add service module `target_num_relays` parameter per `config.yml`. + // We don't use `GetParams()` to avoid potential protobuf issues and all networks have the same value (no need to read). + serviceParams := servicetypes.Params{ + AddServiceFee: &cosmosTypes.Coin{ + Denom: "upokt", + Amount: math.NewInt(1000000000), + }, + TargetNumRelays: 100, + } + err = keepers.ServiceKeeper.SetParams(ctx, serviceParams) + if err != nil { + logger.Error("Failed to set service params", "error", err) + return err + } + logger.Info("Successfully updated service params", "new_params", serviceParams) + + // Add tokenomics module `global_inflation_per_claim` parameter per `config.yml`. + // We use GetParams() as `DaoRewardAddress` is different between networks and we don't want to hardcode it. + tokenomicsParams := keepers.TokenomicsKeeper.GetParams(ctx) + tokenomicsParams.GlobalInflationPerClaim = 0.1 + err = keepers.TokenomicsKeeper.SetParams(ctx, tokenomicsParams) + if err != nil { + logger.Error("Failed to set tokenomics params", "error", err) + return err + } + return + } + + // Returns the upgrade handler for v0.0.12 + return func(ctx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + logger := cosmosTypes.UnwrapSDKContext(ctx).Logger() + logger.Info("Starting v0.0.12 upgrade handler") + + err := applyNewParameters(ctx) + if err != nil { + logger.Error("Failed to apply new parameters", "error", err) + return vm, err + } + + logger.Info("Running module migrations") + vm, err = mm.RunMigrations(ctx, configurator, vm) + if err != nil { + logger.Error("Failed to run migrations", "error", err) + return vm, err + } + + logger.Info("Successfully completed v0.0.12 upgrade handler") + return vm, nil + } + }, + // No changes to the KVStore in this upgrade. + StoreUpgrades: storetypes.StoreUpgrades{}, +} From adc3c4d80d7e4625ea642fc37fa70da06871431d Mon Sep 17 00:00:00 2001 From: Dmitry K Date: Thu, 30 Jan 2025 17:53:57 -0800 Subject: [PATCH 2/2] set RevSharePercentage for all --- app/upgrades/v0.0.12.go | 26 +++++++++++++++---- .../relayminer_config_localnet_vscode.yaml | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/upgrades/v0.0.12.go b/app/upgrades/v0.0.12.go index 5d124f73e..4859d8d9d 100644 --- a/app/upgrades/v0.0.12.go +++ b/app/upgrades/v0.0.12.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/pokt-network/poktroll/app/keepers" servicetypes "github.com/pokt-network/poktroll/x/service/types" + sharedtypes "github.com/pokt-network/poktroll/x/shared/types" suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" ) @@ -20,11 +21,6 @@ import ( // This upgrade introduces a type change to RevSharePercent from float32 to uint64, which is introduced as a separate // protobuf field. As a result, we expect existing on-chain data to switch to default value. // Investigate the impact of this change on existing on-chain data. -// -// TODO_IN_THIS_PR: decide if we need a proper module migration. - -// TODO_IN_THIS_PR: WIP. Using this diff as a starting point: https://github.com/pokt-network/poktroll/compare/v0.0.11...feat/proof-endblocker -// TODO_IN_THIS_PR: Wait for https://github.com/pokt-network/poktroll/pull/1042 var Upgrade_0_0_12 = Upgrade{ PlanName: "v0.0.12", CreateUpgradeHandler: func(mm *module.Manager, @@ -98,6 +94,26 @@ var Upgrade_0_0_12 = Upgrade{ return vm, err } + // Since we changed the type of RevSharePercent from float32 to uint64, we need to update all on-chain data. + // The easiest way to do this is to iterate over all suppliers and services and set the revshare to 100 by default. + suppliers := keepers.SupplierKeeper.GetAllSuppliers(ctx) + logger.Info("Updating all suppliers to have a 100% revshare to the supplier", "num_suppliers", len(suppliers)) + for _, supplier := range suppliers { + for _, service := range supplier.Services { + // Force all services to have a 100% revshare to the supplier. + // Not something we would do on a real mainnet, but it's a quick way to resolve the issue. + // Currently, we don't break any existing suppliers (as all of them have a 100% revshare to the supplier). + service.RevShare = []*sharedtypes.ServiceRevenueShare{ + { + Address: supplier.OperatorAddress, + RevSharePercentage: uint64(100), + }, + } + } + keepers.SupplierKeeper.SetSupplier(ctx, supplier) + logger.Info("Updated supplier", "supplier", supplier.OperatorAddress) + } + logger.Info("Running module migrations") vm, err = mm.RunMigrations(ctx, configurator, vm) if err != nil { diff --git a/localnet/poktrolld/config/relayminer_config_localnet_vscode.yaml b/localnet/poktrolld/config/relayminer_config_localnet_vscode.yaml index 451914f9f..de20c4d13 100644 --- a/localnet/poktrolld/config/relayminer_config_localnet_vscode.yaml +++ b/localnet/poktrolld/config/relayminer_config_localnet_vscode.yaml @@ -23,7 +23,7 @@ metrics: addr: :9070 pocket_node: query_node_rpc_url: tcp://localhost:26657 - query_node_grpc_url: tcp://localhost:36658 + query_node_grpc_url: tcp://localhost:9090 tx_node_rpc_url: tcp://localhost:26657 suppliers: - service_id: anvil