From 70004a74627c7ea58ce0298b363220f133d88e54 Mon Sep 17 00:00:00 2001 From: izyak <76203436+izyak@users.noreply.github.com> Date: Tue, 25 Jul 2023 14:36:37 +0545 Subject: [PATCH] chore: TODOs for reviews (#115) * chore: TODOs for reviews * chore: remove move method from interface * chore: panic unimplemented methods * feat: Validate archway and icon addresses * chore: comments * chore: use enums to compare * feat: contract address validation * chore: rename method for contract address * fix: remove some comments * chore: save contract addrss size to const * chore: use actual address to fix tests --------- Co-authored-by: izyak Co-authored-by: viveksharmapoudel --- relayer/chains/archway/consts.go | 4 ++ relayer/chains/archway/provider.go | 45 ++++++++++++++----- relayer/chains/archway/query.go | 33 ++++++++------ relayer/chains/archway/tx.go | 33 +++++--------- relayer/chains/cosmos/tx.go | 12 ----- relayer/chains/icon/icon_chain_processor.go | 9 +--- relayer/chains/icon/keys_test.go | 2 +- relayer/chains/icon/message_handler.go | 2 - relayer/chains/icon/provider.go | 47 ++++---------------- relayer/chains/icon/provider_test.go | 7 +++ relayer/chains/icon/query.go | 49 ++++++++------------- relayer/chains/icon/utils.go | 15 +++++++ relayer/provider/provider.go | 3 -- 13 files changed, 121 insertions(+), 140 deletions(-) diff --git a/relayer/chains/archway/consts.go b/relayer/chains/archway/consts.go index bb21b923b..cb8704bad 100644 --- a/relayer/chains/archway/consts.go +++ b/relayer/chains/archway/consts.go @@ -30,3 +30,7 @@ const ( ConnectionPrefix = "connection" ChannelPrefix = "channel" ) + +const ( + ContractAddressSizeMinusPrefix = 59 +) diff --git a/relayer/chains/archway/provider.go b/relayer/chains/archway/provider.go index ade4acca1..700b359df 100644 --- a/relayer/chains/archway/provider.go +++ b/relayer/chains/archway/provider.go @@ -22,6 +22,7 @@ import ( prov "github.com/cometbft/cometbft/light/provider/http" "github.com/cosmos/cosmos-sdk/crypto/keyring" + "github.com/cosmos/cosmos-sdk/types/bech32" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/gogoproto/proto" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" @@ -183,14 +184,34 @@ func (a ArchwayIBCHeader) ShouldUpdateWithZeroMessage() bool { return false } +func (pp *ArchwayProviderConfig) ValidateContractAddress(addr string) bool { + prefix, _, err := bech32.DecodeAndConvert(addr) + if err != nil { + return false + } + if pp.AccountPrefix != prefix { + return false + } + + // TODO: Is this needed? + // Confirmed working for neutron, archway, osmosis + prefixLen := len(pp.AccountPrefix) + if len(addr) != prefixLen+ContractAddressSizeMinusPrefix { + return false + } + + return true +} + func (pp *ArchwayProviderConfig) Validate() error { if _, err := time.ParseDuration(pp.Timeout); err != nil { return fmt.Errorf("invalid Timeout: %w", err) } - if pp.IbcHandlerAddress == "" { - return fmt.Errorf("Ibc handler contract cannot be empty") + if !pp.ValidateContractAddress(pp.IbcHandlerAddress) { + return fmt.Errorf("Invalid contract address") } + return nil } @@ -351,11 +372,13 @@ func (ap *ArchwayProvider) Address() (string, error) { return out, err } +// TODO: CHECK AGAIN func (cc *ArchwayProvider) TrustingPeriod(ctx context.Context) (time.Duration, error) { + panic(fmt.Sprintf("%s%s", cc.ChainName(), NOT_IMPLEMENTED)) // res, err := cc.QueryStakingParams(ctx) // TODO: check and rewrite - var unbondingTime time.Duration + // var unbondingTime time.Duration // if err != nil { // // Attempt ICS query // consumerUnbondingPeriod, consumerErr := cc.queryConsumerUnbondingPeriod(ctx) @@ -374,15 +397,15 @@ func (cc *ArchwayProvider) TrustingPeriod(ctx context.Context) (time.Duration, e // // by converting int64 to float64. // // Use integer math the whole time, first reducing by a factor of 100 // // and then re-growing by 85x. - tp := unbondingTime / 100 * 85 + // tp := unbondingTime / 100 * 85 // // And we only want the trusting period to be whole hours. // // But avoid rounding if the time is less than 1 hour // // (otherwise the trusting period will go to 0) - if tp > time.Hour { - tp = tp.Truncate(time.Hour) - } - return tp, nil + // if tp > time.Hour { + // tp = tp.Truncate(time.Hour) + // } + // return tp, nil } func (cc *ArchwayProvider) Sprint(toPrint proto.Message) (string, error) { @@ -403,6 +426,7 @@ func (cc *ArchwayProvider) QueryStatus(ctx context.Context) (*ctypes.ResultStatu // WaitForNBlocks blocks until the next block on a given chain func (cc *ArchwayProvider) WaitForNBlocks(ctx context.Context, n int64) error { + panic(fmt.Sprintf("%s%s", cc.ChainName(), NOT_IMPLEMENTED)) // var initial int64 // h, err := cc.RPCClient.Status(ctx) // if err != nil { @@ -427,7 +451,6 @@ func (cc *ArchwayProvider) WaitForNBlocks(ctx context.Context, n int64) error { // return ctx.Err() // } // } - return nil } func (ac *ArchwayProvider) BlockTime(ctx context.Context, height int64) (time.Time, error) { @@ -452,8 +475,8 @@ func (ap *ArchwayProvider) updateNextAccountSequence(seq uint64) { } } -func (app *ArchwayProvider) MsgRegisterCounterpartyPayee(portID, channelID, relayerAddr, counterpartyPayeeAddr string) (provider.RelayerMessage, error) { - return nil, fmt.Errorf("Not implemented for Icon") +func (ap *ArchwayProvider) MsgRegisterCounterpartyPayee(portID, channelID, relayerAddr, counterpartyPayeeAddr string) (provider.RelayerMessage, error) { + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } func (cc *ArchwayProvider) FirstRetryBlockAfter() uint64 { diff --git a/relayer/chains/archway/query.go b/relayer/chains/archway/query.go index 24944d8c7..3b1610239 100644 --- a/relayer/chains/archway/query.go +++ b/relayer/chains/archway/query.go @@ -34,7 +34,10 @@ import ( "github.com/cosmos/relayer/v2/relayer/provider" ) -const PaginationDelay = 10 * time.Millisecond +const ( + PaginationDelay = 10 * time.Millisecond + NOT_IMPLEMENTED = " :: Not implemented for WASM" +) func (ap *ArchwayProvider) QueryTx(ctx context.Context, hashHex string) (*provider.RelayerTxResponse, error) { hash, err := hex.DecodeString(hashHex) @@ -95,6 +98,7 @@ func (ap *ArchwayProvider) QueryTxs(ctx context.Context, page, limit int, events // parseEventsFromResponseDeliverTx parses the events from a ResponseDeliverTx and builds a slice // of provider.RelayerEvent's. +// TODO: Comet check needed? func parseEventsFromResponseDeliverTx(resp abci.ResponseDeliverTx) []provider.RelayerEvent { var events []provider.RelayerEvent @@ -202,6 +206,7 @@ func DefaultPageRequest() *querytypes.PageRequest { // staking func (ap *ArchwayProvider) QueryUnbondingPeriod(context.Context) (time.Duration, error) { + // move to provider, panic return 0, nil } @@ -219,6 +224,7 @@ func (ap *ArchwayProvider) QueryClientState(ctx context.Context, height int64, c return clientStateExported, nil } +// TODO: Check revision number func (ap *ArchwayProvider) QueryClientStateResponse(ctx context.Context, height int64, srcClientId string) (*clienttypes.QueryClientStateResponse, error) { clS, err := ap.QueryClientStateContract(ctx, srcClientId) @@ -343,11 +349,11 @@ func (ap *ArchwayProvider) QueryIBCHandlerContractProcessed(ctx context.Context, } func (ap *ArchwayProvider) QueryUpgradedClient(ctx context.Context, height int64) (*clienttypes.QueryClientStateResponse, error) { - return nil, fmt.Errorf("Not implemented for Archway") + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } func (ap *ArchwayProvider) QueryUpgradedConsState(ctx context.Context, height int64) (*clienttypes.QueryConsensusStateResponse, error) { - return nil, fmt.Errorf("Not implemented for Archway") + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } func (ap *ArchwayProvider) QueryConsensusState(ctx context.Context, height int64) (ibcexported.ConsensusState, int64, error) { @@ -546,7 +552,7 @@ func (ap *ArchwayProvider) QueryConnections(ctx context.Context) (conns []*connt } // Only return open conenctions - if conn.State == 3 { + if conn.State == conntypes.OPEN { identifiedConn := conntypes.IdentifiedConnection{ Id: connectionId, ClientId: conn.ClientId, @@ -563,7 +569,7 @@ func (ap *ArchwayProvider) QueryConnections(ctx context.Context) (conns []*connt } func (ap *ArchwayProvider) QueryConnectionsUsingClient(ctx context.Context, height int64, clientid string) (*conntypes.QueryConnectionsResponse, error) { - return nil, fmt.Errorf("Not implemented for Archway") + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } func (ap *ArchwayProvider) GenerateConnHandshakeProof(ctx context.Context, height int64, clientId, connId string) (clientState ibcexported.ClientState, @@ -624,7 +630,7 @@ func (ap *ArchwayProvider) QueryChannel(ctx context.Context, height int64, chann } func (ap *ArchwayProvider) QueryChannelClient(ctx context.Context, height int64, channelid, portid string) (*clienttypes.IdentifiedClientState, error) { - return nil, fmt.Errorf("Not implemented for Archway") + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } func (ap *ArchwayProvider) QueryConnectionChannels(ctx context.Context, height int64, connectionid string) ([]*chantypes.IdentifiedChannel, error) { @@ -665,7 +671,7 @@ func (ap *ArchwayProvider) QueryChannels(ctx context.Context) ([]*chantypes.Iden } // check if the channel is open - if channel.State == 3 { + if channel.State == chantypes.OPEN { identifiedChannel := chantypes.IdentifiedChannel{ State: channel.State, Ordering: channel.Ordering, @@ -682,20 +688,21 @@ func (ap *ArchwayProvider) QueryChannels(ctx context.Context) ([]*chantypes.Iden return channels, nil } + func (ap *ArchwayProvider) QueryPacketCommitments(ctx context.Context, height uint64, channelid, portid string) (commitments *chantypes.QueryPacketCommitmentsResponse, err error) { - return nil, fmt.Errorf("Not implemented for Archway") + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } func (ap *ArchwayProvider) QueryPacketAcknowledgements(ctx context.Context, height uint64, channelid, portid string) (acknowledgements []*chantypes.PacketState, err error) { - return nil, fmt.Errorf("Not implemented for Archway") + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } func (ap *ArchwayProvider) QueryUnreceivedPackets(ctx context.Context, height uint64, channelid, portid string, seqs []uint64) ([]uint64, error) { - return nil, fmt.Errorf("Not implemented for Archway") + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } func (ap *ArchwayProvider) QueryUnreceivedAcknowledgements(ctx context.Context, height uint64, channelid, portid string, seqs []uint64) ([]uint64, error) { - return nil, fmt.Errorf("Not implemented for Archway") + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } func (ap *ArchwayProvider) QueryNextSeqRecv(ctx context.Context, height int64, channelid, portid string) (recvRes *chantypes.QueryNextSequenceReceiveResponse, err error) { @@ -800,8 +807,8 @@ func (ap *ArchwayProvider) GetCommitmentPrefixFromContract(ctx context.Context) // ics 20 - transfer func (ap *ArchwayProvider) QueryDenomTrace(ctx context.Context, denom string) (*transfertypes.DenomTrace, error) { - return nil, fmt.Errorf("Not implemented for Archway") + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } func (ap *ArchwayProvider) QueryDenomTraces(ctx context.Context, offset, limit uint64, height int64) ([]transfertypes.DenomTrace, error) { - return nil, fmt.Errorf("Not implemented for Archway") + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } diff --git a/relayer/chains/archway/tx.go b/relayer/chains/archway/tx.go index ef878a70c..a5312a02f 100644 --- a/relayer/chains/archway/tx.go +++ b/relayer/chains/archway/tx.go @@ -35,7 +35,6 @@ import ( conntypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" "github.com/cosmos/relayer/v2/relayer/provider" - "github.com/icon-project/IBC-Integration/libraries/go/common/icon" itm "github.com/icon-project/IBC-Integration/libraries/go/common/tendermint" "github.com/cosmos/cosmos-sdk/client" @@ -164,18 +163,6 @@ func (ap *ArchwayProvider) NewClientState(dstChainID string, dstIBCHeader provid }, nil } -func (ap *ArchwayProvider) NewClientStateMock(dstChainID string, dstIBCHeader provider.IBCHeader, dstTrustingPeriod, dstUbdPeriod time.Duration, allowUpdateAfterExpiry, allowUpdateAfterMisbehaviour bool) (ibcexported.ClientState, error) { - - // btpHeader := dstIBCHeader.(*iconchain.IconIBCHeader) - - return &icon.ClientState{ - TrustingPeriod: uint64(dstTrustingPeriod), - FrozenHeight: 0, - MaxClockDrift: 20 * 60, - LatestHeight: dstIBCHeader.Height(), - }, nil -} - func (ap *ArchwayProvider) MsgCreateClient(clientState ibcexported.ClientState, consensusState ibcexported.ConsensusState) (provider.RelayerMessage, error) { signer, err := ap.Address() if err != nil { @@ -202,11 +189,11 @@ func (ap *ArchwayProvider) MsgCreateClient(clientState ibcexported.ClientState, } func (ap *ArchwayProvider) MsgUpgradeClient(srcClientId string, consRes *clienttypes.QueryConsensusStateResponse, clientRes *clienttypes.QueryClientStateResponse) (provider.RelayerMessage, error) { - return nil, fmt.Errorf("Not implemented for Archway") + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } func (ap *ArchwayProvider) MsgSubmitMisbehaviour(clientID string, misbehaviour ibcexported.ClientMessage) (provider.RelayerMessage, error) { - return nil, fmt.Errorf("Not implemented for Archway") + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } func (ap *ArchwayProvider) ValidatePacket(msgTransfer provider.PacketInfo, latest provider.LatestBlock) error { @@ -289,6 +276,7 @@ func (ap *ArchwayProvider) NextSeqRecv(ctx context.Context, msgTransfer provider } func (ap *ArchwayProvider) MsgTransfer(dstAddr string, amount sdk.Coin, info provider.PacketInfo) (provider.RelayerMessage, error) { + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) return nil, fmt.Errorf("Not implemented for Archway") } @@ -343,10 +331,13 @@ func (ap *ArchwayProvider) MsgTimeout(msgTransfer provider.PacketInfo, proof pro } func (ap *ArchwayProvider) MsgTimeoutRequest(msgTransfer provider.PacketInfo, proof provider.PacketProof) (provider.RelayerMessage, error) { + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) return nil, fmt.Errorf("MsgTimeoutRequest Not implemented for Archway module") } +// panic func (ap *ArchwayProvider) MsgTimeoutOnClose(msgTransfer provider.PacketInfo, proofUnreceived provider.PacketProof) (provider.RelayerMessage, error) { + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) return nil, nil } @@ -650,19 +641,19 @@ func (ap *ArchwayProvider) MsgUpdateClient(clientID string, dstHeader ibcexporte } func (ap *ArchwayProvider) QueryICQWithProof(ctx context.Context, msgType string, request []byte, height uint64) (provider.ICQProof, error) { - return provider.ICQProof{}, nil + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } func (ap *ArchwayProvider) MsgSubmitQueryResponse(chainID string, queryID provider.ClientICQQueryID, proof provider.ICQProof) (provider.RelayerMessage, error) { - return nil, nil + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } func (ap *ArchwayProvider) RelayPacketFromSequence(ctx context.Context, src provider.ChainProvider, srch, dsth, seq uint64, srcChanID, srcPortID string, order chantypes.Order) (provider.RelayerMessage, provider.RelayerMessage, error) { - return nil, nil, nil + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } func (ap *ArchwayProvider) AcknowledgementFromSequence(ctx context.Context, dst provider.ChainProvider, dsth, seq uint64, dstChanID, dstPortID, srcChanID, srcPortID string) (provider.RelayerMessage, error) { - return nil, nil + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } func (ap *ArchwayProvider) SendMessage(ctx context.Context, msg provider.RelayerMessage, memo string) (*provider.RelayerTxResponse, bool, error) { @@ -1032,6 +1023,7 @@ func (ap *ArchwayProvider) BroadcastTx( // BroadcastTx attempts to generate, sign and broadcast a transaction with the // given set of messages. It will also simulate gas requirements if necessary. // It will return an error upon failure. +// UNUSED: PANIC func (ap *ArchwayProvider) broadcastTx( ctx context.Context, // context for tx broadcast tx []byte, // raw tx to be broadcasted @@ -1042,7 +1034,7 @@ func (ap *ArchwayProvider) broadcastTx( asyncTimeout time.Duration, // timeout for waiting for block inclusion asyncCallback func(*provider.RelayerTxResponse, error), // callback for success/fail of the wait for block inclusion ) error { - return nil + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } func (ap *ArchwayProvider) waitForTx( @@ -1280,7 +1272,6 @@ func (cc *ArchwayProvider) handleAccountSequenceMismatchError(err error) { return } - fmt.Printf("the next sequence is %d \n", seq) cc.nextAccountSeq = seq } diff --git a/relayer/chains/cosmos/tx.go b/relayer/chains/cosmos/tx.go index 91c1c5bb3..e553ee339 100644 --- a/relayer/chains/cosmos/tx.go +++ b/relayer/chains/cosmos/tx.go @@ -1237,18 +1237,6 @@ func (cc *CosmosProvider) queryTMClientState(ctx context.Context, srch int64, sr // DefaultUpgradePath is the default IBC upgrade path set for an on-chain light client var defaultUpgradePath = []string{"upgrade", "upgradedIBCState"} -// TODO: Remove later -func (cc *CosmosProvider) NewClientStateMock( - dstChainID string, - dstUpdateHeader provider.IBCHeader, - dstTrustingPeriod, - dstUbdPeriod time.Duration, - allowUpdateAfterExpiry, - allowUpdateAfterMisbehaviour bool, -) (ibcexported.ClientState, error) { - return nil, nil -} - // NewClientState creates a new tendermint client state tracking the dst chain. func (cc *CosmosProvider) NewClientState( dstChainID string, diff --git a/relayer/chains/icon/icon_chain_processor.go b/relayer/chains/icon/icon_chain_processor.go index 5753bd707..60a307aee 100644 --- a/relayer/chains/icon/icon_chain_processor.go +++ b/relayer/chains/icon/icon_chain_processor.go @@ -227,7 +227,6 @@ func (icp *IconChainProcessor) GetLatestHeight() uint64 { return icp.latestBlock.Height } -// TODO: review add verifier func (icp *IconChainProcessor) monitoring(ctx context.Context, persistence *queryCyclePersistence) error { errCh := make(chan error) // error channel @@ -338,13 +337,7 @@ loop: ) break } - - // TODO: this is temporary adjustment - // if icp.firstTime { - // time.Sleep(4000 * time.Millisecond) - // } else { - // time.Sleep(100 * time.Millisecond) - // } + time.Sleep(10 * time.Millisecond) icp.firstTime = false if br = nil; len(btpBlockRespCh) > 0 { br = <-btpBlockRespCh diff --git a/relayer/chains/icon/keys_test.go b/relayer/chains/icon/keys_test.go index 0da772581..798c5109a 100644 --- a/relayer/chains/icon/keys_test.go +++ b/relayer/chains/icon/keys_test.go @@ -44,7 +44,7 @@ func TestRestoreIconKeyStore(t *testing.T) { Timeout: "20s", ChainName: "icon", StartHeight: 10, - IbcHandlerAddress: "aa", + IbcHandlerAddress: "cxb6b5791be0b5ef67063b3c10b840fb81514db2fd", } p, err := pcfg.NewProvider(zap.NewNop(), "not_correct", false, "icon") require.NoError(t, err) diff --git a/relayer/chains/icon/message_handler.go b/relayer/chains/icon/message_handler.go index fbdc69625..eae218d9c 100644 --- a/relayer/chains/icon/message_handler.go +++ b/relayer/chains/icon/message_handler.go @@ -12,7 +12,6 @@ import ( "go.uber.org/zap/zapcore" ) -// TODO: implement for all the message types func (icp *IconChainProcessor) handleMessage(ctx context.Context, m ibcMessage, c processor.IBCMessagesCache) { switch t := m.info.(type) { case *packetInfo: @@ -27,7 +26,6 @@ func (icp *IconChainProcessor) handleMessage(ctx context.Context, m ibcMessage, } func (icp *IconChainProcessor) handlePacketMessage(eventType string, pi provider.PacketInfo, c processor.IBCMessagesCache) { - // TODO: implement for packet messages k, err := processor.PacketInfoChannelKey(eventType, pi) if err != nil { icp.log.Error("Unexpected error handling packet message", diff --git a/relayer/chains/icon/provider.go b/relayer/chains/icon/provider.go index acd899520..b736f305c 100644 --- a/relayer/chains/icon/provider.go +++ b/relayer/chains/icon/provider.go @@ -14,7 +14,6 @@ import ( "github.com/cosmos/relayer/v2/relayer/processor" "github.com/cosmos/relayer/v2/relayer/provider" "github.com/icon-project/IBC-Integration/libraries/go/common/icon" - itm "github.com/icon-project/IBC-Integration/libraries/go/common/tendermint" "github.com/icon-project/goloop/common/wallet" "github.com/icon-project/goloop/module" @@ -45,6 +44,8 @@ var ( Identifier: DefaultIBCVersionIdentifier, Features: []string{"ORDER_ORDERED", "ORDER_UNORDERED"}, } + + NOT_IMPLEMENTED = " :: Not implemented for ICON" ) type IconProviderConfig struct { @@ -69,7 +70,7 @@ func (pp *IconProviderConfig) Validate() error { return fmt.Errorf("invalid Timeout: %w", err) } - if pp.IbcHandlerAddress == "" { + if !isValidIconContractAddress(pp.IbcHandlerAddress) { return fmt.Errorf("Ibc handler Address cannot be empty") } @@ -196,38 +197,6 @@ func (icp *IconProvider) Init(ctx context.Context) error { return nil } -// TODO: Remove later -func (icp *IconProvider) NewClientStateMock( - dstChainID string, - dstUpdateHeader provider.IBCHeader, - dstTrustingPeriod, - dstUbdPeriod time.Duration, - allowUpdateAfterExpiry, - allowUpdateAfterMisbehaviour bool, -) (ibcexported.ClientState, error) { - - return &itm.ClientState{ - ChainId: dstChainID, - TrustLevel: &itm.Fraction{ - Numerator: 2, - Denominator: 3, - }, - TrustingPeriod: &itm.Duration{ - Seconds: int64(dstTrustingPeriod), - }, - UnbondingPeriod: &itm.Duration{ - Seconds: int64(dstUbdPeriod), - }, - MaxClockDrift: &itm.Duration{ - Seconds: int64(time.Minute) * 20, - }, - FrozenHeight: 0, - LatestHeight: int64(dstUpdateHeader.Height()), - AllowUpdateAfterExpiry: allowUpdateAfterExpiry, - AllowUpdateAfterMisbehaviour: allowUpdateAfterMisbehaviour, - }, nil -} - func (icp *IconProvider) NewClientState( dstChainID string, dstUpdateHeader provider.IBCHeader, @@ -385,15 +354,15 @@ func (icp *IconProvider) NextSeqRecv(ctx context.Context, msgTransfer provider.P } func (icp *IconProvider) MsgTransfer(dstAddr string, amount sdk.Coin, info provider.PacketInfo) (provider.RelayerMessage, error) { - return nil, fmt.Errorf("Method not supported on ICON") + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } func (icp *IconProvider) QueryICQWithProof(ctx context.Context, msgType string, request []byte, height uint64) (provider.ICQProof, error) { - return provider.ICQProof{}, nil + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } func (icp *IconProvider) MsgSubmitQueryResponse(chainID string, queryID provider.ClientICQQueryID, proof provider.ICQProof) (provider.RelayerMessage, error) { - return nil, nil + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } func (icp *IconProvider) RelayPacketFromSequence(ctx context.Context, src provider.ChainProvider, srch, dsth, seq uint64, srcChanID, srcPortID string, order chantypes.Order) (provider.RelayerMessage, provider.RelayerMessage, error) { @@ -433,7 +402,7 @@ func (icp *IconProvider) AcknowledgementFromSequence(ctx context.Context, dst pr } func (icp *IconProvider) MsgSubmitMisbehaviour(clientID string, misbehaviour ibcexported.ClientMessage) (provider.RelayerMessage, error) { - return nil, fmt.Errorf("Not implemented") + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } func (icp *IconProvider) ChainName() string { @@ -563,7 +532,7 @@ func (icp *IconProvider) GetCurrentBtpNetworkStartHeight() (int64, error) { } func (icp *IconProvider) MsgRegisterCounterpartyPayee(portID, channelID, relayerAddr, counterpartyPayeeAddr string) (provider.RelayerMessage, error) { - return nil, fmt.Errorf("Not implemented for Icon") + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } func (cc *IconProvider) FirstRetryBlockAfter() uint64 { diff --git a/relayer/chains/icon/provider_test.go b/relayer/chains/icon/provider_test.go index 79f6c6a32..3590126c4 100644 --- a/relayer/chains/icon/provider_test.go +++ b/relayer/chains/icon/provider_test.go @@ -23,6 +23,13 @@ const ( testCA = "cx58bca8a4110e96b50e1bd9eeb5e429eed5ba94b4" ) +func TestAddr(t *testing.T) { + b := isValidIconContractAddress(testCA) + assert.True(t, b) + + assert.False(t, isValidIconContractAddress(testCA[1:])) +} + func TestConnectionDecode(t *testing.T) { input := types.HexBytes("0a0f30372d74656e6465726d696e742d3012230a0131120d4f524445525f4f524445524544120f4f524445525f554e4f524445524544180322200a0f30372d74656e6465726d696e742d30120d636f6e6e656374696f6e2d3533") diff --git a/relayer/chains/icon/query.go b/relayer/chains/icon/query.go index 8b23267e7..a17dec281 100644 --- a/relayer/chains/icon/query.go +++ b/relayer/chains/icon/query.go @@ -81,12 +81,12 @@ func (icp *IconProvider) BlockTime(ctx context.Context, height int64) (time.Time // required for cosmos only func (icp *IconProvider) QueryTx(ctx context.Context, hashHex string) (*provider.RelayerTxResponse, error) { - return nil, fmt.Errorf("Not implemented for ICON") + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } // required for cosmos only func (icp *IconProvider) QueryTxs(ctx context.Context, page, limit int, events []string) ([]*provider.RelayerTxResponse, error) { - return nil, fmt.Errorf("Not implemented for ICON") + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } func (icp *IconProvider) QueryLatestHeight(ctx context.Context) (int64, error) { @@ -125,11 +125,11 @@ func (icp *IconProvider) QueryIBCHeader(ctx context.Context, h int64) (provider. } func (icp *IconProvider) QuerySendPacket(ctx context.Context, srcChanID, srcPortID string, sequence uint64) (provider.PacketInfo, error) { - return provider.PacketInfo{}, nil + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } func (icp *IconProvider) QueryRecvPacket(ctx context.Context, dstChanID, dstPortID string, sequence uint64) (provider.PacketInfo, error) { - return provider.PacketInfo{}, nil + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } func (icp *IconProvider) QueryBalance(ctx context.Context, keyName string) (sdk.Coins, error) { @@ -143,7 +143,7 @@ func (icp *IconProvider) QueryBalance(ctx context.Context, keyName string) (sdk. // implementing is not required func (icp *IconProvider) QueryBalanceWithAddress(ctx context.Context, addr string) (sdk.Coins, error) { - return sdk.Coins{}, fmt.Errorf("Not implemented for ICON") + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } func (icp *IconProvider) QueryUnbondingPeriod(context.Context) (time.Duration, error) { @@ -282,15 +282,15 @@ func (icp *IconProvider) QueryClientConsensusState(ctx context.Context, chainHei } func (icp *IconProvider) QueryUpgradedClient(ctx context.Context, height int64) (*clienttypes.QueryClientStateResponse, error) { - return nil, fmt.Errorf("Not implemented for ICON") + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } func (icp *IconProvider) QueryUpgradedConsState(ctx context.Context, height int64) (*clienttypes.QueryConsensusStateResponse, error) { - return nil, fmt.Errorf("Not implemented for ICON") + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } func (icp *IconProvider) QueryConsensusState(ctx context.Context, height int64) (ibcexported.ConsensusState, int64, error) { - return nil, height, fmt.Errorf("Not implemented for ICON. Check QueryClientConsensusState instead") + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } // query all the clients of the chain @@ -413,7 +413,7 @@ func (icp *IconProvider) QueryConnections(ctx context.Context) (conns []*conntyp continue } // Only return open conenctions - if conn.State == 3 { + if conn.State == conntypes.OPEN { identifiedConn := conntypes.IdentifiedConnection{ Id: connectionId, ClientId: conn.ClientId, @@ -465,8 +465,7 @@ func (icp *IconProvider) getAllPorts(ctx context.Context) ([]string, error) { } func (icp *IconProvider) QueryConnectionsUsingClient(ctx context.Context, height int64, clientid string) (*conntypes.QueryConnectionsResponse, error) { - // TODO - return nil, fmt.Errorf("not implemented") + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } func (icp *IconProvider) GenerateConnHandshakeProof(ctx context.Context, height int64, clientId, connId string) (ibcexported.ClientState, []byte, []byte, []byte, @@ -561,9 +560,7 @@ var emptyChannelRes = chantypes.NewQueryChannelResponse( ) func (icp *IconProvider) QueryChannelClient(ctx context.Context, height int64, channelid, portid string) (*clienttypes.IdentifiedClientState, error) { - // TODO: - //if method given can be easily fetched... - return nil, nil + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } // is not needed currently for the operation @@ -626,7 +623,7 @@ func (icp *IconProvider) QueryChannels(ctx context.Context) ([]*chantypes.Identi } // check if the channel is open - if channel.State == 3 { + if channel.State == chantypes.OPEN { identifiedChannel := chantypes.IdentifiedChannel{ State: channel.State, Ordering: channel.Ordering, @@ -646,28 +643,21 @@ func (icp *IconProvider) QueryChannels(ctx context.Context) ([]*chantypes.Identi // required to flush packets func (icp *IconProvider) QueryPacketCommitments(ctx context.Context, height uint64, channelid, portid string) (commitments *chantypes.QueryPacketCommitmentsResponse, err error) { - - //get-all-packets - return nil, nil - + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } + func (icp *IconProvider) QueryPacketAcknowledgements(ctx context.Context, height uint64, channelid, portid string) (acknowledgements []*chantypes.PacketState, err error) { - return nil, nil + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } -// legacy func (icp *IconProvider) QueryUnreceivedPackets(ctx context.Context, height uint64, channelid, portid string, seqs []uint64) ([]uint64, error) { - // TODO: onl - return nil, nil + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } -// legacy func (icp *IconProvider) QueryUnreceivedAcknowledgements(ctx context.Context, height uint64, channelid, portid string, seqs []uint64) ([]uint64, error) { - // TODO: Implement - return nil, nil + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } -// legacy func (icp *IconProvider) QueryNextSeqRecv(ctx context.Context, height int64, channelid, portid string) (recvRes *chantypes.QueryNextSequenceReceiveResponse, err error) { callParam := icp.prepareCallParams(MethodGetNextSequenceReceive, map[string]interface{}{ "portId": portid, @@ -677,7 +667,6 @@ func (icp *IconProvider) QueryNextSeqRecv(ctx context.Context, height int64, cha if err := icp.client.Call(callParam, &nextSeqRecv); err != nil { return nil, err } - // TODO: Get proof and proofheight key := common.GetNextSequenceRecvCommitmentKey(portid, channelid) keyHash := common.Sha3keccak256(key, []byte(types.NewHexInt(int64(nextSeqRecv)))) @@ -791,12 +780,12 @@ func (icp *IconProvider) QueryPacketReceipt(ctx context.Context, height int64, c // ics 20 - transfer // not required for icon func (icp *IconProvider) QueryDenomTrace(ctx context.Context, denom string) (*transfertypes.DenomTrace, error) { - return nil, fmt.Errorf("Not implemented for ICON") + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } // not required for icon func (icp *IconProvider) QueryDenomTraces(ctx context.Context, offset, limit uint64, height int64) ([]transfertypes.DenomTrace, error) { - return nil, fmt.Errorf("Not implemented for ICON") + panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED)) } func (icp *IconProvider) QueryIconProof(ctx context.Context, height int64, keyHash []byte) ([]byte, error) { diff --git a/relayer/chains/icon/utils.go b/relayer/chains/icon/utils.go index 12fdf94a5..4c1fc0eda 100644 --- a/relayer/chains/icon/utils.go +++ b/relayer/chains/icon/utils.go @@ -3,6 +3,7 @@ package icon import ( "bytes" "encoding/base64" + "encoding/hex" "fmt" "strings" @@ -197,3 +198,17 @@ func newEthAddressFromPubKey(pubKey []byte) ([]byte, error) { digest := common.Sha3keccak256(pubKey[1:]) return digest[len(digest)-ethAddressLen:], nil } + +func isValidIconContractAddress(addr string) bool { + if !strings.HasPrefix(addr, "cx") { + return false + } + if len(addr) != 42 { + return false + } + _, err := hex.DecodeString(addr[2:]) + if err != nil { + return false + } + return true +} diff --git a/relayer/provider/provider.go b/relayer/provider/provider.go index e16ecdfaf..df8b4d41a 100644 --- a/relayer/provider/provider.go +++ b/relayer/provider/provider.go @@ -236,9 +236,6 @@ type ChainProvider interface { // [Begin] Client IBC message assembly functions NewClientState(dstChainID string, dstIBCHeader IBCHeader, dstTrustingPeriod, dstUbdPeriod time.Duration, allowUpdateAfterExpiry, allowUpdateAfterMisbehaviour bool) (ibcexported.ClientState, error) - // TODO: Remove later - // NewClientStateMock(dstChainID string, dstIBCHeader IBCHeader, dstTrustingPeriod, dstUbdPeriod time.Duration, allowUpdateAfterExpiry, allowUpdateAfterMisbehaviour bool) (ibcexported.ClientState, error) - MsgCreateClient(clientState ibcexported.ClientState, consensusState ibcexported.ConsensusState) (RelayerMessage, error) MsgUpgradeClient(srcClientId string, consRes *clienttypes.QueryConsensusStateResponse, clientRes *clienttypes.QueryClientStateResponse) (RelayerMessage, error)