Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/bridge -> release/v0.4.2 #687

Open
wants to merge 21 commits into
base: release/v0.4.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
bridgetypes "github.com/KiraCore/sekai/x/bridge/types"
"time"

errorsmod "cosmossdk.io/errors"
kiratypes "github.com/KiraCore/sekai/types"
bridgekeeper "github.com/KiraCore/sekai/x/bridge/keeper"
custodykeeper "github.com/KiraCore/sekai/x/custody/keeper"
custodytypes "github.com/KiraCore/sekai/x/custody/types"
feeprocessingkeeper "github.com/KiraCore/sekai/x/feeprocessing/keeper"
Expand Down Expand Up @@ -36,6 +38,7 @@ func NewAnteHandler(
ak keeper.AccountKeeper,
bk types.BankKeeper,
ck custodykeeper.Keeper,
brk bridgekeeper.Keeper,
feegrantKeeper ante.FeegrantKeeper,
extensionOptionChecker ante.ExtensionOptionChecker,
sigGasConsumer ante.SignatureVerificationGasConsumer,
Expand All @@ -45,6 +48,7 @@ func NewAnteHandler(
) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
NewBridgeDecorator(brk, cgk),
NewCustodyDecorator(ck, cgk),
NewZeroGasMeterDecorator(),
ante.NewExtensionOptionsDecorator(extensionOptionChecker),
Expand All @@ -68,6 +72,43 @@ func NewAnteHandler(
)
}

type BridgeDecorator struct {
brk bridgekeeper.Keeper
gk customgovkeeper.Keeper
}

func NewBridgeDecorator(brk bridgekeeper.Keeper, gk customgovkeeper.Keeper) BridgeDecorator {
return BridgeDecorator{
brk: brk,
gk: gk,
}
}

func (bd BridgeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type")
}

properties := bd.gk.GetNetworkProperties(ctx)

for _, msg := range feeTx.GetMsgs() {
switch kiratypes.MsgType(msg) {
case kiratypes.MsgTypeChangeEthereumCosmos:
msg, ok := msg.(*bridgetypes.MsgChangeEthereumCosmos)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "Not a MsgChangeEthereumCosmos")
}

if msg.Addr.String() != properties.BridgeAddress {
return ctx, sdkerrors.Wrap(bridgetypes.ErrWrongBridgeAddr, "Not valid bridge sender")
}
}
}

return next(ctx, tx, simulate)
}

