Skip to content

Commit

Permalink
feat: replaces query canonical client with sending a tx to try to set…
Browse files Browse the repository at this point in the history
… it (#57)
  • Loading branch information
danwt authored Nov 29, 2024
1 parent 7405c3f commit 2a533df
Show file tree
Hide file tree
Showing 15 changed files with 566 additions and 85 deletions.
3 changes: 2 additions & 1 deletion client/client_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"fmt"

"github.com/cometbft/cometbft/abci/types"
cometcrypto "github.com/cometbft/cometbft/crypto"
Expand Down Expand Up @@ -81,7 +82,7 @@ func (r RPCClient) ABCIQueryWithOptions(

res, err := r.c.ABCIQueryWithOptions(ctx, path, slbytes.HexBytes(data), o)
if err != nil {
return nil, err
return nil, fmt.Errorf("raw client ABCIQueryWithOptions: %w", err)
}

return convertResultABCIQuery(res), nil
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ require (
github.com/cosmos/gogoproto v1.4.11
github.com/cosmos/ibc-go/modules/capability v1.0.0
github.com/cosmos/ibc-go/v8 v8.0.0
github.com/cosmos/ics23/go v0.10.0
github.com/danwt/gerr v1.0.2
github.com/dymensionxyz/gerr-cosmos v1.1.0
github.com/ethereum/go-ethereum v1.13.14
github.com/gofrs/flock v0.8.1
github.com/google/go-github/v43 v43.0.0
Expand Down Expand Up @@ -82,6 +82,7 @@ require (
github.com/cosmos/cosmos-db v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.0.1 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/dvsekhvalnov/jose2go v1.6.0 h1:Y9gnSnP4qEI0+/uQkHvFXeD2PLPJeXEL+ySMEA2EjTY=
github.com/dvsekhvalnov/jose2go v1.6.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
github.com/dymensionxyz/gerr-cosmos v1.1.0 h1:IW/P7HCB/iP9kgk3VXaWUoMoyx3vD76YO6p1fnubHVc=
github.com/dymensionxyz/gerr-cosmos v1.1.0/go.mod h1:n+0olxPogzWqFKba45mCpvrHLGmeS8W9UZjggHnWk6c=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
Expand Down
20 changes: 20 additions & 0 deletions proto/dymensionxyz/dymension/lightclient/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto3";
package dymensionxyz.dymension.lightclient;

import "cosmos/msg/v1/msg.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/cosmos/relayer/relayer/chains/cosmos/dym/lightclient/types";


// verify a client state and its consensus states against the rollapp
// if it matches, set the client as the canonical client for the rollapp
message MsgSetCanonicalClient {
option (cosmos.msg.v1.signer) = "signer";
string signer = 1;
// id of ibc client state
string client_id = 2;
}



6 changes: 6 additions & 0 deletions relayer/chains/cosmos/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/cosmos/ibc-go/v8/modules/apps/transfer"
ibc "github.com/cosmos/ibc-go/v8/modules/core"

dymtypes "github.com/cosmos/relayer/v2/relayer/chains/cosmos/dym/lightclient/types"
cosmosmodule "github.com/cosmos/relayer/v2/relayer/chains/cosmos/module"
"github.com/cosmos/relayer/v2/relayer/chains/cosmos/stride"
ethermintcodecs "github.com/cosmos/relayer/v2/relayer/codecs/ethermint"
Expand Down Expand Up @@ -88,6 +89,11 @@ func MakeCodec(moduleBasics []module.AppModuleBasic, extraCodecs []string, accBe
encodingConfig.Amino.RegisterConcrete(&injectivecodecs.PrivKey{}, injectivecodecs.PrivKeyName, nil)
}
}
{
// DYMENSION
dymtypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
encodingConfig.Amino.RegisterConcrete(&dymtypes.MsgSetCanonicalClient{}, "/lightclient.SetCanonicalClient", nil)
}

return encodingConfig
}
Expand Down
20 changes: 20 additions & 0 deletions relayer/chains/cosmos/dym/lightclient/types/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package types

import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

var ModuleName = "lightclient"

var (
amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewAminoCodec(amino)
)

func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgSetCanonicalClient{},
)
}
49 changes: 49 additions & 0 deletions relayer/chains/cosmos/dym/lightclient/types/tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package types

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
)

const (
TypeMsgSetCanonicalClient = "set_canonical_client"
)

var (
_ sdk.Msg = &MsgSetCanonicalClient{}
_ legacytx.LegacyMsg = &MsgSetCanonicalClient{}
)

func (msg *MsgSetCanonicalClient) Route() string {
return ModuleName
}

func (msg *MsgSetCanonicalClient) Type() string {
return TypeMsgSetCanonicalClient
}

func (msg *MsgSetCanonicalClient) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
panic(err)
}
return []sdk.AccAddress{creator}
}

func (msg *MsgSetCanonicalClient) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}

func (msg *MsgSetCanonicalClient) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return errorsmod.Wrapf(gerrc.ErrInvalidArgument, "invalid creator address (%s)", err)
}
if msg.ClientId == "" {
return gerrc.ErrInvalidArgument.Wrap("empty client id")
}
return nil
}
Loading

0 comments on commit 2a533df

Please sign in to comment.