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

[Upgrades] v0.0.12 upgrade #1043

Merged
merged 10 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
14 changes: 11 additions & 3 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ import (
// The chain upgrade can be scheduled AFTER the new version (with upgrade strategy implemented) is released,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a certain .md you're supposed to update (for documentation purposes) when we do an upgrade?

https://dev.poktroll.com/protocol/upgrades/upgrade_list

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment of release, we don't know when the upgrade will happen. My thinking, this should be a separate PR. But! We can prepare some changes in advance - that's a good idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But! We can prepare some changes in advance - that's a good idea.

Let's do it!

Wdyt of creating another PR (updating the docs that's a draft), and leave a TODO here.

var allUpgrades = []upgrades.Upgrade{
	// v0.0.4 was the first upgrade we implemented and tested on network that is no longer used.
	// upgrades.Upgrade_0_0_4,

	// v0.0.10 was the first upgrade we implemented on Alpha TestNet.
	// upgrades.Upgrade_0_0_10,

	// v0.0.11 was the Alpha TestNet exclusive upgrade to bring it on par with Beta TestNet.
	// upgrades.Upgrade_0_0_11,

	// TODO(@okdas, #XX): Update the documentation once a block height has been selected.
	// Ref: https://dev.poktroll.com/protocol/upgrades/upgrade_list
	// v0.0.12 - the first upgrade going live on both Alpha and Beta TestNets.
	upgrades.Upgrade_0_0_12,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm: I saw your changes in .md AFTER writing the message above. Leaving it as a reference.

Wdyt of adding the output of the CLI transaction to say "Please update docusaurus/docs/protocol/upgrades/upgrade_list.md` now that you've submitted the plan?

You know how they say "Go to where your users are", I'm trying to "Go where the dev's eyes are".

They're looking at the CLI when something says !!!!!!!!! :)

// 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,
// v0.0.4 was the first upgrade we implemented and tested on network that is no longer used.
// upgrades.Upgrade_0_0_4,

// v0.0.10 was the first upgrade we implemented on Alpha TestNet.
// upgrades.Upgrade_0_0_10,

// v0.0.11 was the Alpha TestNet exclusive upgrade to bring it on par with Beta TestNet.
// upgrades.Upgrade_0_0_11,

// v0.0.12 - the first upgrade going live on both Alpha and Beta TestNets.
upgrades.Upgrade_0_0_12,
okdas marked this conversation as resolved.
Show resolved Hide resolved
}

// setUpgrades sets upgrade handlers for all upgrades and executes KVStore migration if an upgrade plan file exists.
Expand Down
3 changes: 3 additions & 0 deletions app/upgrades/historical.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
// For example, even if `ConsensusVersion` is not modified for any modules, it still might be beneficial to create
// an upgrade so node runners are signaled to start utilizing `Cosmovisor` for new binaries.
var UpgradeExample = Upgrade{
// PlanName can be any string. This code is executed when the upgrade with this plan name is submitted to the network.
// It is not necessarly should be a version, but it's usually the case as we introduce breaking changes and force

Check warning on line 44 in app/upgrades/historical.go

View workflow job for this annotation

GitHub Actions / misspell

[misspell] app/upgrades/historical.go#L44

"necessarly" is a misspelling of "necessary"
Raw output
./app/upgrades/historical.go:44:14: "necessarly" is a misspelling of "necessary"
// the community to upgrade.
okdas marked this conversation as resolved.
Show resolved Hide resolved
PlanName: "v0.0.0-Example",
CreateUpgradeHandler: defaultUpgradeHandler,

Expand Down
9 changes: 8 additions & 1 deletion app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ 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.

// Authority address. Defaults to x/gov module account address. Used to create new authz authorizations.
// TECHDEBT: DO NOT use AlphaTestNetAuthorityAddress.
// Use `keepers.UpgradeKeeper.Authority(ctx, &upgradetypes.QueryAuthorityRequest{})` to query the authority address of the current Alpha Network.
// This hard-coded address is kept for record keeping historical purposes.
okdas marked this conversation as resolved.
Show resolved Hide resolved
AlphaTestNetAuthorityAddress = "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t"

// The default PNF/DAO address in the genesis file for Beta TestNet. Used to create new authz authorizations.
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
BetaTestNetPnfAddress = "pokt1f0c9y7mahf2ya8tymy8g4rr75ezh3pkklu4c3e"
)

// Upgrade represents a protocol upgrade in code.
Expand Down
154 changes: 154 additions & 0 deletions app/upgrades/v0.0.12.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
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"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
)

const Upgrade_0_0_12_PlanName = "v0.0.12"

// Upgrade_0_0_12 handles the upgrade to release `v0.0.12`. To be issued on both Alpha and Beta TestNets.
okdas marked this conversation as resolved.
Show resolved Hide resolved
var Upgrade_0_0_12 = Upgrade{
PlanName: Upgrade_0_0_12_PlanName,
CreateUpgradeHandler: func(mm *module.Manager,
keepers *keepers.Keepers,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
// Parameter configurations aligned with repository config.yml specifications
okdas marked this conversation as resolved.
Show resolved Hide resolved
// These values reflect the delta between v0.0.11 and current main branch
okdas marked this conversation as resolved.
Show resolved Hide resolved
// Reference:
// - Comparison: https://github.com/pokt-network/poktroll/compare/v0.0.11..main
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be using main or a specific sha (that equals to main) when you're preparing this PR?

That way this will be "evergreen"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TLDR: I want to use main here. This link is for the purpose of writing an upgrade. Once we go through the upgrade - we no longer need this code, perhaps only as a reference.

Complex answer, feel free to skip:

We're supposed to create a release and use artifacts (binaries & images) produced by that release to upgrade validators, full nodes, seeds, and relayminers.

The release can be created off any branch or any commit. It MUST include the upgrade plan code (introduced by this PR).

Now, the code in the main branch can drift between the moment of writing this upgrade code and creating a new release. So if we want to make things "right" - we need to have more branches, perhaps dedicated version branches. Do you remember we talked about how cosmos-sdk branches work? We also talked about over-engineering? If the codebase is active enough, we'd have no other choice but to have a similar complex branching system. For example, if there's a feature in the main branch we DON'T want to be included in the release - there's just no other way I can think of.

But we are a small team, and we can track that drift to changes to upgrade, if necessary, before the release. So I want to compare to main.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving conversation to discord to get this over the finish line.

https://discord.com/channels/824324475256438814/1332065342746525778/1336434350660784239

// - Direct diff: `git diff v0.0.11..main -- config.yml`
//
// Note: Parameter updates are derived from config.yml modifications, which serves
// as the source of truth for all parameter changes.
okdas marked this conversation as resolved.
Show resolved Hide resolved
const (
supplierStakingFee = 1000000
serviceTargetNumRelays = 100
tokenomicsGlobalInflationPerClaim = 0.1
okdas marked this conversation as resolved.
Show resolved Hide resolved
)

applyNewParameters := func(ctx context.Context) (err error) {
logger := cosmosTypes.UnwrapSDKContext(ctx).Logger()
logger.Info("Starting parameter updates", "upgrade_plan_name", Upgrade_0_0_12_PlanName)

// Set supplier module staking_fee to 1000000upokt, in line with the config.yml in the repo.
// Verify via:
// $ poktrolld q supplier params --node=...
supplierParams := keepers.SupplierKeeper.GetParams(ctx)
supplierParams.MinStake = &cosmosTypes.Coin{
Denom: "upokt",
Amount: math.NewInt(supplierStakingFee),
}
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, in line with the config.yml in the repo.
// Verify via:
// $ poktrolld q service params --node=...
serviceParams := keepers.ServiceKeeper.GetParams(ctx)
serviceParams.TargetNumRelays = serviceTargetNumRelays
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, in line with the config.yml in the repo.
// Verify via:
// $ poktrolld q tokenomics params --node=...
tokenomicsParams := keepers.TokenomicsKeeper.GetParams(ctx)
tokenomicsParams.GlobalInflationPerClaim = tokenomicsGlobalInflationPerClaim
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 nil
}

// Helper function to update all suppliers' RevShare to 100%. This is necessary to ensure that
// we have that value populated before suppliers are connected.
okdas marked this conversation as resolved.
Show resolved Hide resolved
updateSuppliersRevShare := func(ctx context.Context) error {
logger := cosmosTypes.UnwrapSDKContext(ctx).Logger()
suppliers := keepers.SupplierKeeper.GetAllSuppliers(ctx)
logger.Info("Updating all suppliers to have a 100% revshare to the supplier",
okdas marked this conversation as resolved.
Show resolved Hide resolved
"num_suppliers", len(suppliers))

for _, supplier := range suppliers {
for _, service := range supplier.Services {
// Add warning log if we're overwriting existing revshare settings. We can't get the previous
// revshare percentage due to a protobuf change, but we can at least log the number of previous revshares.
okdas marked this conversation as resolved.
Show resolved Hide resolved
if len(service.RevShare) > 1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to check if the address is different

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the logic a bit.

If more than 1 supplier: log and overwrite,
if 1 supplier: just update the data keeping existing revshare address (assuming 100% goes to that one address)

logger.Warn(
"Overwriting existing revenue share configuration",
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
"supplier", supplier.OperatorAddress,
okdas marked this conversation as resolved.
Show resolved Hide resolved
"service", service.ServiceId,
"previous_revshare_count", len(service.RevShare),
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
)
}
service.RevShare = []*sharedtypes.ServiceRevenueShare{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we would be able to loop over the old revshare map by unmashalling to the old proto type then create the new Supplier proto with the new values.

But since we don't have proto versioning and we marked the old (float32) value as reserved, this is the next best option offered to us.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@red-0ne Really appreciate this feedback & input.

@okdas Can you #PUC what the "best" approach would be an "why" - essentially paragraphsing @red-0ne's comments.

In particular, explaining why we're not doing it would help. I'm thinking:

  1. Requires multiple copies of the protobuf
  2. Requiers multiple steps in the migration (overkill given that we're not in prod)
  3. Etc...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rephrased the whole block.

{
Address: supplier.OperatorAddress,
RevSharePercentage: uint64(100),
},
}
}
keepers.SupplierKeeper.SetSupplier(ctx, supplier)
logger.Info("Updated supplier",
"supplier", supplier.OperatorAddress)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Owner & operator please!

}
return nil
}

// 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 upgrade handler", "upgrade_plan_name", Upgrade_0_0_12_PlanName)

err := applyNewParameters(ctx)
okdas marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
logger.Error("Failed to apply new parameters",
"upgrade_plan_name", Upgrade_0_0_12_PlanName,
"error", err)
return vm, err
}

// Update all suppliers' RevShare
okdas marked this conversation as resolved.
Show resolved Hide resolved
err = updateSuppliersRevShare(ctx)
if err != nil {
logger.Error("Failed to update suppliers RevShare",
"upgrade_plan_name", Upgrade_0_0_12_PlanName,
"error", err)
return vm, err
}

logger.Info("Running module migrations", "upgrade_plan_name", Upgrade_0_0_12_PlanName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a log like this before every section / update?

vm, err = mm.RunMigrations(ctx, configurator, vm)
if err != nil {
logger.Error("Failed to run migrations",
"upgrade_plan_name", Upgrade_0_0_12_PlanName,
"error", err)
return vm, err
}

logger.Info("Successfully completed upgrade handler", "upgrade_plan_name", Upgrade_0_0_12_PlanName)
return vm, nil
}
},
// No changes to the KVStore in this upgrade.
StoreUpgrades: storetypes.StoreUpgrades{},
}
15 changes: 9 additions & 6 deletions docusaurus/docs/protocol/upgrades/upgrade_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Coming...

