Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: TODOs for reviews #115

Merged
merged 15 commits into from
Jul 25, 2023
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 @@
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 @@
return false
}

func (pp *ArchwayProviderConfig) ValidateContractAddress(addr string) bool {
prefix, _, err := bech32.DecodeAndConvert(addr)
if err != nil {
return false
}

Check warning on line 191 in relayer/chains/archway/provider.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/provider.go#L190-L191

Added lines #L190 - L191 were not covered by tests
if pp.AccountPrefix != prefix {
return false
}

Check warning on line 194 in relayer/chains/archway/provider.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/provider.go#L193-L194

Added lines #L193 - L194 were not covered by tests

// TODO: Is this needed?
// Confirmed working for neutron, archway, osmosis
prefixLen := len(pp.AccountPrefix)
if len(addr) != prefixLen+ContractAddressSizeMinusPrefix {
return false
}

Check warning on line 201 in relayer/chains/archway/provider.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/provider.go#L200-L201

Added lines #L200 - L201 were not covered by tests

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")

Check warning on line 212 in relayer/chains/archway/provider.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/provider.go#L212

Added line #L212 was not covered by tests
}

return nil
}

Expand Down Expand Up @@ -351,11 +372,13 @@
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))

Check warning on line 377 in relayer/chains/archway/provider.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/provider.go#L377

Added line #L377 was not covered by tests
// 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 @@
// // 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 @@

// 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))

Check warning on line 429 in relayer/chains/archway/provider.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/provider.go#L429

Added line #L429 was not covered by tests
// var initial int64
// h, err := cc.RPCClient.Status(ctx)
// if err != nil {
Expand All @@ -427,7 +451,6 @@
// return ctx.Err()
// }
// }
return nil
}

func (ac *ArchwayProvider) BlockTime(ctx context.Context, height int64) (time.Time, error) {
Expand All @@ -452,15 +475,15 @@
}
}

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))

Check warning on line 479 in relayer/chains/archway/provider.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/provider.go#L478-L479

Added lines #L478 - L479 were not covered by tests
}

func (cc *ArchwayProvider) FirstRetryBlockAfter() uint64 {
if cc.PCfg.FirstRetryBlockAfter != 0 {
return cc.PCfg.FirstRetryBlockAfter
}
return 3

Check warning on line 486 in relayer/chains/archway/provider.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/provider.go#L482-L486

Added lines #L482 - L486 were not covered by tests
}

// keysDir returns a string representing the path on the local filesystem where the keystore will be initialized.
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 @@
"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 @@

// 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 @@ -135,16 +139,16 @@
return NewArchwayIBCHeaderFromLightBlock(lightBlock), nil
}

func (ap *ArchwayProvider) QueryLightBlock(ctx context.Context, h int64) (provider.IBCHeader, *tmtypes.LightBlock, error) {
if h == 0 {
return nil, nil, fmt.Errorf("No header at height 0")
}
lightBlock, err := ap.LightProvider.LightBlock(ctx, h)
if err != nil {
return nil, nil, err
}

Check warning on line 149 in relayer/chains/archway/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/query.go#L142-L149

Added lines #L142 - L149 were not covered by tests

return NewArchwayIBCHeaderFromLightBlock(lightBlock), lightBlock, nil

Check warning on line 151 in relayer/chains/archway/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/query.go#L151

Added line #L151 was not covered by tests
}

// query packet info for sequence
Expand Down Expand Up @@ -202,6 +206,7 @@

// staking
func (ap *ArchwayProvider) QueryUnbondingPeriod(context.Context) (time.Duration, error) {
// move to provider, panic

Check warning on line 209 in relayer/chains/archway/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/query.go#L209

Added line #L209 was not covered by tests
return 0, nil
}

Expand All @@ -219,6 +224,7 @@
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) 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))

Check warning on line 352 in relayer/chains/archway/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/query.go#L352

Added line #L352 was not covered by tests
}

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))

Check warning on line 356 in relayer/chains/archway/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/query.go#L356

Added line #L356 was not covered by tests
}

func (ap *ArchwayProvider) QueryConsensusState(ctx context.Context, height int64) (ibcexported.ConsensusState, int64, error) {
Expand Down Expand Up @@ -546,7 +552,7 @@
}

// Only return open conenctions
if conn.State == 3 {
if conn.State == conntypes.OPEN {

Check warning on line 555 in relayer/chains/archway/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/query.go#L555

Added line #L555 was not covered by tests
identifiedConn := conntypes.IdentifiedConnection{
Id: connectionId,
ClientId: conn.ClientId,
Expand All @@ -563,7 +569,7 @@
}

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))

