Skip to content

Commit

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

- add module to app
- verify address format
- fix pystarport config files
- replace keyring with patched version
  • Loading branch information
yihuang committed Aug 16, 2021
1 parent 587f710 commit 27d8cb6
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 8 deletions.
57 changes: 55 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 @@ -372,6 +394,17 @@ func New(
bApp.Trace(), // debug EVM based on Baseapp options
)

app.GravityKeeper = gravitykeeper.NewKeeper(
appCodec,
keys[gravitytypes.StoreKey],
app.GetSubspace(gravitytypes.ModuleName),
app.AccountKeeper,
stakingKeeper,
app.BankKeeper,
app.SlashingKeeper,
sdk.DefaultPowerReduction,
)

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

app.CronosKeeper = *cronosmodulekeeper.NewKeeper(
Expand Down Expand Up @@ -425,6 +458,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 +472,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 +503,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 +689,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()
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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/spf13/cast v1.4.0
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
Expand All @@ -24,3 +25,5 @@ require (
replace google.golang.org/grpc => google.golang.org/grpc v1.33.2

replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1

replace github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ collectd.org v0.3.0/go.mod h1:A/8DzQBkF6abtvrT2j/AU/4tiBgJWYyh0y/oB/4MlWE=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.0.0-beta.2 h1:/BZRNzm8N4K4eWfK28dL4yescorxtO7YG1yun8fy+pI=
filippo.io/edwards25519 v1.0.0-beta.2/go.mod h1:X+pm78QAUPtFLi1z9PYIlS/bdDnvbCOGKtZ+ACWEf7o=
github.com/99designs/keyring v1.1.6 h1:kVDC2uCgVwecxCk+9zoCt2uEL6dt+dfVzMvGgnVcIuM=
github.com/99designs/keyring v1.1.6/go.mod h1:16e0ds7LGQQcT59QqkTg72Hh5ShM51Byv5PEmW6uoRU=
github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4=
github.com/Azure/azure-pipeline-go v0.2.2/go.mod h1:4rQ/NZncSvGqNkkOsNpOU1tgoNuIlp9AfUH5G1tvCHc=
github.com/Azure/azure-storage-blob-go v0.7.0/go.mod h1:f9YQKtsG1nMisotuTPpO0tjNuEjKRYAcJU8/ydDI++4=
Expand Down Expand Up @@ -223,6 +221,8 @@ github.com/cosmos/iavl v0.16.0 h1:ICIOB8xysirTX27GmVAaoeSpeozzgSu9d49w36xkVJA=
github.com/cosmos/iavl v0.16.0/go.mod h1:2A8O/Jz9YwtjqXMO0CjnnbTYEEaovE8jWcwrakH3PoE=
github.com/cosmos/ibc-go v1.0.0 h1:RtIRERSENyApp6WK7Germ3/wq8xvHxfsqfW/Xh+CJ2o=
github.com/cosmos/ibc-go v1.0.0/go.mod h1:2wHKQUa+BLJMEyN635KrHfmTTwSNHBtXcqdY8JWGuXA=
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 h1:DdzS1m6o/pCqeZ8VOAit/gyATedRgjvkVI+UCrLpyuU=
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76/go.mod h1:0mkLWIoZuQ7uBoospo5Q9zIpqq6rYCPJDSUdeCJvPM8=
github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4=
github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY=
github.com/cosmos/ledger-go v0.9.2 h1:Nnao/dLwaVTk1Q5U9THldpUMMXU94BOTWPddSmVB6pI=
Expand Down Expand Up @@ -679,7 +679,6 @@ github.com/minio/highwayhash v1.0.1 h1:dZ6IIu8Z14VlC0VpfKofAhCy74wu/Qb5gcn52yWoz
github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
Expand Down Expand Up @@ -765,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
2 changes: 1 addition & 1 deletion integration_tests/configs/default.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cronosd-777:
cmd: ethermintd
cmd: cronosd
start-flags: "--trace"
validators:
- coins: 1000000000000000000stake,1000000000000000000basetcro
Expand Down
2 changes: 1 addition & 1 deletion scripts/cronos-devnet.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cronosd-777:
cmd: ethermintd
cmd: cronosd
start-flags: "--trace"
validators:
- coins: 1000000000000000000stake,1000000000000000000basetcro
Expand Down
2 changes: 1 addition & 1 deletion scripts/devnet.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
chainmaind-777:
cmd: ./build/ethermintd
cmd: ./build/cronosd
start-flags: "--trace --evm-rpc.enable-unsafe-cors"
validators:
- coins: 1000000000000000000stake,1000000000000000000basetcro
Expand Down

0 comments on commit 27d8cb6

Please sign in to comment.