Skip to content

Commit c611125

Browse files
committed
add more cases; specific file for connectors
1 parent 4cb6210 commit c611125

20 files changed

Lines changed: 134 additions & 70 deletions

node/pkg/adminrpc/adminserver.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,12 +1110,13 @@ func (s *nodePrivilegedService) fetchMissing(
11101110
// #nosec G704 -- Admin RPC: BackfillNodes from authorized admin request
11111111
resp, err := c.Do(req)
11121112
if err != nil {
1113+
safeErr := common.SafeErrorForLogging(err, requestURL)
11131114
s.logger.Warn("failed to fetch missing VAA",
11141115
zap.String("node", common.SafeURLForLogging(node)),
11151116
zap.String("chain", chain.String()),
11161117
zap.String("address", addr),
11171118
zap.Uint64("sequence", seq),
1118-
zap.Error(err),
1119+
zap.String("error", safeErr),
11191120
)
11201121
continue
11211122
}
@@ -1132,7 +1133,7 @@ func (s *nodePrivilegedService) fetchMissing(
11321133
if err := json.NewDecoder(resp.Body).Decode(&respBody); err != nil {
11331134
resp.Body.Close()
11341135
s.logger.Warn("failed to decode VAA response",
1135-
zap.String("node", node),
1136+
zap.String("node", common.SafeURLForLogging(node)),
11361137
zap.String("chain", chain.String()),
11371138
zap.String("address", addr),
11381139
zap.Uint64("sequence", seq),
@@ -1146,7 +1147,7 @@ func (s *nodePrivilegedService) fetchMissing(
11461147
if err != nil {
11471148
resp.Body.Close()
11481149
s.logger.Warn("failed to decode VAA body",
1149-
zap.String("node", node),
1150+
zap.String("node", common.SafeURLForLogging(node)),
11501151
zap.String("chain", chain.String()),
11511152
zap.String("address", addr),
11521153
zap.Uint64("sequence", seq),

node/pkg/watchers/cosmwasm/watcher.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,10 @@ func (e *Watcher) Run(ctx context.Context) error {
213213
case <-t.C:
214214
msm := time.Now()
215215
// Query and report height and set currentSlotHeight
216-
resp, err := client.Get(fmt.Sprintf("%s/%s", e.urlLCD, e.latestBlockURL)) //nolint:noctx // TODO FIXME we should propagate context with Deadline here.
216+
requestURL := fmt.Sprintf("%s/%s", e.urlLCD, e.latestBlockURL)
217+
resp, err := client.Get(requestURL) //nolint:noctx // TODO FIXME we should propagate context with Deadline here.
217218
if err != nil {
218-
logger.Error("query latest block response error", zap.String("network", e.networkName), zap.Error(err))
219+
logger.Error("query latest block response error", zap.String("network", e.networkName), zap.String("error", common.SafeErrorForLogging(err, requestURL)))
219220
continue
220221
}
221222
blocksBody, err := common.SafeRead(resp.Body)
@@ -269,9 +270,10 @@ func (e *Watcher) Run(ctx context.Context) error {
269270
}
270271

271272
// Query for tx by hash
272-
resp, err := client.Get(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", e.urlLCD, tx)) //nolint:noctx // TODO FIXME we should propagate context with Deadline here.
273+
requestURL := fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", e.urlLCD, tx)
274+
resp, err := client.Get(requestURL) //nolint:noctx // TODO FIXME we should propagate context with Deadline here.
273275
if err != nil {
274-
logger.Error("query tx response error", zap.String("network", e.networkName), zap.Error(err))
276+
logger.Error("query tx response error", zap.String("network", e.networkName), zap.String("error", common.SafeErrorForLogging(err, requestURL)))
275277
continue
276278
}
277279
txBody, err := common.SafeRead(resp.Body)

node/pkg/watchers/evm/by_transaction.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ var (
2121
LogMessagePublishedTopic = eth_common.HexToHash("0x6eb224fb001ed210e379b335e35efe88672a8ce935d981a6896b27ffdf52a3b2")
2222
)
2323

24+
type connectorWithRPCURL interface {
25+
RPCURL() string
26+
}
27+
28+
func safeConnectorErrorForLogging(err error, ethConn any) string {
29+
if err == nil {
30+
return ""
31+
}
32+
33+
if connector, ok := ethConn.(connectorWithRPCURL); ok {
34+
return common.SafeErrorForLogging(err, connector.RPCURL())
35+
}
36+
37+
return err.Error()
38+
}
39+
2440
// isValidCoreBridgeMessagePublicationLog checks that a log entry was emitted by the expected contract,
2541
// has the expected LogMessagePublished event topic, and has not been removed
2642
// due to a chain reorganization. This is called from both the real-time
@@ -55,7 +71,7 @@ func MessageEventsForTransaction(
5571
// API only returns transactions that have been included in a block. Nothing in the mempool
5672
receipt, err := ethConn.TransactionReceipt(ctx, tx)
5773
if receipt == nil || err != nil {
58-
return nil, 0, nil, fmt.Errorf("failed to get transaction receipt: %w", err)
74+
return nil, 0, nil, fmt.Errorf("failed to get transaction receipt: %s", safeConnectorErrorForLogging(err, ethConn))
5975
}
6076

6177
// SECURITY
@@ -74,7 +90,7 @@ func MessageEventsForTransaction(
7490
// Get block
7591
blockTime, err := ethConn.TimeOfBlockByHash(ctx, receipt.BlockHash)
7692
if err != nil {
77-
return nil, 0, nil, fmt.Errorf("failed to get block time: %w", err)
93+
return nil, 0, nil, fmt.Errorf("failed to get block time: %s", safeConnectorErrorForLogging(err, ethConn))
7894
}
7995

8096
msgs := make([]*common.MessagePublication, 0, len(receipt.Logs))

node/pkg/watchers/evm/ccq_backfill.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ func ccqBackFillDetermineMaxBatchSize(ctx context.Context, logger *zap.Logger, c
193193
}
194194
prevSuccess = batchSize
195195
} else {
196-
logger.Info("batch query failed", zap.Int64("batchSize", batchSize), zap.Error(err))
196+
logger.Info("batch query failed", zap.Int64("batchSize", batchSize), zap.String("error", safeConnectorErrorForLogging(err, conn)))
197197
prevFailure = batchSize
198198
}
199199
batchSize = (prevFailure + prevSuccess) / 2
200200
if batchSize == 0 {
201-
return 0, nil, fmt.Errorf("failed to determine batch size: %w", err)
201+
return 0, nil, fmt.Errorf("failed to determine batch size: %s", safeConnectorErrorForLogging(err, conn))
202202
}
203203

204204
time.Sleep(delay) //nolint:forbidigo // TODO: This code should be refactored to not use time.Sleep
@@ -254,10 +254,10 @@ func (w *Watcher) ccqBackfillGetBlocks(ctx context.Context, initialBlockNum uint
254254
zap.Uint64("initialBlockNum", initialBlockNum),
255255
zap.Int64("numBlocks", numBlocks),
256256
zap.Uint64("finalBlockNum", blockNum),
257-
zap.Error(err),
257+
zap.String("error", safeConnectorErrorForLogging(err, w.ethConn)),
258258
)
259259

260-
return nil, err
260+
return nil, fmt.Errorf("failed to get batch of blocks: %s", safeConnectorErrorForLogging(err, w.ethConn))
261261
}
262262

263263
blocks := Blocks{}

node/pkg/watchers/evm/chain_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func QueryEvmChainID(ctx context.Context, url string) (uint64, error) {
244244
var str string
245245
err = c.CallContext(ctx, &str, "eth_chainId")
246246
if err != nil {
247-
return 0, fmt.Errorf("failed to read evm chain id: %w", err)
247+
return 0, fmt.Errorf("failed to read evm chain id: %s", common.SafeErrorForLogging(err, url))
248248
}
249249

250250
evmChainID, err := strconv.ParseUint(strings.TrimPrefix(str, "0x"), 16, 64)
@@ -274,7 +274,7 @@ func (w *Watcher) verifyEvmChainID(ctx context.Context, logger *zap.Logger, url
274274
var str string
275275
err = c.CallContext(ctx, &str, "eth_chainId")
276276
if err != nil {
277-
return fmt.Errorf("failed to read evm chain id: %w", err)
277+
return fmt.Errorf("failed to read evm chain id: %s", common.SafeErrorForLogging(err, url))
278278
}
279279

280280
evmChainID, err := strconv.ParseUint(strings.TrimPrefix(str, "0x"), 16, 64)

node/pkg/watchers/evm/connectors/batch_poller.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ func NewBatchPollConnector(_ context.Context, logger *zap.Logger, baseConnector
6262
return connector
6363
}
6464

65+
func (b *BatchPollConnector) RPCURL() string {
66+
if connector, ok := b.Connector.(rpcURLErrorSanitizer); ok {
67+
return connector.RPCURL()
68+
}
69+
70+
return ""
71+
}
72+
6573
func (b *BatchPollConnector) SubscribeForBlocks(ctx context.Context, errC chan error, sink chan<- *NewBlock) (ethereum.Subscription, error) {
6674
// Use the standard geth head sink to get latest blocks. We do this so that we will be notified of rollbacks. The following document
6775
// indicates that the subscription will receive a replay of all blocks affected by a rollback. This is important for latest because the
@@ -76,8 +84,8 @@ func (b *BatchPollConnector) SubscribeForBlocks(ctx context.Context, errC chan e
7684
// Get the initial blocks.
7785
lastBlocks, err := b.getBlocks(ctx, b.logger)
7886
if err != nil {
79-
b.logger.Error("failed to get initial blocks", zap.Error(err))
80-
return headerSubscription, fmt.Errorf("failed to get initial blocks: %w", err)
87+
b.logger.Error("failed to get initial blocks", zap.String("error", safeConnectorErrorForLogging(err, b.Connector)))
88+
return headerSubscription, fmt.Errorf("failed to get initial blocks: %s", safeConnectorErrorForLogging(err, b.Connector))
8189
}
8290

8391
errCount := 0
@@ -104,9 +112,9 @@ func (b *BatchPollConnector) SubscribeForBlocks(ctx context.Context, errC chan e
104112
lastBlocks, err = b.pollBlocks(ctx, sink, lastBlocks)
105113
if err != nil {
106114
errCount++
107-
b.logger.Error("batch polling encountered an error", zap.Int("errCount", errCount), zap.Error(err))
115+
b.logger.Error("batch polling encountered an error", zap.Int("errCount", errCount), zap.String("error", safeConnectorErrorForLogging(err, b.Connector)))
108116
if errCount > 3 {
109-
errC <- fmt.Errorf("polling encountered too many errors: %w", err) // Note on channel capacity: The watcher will exit anyway
117+
errC <- fmt.Errorf("polling encountered too many errors: %s", safeConnectorErrorForLogging(err, b.Connector)) // Note on channel capacity: The watcher will exit anyway
110118
return nil
111119
}
112120
} else if errCount != 0 {
@@ -251,7 +259,7 @@ func (b *BatchPollConnector) getBlocks(ctx context.Context, logger *zap.Logger)
251259

252260
err := b.Connector.RawBatchCallContext(timeout, batch)
253261
if err != nil {
254-
logger.Error("failed to get blocks", zap.Error(err))
262+
logger.Error("failed to get blocks", zap.String("error", safeConnectorErrorForLogging(err, b.Connector)))
255263
return nil, err
256264
}
257265

node/pkg/watchers/evm/connectors/block_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func GetBlock(ctx context.Context, conn Connector, str string, blockFinality Fin
2626
var m BlockMarshaller
2727
err := conn.RawCallContext(timeout, &m, "eth_getBlockByNumber", str, false)
2828
if err != nil {
29-
return nil, fmt.Errorf("failed to get block for %s: %w", str, err)
29+
return nil, fmt.Errorf("failed to get block for %s: %s", str, safeConnectorErrorForLogging(err, conn))
3030
}
3131
if m.Number == nil {
3232
return nil, fmt.Errorf("failed to unmarshal block for %s: Number is nil", str)

node/pkg/watchers/evm/connectors/ethereum.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type EthereumBaseConnector struct {
2828
logger *zap.Logger
2929
client *ethClient.Client
3030
rawClient *ethRpc.Client
31+
rawURL string
3132
filterer *ethAbi.AbiFilterer
3233
caller *ethAbi.AbiCaller
3334
dgCaller *dgAbi.DelegatedguardiansCaller
@@ -69,6 +70,7 @@ func NewEthereumBaseConnector(ctx context.Context, networkName, rawUrl string, a
6970
filterer: filterer,
7071
caller: caller,
7172
rawClient: rawClient,
73+
rawURL: rawUrl,
7274
dgCaller: dgCaller,
7375
dgAddress: dgAddress,
7476
}, nil
@@ -82,6 +84,10 @@ func (e *EthereumBaseConnector) ContractAddress() ethCommon.Address {
8284
return e.address
8385
}
8486

87+
func (e *EthereumBaseConnector) RPCURL() string {
88+
return e.rawURL
89+
}
90+
8591
func (e *EthereumBaseConnector) GetCurrentGuardianSetIndex(ctx context.Context) (uint32, error) {
8692
return e.caller.GetCurrentGuardianSetIndex(&ethBind.CallOpts{Context: ctx})
8793
}

node/pkg/watchers/evm/connectors/instant_finality.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ func NewInstantFinalityConnector(baseConnector Connector, logger *zap.Logger) *I
2626
return connector
2727
}
2828

29+
func (c *InstantFinalityConnector) RPCURL() string {
30+
if connector, ok := c.Connector.(rpcURLErrorSanitizer); ok {
31+
return connector.RPCURL()
32+
}
33+
34+
return ""
35+
}
36+
2937
func (c *InstantFinalityConnector) SubscribeForBlocks(ctx context.Context, errC chan error, sink chan<- *NewBlock) (ethereum.Subscription, error) {
3038
headSink := make(chan *ethTypes.Header, 2)
3139
headerSubscription, err := c.Connector.Client().SubscribeNewHead(ctx, headSink)

node/pkg/watchers/evm/connectors/poller.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ func (p *PollConnector) SubscribeForBlocks(ctx context.Context, errC chan error,
120120
lastBlocks, err = p.pollBlocks(ctx, sink, lastBlocks)
121121
if err != nil {
122122
errCount++
123-
p.logger.Error("poll connector encountered an error", zap.Int("errCount", errCount), zap.Error(err))
123+
p.logger.Error("poll connector encountered an error", zap.Int("errCount", errCount), zap.String("error", safeConnectorErrorForLogging(err, p.Connector)))
124124
if errCount > pollMaxErrors {
125125
// Return the error rather than writing to errC directly: a
126126
// blocking send could hang if the watcher is already shutting
127127
// down and no longer reading errC, which would prevent the
128128
// deferred signalUnsubscribed from running. RunWithScissors
129129
// delivers the returned error to errC without blocking.
130-
return fmt.Errorf("polling encountered too many errors: %w", err)
130+
return fmt.Errorf("polling encountered too many errors: %s", safeConnectorErrorForLogging(err, p.Connector))
131131
}
132132
} else if errCount != 0 {
133133
errCount = 0
@@ -178,13 +178,13 @@ func (p *PollConnector) watchLogMessagePublishedFrom(ctx context.Context, errC c
178178
latest, err := GetBlockByFinality(ctx, p.Connector, Latest)
179179
if err != nil {
180180
errCount++
181-
p.logger.Error("log poller failed to get latest block", zap.Int("errCount", errCount), zap.Error(err))
181+
p.logger.Error("log poller failed to get latest block", zap.Int("errCount", errCount), zap.String("error", safeConnectorErrorForLogging(err, p.Connector)))
182182
if errCount > pollMaxErrors {
183183
// Return rather than send to errC directly: a blocking send could hang
184184
// during watcher shutdown and strand the deferred signalUnsubscribed,
185185
// re-introducing the Unsubscribe deadlock. RunWithScissors forwards
186186
// the returned error to errC without blocking.
187-
return fmt.Errorf("log polling encountered too many errors: %w", err)
187+
return fmt.Errorf("log polling encountered too many errors: %s", safeConnectorErrorForLogging(err, p.Connector))
188188
}
189189
timer.Reset(p.Delay)
190190
continue
@@ -214,13 +214,13 @@ func (p *PollConnector) watchLogMessagePublishedFrom(ctx context.Context, errC c
214214
cancel()
215215
if err != nil {
216216
errCount++
217-
p.logger.Error("log poller failed to get logs", zap.Int("errCount", errCount), zap.Error(err), zap.Uint64("fromBlock", fromBlock), zap.Uint64("toBlock", toBlock))
217+
p.logger.Error("log poller failed to get logs", zap.Int("errCount", errCount), zap.String("error", safeConnectorErrorForLogging(err, p.Connector)), zap.Uint64("fromBlock", fromBlock), zap.Uint64("toBlock", toBlock))
218218
if errCount > pollMaxErrors {
219219
// Return rather than send to errC directly: a blocking send could hang
220220
// during watcher shutdown and strand the deferred signalUnsubscribed,
221221
// re-introducing the Unsubscribe deadlock. RunWithScissors forwards
222222
// the returned error to errC without blocking.
223-
return fmt.Errorf("log polling encountered too many errors: %w", err)
223+
return fmt.Errorf("log polling encountered too many errors: %s", safeConnectorErrorForLogging(err, p.Connector))
224224
}
225225
timer.Reset(p.Delay)
226226
continue
@@ -257,7 +257,7 @@ func (p *PollConnector) TimeOfBlockByHash(ctx context.Context, hash ethCommon.Ha
257257
var m *BlockMarshaller
258258
err := p.RawCallContext(ctx, &m, "eth_getBlockByHash", hash, false)
259259
if err != nil {
260-
return 0, fmt.Errorf("failed to get block by hash: %w", err)
260+
return 0, fmt.Errorf("failed to get block by hash: %s", safeConnectorErrorForLogging(err, p.Connector))
261261
}
262262
// eth_getBlockByHash returns a JSON null result for an unknown block, which
263263
// unmarshals into a nil pointer without an error. Mirror go-ethereum's

0 commit comments

Comments
 (0)