Skip to content

Commit 3b0ecdf

Browse files
committed
Improve logging for eth_call & eth_estimateGas JSON-RPC endpoints
1 parent fee80d0 commit 3b0ecdf

File tree

1 file changed

+45
-15
lines changed

1 file changed

+45
-15
lines changed

api/api.go

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package api
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"math/big"
78

@@ -529,25 +530,42 @@ func (b *BlockChainAPI) Call(
529530
stateOverrides *ethTypes.StateOverride,
530531
blockOverrides *ethTypes.BlockOverrides,
531532
) (hexutil.Bytes, error) {
533+
// Default to "latest" block tag
534+
if blockNumberOrHash == nil {
535+
blockNumberOrHash = &latestBlockNumberOrHash
536+
}
537+
538+
stateOverridesArgs, err := json.Marshal(stateOverrides)
539+
if err != nil {
540+
return handleError[hexutil.Bytes](err, b.logger, b.collector)
541+
}
542+
543+
blockOverridesArgs, err := json.Marshal(blockOverrides)
544+
if err != nil {
545+
return handleError[hexutil.Bytes](err, b.logger, b.collector)
546+
}
547+
548+
txArgs, err := json.Marshal(args)
549+
if err != nil {
550+
return handleError[hexutil.Bytes](err, b.logger, b.collector)
551+
}
552+
532553
l := b.logger.With().
533554
Str("endpoint", EthCall).
534-
Str("args", fmt.Sprintf("%v", args)).
555+
RawJSON("args", txArgs).
556+
Str("blockTag", fmt.Sprintf("%v", blockNumberOrHash)).
557+
RawJSON("stateOverrides", stateOverridesArgs).
558+
RawJSON("blockOverrides", blockOverridesArgs).
535559
Logger()
536560

537561
if err := b.rateLimiter.Apply(ctx, EthCall); err != nil {
538562
return nil, err
539563
}
540564

541-
err := args.Validate()
542-
if err != nil {
565+
if err := args.Validate(); err != nil {
543566
return handleError[hexutil.Bytes](err, l, b.collector)
544567
}
545568

546-
// Default to "latest" block tag
547-
if blockNumberOrHash == nil {
548-
blockNumberOrHash = &latestBlockNumberOrHash
549-
}
550-
551569
height, err := resolveBlockTag(blockNumberOrHash, b.blocks, b.logger)
552570
if err != nil {
553571
return handleError[hexutil.Bytes](err, l, b.collector)
@@ -695,17 +713,33 @@ func (b *BlockChainAPI) EstimateGas(
695713
stateOverrides *ethTypes.StateOverride,
696714
blockOverrides *ethTypes.BlockOverrides,
697715
) (hexutil.Uint64, error) {
716+
// Default to "latest" block tag
717+
if blockNumberOrHash == nil {
718+
blockNumberOrHash = &latestBlockNumberOrHash
719+
}
720+
721+
stateOverridesArgs, err := json.Marshal(stateOverrides)
722+
if err != nil {
723+
return handleError[hexutil.Uint64](err, b.logger, b.collector)
724+
}
725+
726+
txArgs, err := json.Marshal(args)
727+
if err != nil {
728+
return handleError[hexutil.Uint64](err, b.logger, b.collector)
729+
}
730+
698731
l := b.logger.With().
699732
Str("endpoint", EthEstimateGas).
700-
Str("args", fmt.Sprintf("%v", args)).
733+
RawJSON("args", txArgs).
734+
Str("blockTag", fmt.Sprintf("%v", blockNumberOrHash)).
735+
RawJSON("stateOverrides", stateOverridesArgs).
701736
Logger()
702737

703738
if err := b.rateLimiter.Apply(ctx, EthEstimateGas); err != nil {
704739
return 0, err
705740
}
706741

707-
err := args.Validate()
708-
if err != nil {
742+
if err := args.Validate(); err != nil {
709743
return handleError[hexutil.Uint64](err, l, b.collector)
710744
}
711745

@@ -715,10 +749,6 @@ func (b *BlockChainAPI) EstimateGas(
715749
from = *args.From
716750
}
717751

718-
if blockNumberOrHash == nil {
719-
blockNumberOrHash = &latestBlockNumberOrHash
720-
}
721-
722752
height, err := resolveBlockTag(blockNumberOrHash, b.blocks, b.logger)
723753
if err != nil {
724754
return handleError[hexutil.Uint64](err, l, b.collector)

0 commit comments

Comments
 (0)