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
  • Loading branch information
yihuang committed Aug 17, 2021
1 parent 2e087b9 commit 263e287
Show file tree
Hide file tree
Showing 14 changed files with 659 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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 @@ -23,6 +23,7 @@ import (
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
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 @@ -98,13 +99,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 @@ -151,6 +163,7 @@ var (
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
evm.AppModuleBasic{},
gravity.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
cronosmodule.AppModuleBasic{},
)
Expand All @@ -165,6 +178,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 @@ -226,6 +240,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 @@ -265,6 +282,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 @@ -332,7 +350,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 @@ -386,6 +408,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 @@ -425,6 +459,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 @@ -438,11 +473,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 @@ -467,6 +504,7 @@ func New(
evidencetypes.ModuleName,
ibctransfertypes.ModuleName,
evmtypes.ModuleName,
gravitytypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
cronosmoduletypes.ModuleName,
)
Expand Down Expand Up @@ -652,8 +690,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()
}
Loading

0 comments on commit 263e287

Please sign in to comment.