| Version | Planned | Breaking | Requires Manual Intervention | Upgrade Height |
| -------------------------------------------------------------------------------- | :-----: | :------: | :--------------------------: | -------------- |
| [`v0.0.12`](https://github.com/pokt-network/poktroll/releases/tag/v0.0.12) | ✅ | ✅ | ❌ | TBA |
| [`v0.0.11-rc`](https://github.com/pokt-network/poktroll/releases/tag/v0.0.11-rc) | N/A | N/A | ❌ genesis version | N/A |

## Alpha TestNet
Expand All @@ -36,12 +37,14 @@ Some manual steps are currently required to sync to the latest block. Please fol

<!-- DEVELOPER: if important information about the release is changing (e.g. upgrade height is changed) - make sure to update the information in GitHub release as well. -->

| Version | Planned | Breaking | Requires Manual Intervention | Upgrade Height |
| ---------------------------------------------------------------------------- | :-----: | :------: | :--------------------------------------------------------------------------------------------------------------------------------------------: | -------------------------------------------------------------------------------------------------------------------------------- |
| [`v0.0.10`](https://github.com/pokt-network/poktroll/releases/tag/v0.0.10) | ✅ | ✅ | ❌ (automatic upgrade) | [56860](https://shannon.alpha.testnet.pokt.network/poktroll/tx/4E201E5C397AB881F417266154C907D38404BE00BE9A443DE28E44A2B09C5CFB) |
| [`v0.0.9-4`](https://github.com/pokt-network/poktroll/releases/tag/v0.0.9-4) | ❌ | ✅ | ⚠️ [follow manual upgrade instructions](https://github.com/pokt-network/poktroll/releases/tag/v0.0.9-4) ⚠️ | `46329` |
| [`v0.0.9-3`](https://github.com/pokt-network/poktroll/releases/tag/v0.0.9-3) | ❌ | ✅ | ❌ Active Alpha TestNet Participants Only: [follow manual upgrade instructions](https://github.com/pokt-network/poktroll/releases/tag/v0.0.9-3) | `17102` |
| [`v0.0.9`](https://github.com/pokt-network/poktroll/releases/tag/v0.0.9) | N/A | N/A | ❌ genesis version | N/A |
| Version | Planned | Breaking | Requires Manual Intervention | Upgrade Height |
| ---------------------------------------------------------------------------- | :-----: | :------: | :--------------------------------------------------------------------------------------------------------------------------------------------: | --------------------------------------------------------------------------------------------------------------------------------- |
| [`v0.0.12`](https://github.com/pokt-network/poktroll/releases/tag/v0.0.12) | ✅ | ✅ | ❌ | TBA |
| [`v0.0.11`](https://github.com/pokt-network/poktroll/releases/tag/v0.0.11) | ✅ | ✅ | ❌ (automatic upgrade) | [156245](https://shannon.alpha.testnet.pokt.network/poktroll/tx/EE72B1D0744872CFFF4AC34DA9573B0BC2E32FFF998A8F25BF817FBE44F53543) |
| [`v0.0.10`](https://github.com/pokt-network/poktroll/releases/tag/v0.0.10) | ✅ | ✅ | ❌ (automatic upgrade) | [56860](https://shannon.alpha.testnet.pokt.network/poktroll/tx/4E201E5C397AB881F417266154C907D38404BE00BE9A443DE28E44A2B09C5CFB) |
| [`v0.0.9-4`](https://github.com/pokt-network/poktroll/releases/tag/v0.0.9-4) | ❌ | ✅ | ⚠️ [follow manual upgrade instructions](https://github.com/pokt-network/poktroll/releases/tag/v0.0.9-4) ⚠️ | `46329` |
| [`v0.0.9-3`](https://github.com/pokt-network/poktroll/releases/tag/v0.0.9-3) | ❌ | ✅ | ❌ Active Alpha TestNet Participants Only: [follow manual upgrade instructions](https://github.com/pokt-network/poktroll/releases/tag/v0.0.9-3) | `17102` |
| [`v0.0.9`](https://github.com/pokt-network/poktroll/releases/tag/v0.0.9) | N/A | N/A | ❌ genesis version | N/A |

### Syncing from genesis - manual steps
<!-- TODO(@okdas): when the next cosmovisor version released with `https://github.com/cosmos/cosmos-sdk/pull/21790` included - provide automated solution (csv file + pre-downloaded binaries) that will add hot-fixes automatically, allowing to sync from block #1 without any intervention -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ metrics:
addr: :9070
pocket_node:
query_node_rpc_url: tcp://localhost:26657
query_node_grpc_url: tcp://localhost:36658
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity - when/why did we change this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh - I wanted to test if relayminer works when connected to the node running on localhost.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So confirming this should be left as is or no?

It's just a little confusing (without comments) why some ports are 26657 but the other is 9090

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9090 is the default gRPC port in cosmos-sdk. If you start the node without LocalNet, that'll be the port the gRPC endpoint is available on. This particular file is only used to debug in VSCode, probably just by me. I haven't seen anybody else using this setup.

query_node_grpc_url: tcp://localhost:9090
tx_node_rpc_url: tcp://localhost:26657
suppliers:
- service_id: anvil
Expand Down