Skip to content

Commit

Permalink
chore: TODOs for reviews (#115)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: viveksharmapoudel <[email protected]>
  • Loading branch information
3 people authored Jul 25, 2023
1 parent e2431d1 commit 70004a7
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 140 deletions.
4 changes: 4 additions & 0 deletions relayer/chains/archway/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ const (
ConnectionPrefix = "connection"
ChannelPrefix = "channel"
)

const (
ContractAddressSizeMinusPrefix = 59
)
45 changes: 34 additions & 11 deletions relayer/chains/archway/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand All @@ -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 {
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down
33 changes: 20 additions & 13 deletions relayer/chains/archway/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
}

Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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))
}
33 changes: 12 additions & 21 deletions relayer/chains/archway/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -1280,7 +1272,6 @@ func (cc *ArchwayProvider) handleAccountSequenceMismatchError(err error) {
return
}

fmt.Printf("the next sequence is %d \n", seq)
cc.nextAccountSeq = seq
}

Expand Down
12 changes: 0 additions & 12 deletions relayer/chains/cosmos/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 1 addition & 8 deletions relayer/chains/icon/icon_chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 70004a7

Please sign in to comment.