From 6a9bd0297d0c6ef7d2ed6360532c01348ebe3177 Mon Sep 17 00:00:00 2001 From: izyak Date: Thu, 20 Jul 2023 11:26:16 +0545 Subject: [PATCH 01/11] chore: TODOs for reviews --- relayer/chains/archway/provider.go | 10 +++++++--- relayer/chains/archway/query.go | 8 ++++++++ relayer/chains/archway/tx.go | 5 +++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/relayer/chains/archway/provider.go b/relayer/chains/archway/provider.go index ade4acca1..38f0d7f3c 100644 --- a/relayer/chains/archway/provider.go +++ b/relayer/chains/archway/provider.go @@ -188,6 +188,8 @@ func (pp *ArchwayProviderConfig) Validate() error { return fmt.Errorf("invalid Timeout: %w", err) } + // TODO: Valid address for that chain + // Check: COSMOS if pp.IbcHandlerAddress == "" { return fmt.Errorf("Ibc handler contract cannot be empty") } @@ -351,7 +353,9 @@ func (ap *ArchwayProvider) Address() (string, error) { return out, err } +// TODO: CHECK AGAIN func (cc *ArchwayProvider) TrustingPeriod(ctx context.Context) (time.Duration, error) { + panic("Archway: Not Implemented") // res, err := cc.QueryStakingParams(ctx) // TODO: check and rewrite @@ -403,6 +407,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("Archway: Not implemented") // var initial int64 // h, err := cc.RPCClient.Status(ctx) // if err != nil { @@ -427,7 +432,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 +456,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) { + return nil, fmt.Errorf("Not implemented for Archway") } func (cc *ArchwayProvider) FirstRetryBlockAfter() uint64 { diff --git a/relayer/chains/archway/query.go b/relayer/chains/archway/query.go index 664f7d0eb..f504a3608 100644 --- a/relayer/chains/archway/query.go +++ b/relayer/chains/archway/query.go @@ -95,6 +95,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 @@ -190,6 +191,7 @@ func DefaultPageRequest() *querytypes.PageRequest { // staking func (ap *ArchwayProvider) QueryUnbondingPeriod(context.Context) (time.Duration, error) { + // move to provider, panic return 0, nil } @@ -207,6 +209,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) @@ -330,6 +333,7 @@ func (ap *ArchwayProvider) QueryIBCHandlerContractProcessed(ctx context.Context, return ProcessContractResponse(res) } +// TODO: Panic for unused functions func (ap *ArchwayProvider) QueryUpgradedClient(ctx context.Context, height int64) (*clienttypes.QueryClientStateResponse, error) { return nil, fmt.Errorf("Not implemented for Archway") } @@ -534,6 +538,7 @@ func (ap *ArchwayProvider) QueryConnections(ctx context.Context) (conns []*connt } // Only return open conenctions + // TODO: Use ENUM if conn.State == 3 { identifiedConn := conntypes.IdentifiedConnection{ Id: connectionId, @@ -653,6 +658,7 @@ func (ap *ArchwayProvider) QueryChannels(ctx context.Context) ([]*chantypes.Iden } // check if the channel is open + // TODO: Use enum if channel.State == 3 { identifiedChannel := chantypes.IdentifiedChannel{ State: channel.State, @@ -670,6 +676,8 @@ func (ap *ArchwayProvider) QueryChannels(ctx context.Context) ([]*chantypes.Iden return channels, nil } + +// TODO: panic or implement 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") } diff --git a/relayer/chains/archway/tx.go b/relayer/chains/archway/tx.go index 2893d31fc..2667fa534 100644 --- a/relayer/chains/archway/tx.go +++ b/relayer/chains/archway/tx.go @@ -132,6 +132,7 @@ func (ap *ArchwayProvider) PrepareFactory(txf tx.Factory) (tx.Factory, error) { } } + // CHECK : RESON FOR TXN COST 1 if ap.PCfg.MinGasAmount != 0 { txf = txf.WithGas(ap.PCfg.MinGasAmount) } @@ -164,6 +165,7 @@ func (ap *ArchwayProvider) NewClientState(dstChainID string, dstIBCHeader provid }, nil } +// TODO: DELETE func (ap *ArchwayProvider) NewClientStateMock(dstChainID string, dstIBCHeader provider.IBCHeader, dstTrustingPeriod, dstUbdPeriod time.Duration, allowUpdateAfterExpiry, allowUpdateAfterMisbehaviour bool) (ibcexported.ClientState, error) { btpHeader := dstIBCHeader.(*iconchain.IconIBCHeader) @@ -241,6 +243,7 @@ func (ap *ArchwayProvider) ValidatePacket(msgTransfer provider.PacketInfo, lates return nil } +// TODO MOVE TO QUERY func (ap *ArchwayProvider) PacketCommitment(ctx context.Context, msgTransfer provider.PacketInfo, height uint64) (provider.PacketProof, error) { packetCommitmentResponse, err := ap.QueryPacketCommitment( ctx, int64(height), msgTransfer.SourceChannel, msgTransfer.SourcePort, msgTransfer.Sequence, @@ -348,6 +351,7 @@ func (ap *ArchwayProvider) MsgTimeoutRequest(msgTransfer provider.PacketInfo, pr return nil, fmt.Errorf("MsgTimeoutRequest Not implemented for Archway module") } +// panic func (ap *ArchwayProvider) MsgTimeoutOnClose(msgTransfer provider.PacketInfo, proofUnreceived provider.PacketProof) (provider.RelayerMessage, error) { return nil, nil } @@ -1033,6 +1037,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 From c7e5f3736351b2792d451984e64dc4096693c6a1 Mon Sep 17 00:00:00 2001 From: izyak Date: Tue, 25 Jul 2023 11:01:32 +0545 Subject: [PATCH 02/11] chore: remove move method from interface --- relayer/chains/archway/tx.go | 16 ---------------- relayer/chains/icon/provider.go | 32 -------------------------------- relayer/provider/provider.go | 3 --- 3 files changed, 51 deletions(-) diff --git a/relayer/chains/archway/tx.go b/relayer/chains/archway/tx.go index 2667fa534..493c4e2d0 100644 --- a/relayer/chains/archway/tx.go +++ b/relayer/chains/archway/tx.go @@ -34,9 +34,7 @@ import ( rpcclient "github.com/cometbft/cometbft/rpc/client" conntypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" - iconchain "github.com/cosmos/relayer/v2/relayer/chains/icon" "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" @@ -165,20 +163,6 @@ func (ap *ArchwayProvider) NewClientState(dstChainID string, dstIBCHeader provid }, nil } -// TODO: DELETE -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(), - NetworkSectionHash: btpHeader.Header.PrevNetworkSectionHash, - Validators: btpHeader.Validators, - }, nil -} func (ap *ArchwayProvider) MsgCreateClient(clientState ibcexported.ClientState, consensusState ibcexported.ConsensusState) (provider.RelayerMessage, error) { signer, err := ap.Address() diff --git a/relayer/chains/icon/provider.go b/relayer/chains/icon/provider.go index 6e51bdf42..fbb1f5774 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" @@ -195,37 +194,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, 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) From 30a600fe9e265ded132e2acb906ade86a6590fe6 Mon Sep 17 00:00:00 2001 From: izyak Date: Tue, 25 Jul 2023 11:01:58 +0545 Subject: [PATCH 03/11] chore: panic unimplemented methods --- relayer/chains/archway/query.go | 26 +++++++++++---------- relayer/chains/archway/tx.go | 20 ++++++++-------- relayer/chains/cosmos/tx.go | 12 ---------- relayer/chains/icon/provider.go | 13 ++++++----- relayer/chains/icon/query.go | 41 ++++++++++++++------------------- 5 files changed, 48 insertions(+), 64 deletions(-) diff --git a/relayer/chains/archway/query.go b/relayer/chains/archway/query.go index f504a3608..abc8f1950 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) @@ -333,13 +336,12 @@ func (ap *ArchwayProvider) QueryIBCHandlerContractProcessed(ctx context.Context, return ProcessContractResponse(res) } -// TODO: Panic for unused functions 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) { @@ -556,7 +558,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, @@ -617,7 +619,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) { @@ -679,19 +681,19 @@ func (ap *ArchwayProvider) QueryChannels(ctx context.Context) ([]*chantypes.Iden // TODO: panic or implement 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) { @@ -796,8 +798,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 493c4e2d0..9202d8873 100644 --- a/relayer/chains/archway/tx.go +++ b/relayer/chains/archway/tx.go @@ -163,7 +163,6 @@ func (ap *ArchwayProvider) NewClientState(dstChainID string, dstIBCHeader provid }, nil } - func (ap *ArchwayProvider) MsgCreateClient(clientState ibcexported.ClientState, consensusState ibcexported.ConsensusState) (provider.RelayerMessage, error) { signer, err := ap.Address() if err != nil { @@ -190,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 { @@ -227,7 +226,6 @@ func (ap *ArchwayProvider) ValidatePacket(msgTransfer provider.PacketInfo, lates return nil } -// TODO MOVE TO QUERY func (ap *ArchwayProvider) PacketCommitment(ctx context.Context, msgTransfer provider.PacketInfo, height uint64) (provider.PacketProof, error) { packetCommitmentResponse, err := ap.QueryPacketCommitment( ctx, int64(height), msgTransfer.SourceChannel, msgTransfer.SourcePort, msgTransfer.Sequence, @@ -278,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") } @@ -332,11 +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 } @@ -640,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,7 +1033,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( @@ -1270,7 +1271,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/provider.go b/relayer/chains/icon/provider.go index fbb1f5774..3129534b5 100644 --- a/relayer/chains/icon/provider.go +++ b/relayer/chains/icon/provider.go @@ -44,6 +44,8 @@ var ( Identifier: DefaultIBCVersionIdentifier, Features: []string{"ORDER_ORDERED", "ORDER_UNORDERED"}, } + + NOT_IMPLEMENTED = " :: Not implemented for ICON" ) type IconProviderConfig struct { @@ -194,7 +196,6 @@ func (icp *IconProvider) Init(ctx context.Context) error { return nil } - func (icp *IconProvider) NewClientState( dstChainID string, dstUpdateHeader provider.IBCHeader, @@ -356,15 +357,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) { @@ -404,7 +405,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 { @@ -534,7 +535,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/query.go b/relayer/chains/icon/query.go index 8b23267e7..4ae8d9806 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 @@ -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 @@ -646,25 +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 @@ -791,12 +784,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) { From d62785df2b0f1462c5bfe17ee7c46c56778e411f Mon Sep 17 00:00:00 2001 From: izyak Date: Tue, 25 Jul 2023 12:43:32 +0545 Subject: [PATCH 04/11] feat: Validate archway and icon addresses --- relayer/chains/archway/provider.go | 8 ++++---- relayer/chains/icon/provider.go | 2 +- relayer/chains/icon/provider_test.go | 7 +++++++ relayer/chains/icon/utils.go | 15 +++++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/relayer/chains/archway/provider.go b/relayer/chains/archway/provider.go index 38f0d7f3c..feb44d207 100644 --- a/relayer/chains/archway/provider.go +++ b/relayer/chains/archway/provider.go @@ -14,6 +14,7 @@ import ( comettypes "github.com/cometbft/cometbft/types" "github.com/cosmos/cosmos-sdk/client" + sdk "github.com/cosmos/cosmos-sdk/types" itm "github.com/icon-project/IBC-Integration/libraries/go/common/tendermint" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" @@ -188,10 +189,9 @@ func (pp *ArchwayProviderConfig) Validate() error { return fmt.Errorf("invalid Timeout: %w", err) } - // TODO: Valid address for that chain - // Check: COSMOS - if pp.IbcHandlerAddress == "" { - return fmt.Errorf("Ibc handler contract cannot be empty") + _, err := sdk.ValAddressFromBech32(pp.IbcHandlerAddress) + if err != nil { + return err } return nil } diff --git a/relayer/chains/icon/provider.go b/relayer/chains/icon/provider.go index 3129534b5..c337ec822 100644 --- a/relayer/chains/icon/provider.go +++ b/relayer/chains/icon/provider.go @@ -69,7 +69,7 @@ func (pp *IconProviderConfig) Validate() error { return fmt.Errorf("invalid Timeout: %w", err) } - if pp.IbcHandlerAddress == "" { + if !isValidIconAddress(pp.IbcHandlerAddress) { return fmt.Errorf("Ibc handler Address cannot be empty") } diff --git a/relayer/chains/icon/provider_test.go b/relayer/chains/icon/provider_test.go index 79f6c6a32..d5b547048 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 := isValidIconAddress(testCA) + assert.True(t, b) + + assert.False(t, isValidIconAddress(testCA[1:])) +} + func TestConnectionDecode(t *testing.T) { input := types.HexBytes("0a0f30372d74656e6465726d696e742d3012230a0131120d4f524445525f4f524445524544120f4f524445525f554e4f524445524544180322200a0f30372d74656e6465726d696e742d30120d636f6e6e656374696f6e2d3533") diff --git a/relayer/chains/icon/utils.go b/relayer/chains/icon/utils.go index 12fdf94a5..4bf51255f 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 isValidIconAddress(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 +} From bfec5837c3295d9134ff15a16d8a9de9dbb7f710 Mon Sep 17 00:00:00 2001 From: izyak Date: Tue, 25 Jul 2023 12:49:52 +0545 Subject: [PATCH 05/11] chore: comments --- relayer/chains/archway/provider.go | 18 +++++++++--------- relayer/chains/archway/tx.go | 1 - 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/relayer/chains/archway/provider.go b/relayer/chains/archway/provider.go index feb44d207..32d4905e1 100644 --- a/relayer/chains/archway/provider.go +++ b/relayer/chains/archway/provider.go @@ -355,11 +355,11 @@ func (ap *ArchwayProvider) Address() (string, error) { // TODO: CHECK AGAIN func (cc *ArchwayProvider) TrustingPeriod(ctx context.Context) (time.Duration, error) { - panic("Archway: Not Implemented") + 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) @@ -378,15 +378,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) { @@ -407,7 +407,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("Archway: Not implemented") + panic(fmt.Sprintf("%s%s", cc.ChainName(), NOT_IMPLEMENTED)) // var initial int64 // h, err := cc.RPCClient.Status(ctx) // if err != nil { @@ -457,7 +457,7 @@ func (ap *ArchwayProvider) updateNextAccountSequence(seq uint64) { } func (ap *ArchwayProvider) MsgRegisterCounterpartyPayee(portID, channelID, relayerAddr, counterpartyPayeeAddr string) (provider.RelayerMessage, error) { - return nil, fmt.Errorf("Not implemented for Archway") + panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } func (cc *ArchwayProvider) FirstRetryBlockAfter() uint64 { diff --git a/relayer/chains/archway/tx.go b/relayer/chains/archway/tx.go index b2b844371..a5312a02f 100644 --- a/relayer/chains/archway/tx.go +++ b/relayer/chains/archway/tx.go @@ -131,7 +131,6 @@ func (ap *ArchwayProvider) PrepareFactory(txf tx.Factory) (tx.Factory, error) { } } - // CHECK : RESON FOR TXN COST 1 if ap.PCfg.MinGasAmount != 0 { txf = txf.WithGas(ap.PCfg.MinGasAmount) } From 64255eec0b5e267fb344087bbff55dca556b986f Mon Sep 17 00:00:00 2001 From: izyak Date: Tue, 25 Jul 2023 12:50:03 +0545 Subject: [PATCH 06/11] chore: use enums to compare --- relayer/chains/archway/query.go | 6 ++---- relayer/chains/icon/query.go | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/relayer/chains/archway/query.go b/relayer/chains/archway/query.go index 70f949258..54d31f1b9 100644 --- a/relayer/chains/archway/query.go +++ b/relayer/chains/archway/query.go @@ -552,8 +552,7 @@ func (ap *ArchwayProvider) QueryConnections(ctx context.Context) (conns []*connt } // Only return open conenctions - // TODO: Use ENUM - if conn.State == 3 { + if conn.State == conntypes.OPEN { identifiedConn := conntypes.IdentifiedConnection{ Id: connectionId, ClientId: conn.ClientId, @@ -673,7 +672,7 @@ func (ap *ArchwayProvider) QueryChannels(ctx context.Context) ([]*chantypes.Iden // check if the channel is open // TODO: Use enum - if channel.State == 3 { + if channel.State == chantypes.OPEN { identifiedChannel := chantypes.IdentifiedChannel{ State: channel.State, Ordering: channel.Ordering, @@ -691,7 +690,6 @@ func (ap *ArchwayProvider) QueryChannels(ctx context.Context) ([]*chantypes.Iden return channels, nil } -// TODO: panic or implement func (ap *ArchwayProvider) QueryPacketCommitments(ctx context.Context, height uint64, channelid, portid string) (commitments *chantypes.QueryPacketCommitmentsResponse, err error) { panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED)) } diff --git a/relayer/chains/icon/query.go b/relayer/chains/icon/query.go index 4ae8d9806..2aa33e406 100644 --- a/relayer/chains/icon/query.go +++ b/relayer/chains/icon/query.go @@ -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, @@ -623,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, From 8b0896874da6f695ceb077a561c96a617c8ef5be Mon Sep 17 00:00:00 2001 From: izyak Date: Tue, 25 Jul 2023 13:33:02 +0545 Subject: [PATCH 07/11] feat: contract address validation --- relayer/chains/archway/provider.go | 27 +++++++++++++++++++++++---- relayer/chains/archway/query.go | 1 - 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/relayer/chains/archway/provider.go b/relayer/chains/archway/provider.go index 32d4905e1..4f5a64fbb 100644 --- a/relayer/chains/archway/provider.go +++ b/relayer/chains/archway/provider.go @@ -14,7 +14,6 @@ import ( comettypes "github.com/cometbft/cometbft/types" "github.com/cosmos/cosmos-sdk/client" - sdk "github.com/cosmos/cosmos-sdk/types" itm "github.com/icon-project/IBC-Integration/libraries/go/common/tendermint" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" @@ -23,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" @@ -184,15 +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+59 { + return false + } + + return true +} + func (pp *ArchwayProviderConfig) Validate() error { if _, err := time.ParseDuration(pp.Timeout); err != nil { return fmt.Errorf("invalid Timeout: %w", err) } - _, err := sdk.ValAddressFromBech32(pp.IbcHandlerAddress) - if err != nil { - return err + if !pp.ValidateContractAddress(pp.IbcHandlerAddress) { + return fmt.Errorf("Invalid contract address") } + return nil } diff --git a/relayer/chains/archway/query.go b/relayer/chains/archway/query.go index 54d31f1b9..3b1610239 100644 --- a/relayer/chains/archway/query.go +++ b/relayer/chains/archway/query.go @@ -671,7 +671,6 @@ func (ap *ArchwayProvider) QueryChannels(ctx context.Context) ([]*chantypes.Iden } // check if the channel is open - // TODO: Use enum if channel.State == chantypes.OPEN { identifiedChannel := chantypes.IdentifiedChannel{ State: channel.State, From 4139a6299c5f6b5e7256f1ac7e1d3a6e8f641dd9 Mon Sep 17 00:00:00 2001 From: izyak Date: Tue, 25 Jul 2023 13:42:11 +0545 Subject: [PATCH 08/11] chore: rename method for contract address --- relayer/chains/icon/provider.go | 2 +- relayer/chains/icon/provider_test.go | 4 ++-- relayer/chains/icon/utils.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/relayer/chains/icon/provider.go b/relayer/chains/icon/provider.go index 2f152dc83..b736f305c 100644 --- a/relayer/chains/icon/provider.go +++ b/relayer/chains/icon/provider.go @@ -70,7 +70,7 @@ func (pp *IconProviderConfig) Validate() error { return fmt.Errorf("invalid Timeout: %w", err) } - if !isValidIconAddress(pp.IbcHandlerAddress) { + if !isValidIconContractAddress(pp.IbcHandlerAddress) { return fmt.Errorf("Ibc handler Address cannot be empty") } diff --git a/relayer/chains/icon/provider_test.go b/relayer/chains/icon/provider_test.go index d5b547048..3590126c4 100644 --- a/relayer/chains/icon/provider_test.go +++ b/relayer/chains/icon/provider_test.go @@ -24,10 +24,10 @@ const ( ) func TestAddr(t *testing.T) { - b := isValidIconAddress(testCA) + b := isValidIconContractAddress(testCA) assert.True(t, b) - assert.False(t, isValidIconAddress(testCA[1:])) + assert.False(t, isValidIconContractAddress(testCA[1:])) } func TestConnectionDecode(t *testing.T) { diff --git a/relayer/chains/icon/utils.go b/relayer/chains/icon/utils.go index 4bf51255f..4c1fc0eda 100644 --- a/relayer/chains/icon/utils.go +++ b/relayer/chains/icon/utils.go @@ -199,7 +199,7 @@ func newEthAddressFromPubKey(pubKey []byte) ([]byte, error) { return digest[len(digest)-ethAddressLen:], nil } -func isValidIconAddress(addr string) bool { +func isValidIconContractAddress(addr string) bool { if !strings.HasPrefix(addr, "cx") { return false } From 7d891ca764225efc7398c7b6a9ad8427e34c10e0 Mon Sep 17 00:00:00 2001 From: viveksharmapoudel Date: Tue, 25 Jul 2023 14:01:57 +0545 Subject: [PATCH 09/11] fix: remove some comments --- relayer/chains/icon/icon_chain_processor.go | 9 +-------- relayer/chains/icon/message_handler.go | 2 -- relayer/chains/icon/query.go | 4 ---- 3 files changed, 1 insertion(+), 14 deletions(-) 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/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/query.go b/relayer/chains/icon/query.go index 2aa33e406..a17dec281 100644 --- a/relayer/chains/icon/query.go +++ b/relayer/chains/icon/query.go @@ -650,17 +650,14 @@ func (icp *IconProvider) QueryPacketAcknowledgements(ctx context.Context, height 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) { 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) { 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, @@ -670,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)))) From ed29c9274f478fea15df13f3d918122c72216623 Mon Sep 17 00:00:00 2001 From: izyak Date: Tue, 25 Jul 2023 14:08:25 +0545 Subject: [PATCH 10/11] chore: save contract addrss size to const --- relayer/chains/archway/consts.go | 4 ++++ relayer/chains/archway/provider.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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 4f5a64fbb..700b359df 100644 --- a/relayer/chains/archway/provider.go +++ b/relayer/chains/archway/provider.go @@ -196,7 +196,7 @@ func (pp *ArchwayProviderConfig) ValidateContractAddress(addr string) bool { // TODO: Is this needed? // Confirmed working for neutron, archway, osmosis prefixLen := len(pp.AccountPrefix) - if len(addr) != prefixLen+59 { + if len(addr) != prefixLen+ContractAddressSizeMinusPrefix { return false } From 176c55e5ac69f26695d8401a91a6066ef2cfeebf Mon Sep 17 00:00:00 2001 From: izyak Date: Tue, 25 Jul 2023 14:26:33 +0545 Subject: [PATCH 11/11] chore: use actual address to fix tests --- relayer/chains/icon/keys_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)