Skip to content
This repository was archived by the owner on Oct 20, 2024. It is now read-only.

Commit 5c8b5b8

Browse files
authored
Support native tracing for gas estimation (#382)
1 parent 84ea70b commit 5c8b5b8

File tree

8 files changed

+33
-3
lines changed

8 files changed

+33
-3
lines changed

.github/workflows/compliance.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ jobs:
9292
ERC4337_BUNDLER_PORT: 3000
9393
ERC4337_BUNDLER_DEBUG_MODE: true
9494
ERC4337_BUNDLER_NATIVE_BUNDLER_COLLECTOR_TRACER: bundlerCollectorTracer
95+
ERC4337_BUNDLER_NATIVE_BUNDLER_EXECUTOR_TRACER: bundlerExecutorTracer
9596
# This key is for testing purposes only. Do not use for anything else.
9697
ERC4337_BUNDLER_PRIVATE_KEY: c6cbc5ffad570fdad0544d1b5358a36edeb98d163b6567912ac4754e144d4edb
9798

.github/workflows/e2e.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ jobs:
106106
ERC4337_BUNDLER_ETH_CLIENT_URL: http://localhost:8545/
107107
ERC4337_BUNDLER_DEBUG_MODE: true
108108
ERC4337_BUNDLER_NATIVE_BUNDLER_COLLECTOR_TRACER: bundlerCollectorTracer
109+
ERC4337_BUNDLER_NATIVE_BUNDLER_EXECUTOR_TRACER: bundlerExecutorTracer
109110
# This key is for testing purposes only. Do not use for anything else.
110111
ERC4337_BUNDLER_PRIVATE_KEY: c6cbc5ffad570fdad0544d1b5358a36edeb98d163b6567912ac4754e144d4edb
111112

internal/config/values.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Values struct {
2626
OpLookupLimit uint64
2727
Beneficiary string
2828
NativeBundlerCollectorTracer string
29+
NativeBundlerExecutorTracer string
2930
ReputationConstants *entities.ReputationConstants
3031

3132
// Searcher mode variables.
@@ -123,6 +124,7 @@ func GetValues() *Values {
123124
_ = viper.BindEnv("erc4337_bundler_supported_entry_points")
124125
_ = viper.BindEnv("erc4337_bundler_beneficiary")
125126
_ = viper.BindEnv("erc4337_bundler_native_bundler_collector_tracer")
127+
_ = viper.BindEnv("erc4337_bundler_native_bundler_executor_tracer")
126128
_ = viper.BindEnv("erc4337_bundler_max_verification_gas")
127129
_ = viper.BindEnv("erc4337_bundler_max_batch_gas_limit")
128130
_ = viper.BindEnv("erc4337_bundler_max_op_ttl_seconds")
@@ -184,6 +186,7 @@ func GetValues() *Values {
184186
supportedEntryPoints := envArrayToAddressSlice(viper.GetString("erc4337_bundler_supported_entry_points"))
185187
beneficiary := viper.GetString("erc4337_bundler_beneficiary")
186188
nativeBundlerCollectorTracer := viper.GetString("erc4337_bundler_native_bundler_collector_tracer")
189+
nativeBundlerExecutorTracer := viper.GetString("erc4337_bundler_native_bundler_executor_tracer")
187190
maxVerificationGas := big.NewInt(int64(viper.GetInt("erc4337_bundler_max_verification_gas")))
188191
maxBatchGasLimit := big.NewInt(int64(viper.GetInt("erc4337_bundler_max_batch_gas_limit")))
189192
maxOpTTL := time.Second * viper.GetDuration("erc4337_bundler_max_op_ttl_seconds")
@@ -208,6 +211,7 @@ func GetValues() *Values {
208211
SupportedEntryPoints: supportedEntryPoints,
209212
Beneficiary: beneficiary,
210213
NativeBundlerCollectorTracer: nativeBundlerCollectorTracer,
214+
NativeBundlerExecutorTracer: nativeBundlerExecutorTracer,
211215
MaxVerificationGas: maxVerificationGas,
212216
MaxBatchGasLimit: maxBatchGasLimit,
213217
MaxOpTTL: maxOpTTL,

internal/start/private.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,13 @@ func PrivateMode() {
131131
c.SetGetUserOpReceiptFunc(client.GetUserOpReceiptWithEthClient(eth))
132132
c.SetGetGasPricesFunc(client.GetGasPricesWithEthClient(eth))
133133
c.SetGetGasEstimateFunc(
134-
client.GetGasEstimateWithEthClient(rpc, ov, chain, conf.MaxBatchGasLimit),
134+
client.GetGasEstimateWithEthClient(
135+
rpc,
136+
ov,
137+
chain,
138+
conf.MaxBatchGasLimit,
139+
conf.NativeBundlerExecutorTracer,
140+
),
135141
)
136142
c.SetGetUserOpByHashFunc(client.GetUserOpByHashWithEthClient(eth))
137143
c.SetGetStakeFunc(stake.GetStakeWithEthClient(eth))

internal/start/searcher.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,13 @@ func SearcherMode() {
128128
c.SetGetUserOpReceiptFunc(client.GetUserOpReceiptWithEthClient(eth))
129129
c.SetGetGasPricesFunc(client.GetGasPricesWithEthClient(eth))
130130
c.SetGetGasEstimateFunc(
131-
client.GetGasEstimateWithEthClient(rpc, ov, chain, conf.MaxBatchGasLimit),
131+
client.GetGasEstimateWithEthClient(
132+
rpc,
133+
ov,
134+
chain,
135+
conf.MaxBatchGasLimit,
136+
conf.NativeBundlerExecutorTracer,
137+
),
132138
)
133139
c.SetGetUserOpByHashFunc(client.GetUserOpByHashWithEthClient(eth))
134140
c.SetGetStakeFunc(stake.GetStakeWithEthClient(eth))

pkg/client/utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func GetGasEstimateWithEthClient(
7676
ov *gas.Overhead,
7777
chain *big.Int,
7878
maxGasLimit *big.Int,
79+
tracer string,
7980
) GetGasEstimateFunc {
8081
return func(
8182
ep common.Address,
@@ -90,6 +91,7 @@ func GetGasEstimateWithEthClient(
9091
Ov: ov,
9192
ChainID: chain,
9293
MaxGasLimit: maxGasLimit,
94+
Tracer: tracer,
9395
})
9496
}
9597
}

pkg/entrypoint/execution/trace.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type TraceInput struct {
2727
Op *userop.UserOperation
2828
Sos state.OverrideSet
2929
ChainID *big.Int
30+
Tracer string
3031

3132
// Optional params for simulateHandleOps
3233
Target common.Address
@@ -89,6 +90,10 @@ func TraceSimulateHandleOp(in *TraceInput) (*TraceOutput, error) {
8990
if err != nil {
9091
return nil, err
9192
}
93+
t := tracer.Loaded.BundlerExecutionTracer
94+
if in.Tracer != "" {
95+
t = in.Tracer
96+
}
9297
out := &TraceOutput{}
9398

9499
var res tracer.BundlerExecutionReturn
@@ -99,7 +104,7 @@ func TraceSimulateHandleOp(in *TraceInput) (*TraceOutput, error) {
99104
MaxFeePerGas: hexutil.Big(*mf),
100105
}
101106
opts := utils.TraceCallOpts{
102-
Tracer: tracer.Loaded.BundlerExecutionTracer,
107+
Tracer: t,
103108
StateOverrides: state.WithMaxBalanceOverride(common.HexToAddress("0x"), in.Sos),
104109
}
105110
if err := in.Rpc.CallContext(context.Background(), &res, "debug_traceCall", &req, "latest", &opts); err != nil {

pkg/gas/estimate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type EstimateInput struct {
5050
Ov *Overhead
5151
ChainID *big.Int
5252
MaxGasLimit *big.Int
53+
Tracer string
5354

5455
attempts int64
5556
lastVGL int64
@@ -68,6 +69,7 @@ func retryEstimateGas(err error, vgl int64, in *EstimateInput) (uint64, uint64,
6869
Ov: in.Ov,
6970
ChainID: in.ChainID,
7071
MaxGasLimit: in.MaxGasLimit,
72+
Tracer: in.Tracer,
7173
attempts: in.attempts + 1,
7274
lastVGL: vgl,
7375
})
@@ -150,6 +152,7 @@ func EstimateGas(in *EstimateInput) (verificationGas uint64, callGas uint64, err
150152
Sos: in.Sos,
151153
ChainID: in.ChainID,
152154
TraceFeeCap: in.Op.MaxFeePerGas,
155+
Tracer: in.Tracer,
153156
})
154157
if err != nil {
155158
return retryEstimateGas(err, f, in)
@@ -178,6 +181,7 @@ func EstimateGas(in *EstimateInput) (verificationGas uint64, callGas uint64, err
178181
Op: simOp,
179182
Sos: in.Sos,
180183
ChainID: in.ChainID,
184+
Tracer: in.Tracer,
181185
})
182186
if err != nil {
183187
// Execution is successful but one shot tracing has failed. Fallback to binary search with an
@@ -202,6 +206,7 @@ func EstimateGas(in *EstimateInput) (verificationGas uint64, callGas uint64, err
202206
Op: simOp,
203207
Sos: in.Sos,
204208
ChainID: in.ChainID,
209+
Tracer: in.Tracer,
205210
})
206211
simErr = err
207212
if err == nil {

0 commit comments

Comments
 (0)