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

Commit

Permalink
Support native tracing for gas estimation (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
hazim-j authored Feb 21, 2024
1 parent 84ea70b commit 5c8b5b8
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/compliance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions internal/config/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Values struct {
OpLookupLimit uint64
Beneficiary string
NativeBundlerCollectorTracer string
NativeBundlerExecutorTracer string
ReputationConstants *entities.ReputationConstants

// Searcher mode variables.
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -208,6 +211,7 @@ func GetValues() *Values {
SupportedEntryPoints: supportedEntryPoints,
Beneficiary: beneficiary,
NativeBundlerCollectorTracer: nativeBundlerCollectorTracer,
NativeBundlerExecutorTracer: nativeBundlerExecutorTracer,
MaxVerificationGas: maxVerificationGas,
MaxBatchGasLimit: maxBatchGasLimit,
MaxOpTTL: maxOpTTL,
Expand Down
8 changes: 7 additions & 1 deletion internal/start/private.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 7 additions & 1 deletion internal/start/searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions pkg/client/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func GetGasEstimateWithEthClient(
ov *gas.Overhead,
chain *big.Int,
maxGasLimit *big.Int,
tracer string,
) GetGasEstimateFunc {
return func(
ep common.Address,
Expand All @@ -90,6 +91,7 @@ func GetGasEstimateWithEthClient(
Ov: ov,
ChainID: chain,
MaxGasLimit: maxGasLimit,
Tracer: tracer,
})
}
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/entrypoint/execution/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions pkg/gas/estimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type EstimateInput struct {
Ov *Overhead
ChainID *big.Int
MaxGasLimit *big.Int
Tracer string

attempts int64
lastVGL int64
Expand All @@ -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,
})
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 5c8b5b8

Please sign in to comment.