Skip to content

Commit

Permalink
chore(crosschain): remove cosmos bridgecall msg
Browse files Browse the repository at this point in the history
  • Loading branch information
nulnut authored and zakir-code committed Oct 11, 2024
1 parent bcb4d64 commit 6ce24a3
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 1,457 deletions.
2 changes: 1 addition & 1 deletion app/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestRegisterInterfaces(t *testing.T) {
for implInterfaces.Next() {
count2++
}
assert.Equal(t, 300, count2)
assert.Equal(t, 298, count2)

typeURLMap := interfaceRegistry.FieldByName("typeURLMap").MapRange()
for typeURLMap.Next() {
Expand Down
3 changes: 0 additions & 3 deletions app/interface_registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,9 @@
"/fx.gravity.crosschain.v1.MsgAddOracleDeposit",
"/fx.gravity.crosschain.v1.MsgBondedOracle",
"/fx.gravity.crosschain.v1.MsgBondedOracleResponse",
"/fx.gravity.crosschain.v1.MsgBridgeCall",
"/fx.gravity.crosschain.v1.MsgBridgeCallClaim",
"/fx.gravity.crosschain.v1.MsgBridgeCallConfirm",
"/fx.gravity.crosschain.v1.MsgBridgeCallConfirmResponse",
"/fx.gravity.crosschain.v1.MsgBridgeCallResponse",
"/fx.gravity.crosschain.v1.MsgBridgeCallResultClaim",
"/fx.gravity.crosschain.v1.MsgBridgeTokenClaim",
"/fx.gravity.crosschain.v1.MsgCancelSendToExternal",
Expand Down Expand Up @@ -422,7 +420,6 @@
"/fx.gravity.crosschain.v1.MsgAddDelegate",
"/fx.gravity.crosschain.v1.MsgAddOracleDeposit",
"/fx.gravity.crosschain.v1.MsgBondedOracle",
"/fx.gravity.crosschain.v1.MsgBridgeCall",
"/fx.gravity.crosschain.v1.MsgBridgeCallConfirm",
"/fx.gravity.crosschain.v1.MsgCancelSendToExternal",
"/fx.gravity.crosschain.v1.MsgClaim",
Expand Down
24 changes: 0 additions & 24 deletions proto/fx/gravity/crosschain/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ service Msg {

// Deprecated: Please use precompile BridgeCall
rpc SendToExternal(MsgSendToExternal) returns (MsgSendToExternalResponse);
rpc BridgeCall(MsgBridgeCall) returns (MsgBridgeCallResponse);

// UpdateParams defines a governance operation for updating the x/crosschain
// module parameters. The authority is hard-coded to the x/gov module account.
Expand Down Expand Up @@ -278,29 +277,6 @@ message MsgUpdateChainOracles {

message MsgUpdateChainOraclesResponse {}

message MsgBridgeCall {
option (cosmos.msg.v1.signer) = "sender";
option (amino.name) = "crosschain/MsgBridgeCall";

string chain_name = 1;
string sender = 2;
string refund = 3;
repeated cosmos.base.v1beta1.Coin coins = 4 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
string to = 5;
string data = 6;
string value = 7 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
string memo = 8;
}

message MsgBridgeCallResponse {}

message MsgClaim {
option (cosmos.msg.v1.signer) = "bridger_address";
option (amino.name) = "crosschain/MsgClaim";
Expand Down
35 changes: 0 additions & 35 deletions tests/crosschain_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,41 +474,6 @@ func (suite *CrosschainTestSuite) FormatAddress(address gethcommon.Address) stri
return crosschaintypes.ExternalAddrToStr(suite.chainName, address.Bytes())
}

func (suite *CrosschainTestSuite) BridgeCall(amounts sdk.Coins) uint64 {
_, nonce := suite.SendBridgeCallAndResponse(amounts)
return nonce
}

func (suite *CrosschainTestSuite) SendBridgeCallAndResponse(amount sdk.Coins) (*sdk.TxResponse, uint64) {
msg := &crosschaintypes.MsgBridgeCall{
ChainName: suite.chainName,
Sender: suite.AccAddress().String(),
Refund: suite.AccAddress().String(),
Coins: amount,
To: crosschaintypes.ExternalAddrToStr(suite.chainName, suite.AccAddress()),
Data: "",
Value: sdkmath.ZeroInt(),
Memo: "",
}
txResponse := suite.BroadcastTx(suite.privKey, msg)
for _, eventLog := range txResponse.Logs {
for _, event := range eventLog.Events {
if event.Type != crosschaintypes.EventTypeBridgeCall {
continue
}
for _, attribute := range event.Attributes {
if attribute.Key != crosschaintypes.AttributeKeyBridgeCallNonce {
continue
}
txId, err := strconv.ParseUint(attribute.Value, 10, 64)
suite.NoError(err)
return txResponse, txId
}
}
}
return txResponse, 0
}

func (suite *CrosschainTestSuite) BridgeCallConfirm(nonce uint64, isSuccess bool) {
bridgeCall := suite.QueryBridgeCallByNonce(nonce)
var checkpoint []byte
Expand Down
97 changes: 0 additions & 97 deletions tests/crosschain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
fxtypes "github.com/functionx/fx-core/v8/types"
bsctypes "github.com/functionx/fx-core/v8/x/bsc/types"
crosschaintypes "github.com/functionx/fx-core/v8/x/crosschain/types"
erc20types "github.com/functionx/fx-core/v8/x/erc20/types"
ethtypes "github.com/functionx/fx-core/v8/x/eth/types"
trontypes "github.com/functionx/fx-core/v8/x/tron/types"
)
Expand Down Expand Up @@ -242,102 +241,6 @@ func (suite *IntegrationTest) BridgeCallToFxcoreTest() {
}
}

func (suite *IntegrationTest) BridgeCallTest() {
chainModules := []string{ethtypes.ModuleName, bsctypes.ModuleName}
tokenAliasesMap := make(map[string][]string)
moduleTokenMap := make(map[string]string)
moduleDenomMap := make(map[string]string)
token1 := "one"
token2 := "two"
tokenMetaDatasMap := map[string]banktypes.Metadata{
token1: fxtypes.GetCrossChainMetadataManyToOne("one", helpers.NewRandSymbol(), 18),
token2: fxtypes.GetCrossChainMetadataManyToOne("two", helpers.NewRandSymbol(), 18),
}
for _, chainName := range chainModules {
suiteChain := suite.GetCrossChainByName(chainName)
for _, metadata := range tokenMetaDatasMap {
tokenAddress := helpers.GenExternalAddr(suiteChain.chainName)
moduleTokenMap[chainName+metadata.Name] = tokenAddress
bridgeDenom := crosschaintypes.NewBridgeDenom(suiteChain.chainName, tokenAddress)
moduleDenomMap[chainName+metadata.Name] = bridgeDenom
suiteChain.AddBridgeTokenClaim(metadata.Name, metadata.Symbol, uint64(metadata.DenomUnits[1].Exponent), tokenAddress, "")
tokenAliasesMap[metadata.Base] = append(tokenAliasesMap[metadata.Base], bridgeDenom)
}
}

for _, metadata := range tokenMetaDatasMap {
metadata.DenomUnits[0].Aliases = tokenAliasesMap[metadata.Base]
suite.erc20.RegisterCoinProposal(metadata)
}

ethChain := suite.GetCrossChainByName(ethtypes.ModuleName)
bscChain := suite.GetCrossChainByName(bsctypes.ModuleName)

transferAmount := sdkmath.NewInt(100)
ethChain.SendToFxClaimAndCheckBalance(moduleTokenMap[ethtypes.ModuleName+token1], transferAmount, "", sdk.NewCoin(tokenMetaDatasMap[token1].Base, transferAmount))
ethChain.SendToFxClaimAndCheckBalance(moduleTokenMap[ethtypes.ModuleName+token2], transferAmount, "", sdk.NewCoin(tokenMetaDatasMap[token2].Base, transferAmount))
bscChain.SendToFxClaimAndCheckBalance(moduleTokenMap[bsctypes.ModuleName+token2], transferAmount, "", sdk.NewCoin(tokenMetaDatasMap[token2].Base, transferAmount))

erc20ModuleAddr := suite.QueryModuleAccountByName(erc20types.ModuleName)
bridgeCallCoins := sdk.NewCoins(
sdk.NewCoin(tokenMetaDatasMap[token1].Base, transferAmount),
sdk.NewCoin(tokenMetaDatasMap[token2].Base, transferAmount),
)
ethChain.Send(bscChain.AccAddress(), bridgeCallCoins...)

// case 1: bridge call with two tokens, expect is error
res, _ := bscChain.SendBridgeCallAndResponse(bridgeCallCoins)
suite.NotEqualValues(0, res.Code)

suite.True(
sdk.NewCoins(
sdk.NewCoin(moduleDenomMap[ethtypes.ModuleName+token1], transferAmount),
sdk.NewCoin(moduleDenomMap[ethtypes.ModuleName+token2], transferAmount),
sdk.NewCoin(moduleDenomMap[bsctypes.ModuleName+token2], transferAmount),
).Equal(suite.QueryBalances(erc20ModuleAddr)))

// case 3: provide liquidit + send bridge call again + confirm + claim with failed

// add liquidity
bscChain.SendToFxClaimAndCheckBalance(moduleTokenMap[bsctypes.ModuleName+token1], transferAmount, "", sdk.NewCoin(tokenMetaDatasMap[token1].Base, transferAmount))
nonce := bscChain.BridgeCall(bridgeCallCoins)
bridgeCalls := bscChain.QueryBridgeCallByNonce(nonce)
suite.EqualValues(nonce, bridgeCalls.Nonce)
suite.EqualValues(2, len(bridgeCalls.Tokens))

suite.True(
sdk.NewCoins(
sdk.NewCoin(moduleDenomMap[ethtypes.ModuleName+token1], transferAmount),
sdk.NewCoin(moduleDenomMap[ethtypes.ModuleName+token2], transferAmount),
).Equal(suite.QueryBalances(erc20ModuleAddr)))

// bridge call result confirm with failed, refund tokens
bscChain.BridgeCallConfirm(nonce, false)
suite.True(sdk.NewCoins(
sdk.NewCoin(moduleDenomMap[ethtypes.ModuleName+token1], transferAmount),
sdk.NewCoin(moduleDenomMap[ethtypes.ModuleName+token2], transferAmount),
sdk.NewCoin(moduleDenomMap[bsctypes.ModuleName+token1], transferAmount),
sdk.NewCoin(moduleDenomMap[bsctypes.ModuleName+token2], transferAmount),
).Equal(suite.QueryBalances(erc20ModuleAddr)))

// case 4: bridge call result confirm with success.
nonce = bscChain.BridgeCall(bridgeCallCoins)
bscAccAddrBalances := suite.QueryBalances(bscChain.AccAddress())
bscChain.BridgeCallConfirm(nonce, true)
suite.True(
sdk.NewCoins(
sdk.NewCoin(moduleDenomMap[ethtypes.ModuleName+token1], transferAmount),
sdk.NewCoin(moduleDenomMap[ethtypes.ModuleName+token2], transferAmount),
).Equal(suite.QueryBalances(erc20ModuleAddr)))
suite.True(bscAccAddrBalances.Equal(suite.QueryBalances(bscChain.AccAddress())))

// Clear test tokens
bscChain.Send(ethChain.AccAddress(), bridgeCallCoins...)
ethBridgeCallNonce := ethChain.BridgeCall(bridgeCallCoins)
ethChain.BridgeCallConfirm(ethBridgeCallNonce, true)
suite.True(suite.QueryBalances(erc20ModuleAddr).IsZero())
}

func (suite *IntegrationTest) UpdateParamsTest() {
for _, chain := range suite.crosschain {
chain.UpdateParams(func(params *crosschaintypes.Params) {
Expand Down
1 change: 0 additions & 1 deletion tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func TestIntegrationTest(t *testing.T) {

func (suite *IntegrationTest) TestRun() {
suite.CrossChainTest()
suite.BridgeCallTest()
suite.OriginalCrossChainTest()

suite.PrecompileTransferCrossChainTest()
Expand Down
54 changes: 0 additions & 54 deletions x/crosschain/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strconv"
"strings"

sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
Expand Down Expand Up @@ -47,7 +46,6 @@ func getTxSubCmds(chainName string) []*cobra.Command {

// send to external chain
CmdSendToExternal(chainName),
CmdBridgeCall(chainName),

// oracle consensus confirm
CmdOracleSetConfirm(chainName),
Expand Down Expand Up @@ -188,58 +186,6 @@ func CmdSendToExternal(chainName string) *cobra.Command {
return cmd
}

func CmdBridgeCall(chainName string) *cobra.Command {
cmd := &cobra.Command{
Use: "bridge-call [to] [coins] [refund] --data [data]",
Short: "Adds a new entry to the bridge call pool",
Args: cobra.RangeArgs(1, 3),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

var coins sdk.Coins
var refund string
if len(args) >= 2 {
coins, err = sdk.ParseCoinsNormalized(args[1])
if err != nil {
return fmt.Errorf("coins: %w", err)
}

if len(args) != 3 {
return fmt.Errorf("refund address is required")
}
refund = args[2]
}

data, err := cmd.Flags().GetString("data")
if err != nil {
return err
}
memo, err := cmd.Flags().GetString("memo")
if err != nil {
return err
}

msg := types.MsgBridgeCall{
Sender: cliCtx.GetFromAddress().String(),
Refund: refund,
To: args[0],
Coins: coins,
Data: data,
Value: sdkmath.NewInt(0),
ChainName: chainName,
Memo: memo,
}
return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), &msg)
},
}
cmd.Flags().String("data", "", "bridge call contract data")
cmd.Flags().String("memo", "", "bridge call memo")
return cmd
}

func CmdRequestBatchConfirm(chainName string) *cobra.Command {
cmd := &cobra.Command{
Use: "request-batch-confirm [contract-address] [nonce] [private-key]",
Expand Down
14 changes: 0 additions & 14 deletions x/crosschain/keeper/bridge_call_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,3 @@ func (k Keeper) IterateOutgoingBridgeCallByNonce(ctx sdk.Context, startNonce uin
}
}
}

func (k Keeper) SetBridgeCallFromMsg(ctx sdk.Context, txID uint64) {
store := ctx.KVStore(k.storeKey)
store.Set(types.GetBridgeCallFromMsgKey(txID), []byte{})
}

func (k Keeper) DeleteBridgeCallFromMsg(ctx sdk.Context, txID uint64) {
store := ctx.KVStore(k.storeKey)
store.Delete(types.GetBridgeCallFromMsgKey(txID))
}

func (k Keeper) HasBridgeCallFromMsg(ctx sdk.Context, txID uint64) bool {
return ctx.KVStore(k.storeKey).Has(types.GetBridgeCallFromMsgKey(txID))
}
16 changes: 2 additions & 14 deletions x/crosschain/keeper/bridge_call_out_v1_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
package keeper_test

import (
"encoding/hex"
"math/big"

sdkmath "cosmossdk.io/math"
tmrand "github.com/cometbft/cometbft/libs/rand"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/functionx/fx-core/v8/testutil/helpers"
fxtypes "github.com/functionx/fx-core/v8/types"
"github.com/functionx/fx-core/v8/x/crosschain/types"
erc20types "github.com/functionx/fx-core/v8/x/erc20/types"
)

/*
func (suite *KeeperTestSuite) TestKeeper_BridgeCallRefund() {
suite.bondedOracle()
oracleAddr, found := suite.Keeper().GetOracleAddrByBridgerAddr(suite.Ctx, suite.bridgerAddrs[0])
Expand Down Expand Up @@ -89,3 +76,4 @@ func (suite *KeeperTestSuite) TestKeeper_BridgeCallRefund() {
suite.Equal(sdkmath.NewInt(0), suite.App.BankKeeper.GetBalance(suite.Ctx, fxAddr1.Bytes(), pair.Denom).Amount)
suite.Equal(sdkmath.NewInt(randomAmount), suite.App.BankKeeper.GetBalance(suite.Ctx, bridgeCallRefundAddr, pair.Denom).Amount)
}
*/
6 changes: 0 additions & 6 deletions x/crosschain/keeper/bridge_call_refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ func (k Keeper) HandleOutgoingBridgeCallRefund(ctx sdk.Context, data *types.Outg
sdk.NewAttribute(types.AttributeKeyRefund, refund.String()),
))

if k.HasBridgeCallFromMsg(ctx, data.Nonce) {
return coins
}
// precompile bridge call, refund to evm
if err = k.bridgeCallTransferTokens(ctx, refund, refund, coins); err != nil {
panic(err)
Expand All @@ -34,7 +31,4 @@ func (k Keeper) DeleteOutgoingBridgeCallRecord(ctx sdk.Context, bridgeCallNonce

// 2. delete bridge call confirm
k.DeleteBridgeCallConfirm(ctx, bridgeCallNonce)

// 3. delete bridge call from msg
k.DeleteBridgeCallFromMsg(ctx, bridgeCallNonce)
}
19 changes: 0 additions & 19 deletions x/crosschain/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,25 +390,6 @@ func (s MsgServer) BridgeCallConfirm(c context.Context, msg *types.MsgBridgeCall
return &types.MsgBridgeCallConfirmResponse{}, err
}

func (s MsgServer) BridgeCall(c context.Context, msg *types.MsgBridgeCall) (*types.MsgBridgeCallResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
outCallNonce, err := s.AddOutgoingBridgeCall(ctx, msg.GetSenderAddr(), msg.GetRefundAddr(), msg.Coins, msg.GetToAddr(), msg.MustData(), msg.MustMemo(), 0)
if err != nil {
return nil, err
}

// bridge call from msg
s.SetBridgeCallFromMsg(ctx, outCallNonce)

ctx.EventManager().EmitEvent(sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, msg.ChainName),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender),
))

return &types.MsgBridgeCallResponse{}, nil
}

func (s MsgServer) UpdateParams(c context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if s.authority != req.Authority {
return nil, govtypes.ErrInvalidSigner.Wrapf("invalid authority; expected %s, got %s", s.authority, req.Authority)
Expand Down
Loading

0 comments on commit 6ce24a3

Please sign in to comment.