Skip to content

Commit

Permalink
add 0.0.9-3 with consensus migration
Browse files Browse the repository at this point in the history
  • Loading branch information
okdas committed Oct 10, 2024
1 parent 9d0fb17 commit 843a96e
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
var allUpgrades = []upgrades.Upgrade{
upgrades.Upgrade_0_0_4,
upgrades.Upgrade_v0_0_9_2,
upgrades.Upgrade_v0_0_9_3,
}

// setUpgrades sets upgrade handlers for all upgrades and executes KVStore migration if an upgrade plan file exists.
Expand Down
8 changes: 8 additions & 0 deletions app/upgrades/v0.0.9-2.go → app/upgrades/v0.0.9.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ var Upgrade_v0_0_9_2 = Upgrade{
CreateUpgradeHandler: defaultUpgradeHandler,
StoreUpgrades: storetypes.StoreUpgrades{},
}

// Upgrade_v0_0_9_2 is an upgrade on Beta TestNet.
var Upgrade_v0_0_9_3 = Upgrade{
// the transaction needs to have a plan with the same name.
PlanName: "v0.0.9-3",
CreateUpgradeHandler: defaultUpgradeHandler,
StoreUpgrades: storetypes.StoreUpgrades{},
}
15 changes: 15 additions & 0 deletions tools/scripts/upgrades/authz_upgrade_tx_example_v0.0.9-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"body": {
"messages": [
{
"@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade",
"authority": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t",
"plan": {
"name": "v0.0.9-2",
"height": "17102",
"info": "{\"binaries\":{\"linux\/amd64\":\"https:\/\/github.com\/pokt-network\/poktroll\/releases\/download\/v0.0.9-2\/poktroll_linux_amd64.tar.gz?checksum=sha256:bbef89b677fa6ee92afa4b93421653b093f0e679ee890f3f6d0fce9b11b11cd3\",\"linux\/arm64\":\"https:\/\/github.com\/pokt-network\/poktroll\/releases\/download\/v0.0.9-2\/poktroll_linux_arm64.tar.gz?checksum=sha256:d5dadb7c5d50493ba7717ec29785b074d4d76ce167e3eb54c183829d3560cc70\",\"darwin\/amd64\":\"https:\/\/github.com\/pokt-network\/poktroll\/releases\/download\/v0.0.9-2\/poktroll_darwin_amd64.tar.gz?checksum=sha256:d0134c208bf85cf4992461a4e3b56557c178edc745e0ae677b8548abf9f56cbb\",\"darwin\/arm64\":\"https:\/\/github.com\/pokt-network\/poktroll\/releases\/download\/v0.0.9-2\/poktroll_darwin_arm64.tar.gz?checksum=sha256:0c7e025cd91e054cd2d95833c339c3875927eb8474142eb61ab21f6bfa648442\"}}"
}
}
]
}
}
15 changes: 15 additions & 0 deletions tools/scripts/upgrades/local_test_v0.0.9-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"body": {
"messages": [
{
"@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade",
"authority": "pokt10d07y265gmmuvt4z0w9aw880jnsr700j8yv32t",
"plan": {
"name": "v0.0.9-2",
"height": "50",
"info": "NOT NEEDED FOR LOCAL TESTING"
}
}
]
}
}
21 changes: 21 additions & 0 deletions x/tokenomics/keeper/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
v2 "github.com/pokt-network/poktroll/x/tokenomics/migrations/v2"
)

// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper Keeper
}

// NewMigrator returns a new Migrator.
func NewMigrator(keeper Keeper) Migrator {
return Migrator{keeper: keeper}
}

// Migrate1to2 migrates from version 1 to 2.
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v2.MigrateStore(ctx, m.keeper.storeService, m.keeper.cdc)
}
15 changes: 15 additions & 0 deletions x/tokenomics/migrations/v2/migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package v2

import (
"context"
"fmt"

corestoretypes "cosmossdk.io/core/store"
"github.com/cosmos/cosmos-sdk/codec"
)

// MigrateStore - NOOP migration to upgrade the consensus version.
func MigrateStore(ctx context.Context, storeService corestoretypes.KVStoreService, cdc codec.BinaryCodec) error {
fmt.Println("Would migrate the store here, but not doing anything - we don't have anything to migrate.")
return nil
}
13 changes: 12 additions & 1 deletion x/tokenomics/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tokenomics
import (
"context"
"encoding/json"
"fmt"

// this line is used by starport scaffolding # 1

Expand Down Expand Up @@ -120,6 +121,12 @@ func NewAppModule(
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.tokenomicsKeeper))
types.RegisterQueryServer(cfg.QueryServer(), am.tokenomicsKeeper)

m := keeper.NewMigrator(am.tokenomicsKeeper)
err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2)
if err != nil {
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err))
}
}

// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted)
Expand All @@ -143,7 +150,11 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
// ConsensusVersion is a sequence number for state-breaking change of the module.
// It should be incremented on each consensus-breaking change introduced by the module.
// To avoid wrong/empty versions, the initial version should be set to 1.
func (AppModule) ConsensusVersion() uint64 { return 1 }
func (AppModule) ConsensusVersion() uint64 {
// Bumping the `ConsensusVersion` to see if it will allow to rollback and fork the network when
// there are other full-nodes gossiping the blocks signed by the same validator.
return 2
}

// BeginBlock contains the logic that is automatically triggered at the beginning of each block.
// The begin block implementation is optional.
Expand Down

0 comments on commit 843a96e

Please sign in to comment.