From b2ae26492866b9e7f913765dca1f3682bfa19155 Mon Sep 17 00:00:00 2001 From: tbjump Date: Wed, 3 May 2023 22:33:03 +0000 Subject: [PATCH] node/watchers/ibc: fix linter warnings --- node/pkg/watchers/ibc/watcher.go | 22 +++++++++++++--------- node/pkg/watchers/ibc/watcher_test.go | 8 ++++---- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/node/pkg/watchers/ibc/watcher.go b/node/pkg/watchers/ibc/watcher.go index 286f3cc2b..dde5d1f54 100644 --- a/node/pkg/watchers/ibc/watcher.go +++ b/node/pkg/watchers/ibc/watcher.go @@ -223,7 +223,7 @@ func (w *Watcher) Run(ctx context.Context) error { // Start a routine to periodically query the wormchain block height. common.RunWithScissors(ctx, errC, "ibc_block_height", func(ctx context.Context) error { - return w.handleQueryBlockHeight(ctx, c) + return w.handleQueryBlockHeight(ctx) }) // Start a routine for each chain to listen for observation requests. @@ -292,7 +292,7 @@ func (w *Watcher) handleEvents(ctx context.Context, c *websocket.Conn) error { } if evt != nil { - if err := w.processIbcReceivePublishEvent(txHash, evt, "new"); err != nil { + if err := w.processIbcReceivePublishEvent(evt, "new"); err != nil { return fmt.Errorf("failed to process new IBC event: %w", err) } } @@ -305,7 +305,7 @@ func (w *Watcher) handleEvents(ctx context.Context, c *websocket.Conn) error { } // handleQueryBlockHeight gets the latest block height from wormchain each interval and updates the status on all the connected chains. -func (w *Watcher) handleQueryBlockHeight(ctx context.Context, c *websocket.Conn) error { +func (w *Watcher) handleQueryBlockHeight(ctx context.Context) error { const latestBlockURL = "blocks/latest" t := time.NewTicker(5 * time.Second) @@ -318,7 +318,7 @@ func (w *Watcher) handleQueryBlockHeight(ctx context.Context, c *websocket.Conn) case <-ctx.Done(): return nil case <-t.C: - resp, err := client.Get(fmt.Sprintf("%s/%s", w.lcdUrl, latestBlockURL)) + resp, err := client.Get(fmt.Sprintf("%s/%s", w.lcdUrl, latestBlockURL)) //nolint:noctx // TODO FIXME we should propagate context with Deadline here. if err != nil { return fmt.Errorf("failed to query latest block: %w", err) } @@ -369,7 +369,7 @@ func (w *Watcher) handleObservationRequests(ctx context.Context, ce *chainEntry) } // Query for tx by hash. - resp, err := client.Get(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", w.lcdUrl, reqTxHashStr)) + resp, err := client.Get(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", w.lcdUrl, reqTxHashStr)) //nolint:noctx // TODO FIXME we should propagate context with Deadline here. if err != nil { w.logger.Error("query tx response error", zap.String("chain", ce.chainName), zap.Error(err)) continue @@ -416,7 +416,7 @@ func (w *Watcher) handleObservationRequests(ctx context.Context, ce *chainEntry) } if evt != nil { - if err := w.processIbcReceivePublishEvent(txHash, evt, "reobservation"); err != nil { + if err := w.processIbcReceivePublishEvent(evt, "reobservation"); err != nil { return fmt.Errorf("failed to process reobserved IBC event: %w", err) } } @@ -507,7 +507,7 @@ func parseIbcReceivePublishEvent(logger *zap.Logger, desiredContract string, eve } // processIbcReceivePublishEvent takes an IBC event, maps it to a message publication and publishes it. -func (w *Watcher) processIbcReceivePublishEvent(txHash ethCommon.Hash, evt *ibcReceivePublishEvent, observationType string) error { +func (w *Watcher) processIbcReceivePublishEvent(evt *ibcReceivePublishEvent, observationType string) error { mappedChainID, err := w.getChainIdFromChannelID(evt.ChannelID) if err != nil { w.logger.Error("query for IBC channel ID failed", @@ -657,7 +657,7 @@ func (w *Watcher) queryChannelIdToChainIdMapping() (map[string]vaa.ChainID, erro } query := fmt.Sprintf(`%s/cosmwasm/wasm/v1/contract/%s/smart/%s`, w.lcdUrl, w.contractAddress, allChannelChainsQuery) - resp, err := client.Get(query) + resp, err := client.Get(query) //nolint:noctx // TODO FIXME we should propagate context with Deadline here. if err != nil { return nil, fmt.Errorf("query failed: %w", err) } @@ -691,7 +691,11 @@ func (w *Watcher) queryChannelIdToChainIdMapping() (map[string]vaa.ChainID, erro } channelID := string(channelIdBytes) - chainID := vaa.ChainID(entry[1].(float64)) + chainIdFloat, ok := entry[1].(float64) + if !ok { + return nil, fmt.Errorf("error converting channelId to float64") + } + chainID := vaa.ChainID(chainIdFloat) ret[channelID] = chainID w.logger.Info("IBC channel ID mapping", zap.String("channelID", channelID), zap.Uint16("chainID", uint16(chainID))) } diff --git a/node/pkg/watchers/ibc/watcher_test.go b/node/pkg/watchers/ibc/watcher_test.go index d27b685db..cd704a97d 100644 --- a/node/pkg/watchers/ibc/watcher_test.go +++ b/node/pkg/watchers/ibc/watcher_test.go @@ -208,8 +208,8 @@ func TestParseIbcAllChannelChainsQueryResults(t *testing.T) { require.Equal(t, 2, len(result.Data.ChannelChains)) require.Equal(t, 2, len(result.Data.ChannelChains[0])) - assert.Equal(t, expectedChannStr1, result.Data.ChannelChains[0][0].(string)) - assert.Equal(t, uint16(18), uint16(result.Data.ChannelChains[0][1].(float64))) - assert.Equal(t, expectedChannStr2, result.Data.ChannelChains[1][0].(string)) - assert.Equal(t, uint16(22), uint16(result.Data.ChannelChains[1][1].(float64))) + assert.Equal(t, expectedChannStr1, result.Data.ChannelChains[0][0].(string)) //nolint:forcetypeassert + assert.Equal(t, uint16(18), uint16(result.Data.ChannelChains[0][1].(float64))) //nolint:forcetypeassert + assert.Equal(t, expectedChannStr2, result.Data.ChannelChains[1][0].(string)) //nolint:forcetypeassert + assert.Equal(t, uint16(22), uint16(result.Data.ChannelChains[1][1].(float64))) //nolint:forcetypeassert }