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

feat(app): Import Fork of Osmosis #252

Merged
merged 12 commits into from
Jun 27, 2023
54 changes: 6 additions & 48 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
Expand All @@ -48,6 +45,7 @@ import (

// upgrades
"github.com/classic-terra/core/v2/app/upgrades"
v1 "github.com/classic-terra/core/v2/app/upgrades/v1"
v2 "github.com/classic-terra/core/v2/app/upgrades/v2"
v3 "github.com/classic-terra/core/v2/app/upgrades/v3"
v4 "github.com/classic-terra/core/v2/app/upgrades/v4"
Expand All @@ -71,6 +69,9 @@ var (

// Upgrades defines upgrades to be applied to the network
Upgrades = []upgrades.Upgrade{v2.Upgrade, v3.Upgrade, v4.Upgrade}

// Forks defines forks to be applied to the network
Forks = []upgrades.Fork{v1.DisableSwapFork, v1.IbcEnableFork, v1.VersionMapEnableFork}
)

// Verify app interface at compile time
Expand Down Expand Up @@ -243,50 +244,7 @@ func (app *TerraApp) Name() string { return app.BaseApp.Name() }

// BeginBlocker application updates every begin block
func (app *TerraApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
if ctx.ChainID() == core.ColumbusChainID && ctx.BlockHeight() == core.SwapDisableForkHeight { // Make min spread to one to disable swap
params := app.MarketKeeper.GetParams(ctx)
params.MinStabilitySpread = sdk.OneDec()
app.MarketKeeper.SetParams(ctx, params)

// Disable IBC Channels
channelIDs := []string{
"channel-1", // Osmosis
"channel-49", // Crescent
"channel-20", // Juno
}
for _, channelID := range channelIDs {
channel, found := app.IBCKeeper.ChannelKeeper.GetChannel(ctx, ibctransfertypes.PortID, channelID)
if !found {
panic(fmt.Sprintf("%s not found", channelID))
}

channel.State = ibcchanneltypes.CLOSED
app.IBCKeeper.ChannelKeeper.SetChannel(ctx, ibctransfertypes.PortID, channelID, channel)
}
}
if ctx.ChainID() == core.ColumbusChainID && ctx.BlockHeight() == core.SwapEnableForkHeight { // Re-enable IBCs
// Enable IBC Channels
channelIDs := []string{
"channel-1", // Osmosis
"channel-49", // Crescent
"channel-20", // Juno
}
for _, channelID := range channelIDs {
channel, found := app.IBCKeeper.ChannelKeeper.GetChannel(ctx, ibctransfertypes.PortID, channelID)
if !found {
panic(fmt.Sprintf("%s not found", channelID))
}

channel.State = ibcchanneltypes.OPEN
app.IBCKeeper.ChannelKeeper.SetChannel(ctx, ibctransfertypes.PortID, channelID, channel)
}
}

// trigger SetModuleVersionMap in upgrade keeper at the VersionMapEnableHeight
if ctx.ChainID() == core.ColumbusChainID && ctx.BlockHeight() == core.VersionMapEnableHeight {
app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
}

BeginBlockForks(ctx, app)
return app.mm.BeginBlock(ctx, req)
}

Expand All @@ -302,7 +260,7 @@ func (app *TerraApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abc
panic(err)
}
if ctx.ChainID() == core.ColumbusChainID {
panic("Must use v1.0.x for importing the columbus genesis (https://github.com/classic-terra/core/v2/releases/)")
panic("Must use v1.0.x for importing the columbus genesis (https://github.com/classic-terra/core/releases/)")
}
app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
Expand Down
15 changes: 15 additions & 0 deletions app/forks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// BeginBlockForks is intended to be ran in a chain upgrade.
func BeginBlockForks(ctx sdk.Context, app *TerraApp) {
for _, fork := range Forks {
if ctx.BlockHeight() == fork.UpgradeHeight {
fork.BeginForkLogic(ctx, &app.AppKeepers, app.mm)
return
}
}
}
52 changes: 52 additions & 0 deletions app/upgrades/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Classic Terra Upgrades

This folder contains sub-folders for every classic terra upgrade. (Both state
migrations, and hard forks) It also defines upgrade & hard fork structs,
that each upgrade implements. These then get included in the application
app.go to run the upgrade.

## Upgrade History
* Initial release (v1)
* (soft-fork) v0.5.20 - Disable swap and IBC
* (soft-fork) v1.0.4 - Enable IBC
* (soft-fork) v1.0.5 - Set module version map for enabling software upgrades
* Upgrade: v2
* (treasury) Tax exemption list, burn tax split
* Upgrade: v3
* (treasury) Minimum initial deposit
* Upgrade: v4
* (staking) Minimum commision rate

## Upgrade types

There are two upgrade types exposed, `Upgrade` and `Fork`. An `Upgrade`
defines an upgrade that is to be acted upon by state migrations from the
SDK `x/upgrade` module. A `Fork` defines a hard fork that changes some
logic at a block height. If the goal is to have a new binary be
compatible with the old binary prior to the upgrade height, as is the
case for all classic terra `Fork`s, then all logic changes must be
height-gated or in the `BeginForkLogic` code.

```go
type Upgrade struct {
// Upgrade version name, for the upgrade handler, e.g. `v7`
UpgradeName string
// Function that creates an upgrade handler
CreateUpgradeHandler func(mm *module.Manager, configurator module.Configurator, keepers *keepers.AppKeepers) upgradetypes.UpgradeHandler
// Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed.
StoreUpgrades store.StoreUpgrades
}

type Fork struct {
// Upgrade version name, for the upgrade handler, e.g. `v7`
UpgradeName string
// height the upgrade occurs at
UpgradeHeight int64

// Function that runs some custom state transition code at the beginning of a fork.
BeginForkLogic ForkLogicFunc
}

// ForkLogicFunc defines a function that is run at the beginning of a fork.
type ForkLogicFunc = func(ctx sdk.Context, keppers *keepers.AppKeepers, mm *module.Manager)
```
18 changes: 18 additions & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,21 @@ type Upgrade struct {
// Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed.
StoreUpgrades store.StoreUpgrades
}

// Fork defines a struct containing the requisite fields for a non-software upgrade proposal
// Hard Fork at a given height to implement.
// There is one time code that can be added for the start of the Fork, in `BeginForkLogic`.
// Any other change in the code should be height-gated, if the goal is to have old and new binaries
// to be compatible prior to the upgrade height.
type Fork struct {
// Upgrade version name, for the upgrade handler, e.g. `v7`
UpgradeName string
// height the upgrade occurs at
UpgradeHeight int64

// Function that runs some custom state transition code at the beginning of a fork.
BeginForkLogic ForkLogicFunc
}

// ForkLogicFunc defines a function that is run at the beginning of a fork.
type ForkLogicFunc = func(ctx sdk.Context, keppers *keepers.AppKeepers, mm *module.Manager)
24 changes: 24 additions & 0 deletions app/upgrades/v1/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package v1

import (
"github.com/classic-terra/core/v2/app/upgrades"
"github.com/classic-terra/core/v2/types/fork"
)

var DisableSwapFork = upgrades.Fork{
UpgradeName: "v0.5.20",
UpgradeHeight: fork.SwapDisableHeight,
BeginForkLogic: runForkLogicSwapDisable,
}

var IbcEnableFork = upgrades.Fork{
UpgradeName: "v1.0.4",
UpgradeHeight: fork.IbcEnableHeight,
BeginForkLogic: runForkLogicIbcEnable,
}

var VersionMapEnableFork = upgrades.Fork{
UpgradeName: "v1.0.5",
UpgradeHeight: fork.VersionMapEnableHeight,
BeginForkLogic: runForkLogicVersionMapEnable,
}
64 changes: 64 additions & 0 deletions app/upgrades/v1/forks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package v1

import (
"fmt"

"github.com/classic-terra/core/v2/app/keepers"
core "github.com/classic-terra/core/v2/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types"
)

func runForkLogicSwapDisable(ctx sdk.Context, keppers *keepers.AppKeepers, _ *module.Manager) {
if ctx.ChainID() == core.ColumbusChainID {
// Make min spread to 100% to disable swap
params := keppers.MarketKeeper.GetParams(ctx)
params.MinStabilitySpread = sdk.OneDec()
keppers.MarketKeeper.SetParams(ctx, params)

// Disable IBC Channels
channelIDs := []string{
"channel-1", // Osmosis
"channel-49", // Crescent
"channel-20", // Juno
}
for _, channelID := range channelIDs {
channel, found := keppers.IBCKeeper.ChannelKeeper.GetChannel(ctx, ibctransfertypes.PortID, channelID)
if !found {
panic(fmt.Sprintf("%s not found", channelID))
}

channel.State = ibcchanneltypes.CLOSED
keppers.IBCKeeper.ChannelKeeper.SetChannel(ctx, ibctransfertypes.PortID, channelID, channel)
}
}
}

func runForkLogicIbcEnable(ctx sdk.Context, keppers *keepers.AppKeepers, _ *module.Manager) {
if ctx.ChainID() == core.ColumbusChainID {
// Enable IBC Channels
channelIDs := []string{
"channel-1", // Osmosis
"channel-49", // Crescent
"channel-20", // Juno
}
for _, channelID := range channelIDs {
channel, found := keppers.IBCKeeper.ChannelKeeper.GetChannel(ctx, ibctransfertypes.PortID, channelID)
if !found {
panic(fmt.Sprintf("%s not found", channelID))
}

channel.State = ibcchanneltypes.OPEN
keppers.IBCKeeper.ChannelKeeper.SetChannel(ctx, ibctransfertypes.PortID, channelID, channel)
}
}
}

func runForkLogicVersionMapEnable(ctx sdk.Context, keppers *keepers.AppKeepers, mm *module.Manager) {
// trigger SetModuleVersionMap in upgrade keeper at the VersionMapEnableHeight
if ctx.ChainID() == core.ColumbusChainID {
keppers.UpgradeKeeper.SetModuleVersionMap(ctx, mm.GetVersionMap())
}
}
4 changes: 2 additions & 2 deletions app/upgrades/v4/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func CreateV4UpgradeHandler(
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// to run staking store migration
stakingKeeper := keepers.StakingKeeper
stkingMigrator := keeper.NewMigrator(stakingKeeper)
stkingMigrator.Migrate13to14(ctx)
stakingMigrator := keeper.NewMigrator(stakingKeeper)
stakingMigrator.Migrate13to14(ctx)
// to run wasm store migration
return mm.RunMigrations(ctx, cfg, fromVM)
}
Expand Down
10 changes: 3 additions & 7 deletions custom/auth/ante/burntax.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package ante

import (
"github.com/classic-terra/core/v2/types/fork"
treasury "github.com/classic-terra/core/v2/x/treasury/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
cosmosante "github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/types"
)

// TaxPowerUpgradeHeight is when taxes are allowed to go into effect
// This will still need a parameter change proposal, but can be activated
// anytime after this height
const TaxPowerUpgradeHeight = 9346889

// BurnTaxFeeDecorator will immediately burn the collected Tax
type BurnTaxFeeDecorator struct {
accountKeeper cosmosante.AccountKeeper
Expand All @@ -34,8 +30,8 @@ func NewBurnTaxFeeDecorator(accountKeeper cosmosante.AccountKeeper, treasuryKeep
// AnteHandle handles msg tax fee checking
func (btfd BurnTaxFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
// Do not proceed if you are below this block height
currHeight := ctx.BlockHeight()
if currHeight < TaxPowerUpgradeHeight {
// ChainID check is required to test burn tax in the testnet
if fork.IsBeforeTaxPowerUpgradeHeight(ctx) {
return next(ctx, tx, simulate)
}

Expand Down
3 changes: 2 additions & 1 deletion custom/auth/ante/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
customante "github.com/classic-terra/core/v2/custom/auth/ante"
core "github.com/classic-terra/core/v2/types"
"github.com/classic-terra/core/v2/types/fork"
treasurytypes "github.com/classic-terra/core/v2/x/treasury/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
Expand Down Expand Up @@ -147,7 +148,7 @@ func (suite *AnteTestSuite) TestIntegrationTaxExemption() {
)
suite.Require().NoError(err)

suite.ctx = suite.ctx.WithBlockHeight(customante.TaxPowerUpgradeHeight)
suite.ctx = suite.ctx.WithBlockHeight(fork.TaxPowerUpgradeHeight)
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder()

tk.AddBurnTaxExemptionAddress(suite.ctx, addrs[0].String())
Expand Down
6 changes: 3 additions & 3 deletions custom/auth/ante/tax.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
authz "github.com/cosmos/cosmos-sdk/x/authz"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

core "github.com/classic-terra/core/v2/types"
"github.com/classic-terra/core/v2/types"
"github.com/classic-terra/core/v2/types/fork"
marketexported "github.com/classic-terra/core/v2/x/market/exported"
oracleexported "github.com/classic-terra/core/v2/x/oracle/exported"
)
Expand Down Expand Up @@ -166,7 +167,6 @@ func FilterMsgAndComputeTax(ctx sdk.Context, tk TreasuryKeeper, msgs ...sdk.Msg)

// computes the stability tax according to tax-rate and tax-cap
func computeTax(ctx sdk.Context, tk TreasuryKeeper, principal sdk.Coins) sdk.Coins {
currHeight := ctx.BlockHeight()
taxRate := tk.GetTaxRate(ctx)
if taxRate.Equal(sdk.ZeroDec()) {
return sdk.Coins{}
Expand All @@ -176,7 +176,7 @@ func computeTax(ctx sdk.Context, tk TreasuryKeeper, principal sdk.Coins) sdk.Coi

for _, coin := range principal {
// Originally only a stability tax on UST. Changed to tax Luna as well after TaxPowerUpgradeHeight
if (coin.Denom == core.MicroLunaDenom || coin.Denom == sdk.DefaultBondDenom) && currHeight < TaxPowerUpgradeHeight {
if (coin.Denom == types.MicroLunaDenom || coin.Denom == sdk.DefaultBondDenom) && fork.IsBeforeTaxPowerUpgradeHeight(ctx) {
continue
}
if coin.Denom == sdk.DefaultBondDenom {
Expand Down
3 changes: 2 additions & 1 deletion custom/auth/ante/tax_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/classic-terra/core/v2/custom/auth/ante"
core "github.com/classic-terra/core/v2/types"
"github.com/classic-terra/core/v2/types/fork"
markettypes "github.com/classic-terra/core/v2/x/market/types"
)

Expand Down Expand Up @@ -883,7 +884,7 @@ func (suite *AnteTestSuite) TestTaxExemption() {
tk.SetBurnSplitRate(suite.ctx, sdk.NewDecWithPrec(5, 1))

fmt.Printf("CASE = %s \n", c.name)
suite.ctx = suite.ctx.WithBlockHeight(ante.TaxPowerUpgradeHeight)
suite.ctx = suite.ctx.WithBlockHeight(fork.TaxPowerUpgradeHeight)
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder()

tk.AddBurnTaxExemptionAddress(suite.ctx, addrs[0].String())
Expand Down
Loading