Skip to content

Commit

Permalink
feat: integrate greenfield with cosmos sdk v0.47 (#188)
Browse files Browse the repository at this point in the history
* feat: integrate cosmos sdk v0.47

* fix proto files

* remove dependency of evmos

* update go version to 1.20

* fix the test cases of bridge module

* update cosmos sdk
  • Loading branch information
yutianwu authored Apr 20, 2023
1 parent 8e048f7 commit 02f2921
Show file tree
Hide file tree
Showing 193 changed files with 4,705 additions and 4,976 deletions.
473 changes: 237 additions & 236 deletions app/ante/ante_test.go

Large diffs are not rendered by default.

761 changes: 382 additions & 379 deletions app/ante/utils_test.go

Large diffs are not rendered by default.

241 changes: 113 additions & 128 deletions app/app.go

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import (
"encoding/json"
"log"

storetypes "cosmossdk.io/store/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

// ExportAppStateAndValidators exports the state of the application for a genesis
// file.
func (app *App) ExportAppStateAndValidators(
forZeroHeight bool, jailAllowedAddrs []string,
forZeroHeight bool, jailAllowedAddrs, modulesToExport []string,
) (servertypes.ExportedApp, error) {
// as if they could withdraw from the start of the next block
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
Expand All @@ -28,7 +29,11 @@ func (app *App) ExportAppStateAndValidators(
app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs)
}

genState := app.mm.ExportGenesis(ctx, app.appCodec)
genState, err := app.mm.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
if err != nil {
return servertypes.ExportedApp{}, err
}

appState, err := json.MarshalIndent(genState, "", " ")
if err != nil {
return servertypes.ExportedApp{}, err
Expand Down Expand Up @@ -150,7 +155,7 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
// Iterate through validators by power descending, reset bond heights, and
// update bond intra-tx counters.
store := ctx.KVStore(app.keys[stakingtypes.StoreKey])
iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
iter := storetypes.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
counter := int16(0)

for ; iter.Valid(); iter.Next() {
Expand Down
186 changes: 94 additions & 92 deletions app/simulation_test.go
Original file line number Diff line number Diff line change
@@ -1,94 +1,96 @@
package app_test

import (
"os"
"testing"
"time"

"github.com/cosmos/cosmos-sdk/simapp"
simulationtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/bnb-chain/greenfield/app"
)

func init() {
simapp.GetSimulatorFlags()
}

// nolint
var defaultConsensusParams = &abci.ConsensusParams{
Block: &abci.BlockParams{
MaxBytes: 200000,
MaxGas: 2000000,
},
Evidence: &tmproto.EvidenceParams{
MaxAgeNumBlocks: 302400,
MaxAgeDuration: 504 * time.Hour, // 3 weeks is the max duration
MaxBytes: 10000,
},
Validator: &tmproto.ValidatorParams{
PubKeyTypes: []string{
tmtypes.ABCIPubKeyTypeEd25519,
},
},
}

// BenchmarkSimulation run the chain simulation
// Running using starport command:
// `starport chain simulate -v --numBlocks 200 --blockSize 50`
// Running as go benchmark test:
// `go test -benchmem -run=^$ -bench ^BenchmarkSimulation ./app -NumBlocks=200 -BlockSize 50 -Commit=true -Verbose=true -Enabled=true`
func BenchmarkSimulation(b *testing.B) {
simapp.FlagEnabledValue = true
simapp.FlagCommitValue = true

config, db, dir, logger, _, err := simapp.SetupSimulation("goleveldb-app-sim", "Simulation")
require.NoError(b, err, "simulation setup failed")

b.Cleanup(func() {
db.Close()
err = os.RemoveAll(dir)
require.NoError(b, err)
})

encoding := app.MakeEncodingConfig()

app := app.New(
logger,
db,
nil,
true,
app.DefaultNodeHome,
0,
encoding,
app.NewDefaultAppConfig(),
simapp.EmptyAppOptions{},
)

// Run randomized simulations
_, simParams, simErr := simulation.SimulateFromSeed(
b,
os.Stdout,
app.BaseApp,
simapp.AppStateFn(app.AppCodec(), app.SimulationManager()),
simulationtypes.RandomAccounts,
simapp.SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
app.AppCodec(),
)

// export state and simParams before the simulation error is checked
err = simapp.CheckExportSimulation(app, config, simParams)
require.NoError(b, err)
require.NoError(b, simErr)

if config.Commit {
simapp.PrintStats(db)
}
}
// todo: fix this
//
//import (
// "os"
// "testing"
// "time"
//
// abci "github.com/cometbft/cometbft/abci/types"
// tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
// tmtypes "github.com/cometbft/cometbft/types"
// "github.com/cosmos/cosmos-sdk/simapp"
// simulationtypes "github.com/cosmos/cosmos-sdk/types/simulation"
// "github.com/cosmos/cosmos-sdk/x/simulation"
// "github.com/stretchr/testify/require"
//
// "github.com/bnb-chain/greenfield/app"
//)
//
//func init() {
// simapp.GetSimulatorFlags()
//}
//
//// nolint
//var defaultConsensusParams = &abci.ConsensusParams{
// Block: &abci.BlockParams{
// MaxBytes: 200000,
// MaxGas: 2000000,
// },
// Evidence: &tmproto.EvidenceParams{
// MaxAgeNumBlocks: 302400,
// MaxAgeDuration: 504 * time.Hour, // 3 weeks is the max duration
// MaxBytes: 10000,
// },
// Validator: &tmproto.ValidatorParams{
// PubKeyTypes: []string{
// tmtypes.ABCIPubKeyTypeEd25519,
// },
// },
//}
//
//// BenchmarkSimulation run the chain simulation
//// Running using starport command:
//// `starport chain simulate -v --numBlocks 200 --blockSize 50`
//// Running as go benchmark test:
//// `go test -benchmem -run=^$ -bench ^BenchmarkSimulation ./app -NumBlocks=200 -BlockSize 50 -Commit=true -Verbose=true -Enabled=true`
//func BenchmarkSimulation(b *testing.B) {
// simapp.FlagEnabledValue = true
// simapp.FlagCommitValue = true
//
// config, db, dir, logger, _, err := simapp.SetupSimulation("goleveldb-app-sim", "Simulation")
// require.NoError(b, err, "simulation setup failed")
//
// b.Cleanup(func() {
// db.Close()
// err = os.RemoveAll(dir)
// require.NoError(b, err)
// })
//
// encoding := app.MakeEncodingConfig()
//
// app := app.New(
// logger,
// db,
// nil,
// true,
// app.DefaultNodeHome,
// 0,
// encoding,
// app.NewDefaultAppConfig(),
// simapp.EmptyAppOptions{},
// )
//
// // Run randomized simulations
// _, simParams, simErr := simulation.SimulateFromSeed(
// b,
// os.Stdout,
// app.BaseApp,
// simapp.AppStateFn(app.AppCodec(), app.SimulationManager()),
// simulationtypes.RandomAccounts,
// simapp.SimulationOperations(app, app.AppCodec(), config),
// app.ModuleAccountAddrs(),
// config,
// app.AppCodec(),
// )
//
// // export state and simParams before the simulation error is checked
// err = simapp.CheckExportSimulation(app, config, simParams)
// require.NoError(b, err)
// require.NoError(b, simErr)
//
// if config.Commit {
// simapp.PrintStats(db)
// }
//}
2 changes: 1 addition & 1 deletion app/upgrade.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package app

import (
upgradetypes "cosmossdk.io/x/upgrade/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

func UpgradeInitializerAndHandler(
Expand Down
Loading

0 comments on commit 02f2921

Please sign in to comment.