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

feat: implement cross-chain mechanism between op and greenfield #266

Merged
merged 4 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
356 changes: 267 additions & 89 deletions api/cosmos/crosschain/v1/query.pulsar.go

Large diffs are not rendered by default.

181 changes: 120 additions & 61 deletions api/cosmos/gov/v1/tx.pulsar.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.23.0

github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v0.0.2
github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v0.0.0-20230810120916-f5f3421ab490
github.com/cometbft/cometbft-db => github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1
github.com/cosmos/iavl => github.com/bnb-chain/greenfield-iavl v0.20.1-alpha.1

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsy
github.com/bkielbasa/cyclop v1.2.0/go.mod h1:qOI0yy6A7dYC4Zgsa72Ppm9kONl0RoIlPbzot9mhmeI=
github.com/blizzy78/varnamelen v0.8.0/go.mod h1:V9TzQZ4fLJ1DSrjVDfl89H7aMnTvKkApdHeyESmyR7k=
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=
github.com/bnb-chain/greenfield-cometbft v0.0.2 h1:bRamS8Lq1lA3ttRLZBha22uiNG5tqN+diD3hapdUCYI=
github.com/bnb-chain/greenfield-cometbft v0.0.2/go.mod h1:EBmwmUdaNbGPyGjf1cMuoN3pAeM2tQu7Lfg95813EAw=
github.com/bnb-chain/greenfield-cometbft v0.0.0-20230810120916-f5f3421ab490 h1:sztr3uiKE/iI8O6ccIb6Bc9b9K0GVJryPXMhWx6Xk/U=
github.com/bnb-chain/greenfield-cometbft v0.0.0-20230810120916-f5f3421ab490/go.mod h1:3nGT4Z9fHwgRlBY/rofn0rSarnIcNbuhz/eq0XlLlkg=
github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1 h1:XcWulGacHVRiSCx90Q8Y//ajOrLNBQWR/KDB89dy3cU=
github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1/go.mod h1:ey1CiK4bYo1RBNJLRiVbYr5CMdSxci9S/AZRINLtppI=
github.com/bnb-chain/greenfield-iavl v0.20.1-alpha.1 h1:ZnIcvkkQVurg0OaAwmUGn2cK5bZbffjVChFyhh86HMk=
Expand Down
14 changes: 10 additions & 4 deletions proto/cosmos/crosschain/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ message QueryParamsResponse {

// QueryCrossChainPackageRequest is the request type for the Query/CrossChainPackage RPC method.
message QueryCrossChainPackageRequest {
// destination chain id
uint32 dest_chain_id = 1;
// channel id of the cross chain package
uint32 channel_id = 1;
uint32 channel_id = 2;
// sequence of the cross chain package
uint64 sequence = 2;
uint64 sequence = 3;
}

// QueryCrossChainPackageResponse is the response type for the Query/CrossChainPackage RPC method.
Expand All @@ -55,8 +57,10 @@ message QueryCrossChainPackageResponse {

// QuerySendSequenceRequest is the request type for the Query/SendSequence RPC method.
message QuerySendSequenceRequest {
// destination chain id
uint32 dest_chain_id = 1;
// channel id of the cross chain package
uint32 channel_id = 1;
uint32 channel_id = 2;
}

// QuerySendSequenceResponse is the response type for the Query/SendSequence RPC method.
Expand All @@ -67,8 +71,10 @@ message QuerySendSequenceResponse {

// QuerySendSequenceRequest is the request type for the Query/ReceiveSequence RPC method.
message QueryReceiveSequenceRequest {
// destination chain id
uint32 dest_chain_id = 1;
// channel id of the cross chain package
uint32 channel_id = 1;
uint32 channel_id = 2;
}

// QuerySendSequenceResponse is the response type for the Query/ReceiveSequence RPC method.
Expand Down
1 change: 0 additions & 1 deletion proto/cosmos/gov/v1/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,3 @@ message CrossChainParamsChange {
// targets defines a slice of addresses string in hex format
repeated string targets = 3;
}

2 changes: 2 additions & 0 deletions proto/cosmos/gov/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ message MsgUpdateCrossChainParams {

// for cross chain param change or contract upgrade
CrossChainParamsChange params = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];

uint32 dest_chain_id = 3;
}

// MsgUpdateCrossChainParamsResponse defines the response structure for executing a MsgUpdateCrossChainParams message.
Expand Down
7 changes: 5 additions & 2 deletions x/crosschain/keeper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package keeper
import sdk "github.com/cosmos/cosmos-sdk/types"

type crossChainConfig struct {
srcChainID sdk.ChainID
destBscChainId sdk.ChainID
srcChainID sdk.ChainID
destBscChainId sdk.ChainID
destOpChainId sdk.ChainID

nameToChannelID map[string]sdk.ChannelID
channelIDToName map[sdk.ChannelID]string
channelIDToApp map[sdk.ChannelID]sdk.CrossChainApplication
Expand All @@ -14,6 +16,7 @@ func newCrossChainCfg() *crossChainConfig {
config := &crossChainConfig{
srcChainID: 0,
destBscChainId: 0,
destOpChainId: 0,
nameToChannelID: make(map[string]sdk.ChannelID),
channelIDToName: make(map[sdk.ChannelID]string),
channelIDToApp: make(map[sdk.ChannelID]sdk.CrossChainApplication),
Expand Down
6 changes: 3 additions & 3 deletions x/crosschain/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (k Keeper) CrossChainPackage(c context.Context, req *types.QueryCrossChainP
}

ctx := sdk.UnwrapSDKContext(c)
pack, err := k.GetCrossChainPackage(ctx, k.GetDestBscChainID(), sdk.ChannelID(req.ChannelId), req.Sequence)
pack, err := k.GetCrossChainPackage(ctx, sdk.ChainID(req.DestChainId), sdk.ChannelID(req.ChannelId), req.Sequence)
if err != nil {
return nil, err
}
Expand All @@ -42,7 +42,7 @@ func (k Keeper) SendSequence(c context.Context, req *types.QuerySendSequenceRequ
}

ctx := sdk.UnwrapSDKContext(c)
sequence := k.GetSendSequence(ctx, k.GetDestBscChainID(), sdk.ChannelID(req.ChannelId))
sequence := k.GetSendSequence(ctx, sdk.ChainID(req.DestChainId), sdk.ChannelID(req.ChannelId))

return &types.QuerySendSequenceResponse{
Sequence: sequence,
Expand All @@ -56,7 +56,7 @@ func (k Keeper) ReceiveSequence(c context.Context, req *types.QueryReceiveSequen
}

ctx := sdk.UnwrapSDKContext(c)
sequence := k.GetReceiveSequence(ctx, k.GetDestBscChainID(), sdk.ChannelID(req.ChannelId))
sequence := k.GetReceiveSequence(ctx, sdk.ChainID(req.DestChainId), sdk.ChannelID(req.ChannelId))

return &types.QueryReceiveSequenceResponse{
Sequence: sequence,
Expand Down
22 changes: 19 additions & 3 deletions x/crosschain/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,13 @@ func (k Keeper) RegisterChannel(name string, id sdk.ChannelID, app sdk.CrossChai

// IsDestChainSupported returns the support status of a dest chain
func (k Keeper) IsDestChainSupported(chainID sdk.ChainID) bool {
return chainID == k.cfg.destBscChainId
if chainID == k.cfg.destBscChainId {
yutianwu marked this conversation as resolved.
Show resolved Hide resolved
return true
}
if k.cfg.destOpChainId != 0 && chainID == k.cfg.destOpChainId {
return true
}
return false
}

// IsChannelSupported returns the support status of a channel
Expand Down Expand Up @@ -210,8 +216,8 @@ func (k Keeper) GetSrcChainID() sdk.ChainID {
return k.cfg.srcChainID
}

// SetDestChainID sets the destination chain id
func (k Keeper) SetDestChainID(destChainId sdk.ChainID) {
// SetDestBscChainID sets the destination chain id
func (k Keeper) SetDestBscChainID(destChainId sdk.ChainID) {
k.cfg.destBscChainId = destChainId
}

Expand All @@ -220,6 +226,16 @@ func (k Keeper) GetDestBscChainID() sdk.ChainID {
return k.cfg.destBscChainId
}

// SetDestOpChainID sets the destination chain id of op chain
func (k Keeper) SetDestOpChainID(destChainId sdk.ChainID) {
k.cfg.destOpChainId = destChainId
}

// GetDestOpChainID gets the destination chain id of op chain
func (k Keeper) GetDestOpChainID() sdk.ChainID {
return k.cfg.destOpChainId
}

// GetCrossChainPackage returns the ibc package by sequence
func (k Keeper) GetCrossChainPackage(ctx sdk.Context, destChainId sdk.ChainID, channelId sdk.ChannelID, sequence uint64) ([]byte, error) {
kvStore := ctx.KVStore(k.storeKey)
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (s *TestSuite) TestSetChannelSendPermission() {

func (s *TestSuite) TestUpdateChannelPermission() {
s.crossChainKeeper.RegisterChannel("test", 1, &testutil2.MockCrossChainApplication{})
s.crossChainKeeper.SetDestChainID(1)
s.crossChainKeeper.SetDestBscChainID(1)

s.crossChainKeeper.SetChannelSendPermission(s.ctx, sdk.ChainID(1), sdk.ChannelID(1), sdk.ChannelAllow)

Expand Down
Loading
Loading