Skip to content

Commit 6ac7a9c

Browse files
committed
Improve logging for eth_call & eth_estimateGas JSON-RPC endpoints
1 parent 742085b commit 6ac7a9c

1 file changed

Lines changed: 45 additions & 15 deletions

File tree

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)
@@ -694,17 +712,33 @@ func (b *BlockChainAPI) EstimateGas(
694712
blockNumberOrHash *rpc.BlockNumberOrHash,
695713
stateOverrides *ethTypes.StateOverride,
696714
) (hexutil.Uint64, error) {
715+
// Default to "latest" block tag
716+
if blockNumberOrHash == nil {
717+
blockNumberOrHash = &latestBlockNumberOrHash
718+
}
719+
720+
stateOverridesArgs, err := json.Marshal(stateOverrides)
721+
if err != nil {
722+
return handleError[hexutil.Uint64](err, b.logger, b.collector)
723+
}
724+
725+
txArgs, err := json.Marshal(args)
726+
if err != nil {
727+
return handleError[hexutil.Uint64](err, b.logger, b.collector)
728+
}
729+
697730
l := b.logger.With().
698731
Str("endpoint", EthEstimateGas).
699-
Str("args", fmt.Sprintf("%v", args)).
732+
RawJSON("args", txArgs).
733+
Str("blockTag", fmt.Sprintf("%v", blockNumberOrHash)).
734+
RawJSON("stateOverrides", stateOverridesArgs).
700735
Logger()
701736

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

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

@@ -714,10 +748,6 @@ func (b *BlockChainAPI) EstimateGas(
714748
from = *args.From
715749
}
716750

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

0 commit comments

Comments
 (0)