Check warning on line 572 in relayer/chains/archway/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/query.go#L572

Added line #L572 was not covered by tests
}

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) 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))

Check warning on line 633 in relayer/chains/archway/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/query.go#L633

Added line #L633 was not covered by tests
}

func (ap *ArchwayProvider) QueryConnectionChannels(ctx context.Context, height int64, connectionid string) ([]*chantypes.IdentifiedChannel, error) {
Expand Down Expand Up @@ -665,7 +671,7 @@
}

// check if the channel is open
if channel.State == 3 {
if channel.State == chantypes.OPEN {

Check warning on line 674 in relayer/chains/archway/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/query.go#L674

Added line #L674 was not covered by tests
identifiedChannel := chantypes.IdentifiedChannel{
State: channel.State,
Ordering: channel.Ordering,
Expand All @@ -682,20 +688,21 @@

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))

Check warning on line 693 in relayer/chains/archway/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/query.go#L693

Added line #L693 was not covered by tests
}

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))

Check warning on line 697 in relayer/chains/archway/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/query.go#L697

Added line #L697 was not covered by tests
}

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))

Check warning on line 701 in relayer/chains/archway/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/query.go#L701

Added line #L701 was not covered by tests
}

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))

Check warning on line 705 in relayer/chains/archway/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/query.go#L705

Added line #L705 was not covered by tests
}

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 @@

// 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))

Check warning on line 810 in relayer/chains/archway/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/query.go#L810

Added line #L810 was not covered by tests
}
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))

Check warning on line 813 in relayer/chains/archway/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/query.go#L813

Added line #L813 was not covered by tests
}
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 @@
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 @@ -72,8 +71,8 @@
WithGasAdjustment(ap.PCfg.GasAdjustment).
WithGasPrices(ap.PCfg.GasPrices).
WithKeybase(ap.Keybase).
WithSignMode(ap.PCfg.SignMode()).
WithSimulateAndExecute(true)

Check warning on line 75 in relayer/chains/archway/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/tx.go#L74-L75

Added lines #L74 - L75 were not covered by tests
}

// PrepareFactory mutates the tx factory with the appropriate account number, sequence number, and min gas settings.
Expand Down Expand Up @@ -164,18 +163,6 @@
}, 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) 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))

Check warning on line 192 in relayer/chains/archway/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/tx.go#L192

Added line #L192 was not covered by tests
}

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))

Check warning on line 196 in relayer/chains/archway/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/tx.go#L196

Added line #L196 was not covered by tests
}

func (ap *ArchwayProvider) ValidatePacket(msgTransfer provider.PacketInfo, latest provider.LatestBlock) error {
Expand Down Expand Up @@ -289,6 +276,7 @@
}

func (ap *ArchwayProvider) MsgTransfer(dstAddr string, amount sdk.Coin, info provider.PacketInfo) (provider.RelayerMessage, error) {
panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED))

Check warning on line 279 in relayer/chains/archway/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/tx.go#L279

Added line #L279 was not covered by tests
return nil, fmt.Errorf("Not implemented for Archway")
}

Expand Down Expand Up @@ -343,10 +331,13 @@
}

func (ap *ArchwayProvider) MsgTimeoutRequest(msgTransfer provider.PacketInfo, proof provider.PacketProof) (provider.RelayerMessage, error) {
panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED))

Check warning on line 334 in relayer/chains/archway/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/tx.go#L334

Added line #L334 was not covered by tests
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))

Check warning on line 340 in relayer/chains/archway/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/tx.go#L340

Added line #L340 was not covered by tests
return nil, nil
}

Expand Down Expand Up @@ -650,19 +641,19 @@
}

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))

Check warning on line 644 in relayer/chains/archway/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/tx.go#L644

Added line #L644 was not covered by tests
}

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))

Check warning on line 648 in relayer/chains/archway/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/tx.go#L648

Added line #L648 was not covered by tests
}

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))

Check warning on line 652 in relayer/chains/archway/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/tx.go#L652

Added line #L652 was not covered by tests
}

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))

Check warning on line 656 in relayer/chains/archway/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/tx.go#L656

Added line #L656 was not covered by tests
}

func (ap *ArchwayProvider) SendMessage(ctx context.Context, msg provider.RelayerMessage, memo string) (*provider.RelayerTxResponse, bool, error) {
Expand All @@ -677,12 +668,12 @@
)

