From 5c8b5b84e2de1ec34369e3da19dae116a69f7f1a Mon Sep 17 00:00:00 2001 From: hazim Date: Wed, 21 Feb 2024 16:53:31 +1100 Subject: [PATCH] Support native tracing for gas estimation (#382) --- .github/workflows/compliance.yml | 1 + .github/workflows/e2e.yml | 1 + internal/config/values.go | 4 ++++ internal/start/private.go | 8 +++++++- internal/start/searcher.go | 8 +++++++- pkg/client/utils.go | 2 ++ pkg/entrypoint/execution/trace.go | 7 ++++++- pkg/gas/estimate.go | 5 +++++ 8 files changed, 33 insertions(+), 3 deletions(-) diff --git a/.github/workflows/compliance.yml b/.github/workflows/compliance.yml index d42b847a..439c10ab 100644 --- a/.github/workflows/compliance.yml +++ b/.github/workflows/compliance.yml @@ -92,6 +92,7 @@ jobs: ERC4337_BUNDLER_PORT: 3000 ERC4337_BUNDLER_DEBUG_MODE: true ERC4337_BUNDLER_NATIVE_BUNDLER_COLLECTOR_TRACER: bundlerCollectorTracer + ERC4337_BUNDLER_NATIVE_BUNDLER_EXECUTOR_TRACER: bundlerExecutorTracer # This key is for testing purposes only. Do not use for anything else. ERC4337_BUNDLER_PRIVATE_KEY: c6cbc5ffad570fdad0544d1b5358a36edeb98d163b6567912ac4754e144d4edb diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 5adbbf9a..349911df 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -106,6 +106,7 @@ jobs: ERC4337_BUNDLER_ETH_CLIENT_URL: http://localhost:8545/ ERC4337_BUNDLER_DEBUG_MODE: true ERC4337_BUNDLER_NATIVE_BUNDLER_COLLECTOR_TRACER: bundlerCollectorTracer + ERC4337_BUNDLER_NATIVE_BUNDLER_EXECUTOR_TRACER: bundlerExecutorTracer # This key is for testing purposes only. Do not use for anything else. ERC4337_BUNDLER_PRIVATE_KEY: c6cbc5ffad570fdad0544d1b5358a36edeb98d163b6567912ac4754e144d4edb diff --git a/internal/config/values.go b/internal/config/values.go index 932f2314..7e1e243d 100644 --- a/internal/config/values.go +++ b/internal/config/values.go @@ -26,6 +26,7 @@ type Values struct { OpLookupLimit uint64 Beneficiary string NativeBundlerCollectorTracer string + NativeBundlerExecutorTracer string ReputationConstants *entities.ReputationConstants // Searcher mode variables. @@ -123,6 +124,7 @@ func GetValues() *Values { _ = viper.BindEnv("erc4337_bundler_supported_entry_points") _ = viper.BindEnv("erc4337_bundler_beneficiary") _ = viper.BindEnv("erc4337_bundler_native_bundler_collector_tracer") + _ = viper.BindEnv("erc4337_bundler_native_bundler_executor_tracer") _ = viper.BindEnv("erc4337_bundler_max_verification_gas") _ = viper.BindEnv("erc4337_bundler_max_batch_gas_limit") _ = viper.BindEnv("erc4337_bundler_max_op_ttl_seconds") @@ -184,6 +186,7 @@ func GetValues() *Values { supportedEntryPoints := envArrayToAddressSlice(viper.GetString("erc4337_bundler_supported_entry_points")) beneficiary := viper.GetString("erc4337_bundler_beneficiary") nativeBundlerCollectorTracer := viper.GetString("erc4337_bundler_native_bundler_collector_tracer") + nativeBundlerExecutorTracer := viper.GetString("erc4337_bundler_native_bundler_executor_tracer") maxVerificationGas := big.NewInt(int64(viper.GetInt("erc4337_bundler_max_verification_gas"))) maxBatchGasLimit := big.NewInt(int64(viper.GetInt("erc4337_bundler_max_batch_gas_limit"))) maxOpTTL := time.Second * viper.GetDuration("erc4337_bundler_max_op_ttl_seconds") @@ -208,6 +211,7 @@ func GetValues() *Values { SupportedEntryPoints: supportedEntryPoints, Beneficiary: beneficiary, NativeBundlerCollectorTracer: nativeBundlerCollectorTracer, + NativeBundlerExecutorTracer: nativeBundlerExecutorTracer, MaxVerificationGas: maxVerificationGas, MaxBatchGasLimit: maxBatchGasLimit, MaxOpTTL: maxOpTTL, diff --git a/internal/start/private.go b/internal/start/private.go index 758a0d1d..bb1fe7e0 100644 --- a/internal/start/private.go +++ b/internal/start/private.go @@ -131,7 +131,13 @@ func PrivateMode() { c.SetGetUserOpReceiptFunc(client.GetUserOpReceiptWithEthClient(eth)) c.SetGetGasPricesFunc(client.GetGasPricesWithEthClient(eth)) c.SetGetGasEstimateFunc( - client.GetGasEstimateWithEthClient(rpc, ov, chain, conf.MaxBatchGasLimit), + client.GetGasEstimateWithEthClient( + rpc, + ov, + chain, + conf.MaxBatchGasLimit, + conf.NativeBundlerExecutorTracer, + ), ) c.SetGetUserOpByHashFunc(client.GetUserOpByHashWithEthClient(eth)) c.SetGetStakeFunc(stake.GetStakeWithEthClient(eth)) diff --git a/internal/start/searcher.go b/internal/start/searcher.go index 70b7d4f0..2624c9a7 100644 --- a/internal/start/searcher.go +++ b/internal/start/searcher.go @@ -128,7 +128,13 @@ func SearcherMode() { c.SetGetUserOpReceiptFunc(client.GetUserOpReceiptWithEthClient(eth)) c.SetGetGasPricesFunc(client.GetGasPricesWithEthClient(eth)) c.SetGetGasEstimateFunc( - client.GetGasEstimateWithEthClient(rpc, ov, chain, conf.MaxBatchGasLimit), + client.GetGasEstimateWithEthClient( + rpc, + ov, + chain, + conf.MaxBatchGasLimit, + conf.NativeBundlerExecutorTracer, + ), ) c.SetGetUserOpByHashFunc(client.GetUserOpByHashWithEthClient(eth)) c.SetGetStakeFunc(stake.GetStakeWithEthClient(eth)) diff --git a/pkg/client/utils.go b/pkg/client/utils.go index 52886be6..5891eb50 100644 --- a/pkg/client/utils.go +++ b/pkg/client/utils.go @@ -76,6 +76,7 @@ func GetGasEstimateWithEthClient( ov *gas.Overhead, chain *big.Int, maxGasLimit *big.Int, + tracer string, ) GetGasEstimateFunc { return func( ep common.Address, @@ -90,6 +91,7 @@ func GetGasEstimateWithEthClient( Ov: ov, ChainID: chain, MaxGasLimit: maxGasLimit, + Tracer: tracer, }) } } diff --git a/pkg/entrypoint/execution/trace.go b/pkg/entrypoint/execution/trace.go index f3109046..92c70580 100644 --- a/pkg/entrypoint/execution/trace.go +++ b/pkg/entrypoint/execution/trace.go @@ -27,6 +27,7 @@ type TraceInput struct { Op *userop.UserOperation Sos state.OverrideSet ChainID *big.Int + Tracer string // Optional params for simulateHandleOps Target common.Address @@ -89,6 +90,10 @@ func TraceSimulateHandleOp(in *TraceInput) (*TraceOutput, error) { if err != nil { return nil, err } + t := tracer.Loaded.BundlerExecutionTracer + if in.Tracer != "" { + t = in.Tracer + } out := &TraceOutput{} var res tracer.BundlerExecutionReturn @@ -99,7 +104,7 @@ func TraceSimulateHandleOp(in *TraceInput) (*TraceOutput, error) { MaxFeePerGas: hexutil.Big(*mf), } opts := utils.TraceCallOpts{ - Tracer: tracer.Loaded.BundlerExecutionTracer, + Tracer: t, StateOverrides: state.WithMaxBalanceOverride(common.HexToAddress("0x"), in.Sos), } if err := in.Rpc.CallContext(context.Background(), &res, "debug_traceCall", &req, "latest", &opts); err != nil { diff --git a/pkg/gas/estimate.go b/pkg/gas/estimate.go index 9ed0d32e..9ca8b018 100644 --- a/pkg/gas/estimate.go +++ b/pkg/gas/estimate.go @@ -50,6 +50,7 @@ type EstimateInput struct { Ov *Overhead ChainID *big.Int MaxGasLimit *big.Int + Tracer string attempts int64 lastVGL int64 @@ -68,6 +69,7 @@ func retryEstimateGas(err error, vgl int64, in *EstimateInput) (uint64, uint64, Ov: in.Ov, ChainID: in.ChainID, MaxGasLimit: in.MaxGasLimit, + Tracer: in.Tracer, attempts: in.attempts + 1, lastVGL: vgl, }) @@ -150,6 +152,7 @@ func EstimateGas(in *EstimateInput) (verificationGas uint64, callGas uint64, err Sos: in.Sos, ChainID: in.ChainID, TraceFeeCap: in.Op.MaxFeePerGas, + Tracer: in.Tracer, }) if err != nil { return retryEstimateGas(err, f, in) @@ -178,6 +181,7 @@ func EstimateGas(in *EstimateInput) (verificationGas uint64, callGas uint64, err Op: simOp, Sos: in.Sos, ChainID: in.ChainID, + Tracer: in.Tracer, }) if err != nil { // 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 Op: simOp, Sos: in.Sos, ChainID: in.ChainID, + Tracer: in.Tracer, }) simErr = err if err == nil {