diff --git a/api/poktroll/application/types.pulsar.go b/api/poktroll/application/types.pulsar.go index 4a7751438..d1f8f492f 100644 --- a/api/poktroll/application/types.pulsar.go +++ b/api/poktroll/application/types.pulsar.go @@ -2190,14 +2190,12 @@ type Application struct { Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` // The Bech32 address of the application. Stake *v1beta1.Coin `protobuf:"bytes,2,opt,name=stake,proto3" json:"stake,omitempty"` // The total amount of uPOKT the application has staked - // As per this discussion: - // https://github.com/pokt-network/poktroll/pull/750#discussion_r1735025033 - // The number of service_configs is limited to 1 per service. - // This is to ensure that an application could not over service by making multiple - // claims settelments compete to burn the same stake. - // A slice of service_configs is still maintained to allow for future multi-service - // capabilities to be added, such as off-chain application stake tracking by suppliers: - // https://www.notion.so/buildwithgrove/Off-chain-Application-Stake-Tracking-6a8bebb107db4f7f9dc62cbe7ba555f7 + // CRITICAL_DEV_NOTE: The number of service_configs must be EXACTLY ONE. + // This prevents applications from over-servicing. + // The field is kept repeated (a list) for both legacy and future logic reaosns. + // References: + // - https://github.com/pokt-network/poktroll/pull/750#discussion_r1735025033 + // - https://www.notion.so/buildwithgrove/Off-chain-Application-Stake-Tracking-6a8bebb107db4f7f9dc62cbe7ba555f7 ServiceConfigs []*shared.ApplicationServiceConfig `protobuf:"bytes,3,rep,name=service_configs,json=serviceConfigs,proto3" json:"service_configs,omitempty"` // The list of services this appliccation is configured to request service for // TODO_BETA: Rename `delegatee_gateway_addresses` to `gateway_addresses_delegated_to`. // Ensure to rename all relevant configs, comments, variables, function names, etc as well. diff --git a/api/poktroll/tokenomics/event.pulsar.go b/api/poktroll/tokenomics/event.pulsar.go index cf18db79d..4a8a3c0e5 100644 --- a/api/poktroll/tokenomics/event.pulsar.go +++ b/api/poktroll/tokenomics/event.pulsar.go @@ -3730,7 +3730,7 @@ func (x *EventSupplierSlashed) GetSlashingAmount() *v1beta1.Coin { } // EventApplicationReimbursementRequest is emitted when an application requests -// a reimbursement +// a reimbursement. type EventApplicationReimbursementRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache diff --git a/app/upgrades.go b/app/upgrades.go index ab88cc07d..0978f4322 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -12,6 +12,7 @@ import ( // so `cosmovisor` can automatically pull the binary from GitHub. var allUpgrades = []upgrades.Upgrade{ upgrades.Upgrade_0_0_4, + upgrades.Upgrade_0_0_10, } // 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 13b55aa8f..637544cee 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -8,6 +8,18 @@ import ( "github.com/pokt-network/poktroll/app/keepers" ) +// TODO_MAINNET_DISCUSSION(@Olshansk): different networks should have the same gov module address, but might have different DAO addresses, +// unless we specifically write in these addresses in the genesis file. +// Should we use the same address/wallet for DAO or find a way to detect the network the upgrade is being applied to, +// to pick different addresses depending on the name of the network? (e.g chain-id) + +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. + AlphaTestNetAuthorityAddress = "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t" +) + // Upgrade represents a protocol upgrade in code. // Once a `MsgSoftwareUpgrade` is submitted on-chain, and `Upgrade.PlanName` matches the `Plan.Name`, // the upgrade will be scheduled for execution at the corresponding height. diff --git a/app/upgrades/v0.0.10.go b/app/upgrades/v0.0.10.go new file mode 100644 index 000000000..9635d3223 --- /dev/null +++ b/app/upgrades/v0.0.10.go @@ -0,0 +1,146 @@ +package upgrades + +import ( + "context" + "fmt" + "time" + + "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/cosmos/cosmos-sdk/x/authz" + "github.com/pokt-network/poktroll/app/keepers" + prooftypes "github.com/pokt-network/poktroll/x/proof/types" +) + +// Upgrade_0_0_10 is the upgrade handler for v0.0.10 Alpha TestNet upgrade +// Before/after validations should be done using the correct version, mimiching real-world scenario: +// - Before: v0.0.9 +// - After: v0.0.10 +var Upgrade_0_0_10 = Upgrade{ + PlanName: "v0.0.10", + 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.9-3...ff76430 + applyNewParameters := func(ctx context.Context) (err error) { + // Add application min stake + // Validate with: `poktrolld q application params --node=https://testnet-validated-validator-rpc.poktroll.com/` + appParams := keepers.ApplicationKeeper.GetParams(ctx) + newMinStakeApp := cosmosTypes.NewCoin("upokt", math.NewInt(100000000)) + appParams.MinStake = &newMinStakeApp + err = keepers.ApplicationKeeper.SetParams(ctx, appParams) + if err != nil { + return err + } + + // Add supplier min stake + // Validate with: `poktrolld q supplier params --node=https://testnet-validated-validator-rpc.poktroll.com/` + supplierParams := keepers.SupplierKeeper.GetParams(ctx) + newMinStakeSupplier := cosmosTypes.NewCoin("upokt", math.NewInt(1000000)) + supplierParams.MinStake = &newMinStakeSupplier + err = keepers.SupplierKeeper.SetParams(ctx, supplierParams) + if err != nil { + return err + } + + // Add gateway min stake + // Validate with: `poktrolld q gateway params --node=https://testnet-validated-validator-rpc.poktroll.com/` + gatewayParams := keepers.GatewayKeeper.GetParams(ctx) + newMinStakeGW := cosmosTypes.NewCoin("upokt", math.NewInt(1000000)) + gatewayParams.MinStake = &newMinStakeGW + err = keepers.GatewayKeeper.SetParams(ctx, gatewayParams) + if err != nil { + return err + } + + // Adjust proof module parameters + // Validate with: `poktrolld q proof params --node=https://testnet-validated-validator-rpc.poktroll.com/` + newProofRequirementThreshold := cosmosTypes.NewCoin("upokt", math.NewInt(20000000)) + newProofMissingPenalty := cosmosTypes.NewCoin("upokt", math.NewInt(320000000)) + newProofSubmissionFee := cosmosTypes.NewCoin("upokt", math.NewInt(1000000)) + proofParams := prooftypes.NewParams( + 0.25, + &newProofRequirementThreshold, + &newProofMissingPenalty, + &newProofSubmissionFee, + ) + + err = keepers.ProofKeeper.SetParams(ctx, proofParams) + if err != nil { + return err + } + + // Add new shared module params + // Validate with: `poktrolld q shared params --node=https://testnet-validated-validator-rpc.poktroll.com/` + sharedParams := keepers.SharedKeeper.GetParams(ctx) + sharedParams.SupplierUnbondingPeriodSessions = uint64(1) + sharedParams.ApplicationUnbondingPeriodSessions = uint64(1) + sharedParams.ComputeUnitsToTokensMultiplier = uint64(42) + err = keepers.SharedKeeper.SetParams(ctx, sharedParams) + if err != nil { + return err + } + return + } + + // Adds new authz authorizations from the diff: + // https://github.com/pokt-network/poktroll/compare/v0.0.9-3...ff76430 + applyNewAuthorizations := func(ctx context.Context) (err error) { + // Validate before/after with: + // `poktrolld q authz grants-by-granter pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t --node=https://testnet-validated-validator-rpc.poktroll.com/` + grantAuthorizationMessages := []string{ + "/poktroll.gateway.MsgUpdateParam", + "/poktroll.application.MsgUpdateParam", + "/poktroll.supplier.MsgUpdateParam", + } + + expiration, err := time.Parse(time.RFC3339, "2500-01-01T00:00:00Z") + if err != nil { + return fmt.Errorf("failed to parse time: %w", err) + } + + for _, msg := range grantAuthorizationMessages { + err = keepers.AuthzKeeper.SaveGrant( + ctx, + cosmosTypes.AccAddress(AlphaTestNetPnfAddress), + cosmosTypes.AccAddress(AlphaTestNetAuthorityAddress), + authz.NewGenericAuthorization(msg), + &expiration, + ) + if err != nil { + return fmt.Errorf("failed to save grant for message %s: %w", msg, err) + } + } + return + } + + // Returns the upgrade handler for v0.0.10 + return func(ctx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + err := applyNewParameters(ctx) + if err != nil { + return vm, err + } + + err = applyNewAuthorizations(ctx) + if err != nil { + return vm, err + } + + // RelayMiningDifficulty have been moved from `tokenomics` to `services` in this diff. + // Ideally (in prod), we should have migrated the data before removing query/msg types in `tokenomics` module. + // In practice (development), we don't want to spend time on it. + // Since we know that new RelayMiningDifficulty will be re-created and real tokens are not in danger, + // we can skip this step now. + + return mm.RunMigrations(ctx, configurator, vm) + } + }, + // No changes to the KVStore in this upgrade. + StoreUpgrades: storetypes.StoreUpgrades{}, +} diff --git a/tools/scripts/upgrades/local_test_v0.0.10.json b/tools/scripts/upgrades/local_test_v0.0.10.json new file mode 100644 index 000000000..d0153c519 --- /dev/null +++ b/tools/scripts/upgrades/local_test_v0.0.10.json @@ -0,0 +1,15 @@ +{ + "body": { + "messages": [ + { + "@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", + "authority": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t", + "plan": { + "name": "v0.0.10", + "height": "20", + "info": "This field is not used for local testing" + } + } + ] + } +} \ No newline at end of file diff --git a/x/application/types/types.pb.go b/x/application/types/types.pb.go index 9e5b8ff6c..32bc0cc13 100644 --- a/x/application/types/types.pb.go +++ b/x/application/types/types.pb.go @@ -31,14 +31,12 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type Application struct { Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` Stake *types.Coin `protobuf:"bytes,2,opt,name=stake,proto3" json:"stake,omitempty"` - // As per this discussion: - // https://github.com/pokt-network/poktroll/pull/750#discussion_r1735025033 - // The number of service_configs is limited to 1 per service. - // This is to ensure that an application could not over service by making multiple - // claims settelments compete to burn the same stake. - // A slice of service_configs is still maintained to allow for future multi-service - // capabilities to be added, such as off-chain application stake tracking by suppliers: - // https://www.notion.so/buildwithgrove/Off-chain-Application-Stake-Tracking-6a8bebb107db4f7f9dc62cbe7ba555f7 + // CRITICAL_DEV_NOTE: The number of service_configs must be EXACTLY ONE. + // This prevents applications from over-servicing. + // The field is kept repeated (a list) for both legacy and future logic reaosns. + // References: + // - https://github.com/pokt-network/poktroll/pull/750#discussion_r1735025033 + // - https://www.notion.so/buildwithgrove/Off-chain-Application-Stake-Tracking-6a8bebb107db4f7f9dc62cbe7ba555f7 ServiceConfigs []*types1.ApplicationServiceConfig `protobuf:"bytes,3,rep,name=service_configs,json=serviceConfigs,proto3" json:"service_configs,omitempty"` // TODO_BETA: Rename `delegatee_gateway_addresses` to `gateway_addresses_delegated_to`. // Ensure to rename all relevant configs, comments, variables, function names, etc as well. diff --git a/x/tokenomics/types/event.pb.go b/x/tokenomics/types/event.pb.go index 8570fd911..5e69f719f 100644 --- a/x/tokenomics/types/event.pb.go +++ b/x/tokenomics/types/event.pb.go @@ -370,7 +370,7 @@ func (m *EventSupplierSlashed) GetSlashingAmount() *types1.Coin { } // EventApplicationReimbursementRequest is emitted when an application requests -// a reimbursement +// a reimbursement. type EventApplicationReimbursementRequest struct { ApplicationAddr string `protobuf:"bytes,1,opt,name=application_addr,json=applicationAddr,proto3" json:"application_addr,omitempty"` SupplierOperatorAddr string `protobuf:"bytes,2,opt,name=supplier_operator_addr,json=supplierOperatorAddr,proto3" json:"supplier_operator_addr,omitempty"`