callback := func(rtr *provider.RelayerTxResponse, err error) {
callbackErr = err

if err != nil {
wg.Done()
return
}

Check warning on line 676 in relayer/chains/archway/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/tx.go#L671-L676

Added lines #L671 - L676 were not covered by tests

for i, e := range rtr.Events {
if startsWithWasm(e.EventType) {
Expand Down Expand Up @@ -756,21 +747,21 @@
}

if msg.Type() == MethodUpdateClient {
if err := ap.BroadcastTx(cliCtx, txBytes, []provider.RelayerMessage{msg}, asyncCtx, defaultBroadcastWaitTimeout, asyncCallback, true); err != nil {
if strings.Contains(err.Error(), sdkerrors.ErrWrongSequence.Error()) {
ap.handleAccountSequenceMismatchError(err)
}
return fmt.Errorf("Archway: failed during updateClient %v", err)

Check warning on line 754 in relayer/chains/archway/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/tx.go#L750-L754

Added lines #L750 - L754 were not covered by tests
}
ap.updateNextAccountSequence(sequence + 1)

Check warning on line 756 in relayer/chains/archway/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/tx.go#L756

Added line #L756 was not covered by tests
continue
}
if err := ap.BroadcastTx(cliCtx, txBytes, []provider.RelayerMessage{msg}, asyncCtx, defaultBroadcastWaitTimeout, asyncCallback, false); err != nil {
if strings.Contains(err.Error(), sdkerrors.ErrWrongSequence.Error()) {
ap.handleAccountSequenceMismatchError(err)
}

Check warning on line 762 in relayer/chains/archway/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/tx.go#L759-L762

Added lines #L759 - L762 were not covered by tests
}
ap.updateNextAccountSequence(sequence + 1)

Check warning on line 764 in relayer/chains/archway/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/tx.go#L764

Added line #L764 was not covered by tests
}

//uncomment for saving msg
Expand Down Expand Up @@ -1032,6 +1023,7 @@
// 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 @@
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))

Check warning on line 1037 in relayer/chains/archway/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/tx.go#L1037

Added line #L1037 was not covered by tests
}

func (ap *ArchwayProvider) waitForTx(
Expand Down Expand Up @@ -1264,24 +1256,23 @@
return result.Response, nil
}

func (cc *ArchwayProvider) handleAccountSequenceMismatchError(err error) {

clientCtx := cc.ClientContext()
fmt.Println("client context is ", clientCtx.GetFromAddress())

_, seq, err := cc.ClientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, clientCtx.GetFromAddress())

// sequences := numRegex.FindAllString(err.Error(), -1)
// if len(sequences) != 2 {
// return
// }
// nextSeq, err := strconv.ParseUint(sequences[0], 10, 64)
if err != nil {
return
}

Check warning on line 1273 in relayer/chains/archway/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/tx.go#L1259-L1273

Added lines #L1259 - L1273 were not covered by tests

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

Check warning on line 1275 in relayer/chains/archway/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/archway/tx.go#L1275

Added line #L1275 was not covered by tests
}

func sdkErrorToGRPCError(resp abci.ResponseQuery) error {
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 @@ -153,7 +153,7 @@
}

func (icp *IconChainProcessor) initializeConnectionState(ctx context.Context) error {
// TODO: review

Check warning on line 156 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L156

Added line #L156 was not covered by tests
ctx, cancel := context.WithTimeout(ctx, queryTimeout)
defer cancel()

Expand Down Expand Up @@ -227,7 +227,6 @@
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 All @@ -249,7 +248,7 @@
}

var err error
processedheight := int64(icp.chainProvider.StartHeight)

Check warning on line 251 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L251

