Skip to content

Commit

Permalink
Revert gravity delete (#140)
Browse files Browse the repository at this point in the history
* fix: revert gravity deletion

* bump gravity bridge to use v0.47.3compatible
  • Loading branch information
tuantran1702 authored Feb 16, 2024
1 parent d0b3fcb commit 432141e
Show file tree
Hide file tree
Showing 12 changed files with 2,177 additions and 42 deletions.
14 changes: 10 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import (

"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/althea-net/cosmos-gravity-bridge/module/x/gravity"
gravitytypes "github.com/althea-net/cosmos-gravity-bridge/module/x/gravity/types"
dbm "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
tmos "github.com/cometbft/cometbft/libs/os"
"github.com/cosmos/cosmos-sdk/x/consensus"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
"github.com/spf13/cast"

dbm "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
tmos "github.com/cometbft/cometbft/libs/os"

"github.com/CudoVentures/cudos-node/x/admin"
admintypes "github.com/CudoVentures/cudos-node/x/admin/types"
"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -133,6 +134,7 @@ func New(
// this line is used by starport scaffolding # stargate/app/storeKey
cudominttypes.StoreKey,
wasm.StoreKey,
gravitytypes.StoreKey,
feegrant.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -189,6 +191,7 @@ func New(
wasm.NewAppModule(appCodec, &app.wasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
admin.NewAppModule(appCodec, app.adminKeeper),
cudoMint.NewAppModule(appCodec, app.cudoMintKeeper),
gravity.NewAppModule(app.GravityKeeper, app.BankKeeper),
feegrantmod.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.feegrantKeeper, app.interfaceRegistry),
// this line is used by starport scaffolding # stargate/app/appModule
)
Expand All @@ -213,6 +216,7 @@ func New(
genutiltypes.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
gravitytypes.ModuleName,
consensusparamtypes.ModuleName,
admintypes.ModuleName,
ibcexported.ModuleName,
Expand All @@ -237,6 +241,7 @@ func New(
paramstypes.ModuleName,
consensusparamtypes.ModuleName,
upgradetypes.ModuleName,
gravitytypes.ModuleName,
admintypes.ModuleName,
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
Expand All @@ -258,6 +263,7 @@ func New(
govtypes.ModuleName,
cudominttypes.ModuleName,
crisistypes.ModuleName,
gravitytypes.ModuleName, // MUST BE BEFORE GENUTIL!!!!
genutiltypes.ModuleName,
evidencetypes.ModuleName,
feegrant.ModuleName,
Expand Down
10 changes: 9 additions & 1 deletion app/app_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (

custombankkeeper "github.com/CudoVentures/cudos-node/x/bank/keeper"
// vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
tmjson "github.com/cometbft/cometbft/libs/json"
"github.com/cosmos/cosmos-sdk/x/bank"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/capability"
Expand Down Expand Up @@ -79,12 +80,15 @@ import (
ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
tmjson "github.com/tendermint/tendermint/libs/json"

// this line is used by starport scaffolding # stargate/app/moduleImport
"github.com/CudoVentures/cudos-node/x/cudoMint"
cudoMintkeeper "github.com/CudoVentures/cudos-node/x/cudoMint/keeper"
cudoMinttypes "github.com/CudoVentures/cudos-node/x/cudoMint/types"

"github.com/althea-net/cosmos-gravity-bridge/module/x/gravity"
gravitykeeper "github.com/althea-net/cosmos-gravity-bridge/module/x/gravity/keeper"
gravitytypes "github.com/althea-net/cosmos-gravity-bridge/module/x/gravity/types"
)

// We pull these out so we can set them with LDFLAGS in the Makefile
Expand Down Expand Up @@ -145,6 +149,7 @@ var (
wasm.AppModuleBasic{},
admin.AppModuleBasic{},
cudoMint.AppModuleBasic{},
gravity.AppModuleBasic{},
feegrantmod.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)
Expand All @@ -158,6 +163,7 @@ var (
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
cudoMinttypes.ModuleName: {authtypes.Minter},
wasmtypes.ModuleName: {authtypes.Burner},
gravitytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
}

allowedReceivingModAcc = map[string]bool{
Expand Down Expand Up @@ -206,6 +212,7 @@ type App struct {
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper

GravityKeeper gravitykeeper.Keeper
wasmKeeper wasm.Keeper
adminKeeper adminkeeper.Keeper
cudoMintKeeper cudoMintkeeper.Keeper
Expand Down Expand Up @@ -373,6 +380,7 @@ func InitParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(wasm.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace
paramsKeeper.Subspace(cudoMinttypes.ModuleName)
paramsKeeper.Subspace(gravitytypes.ModuleName)
paramsKeeper.Subspace(authz.ModuleName)
paramsKeeper.Subspace(feegrant.ModuleName)

Expand Down
6 changes: 6 additions & 0 deletions app/app_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ import (
// this line is used by starport scaffolding # stargate/app/moduleImport
cudoMintkeeper "github.com/CudoVentures/cudos-node/x/cudoMint/keeper"
cudoMinttypes "github.com/CudoVentures/cudos-node/x/cudoMint/types"

gravitykeeper "github.com/althea-net/cosmos-gravity-bridge/module/x/gravity/keeper"
gravitytypes "github.com/althea-net/cosmos-gravity-bridge/module/x/gravity/types"
)

func (app *App) AddKeepers(skipUpgradeHeights map[int64]bool, homePath string, appOpts servertypes.AppOptions, enabledProposals []wasm.ProposalType,
Expand Down Expand Up @@ -213,5 +216,8 @@ func (app *App) AddKeepers(skipUpgradeHeights map[int64]bool, homePath string, a
app.GetSubspace(cudoMinttypes.ModuleName),
authtypes.FeeCollectorName,
)
app.GravityKeeper = gravitykeeper.NewKeeper(
app.appCodec, app.keys[gravitytypes.StoreKey], app.GetSubspace(gravitytypes.ModuleName), stakingKeeper, app.BankKeeper, app.SlashingKeeper, app.AccountKeeper,
)

}
29 changes: 29 additions & 0 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
appparams "github.com/CudoVentures/cudos-node/app/params"
cudoMintKeeper "github.com/CudoVentures/cudos-node/x/cudoMint/keeper"
cudoMinttypes "github.com/CudoVentures/cudos-node/x/cudoMint/types"
gravitytypes "github.com/althea-net/cosmos-gravity-bridge/module/x/gravity/types"
"github.com/cosmos/cosmos-sdk/baseapp"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
Expand Down Expand Up @@ -253,6 +254,34 @@ func genesisStateWithValSet(t *testing.T,

genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis)

pk, _ := cryptocodec.FromTmPubKeyInterface(valSet.Validators[0].PubKey)

accAddr := sdk.AccAddress(pk.Address())
// Custom Cudos logic for gravity module
// TODO: verify if true, maybe get the current snapshot of the gravity module genesis state

gravityGenesis := &gravitytypes.GenesisState{
Params: gravitytypes.DefaultParams(),
StaticValCosmosAddrs: []string{
accAddr.String(),
},
Erc20ToDenoms: []*gravitytypes.ERC20ToDenom{
{
Erc20: CudosMainnetEthAddr, // just for testing
Denom: "acudos",
},
},
DelegateKeys: []*gravitytypes.MsgSetOrchestratorAddress{
{
Validator: sdk.ValAddress(valSet.Validators[0].Address).String(),
EthAddress: DefaultEthAddress,
Orchestrator: genAccs[0].GetAddress().String(),
},
},
}
genesisState[gravitytypes.ModuleName] = app.AppCodec().MustMarshalJSON(gravityGenesis)

// Add gentxs, MsgCreateValidator and MsgSetOrchestratorAddress
return genesisState
}

Expand Down
4 changes: 3 additions & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.DistrKeeper.SetFeePool(ctx, feePool)

app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()); err != nil {
panic(err)
}
return false
})

Expand Down
5 changes: 5 additions & 0 deletions cmd/cudos-noded/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import (
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
"github.com/cosmos/cosmos-sdk/snapshots"

gravitycmd "github.com/althea-net/cosmos-gravity-bridge/module/cmd/gravity/cmd"
dbm "github.com/cometbft/cometbft-db"
tmcli "github.com/cometbft/cometbft/libs/cli"
"github.com/cometbft/cometbft/libs/log"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/spf13/cast"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -94,6 +96,8 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {

rootCmd.AddCommand(
genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome),
gravitycmd.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
gravitycmd.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
tmcli.NewCompletionCmd(rootCmd, true),
debug.Cmd(),
config.Cmd(),
Expand All @@ -108,6 +112,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
queryCommand(),
txCommand(),
keys.Commands(app.DefaultNodeHome),
gravitycmd.Commands(app.DefaultNodeHome),
)

rootCmd.AddCommand(rosettaCmd.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Codec))
Expand Down
7 changes: 5 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
version: 1
accounts:
- name: user1
coins: [ "1000token", "1000000000stake" ]
coins: ["1000token", "1000000000stake"]
- name: user2
coins: [ "500token" ]
coins: ["500token"]
validator:
name: user1
staked: "100000000stake"
Expand All @@ -13,6 +13,9 @@ genesis:
params:
inflation_max: "0.000000000000000000"
inflation_min: "0.000000000000000000"
gravity:
params:
gravity_id: "cudos-gravity-test"
cudoMint:
params:
blocks_per_day: "14400"
Expand Down
23 changes: 12 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.19
require (
cosmossdk.io/tools/rosetta v0.2.1
github.com/CosmWasm/wasmd v0.40.2
github.com/althea-net/cosmos-gravity-bridge/module v0.0.0-00010101000000-000000000000
github.com/cometbft/cometbft v0.37.1
github.com/cometbft/cometbft-db v0.7.0
github.com/cosmos/cosmos-sdk v0.47.3
Expand All @@ -17,7 +18,6 @@ require (
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.3
github.com/tendermint/tendermint v0.34.20
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4
google.golang.org/grpc v1.55.0
)
Expand All @@ -44,7 +44,6 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/btcsuite/btcd v0.22.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
Expand All @@ -64,6 +63,7 @@ require (
github.com/creachadair/taskgroup v0.4.2 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
Expand All @@ -72,19 +72,20 @@ require (
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
github.com/ethereum/go-ethereum v1.11.6 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
Expand All @@ -106,13 +107,13 @@ require (
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.16.3 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
Expand Down Expand Up @@ -148,7 +149,6 @@ require (
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tidwall/btree v1.6.0 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/zondax/hid v0.9.1 // indirect
github.com/zondax/ledger-go v0.14.1 // indirect
Expand All @@ -173,10 +173,11 @@ require (
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4

replace github.com/CosmWasm/wasmvm v1.2.4 => github.com/CosmWasm/wasmvm v1.2.6

// replace github.com/cosmos/cosmos-sdk v0.47.3 => ../old/cosmos-sdk
// Downgraded to avoid bugs in following commits which caused simulations to fail.
replace github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
replace (
github.com/CosmWasm/wasmvm v1.2.4 => github.com/CosmWasm/wasmvm v1.2.6 // Patched wasmvm
github.com/althea-net/cosmos-gravity-bridge/module => github.com/CudoVentures/cosmos-gravity-bridge/module v0.0.0-20231116111023-21e433157105
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
Loading

0 comments on commit 432141e

Please sign in to comment.