Skip to content

Commit

Permalink
feat(app): Import Fork of Osmosis (#252)
Browse files Browse the repository at this point in the history
Co-authored-by: Inon Man <121477599+inon-man@users.noreply.github.com>
  • Loading branch information
alchemist-ti and inon-man committed Jun 27, 2023
1 parent 4838a2c commit 9d73c0d
Show file tree
Hide file tree
Showing 24 changed files with 322 additions and 147 deletions.
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ Ref: https://keepachangelog.com/en/1.0.0/
# Changelog
## [v2.1.2](https://github.com/classic-terra/core/releases/tag/v2.1.2)

### Features
* (app/upgrades) [#252](https://github.com/classic-terra/core/pull/252) Import Fork of Osmosis

### Bug fixes
* (wasm) [#259](https://github.com/classic-terra/core/pull/259) add legacy wasm types
* [#268](https://github.com/classic-terra/core/pull/268) revert "feat(feeshare): Developer Incentives (#144)"
* (wasm) [#259](https://github.com/classic-terra/core/pull/259) Add legacy wasm types
* [#268](https://github.com/classic-terra/core/pull/268) Revert "feat(feeshare): Developer Incentives (#144)"

## [v2.1.1](https://github.com/classic-terra/core/releases/tag/v2.1.1) - Jun 10, 2023

### State Machine Breaking
* Wasmvm v1.1.2 (Cherry patch included)
* Wasmd [v0.30.0-terra.2](https://github.com/classic-terra/wasmd/releases/tag/v0.30.0-terra.2)
Expand Down Expand Up @@ -69,7 +73,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (build) [#101](https://github.com/classic-terra/core/pull/101) Upgrade test
* (ante) [#103 #113 #134](https://github.com/classic-terra/core/pull/103) Add burn tax split logic
* (ante) [#107 #137 #149](https://github.com/classic-terra/core/pull/107) Burn Tax Whitelist
* (ante) [#107 #137 #149](https://github.com/classic-terra/core/pull/107) Burn Tax Exemption list
* (app) [#128](https://github.com/classic-terra/core/pull/128) Panic at InitChainer for the Columbus mainnet

### Improvements
Expand Down Expand Up @@ -97,7 +101,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/auth) [ebba05](https://github.com/classic-terra/core/commit/ebba0521fec4fc5655d90c0b3fdb2dbb2ec8d11f) Added Z's fix for the feeutils.go
* (x/auth) [7fe446](https://github.com/classic-terra/core/commit/7fe4468fab7a767b8779e093d671a69f26b19781) allow uluna to be taxed

## [v1.0.4](https://github.com/terra-money/classic-core/releases/tag/v0.5.23) - 2022-12-07
## [v0.5.23](https://github.com/terra-money/classic-core/releases/tag/v0.5.23) - 2022-12-07

### State Machine Breaking
* [#800](https://github.com/terra-money/classic-core/pull/800) Tax and Burn
Expand Down
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
### v1 (core v1.0.x)
__NOTE__: initial version without upgrade handler
* (soft-fork) v0.5.20 - Disable swap and IBC [#760](https://github.com/terra-money/classic-core/pull/760)
* (soft-fork) v0.5.21 - Burn Tax and allow Luna to be taxed
* (soft-fork) v0.5.22 - Limit validator power to 20% [cosmos-sdk/pull/104](https://github.com/terra-money/cosmos-sdk/pull/104)
* (soft-fork) v0.5.23 - Enable IBC
* (soft-fork) v1.0.5 - Set module version map for enabling software upgrades
### v2 (core v1.1.x)
* (treasury) Tax exemption list, burn tax split
### v3 (core v2.0.x)
* (treasury) Minimum initial deposit for governance proposals
### v4 (core v2.1.x)
* (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 func(ctx sdk.Context, keppers *keepers.AppKeepers, mm *module.Manager)
}
```
15 changes: 15 additions & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,18 @@ 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 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: "v0.5.23",
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
11 changes: 3 additions & 8 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 @@ -33,9 +29,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 {
// Do not proceed if you are below BurnTaxUpgradeHeight block height
if fork.IsBeforeBurnTaxUpgradeHeight(ctx) {
return next(ctx, tx, simulate)
}

Expand Down
5 changes: 3 additions & 2 deletions custom/auth/ante/burntax_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"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"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/x/auth/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
Expand All @@ -35,8 +36,8 @@ func (suite *AnteTestSuite) runSplitTaxTest(burnSplitRate sdk.Dec) {
mfd := ante.NewBurnTaxFeeDecorator(suite.app.AccountKeeper, tk, bk, dk)
antehandler := sdk.ChainAnteDecorators(mfd)

// Set the blockheight past the tax height block
suite.ctx = suite.ctx.WithBlockHeight(10000000)
// Set the blockheight past the burn tax height block
suite.ctx = suite.ctx.WithBlockHeight(fork.BurnTaxUpgradeHeight)

// Set burn split tax
tk.SetBurnSplitRate(suite.ctx, burnSplitRate)
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.BurnTaxUpgradeHeight)
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder()

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

0 comments on commit 9d73c0d

Please sign in to comment.