From 980a63d2a4a17ce41535106b99f67c442d0c0b8f Mon Sep 17 00:00:00 2001 From: "Dima K." Date: Fri, 24 Jan 2025 12:34:13 -0800 Subject: [PATCH] [Upgrade] Alpha TestNet v0.0.11 (#967) ## Summary An upgrade for Alpha TestNet from v0.0.10 to v0.0.11. ## Issue Beta TestNet has been launched using v0.0.11 (release candidate), and we need to upgrade alpha so both networks use the same version. ## Type of change Chain upgrade. ## Testing - [] An upgrade is tested by upgrading a network provisioned by the old version (v0.0.10) to the new version (v0.0.11) ## Sanity Checklist - [ ] I have tested my changes using the available tooling - [ ] I have commented my code - [ ] I have performed a self-review of my own code; both comments & source code - [ ] I create and reference any new tickets, if applicable - [ ] I have left TODOs throughout the codebase, if applicable --------- Co-authored-by: Daniel Olshansky --- app/upgrades.go | 1 + app/upgrades/v0.0.11.go | 98 +++++++++++++++++++++++++++++++++++++ cmd/poktrolld/cmd/config.go | 8 ++- telemetry/defaults.go | 14 ++++++ telemetry/telemetry.go | 23 +++++++-- 5 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 app/upgrades/v0.0.11.go create mode 100644 telemetry/defaults.go diff --git a/app/upgrades.go b/app/upgrades.go index 42582dc2b..df4543c99 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -13,6 +13,7 @@ import ( var allUpgrades = []upgrades.Upgrade{ upgrades.Upgrade_0_0_4, upgrades.Upgrade_0_0_10, + upgrades.Upgrade_0_0_11, } // setUpgrades sets upgrade handlers for all upgrades and executes KVStore migration if an upgrade plan file exists. diff --git a/app/upgrades/v0.0.11.go b/app/upgrades/v0.0.11.go new file mode 100644 index 000000000..615feecef --- /dev/null +++ b/app/upgrades/v0.0.11.go @@ -0,0 +1,98 @@ +package upgrades + +import ( + "context" + + 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" + sessiontypes "github.com/pokt-network/poktroll/x/session/types" + tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types" +) + +// Upgrade_0_0_11 is the upgrade handler for v0.0.11 Alpha TestNet upgrade +// Beta TestNet was launched with v0.0.11, so this upgrade is exclusively for Alpha TestNet. +// - Before: v0.0.10 +// - After: v0.0.11 +var Upgrade_0_0_11 = Upgrade{ + PlanName: "v0.0.11", + 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. + // https://github.com/pokt-network/poktroll/compare/v0.0.10...v0.0.11-rc + applyNewParameters := func(ctx context.Context) (err error) { + logger := cosmosTypes.UnwrapSDKContext(ctx).Logger() + logger.Info("Starting parameter updates for v0.0.11") + + // Set num_suppliers_per_session to 15 + // Validate with: `poktrolld q session params --node=https://testnet-validated-validator-rpc.poktroll.com/` + sessionParams := sessiontypes.Params{ + NumSuppliersPerSession: uint64(15), + } + + // ALL parameters must be present when setting params. + err = keepers.SessionKeeper.SetParams(ctx, sessionParams) + if err != nil { + logger.Error("Failed to set session params", "error", err) + return err + } + logger.Info("Successfully updated session params", "new_params", sessionParams) + + // Set tokenomics params. The values are based on default values for LocalNet/Beta TestNet. + // Validate with: `poktrolld q tokenomics params --node=https://testnet-validated-validator-rpc.poktroll.com/` + tokenomicsParams := tokenomicstypes.Params{ + MintAllocationPercentages: tokenomicstypes.MintAllocationPercentages{ + Dao: 0.1, + Proposer: 0.05, + Supplier: 0.7, + SourceOwner: 0.15, + Application: 0.0, + }, + DaoRewardAddress: AlphaTestNetPnfAddress, + } + + // ALL parameters must be present when setting params. + err = keepers.TokenomicsKeeper.SetParams(ctx, tokenomicsParams) + if err != nil { + logger.Error("Failed to set tokenomics params", "error", err) + return err + } + logger.Info("Successfully updated tokenomics params", "new_params", tokenomicsParams) + + return + } + + // The diff shows that the only new authz authorization is for the `poktroll.session.MsgUpdateParam` message. + // However, this message is already authorized for the `pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t` address. + // See here: poktrolld q authz grants-by-granter pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t --node=https://shannon-testnet-grove-seed-rpc.alpha.poktroll.com + // If this upgrade would have been applied to other networks, we could have added a separate upgrade handler for each network. + + // Returns the upgrade handler for v0.0.11 + return func(ctx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + logger := cosmosTypes.UnwrapSDKContext(ctx).Logger() + logger.Info("Starting v0.0.11 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.11 upgrade handler") + return vm, nil + } + }, + // No changes to the KVStore in this upgrade. + StoreUpgrades: storetypes.StoreUpgrades{}, +} diff --git a/cmd/poktrolld/cmd/config.go b/cmd/poktrolld/cmd/config.go index ae9520a41..89536a6a1 100644 --- a/cmd/poktrolld/cmd/config.go +++ b/cmd/poktrolld/cmd/config.go @@ -21,12 +21,10 @@ type PoktrollAppConfig struct { } // poktrollAppConfigDefaults sets default values to render in `app.toml`. -// Checkout `customAppConfigTemplate()` for additional information about each setting. +// Checkout `customAppConfigTemplate()` for additional information about each config parameter. func poktrollAppConfigDefaults() PoktrollAppConfig { return PoktrollAppConfig{ - Telemetry: telemetry.PoktrollTelemetryConfig{ - CardinalityLevel: "medium", - }, + Telemetry: telemetry.DefaultConfig(), } } @@ -104,7 +102,6 @@ func initCometBFTConfig() *cmtcfg.Config { // return "", nil if no custom configuration is required for the application. // TODO_MAINNET: Reconsider values - check `app.toml` for possible options. func initAppConfig() (string, interface{}) { - // The following code snippet is just for reference. type CustomAppConfig struct { serverconfig.Config `mapstructure:",squash"` Poktroll PoktrollAppConfig `mapstructure:"poktroll"` @@ -140,6 +137,7 @@ func initAppConfig() (string, interface{}) { srvCfg.GRPC.Enable = true srvCfg.GRPCWeb.Enable = true + // Create the custom config with both server and poktroll configs customAppConfig := CustomAppConfig{ Config: *srvCfg, Poktroll: poktrollAppConfigDefaults(), diff --git a/telemetry/defaults.go b/telemetry/defaults.go new file mode 100644 index 000000000..e059e2c93 --- /dev/null +++ b/telemetry/defaults.go @@ -0,0 +1,14 @@ +package telemetry + +// Default configuration values for telemetry +const ( + // DefaultCardinalityLevel represents the default cardinality level for metrics collection + DefaultCardinalityLevel = "medium" +) + +// DefaultConfig returns the default telemetry configuration +func DefaultConfig() PoktrollTelemetryConfig { + return PoktrollTelemetryConfig{ + CardinalityLevel: DefaultCardinalityLevel, + } +} diff --git a/telemetry/telemetry.go b/telemetry/telemetry.go index 348b73898..d7b93a879 100644 --- a/telemetry/telemetry.go +++ b/telemetry/telemetry.go @@ -11,16 +11,31 @@ import ( // Set once on initialization and remains constant during runtime. var globalTelemetryConfig PoktrollTelemetryConfig -// PoktrollTelemetryConfig represents the telemetry protion of the custom poktroll config section in `app.toml`. +// PoktrollTelemetryConfig represents the telemetry portion of the custom poktroll config section in `app.toml`. type PoktrollTelemetryConfig struct { CardinalityLevel string `mapstructure:"cardinality-level"` } // New sets the globalTelemetryConfig for telemetry package. func New(appOpts servertypes.AppOptions) error { - // Extract the map from appOpts. - // `poktroll.telemetry` comes from `app.toml` which is parsed into a map. - telemetryMap := appOpts.Get("poktroll.telemetry").(map[string]interface{}) + // Get the poktroll config section. If it doesn't exist, use defaults + poktrollConfig := appOpts.Get("poktroll") + if poktrollConfig == nil { + globalTelemetryConfig = DefaultConfig() + return nil + } + + // Try to get the telemetry subsection + poktrollMap, ok := poktrollConfig.(map[string]interface{}) + if !ok { + return fmt.Errorf("invalid poktroll config format: expected map[string]interface{}, got %T", poktrollConfig) + } + + telemetryMap, ok := poktrollMap["telemetry"].(map[string]interface{}) + if !ok { + globalTelemetryConfig = DefaultConfig() + return nil + } // Use mapstructure to decode the map into the struct if err := mapstructure.Decode(telemetryMap, &globalTelemetryConfig); err != nil {