Added line #L251 was not covered by tests
if processedheight == 0 {
processedheight, err = icp.chainProvider.QueryLatestHeight(ctx)
if err != nil {
Expand All @@ -266,7 +265,7 @@
icp.firstTime = true

blockReq := &types.BlockRequest{
Height: types.NewHexInt(int64(icp.chainProvider.PCfg.StartHeight)),

Check warning on line 268 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L268

Added line #L268 was not covered by tests
EventFilters: GetMonitorEventFilters(icp.chainProvider.PCfg.IbcHandlerAddress),
}

Expand Down Expand Up @@ -304,15 +303,15 @@
}(ctxMonitorBlock, cancelMonitorBlock)
case br := <-btpBlockRespCh:
for ; br != nil; processedheight++ {
// verify BTP Block
err := icp.verifyBlock(ctx, br.Header)
if err != nil {
reconnect()
icp.log.Warn("failed to Verify BTP Block",
zap.Int64("got", br.Height),
zap.Error(err),
)
break

Check warning on line 314 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L306-L314

Added lines #L306 - L314 were not covered by tests
}

icp.latestBlock = provider.LatestBlock{
Expand All @@ -330,7 +329,7 @@
icp.log.Info("Queried Latest height: ",
zap.String("chain id ", icp.chainProvider.ChainId()),
zap.Int64("height", br.Height))
err = icp.handlePathProcessorUpdate(ctx, br.Header, ibcMessageCache, ibcHeaderCache)

Check warning on line 332 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L332

Added line #L332 was not covered by tests
if err != nil {
reconnect()
icp.log.Warn("Reconnect: error occured during handle block response ",
Expand All @@ -338,13 +337,7 @@
)
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)

Check warning on line 340 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L340

Added line #L340 was not covered by tests
icp.firstTime = false
if br = nil; len(btpBlockRespCh) > 0 {
br = <-btpBlockRespCh
Expand Down Expand Up @@ -439,62 +432,62 @@
}
}

func (icp *IconChainProcessor) verifyBlock(ctx context.Context, ibcHeader provider.IBCHeader) error {
header, ok := ibcHeader.(IconIBCHeader)
if !ok {
return fmt.Errorf("Provided Header is not compatible with IBCHeader")
}
if icp.firstTime {
proofContext, err := icp.chainProvider.GetProofContextByHeight(int64(header.MainHeight) - 1)
if err != nil {
return err
}
icp.verifier = &Verifier{
nextProofContext: proofContext,
verifiedHeight: int64(header.MainHeight) - 1,
}

Check warning on line 448 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L435-L448

Added lines #L435 - L448 were not covered by tests
}

if !ibcHeader.IsCompleteBlock() {
icp.verifier.nextProofContext = header.Validators
icp.verifier.verifiedHeight = int64(header.Height())
return nil
}

Check warning on line 455 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L451-L455

Added lines #L451 - L455 were not covered by tests

// prevNetworkSectionHash would be nil for first block
if icp.verifier.prevNetworkSectionHash != nil &&
!bytes.Equal(icp.verifier.prevNetworkSectionHash, header.Header.PrevNetworkSectionHash) {
return fmt.Errorf("failed to match prevNetworkSectionHash")
}

Check warning on line 461 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L458-L461

Added lines #L458 - L461 were not covered by tests

sigs, err := icp.chainProvider.GetBTPProof(int64(header.MainHeight))
if err != nil {
return err
}

Check warning on line 466 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L463-L466

Added lines #L463 - L466 were not covered by tests

decision := types.NewNetworkTypeSectionDecision(
getSrcNetworkId(icp.chainProvider.PCfg.ICONNetworkID),
icp.chainProvider.PCfg.BTPNetworkTypeID,
int64(header.MainHeight),
header.Header.Round,
types.NetworkTypeSection{
NextProofContextHash: header.Header.NextProofContextHash,
NetworkSectionsRoot: GetNetworkSectionRoot(header.Header),
})

valid, err := VerifyBtpProof(decision, sigs, icp.verifier.nextProofContext)
if err != nil {
return err
}

Check warning on line 481 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L468-L481

Added lines #L468 - L481 were not covered by tests

if !valid {
return fmt.Errorf("failed to Verify block")
}

Check warning on line 485 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L483-L485

Added lines #L483 - L485 were not covered by tests

icp.verifier.nextProofContext = header.Validators
icp.verifier.verifiedHeight = int64(header.Height())
icp.verifier.prevNetworkSectionHash = types.NewNetworkSection(header.Header).Hash()
return nil

Check warning on line 490 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L487-L490

Added lines #L487 - L490 were not covered by tests
}

func (icp *IconChainProcessor) handleBTPBlockRequest(
Expand Down Expand Up @@ -641,9 +634,9 @@
// clientState will return the most recent client state if client messages
// have already been observed for the clientID, otherwise it will query for it.
func (icp *IconChainProcessor) clientState(ctx context.Context, clientID string) (provider.ClientState, error) {
if state, ok := icp.latestClientState[clientID]; ok {
return state, nil
}

Check warning on line 639 in relayer/chains/icon/icon_chain_processor.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/icon/icon_chain_processor.go#L637-L639

Added lines #L637 - L639 were not covered by tests
cs, err := icp.chainProvider.QueryClientStateWithoutProof(ctx, int64(icp.latestBlock.Height), clientID)
if err != nil {
return provider.ClientState{}, err
Expand Down
Loading
Loading