type CustodyDecorator struct {
ck custodykeeper.Keeper
gk customgovkeeper.Keeper
Expand Down
1 change: 1 addition & 0 deletions app/ante/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (suite *AnteTestSuite) SetupTest(isCheckTx bool) {
suite.app.AccountKeeper,
suite.app.BankKeeper,
suite.app.CustodyKeeper,
suite.app.BridgeKeeper,
nil,
nil,
ante.DefaultSigVerificationGasConsumer,
Expand Down
19 changes: 16 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
"github.com/KiraCore/sekai/x/basket"
basketkeeper "github.com/KiraCore/sekai/x/basket/keeper"
baskettypes "github.com/KiraCore/sekai/x/basket/types"
"github.com/KiraCore/sekai/x/bridge"
bridgekeeper "github.com/KiraCore/sekai/x/bridge/keeper"
bridgetypes "github.com/KiraCore/sekai/x/bridge/types"
"github.com/KiraCore/sekai/x/collectives"
collectiveskeeper "github.com/KiraCore/sekai/x/collectives/keeper"
collectivestypes "github.com/KiraCore/sekai/x/collectives/types"
Expand Down Expand Up @@ -124,6 +127,7 @@ var (
tokens.AppModuleBasic{},
feeprocessing.AppModuleBasic{},
custody.AppModuleBasic{},
bridge.AppModuleBasic{},
multistaking.AppModuleBasic{},
collectives.AppModuleBasic{},
layer2.AppModuleBasic{},
Expand All @@ -142,6 +146,7 @@ var (
collectivestypes.ModuleName: nil,
layer2types.ModuleName: {authtypes.Minter, authtypes.Burner},
recoverytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
bridgetypes.ModuleName: nil,
}

// module accounts that are allowed to receive tokens
Expand Down Expand Up @@ -169,6 +174,7 @@ type SekaiApp struct {
ParamsKeeper paramskeeper.Keeper

CustodyKeeper custodykeeper.Keeper
BridgeKeeper bridgekeeper.Keeper
CustomGovKeeper customgovkeeper.Keeper
CustomStakingKeeper customstakingkeeper.Keeper
CustomSlashingKeeper customslashingkeeper.Keeper
Expand Down Expand Up @@ -234,6 +240,7 @@ func NewInitApp(
feeprocessingtypes.ModuleName,
evidencetypes.StoreKey,
custodytypes.StoreKey,
bridgetypes.StoreKey,
collectivestypes.ModuleName,
layer2types.StoreKey,
consensusparamtypes.StoreKey,
Expand Down Expand Up @@ -335,6 +342,7 @@ func NewInitApp(
app.EvidenceKeeper = *evidenceKeeper

app.CustodyKeeper = custodykeeper.NewKeeper(keys[custodytypes.StoreKey], appCodec, app.CustomGovKeeper, app.BankKeeper)
app.BridgeKeeper = bridgekeeper.NewKeeper(keys[bridgetypes.StoreKey], appCodec, app.BankKeeper)

app.RecoveryKeeper = recoverykeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -436,6 +444,7 @@ func NewInitApp(
feeprocessing.NewAppModule(app.FeeProcessingKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
custody.NewAppModule(app.CustodyKeeper, app.CustomGovKeeper, app.BankKeeper),
bridge.NewAppModule(app.BridgeKeeper, app.BankKeeper),
collectives.NewAppModule(app.CollectivesKeeper),
layer2.NewAppModule(app.Layer2Keeper),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
Expand All @@ -450,9 +459,10 @@ func NewInitApp(
upgradetypes.ModuleName, slashingtypes.ModuleName, recoverytypes.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName,
spendingtypes.ModuleName, ubitypes.ModuleName,
distributortypes.ModuleName, multistakingtypes.ModuleName, custodytypes.ModuleName,
baskettypes.ModuleName,
distributortypes.ModuleName, multistakingtypes.ModuleName, custodytypes.ModuleName,
distributortypes.ModuleName,
multistakingtypes.ModuleName,
custodytypes.ModuleName,
bridgetypes.ModuleName,
baskettypes.ModuleName,
collectivestypes.ModuleName,
layer2types.ModuleName,
Expand All @@ -467,6 +477,7 @@ func NewInitApp(
feeprocessingtypes.ModuleName,
spendingtypes.ModuleName, ubitypes.ModuleName,
distributortypes.ModuleName, multistakingtypes.ModuleName, custodytypes.ModuleName,
bridgetypes.ModuleName,
baskettypes.ModuleName,
collectivestypes.ModuleName,
layer2types.ModuleName,
Expand Down Expand Up @@ -495,6 +506,7 @@ func NewInitApp(
paramstypes.ModuleName,
distributortypes.ModuleName,
custodytypes.ModuleName,
bridgetypes.ModuleName,
multistakingtypes.ModuleName,
baskettypes.ModuleName,
collectivestypes.ModuleName,
Expand Down Expand Up @@ -534,6 +546,7 @@ func NewInitApp(
app.AccountKeeper,
app.BankKeeper,
app.CustodyKeeper,
app.BridgeKeeper,
nil,
nil,
ante.DefaultSigVerificationGasConsumer,
Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.19

require (
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/errors v1.0.0
cosmossdk.io/math v1.2.0
cosmossdk.io/tools/rosetta v0.2.1
github.com/armon/go-metrics v0.4.1
Expand All @@ -13,7 +14,9 @@ require (
github.com/cosmos/cosmos-sdk v0.47.6
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/gogoproto v1.4.10
github.com/ethereum/go-ethereum v1.10.21
github.com/gogo/protobuf v1.3.2
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
Expand All @@ -25,6 +28,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
github.com/tendermint/go-amino v0.16.0
github.com/tendermint/tendermint v0.35.9
golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb
google.golang.org/genproto/googleapis/api v0.0.0-20231002182017-d307bd883b97
google.golang.org/grpc v1.58.3
Expand All @@ -34,15 +38,14 @@ require (
require (
cosmossdk.io/api v0.3.1 // indirect
cosmossdk.io/core v0.5.1 // indirect
cosmossdk.io/errors v1.0.0 // indirect
cosmossdk.io/log v1.2.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/btcsuite/btcd v0.21.0-beta // 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 @@ -67,7 +70,6 @@ require (
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
github.com/ethereum/go-ethereum v1.10.21 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/getsentry/sentry-go v0.23.0 // indirect
Expand All @@ -77,7 +79,6 @@ require (
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/golang/glog v1.1.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
Expand Down Expand Up @@ -109,6 +110,7 @@ require (
github.com/minio/highwayhash v1.0.2 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20210609091139-0a56a4bca00b // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect
Expand Down
Loading
Loading