Skip to content

Commit

Permalink
feat: add more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ckartik committed Jul 5, 2024
1 parent a7ee85d commit 011fb9d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions x/contracts/txmonitor/eth_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package txmonitor

import (
"context"
"log"
"log/slog"
"time"

Expand Down Expand Up @@ -104,9 +103,11 @@ func (e *evmHelper) TraceTransaction(ctx context.Context, txHash common.Hash) (*

// BatchReceipts retrieves multiple receipts for a list of transaction hashes.
func (e *evmHelper) BatchReceipts(ctx context.Context, txHashes []common.Hash) ([]Result, error) {
e.logger.Info("Starting BatchReceipts", "txHashes", txHashes)
batch := make([]rpc.BatchElem, len(txHashes))

for i, hash := range txHashes {
e.logger.Debug("Preparing batch element", "index", i, "hash", hash.Hex())
batch[i] = rpc.BatchElem{
Method: "eth_getTransactionReceipt",
Args: []interface{}{hash},
Expand All @@ -117,24 +118,31 @@ func (e *evmHelper) BatchReceipts(ctx context.Context, txHashes []common.Hash) (
var receipts []Result
var err error
for attempts := 0; attempts < 50; attempts++ {
e.logger.Debug("Attempting batch call", "attempt", attempts+1)
// Execute the batch request
err = e.client.BatchCallContext(context.Background(), batch)
if err != nil {
log.Printf("Batch call attempt %d failed: %v", attempts+1, err)
e.logger.Error("Batch call attempt failed", "attempt", attempts+1, "error", err)
time.Sleep(1 * time.Second)
} else {
e.logger.Info("Batch call attempt succeeded", "attempt", attempts+1)
break
}
}

if err != nil {
e.logger.Error("All batch call attempts failed", "error", err)
return nil, err
}
receipts = make([]Result, len(batch))
for i, elem := range batch {
e.logger.Debug("Processing batch element", "index", i, "result", elem.Result, "error", elem.Error)
receipts[i].Receipt = elem.Result.(*types.Receipt)
if elem.Error != nil {
receipts[i].Err = elem.Error
}
}

e.logger.Info("BatchReceipts completed successfully", "receipts", receipts)
return receipts, nil
}

0 comments on commit 011fb9d

Please sign in to comment.