Skip to content

Commit

Permalink
embed gravity bridge module
Browse files Browse the repository at this point in the history
Closes #9

- add gravity module to app
- verify address format at application level
- fix pystarport config files
- build orchestrator in nix
- add a gravity hook implementation template in cronos module
- add gravity custom gentx command

fix chain id and err handling code

add eth_keys command
  • Loading branch information
yihuang committed Aug 19, 2021
1 parent c29fee3 commit ccd039f
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ This version is a new scaffolding of cronos project where ethermint is included
- (ethermint) [tharsis#383](https://github.com/tharsis/ethermint/pull/383) `GetCommittedState` use the original context.

### Features

- [#11](https://github.com/crypto-org-chain/cronos/pull/11) embed gravity bridge module

### Improvements

- (ethermint) [tharsis#425](https://github.com/tharsis/ethermint/pull/425) Support build on linux arm64
Expand Down
58 changes: 56 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
Expand Down Expand Up @@ -101,13 +102,24 @@ import (
evmkeeper "github.com/tharsis/ethermint/x/evm/keeper"
evmtypes "github.com/tharsis/ethermint/x/evm/types"

"github.com/peggyjv/gravity-bridge/module/x/gravity"
gravitykeeper "github.com/peggyjv/gravity-bridge/module/x/gravity/keeper"
gravitytypes "github.com/peggyjv/gravity-bridge/module/x/gravity/types"

// this line is used by starport scaffolding # stargate/app/moduleImport
cronosmodule "github.com/crypto-org-chain/cronos/x/cronos"
cronosmodulekeeper "github.com/crypto-org-chain/cronos/x/cronos/keeper"
cronosmoduletypes "github.com/crypto-org-chain/cronos/x/cronos/types"
)

const Name = "cronos"
const (
Name = "cronos"

// AddrLen is the allowed length (in bytes) for an address.
//
// NOTE: In the SDK, the default value is 255.
AddrLen = 20
)

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals

Expand Down Expand Up @@ -154,6 +166,7 @@ var (
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
evm.AppModuleBasic{},
gravity.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
cronosmodule.AppModuleBasic{},
)
Expand All @@ -168,6 +181,7 @@ var (
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and subtraction of balance using module account
gravitytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
}
// Module configurator

Expand Down Expand Up @@ -229,6 +243,9 @@ type App struct {
// Ethermint keepers
EvmKeeper *evmkeeper.Keeper

// Gravity module
GravityKeeper gravitykeeper.Keeper

// this line is used by starport scaffolding # stargate/app/keeperDeclaration

CronosKeeper cronosmodulekeeper.Keeper
Expand Down Expand Up @@ -271,6 +288,7 @@ func New(
ibchost.StoreKey, ibctransfertypes.StoreKey,
// ethermint keys
evmtypes.StoreKey,
gravitytypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
cronosmoduletypes.StoreKey,
)
Expand Down Expand Up @@ -338,7 +356,11 @@ func New(
// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper = *stakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
stakingtypes.NewMultiStakingHooks(
app.DistrKeeper.Hooks(),
app.SlashingKeeper.Hooks(),
app.GravityKeeper.Hooks(),
),
)

// ... other modules keepers
Expand Down Expand Up @@ -393,6 +415,18 @@ func New(
&stakingKeeper, govRouter,
)

gravityKeeper := gravitykeeper.NewKeeper(
appCodec,
keys[gravitytypes.StoreKey],
app.GetSubspace(gravitytypes.ModuleName),
app.AccountKeeper,
app.StakingKeeper,
app.BankKeeper,
app.SlashingKeeper,
sdk.DefaultPowerReduction,
)
app.GravityKeeper = *gravityKeeper.SetHooks(app.CronosKeeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferModule)
Expand Down Expand Up @@ -432,6 +466,7 @@ func New(

transferModule,
evm.NewAppModule(app.EvmKeeper, app.AccountKeeper),
gravity.NewAppModule(app.GravityKeeper, app.BankKeeper),
// this line is used by starport scaffolding # stargate/app/appModule
cronosModule,
)
Expand All @@ -446,11 +481,13 @@ func New(
evmtypes.ModuleName,
minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName,
gravitytypes.ModuleName,
)

app.mm.SetOrderEndBlockers(
crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName,
evmtypes.ModuleName,
gravitytypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand All @@ -475,6 +512,7 @@ func New(
authz.ModuleName,
feegrant.ModuleName,
evmtypes.ModuleName,
gravitytypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
cronosmoduletypes.ModuleName,
)
Expand Down Expand Up @@ -691,8 +729,24 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(evmtypes.ModuleName)
paramsKeeper.Subspace(gravitytypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace
paramsKeeper.Subspace(cronosmoduletypes.ModuleName)

return paramsKeeper
}

// VerifyAddressFormat verifis the address is compatible with ethereum
func VerifyAddressFormat(bz []byte) error {
if len(bz) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrUnknownAddress, "invalid address; cannot be empty")
}
if len(bz) != AddrLen {
return sdkerrors.Wrapf(
sdkerrors.ErrUnknownAddress,
"invalid address length; got: %d, expect: %d", len(bz), AddrLen,
)
}

return nil
}
2 changes: 2 additions & 0 deletions app/prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ func SetConfig() {
// use the configurations from ethermint
cmdcfg.SetBech32Prefixes(config)
cmdcfg.SetBip44CoinType(config)
// Make sure address is compatible with ethereum
config.SetAddressVerifier(VerifyAddressFormat)
config.Seal()
}
4 changes: 3 additions & 1 deletion cmd/cronosd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/crisis"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"

gravitycmd "github.com/peggyjv/gravity-bridge/module/cmd/gravity/cmd"
ethermintclient "github.com/tharsis/ethermint/client"
"github.com/tharsis/ethermint/crypto/hd"
ethermintserver "github.com/tharsis/ethermint/server"
Expand Down Expand Up @@ -110,7 +111,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
genutilcli.MigrateGenesisCmd(),
genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
gravitycmd.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
genutilcli.ValidateGenesisCmd(app.ModuleBasics),
AddGenesisAccountCmd(app.DefaultNodeHome),
tmcli.NewCompletionCmd(rootCmd, true),
Expand All @@ -129,6 +130,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
queryCommand(),
txCommand(),
ethermintclient.KeyCommands(app.DefaultNodeHome),
gravitycmd.Commands(app.DefaultNodeHome),
)

// add rosetta
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ require (
github.com/google/go-cmp v0.5.6 // indirect
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/peggyjv/gravity-bridge/module v0.1.21
github.com/pkg/errors v0.9.1
github.com/spf13/cast v1.4.1
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,8 @@ github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144T
github.com/paulbellamy/ratecounter v0.2.0/go.mod h1:Hfx1hDpSGoqxkVVpBi/IlYD7kChlfo5C6hzIHwPqfFE=
github.com/pborman/uuid v0.0.0-20170112150404-1b00554d8222/go.mod h1:VyrYX9gd7irzKovcSS6BIIEwPRkP2Wm2m9ufcdFSJ34=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/peggyjv/gravity-bridge/module v0.1.21 h1:5QBK682gf67vQoCpedeJYzTPPLWvZJtmqLxj7lWEJ+o=
github.com/peggyjv/gravity-bridge/module v0.1.21/go.mod h1:Key1D2z/KaJ5A206L3EQW6RWo4q8w+Jpl+p5HMm896g=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ=
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
Expand Down
9 changes: 9 additions & 0 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2995,6 +2995,15 @@
rev = "8b1b92947f46224e3b97bb1a3a5b0382be00d31e"
sha256 = "0f146yjqwx2mr110kl8scjhqd08hys7vr5z0d0a3lskb6yy22gfg"

["github.com/peggyjv/gravity-bridge/module"]
sumVersion = "v0.1.21"
relPath = "module"
["github.com/peggyjv/gravity-bridge/module".fetch]
type = "git"
url = "https://github.com/peggyjv/gravity-bridge"
rev = "755156abff254420eec2c4e54fb6e8d189556ee2"
sha256 = "1fjkq0jv42pq7fsah4chk2d1xkrdnkb9x52lkyagzlykw08ywcvr"

["github.com/pelletier/go-toml"]
sumVersion = "v1.9.3"
["github.com/pelletier/go-toml".fetch]
Expand Down
15 changes: 15 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ import sources.nixpkgs {
};
}
)
(_: pkgs: {
orchestrator = pkgs.rustPlatform.buildRustPackage rec {
name = "orchestrator";
src = sources.gravity-bridge;
sourceRoot = "gravity-bridge-src/${name}";
cargoSha256 = sha256:1sp1f959qzigrpxi3qz33sr4cbl7s805p72nhv7gymjzjscr578z;
cargoBuildFlags = "-p ${name}";
doCheck = false;
OPENSSL_NO_VENDOR = "1";
OPENSSL_DIR = pkgs.symlinkJoin {
name = "openssl";
paths = with pkgs.openssl; [ out dev ];
};
};
})
];
config = { };
inherit system;
Expand Down
13 changes: 13 additions & 0 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
"url": "https://github.com/tweag/gomod2nix/archive/67f22dd738d092c6ba88e420350ada0ed4992ae8.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"gravity-bridge": {
"branch": "main",
"description": "A CosmosSDK application for moving assets on and off of EVM based, POW chains",
"homepage": "",
"owner": "PeggyJV",
"repo": "gravity-bridge",
"rev": "755156abff254420eec2c4e54fb6e8d189556ee2",
"sha256": "1fjkq0jv42pq7fsah4chk2d1xkrdnkb9x52lkyagzlykw08ywcvr",
"type": "tarball",
"url": "https://github.com/PeggyJV/gravity-bridge/archive/refs/tags/v0.1.21.tar.gz",
"url_template": "https://github.com/PeggyJV/gravity-bridge/archive/refs/tags/v0.1.21.tar.gz",
"version": "0.1.21"
},
"niv": {
"branch": "master",
"description": "Easy dependency management for Nix projects",
Expand Down
19 changes: 19 additions & 0 deletions x/cronos/keeper/hooks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
gravitytypes "github.com/peggyjv/gravity-bridge/module/x/gravity/types"
)

// TODO Implements GravityHooks interface
func (k Keeper) AfterContractCallExecutedEvent(ctx sdk.Context, event gravitytypes.ContractCallExecutedEvent) {
}

func (k Keeper) AfterERC20DeployedEvent(ctx sdk.Context, event gravitytypes.ERC20DeployedEvent) {}

func (k Keeper) AfterSignerSetExecutedEvent(ctx sdk.Context, event gravitytypes.SignerSetTxExecutedEvent) {
}

func (k Keeper) AfterBatchExecutedEvent(ctx sdk.Context, event gravitytypes.BatchExecutedEvent) {}

func (k Keeper) AfterSendToCosmosEvent(ctx sdk.Context, event gravitytypes.SendToCosmosEvent) {}

0 comments on commit ccd039f

Please sign in to comment.