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

Commit

Permalink
Add configuration for op lookup limit (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
hazim-j authored Feb 6, 2024
1 parent c96ae87 commit e9c267a
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 20 deletions.
5 changes: 5 additions & 0 deletions internal/config/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Values struct {
MaxVerificationGas *big.Int
MaxBatchGasLimit *big.Int
MaxOpTTL time.Duration
OpLookupLimit uint64
Beneficiary string
NativeBundlerCollectorTracer string
ReputationConstants *entities.ReputationConstants
Expand Down Expand Up @@ -92,6 +93,7 @@ func GetValues() *Values {
viper.SetDefault("erc4337_bundler_max_verification_gas", 6000000)
viper.SetDefault("erc4337_bundler_max_batch_gas_limit", 18000000)
viper.SetDefault("erc4337_bundler_max_op_ttl_seconds", 180)
viper.SetDefault("erc4337_bundler_op_lookup_limit", 2000)
viper.SetDefault("erc4337_bundler_blocks_in_the_future", 6)
viper.SetDefault("erc4337_bundler_otel_insecure_mode", false)
viper.SetDefault("erc4337_bundler_is_op_stack_network", false)
Expand Down Expand Up @@ -122,6 +124,7 @@ func GetValues() *Values {
_ = viper.BindEnv("erc4337_bundler_max_verification_gas")
_ = viper.BindEnv("erc4337_bundler_max_batch_gas_limit")
_ = viper.BindEnv("erc4337_bundler_max_op_ttl_seconds")
_ = viper.BindEnv("erc4337_bundler_op_lookup_limit")
_ = viper.BindEnv("erc4337_bundler_eth_builder_urls")
_ = viper.BindEnv("erc4337_bundler_blocks_in_the_future")
_ = viper.BindEnv("erc4337_bundler_otel_service_name")
Expand Down Expand Up @@ -181,6 +184,7 @@ func GetValues() *Values {
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")
opLookupLimit := viper.GetUint64("erc4337_bundler_op_lookup_limit")
ethBuilderUrls := envArrayToStringSlice(viper.GetString("erc4337_bundler_eth_builder_urls"))
blocksInTheFuture := viper.GetInt("erc4337_bundler_blocks_in_the_future")
otelServiceName := viper.GetString("erc4337_bundler_otel_service_name")
Expand All @@ -203,6 +207,7 @@ func GetValues() *Values {
MaxVerificationGas: maxVerificationGas,
MaxBatchGasLimit: maxBatchGasLimit,
MaxOpTTL: maxOpTTL,
OpLookupLimit: opLookupLimit,
ReputationConstants: NewReputationConstantsFromEnv(),
EthBuilderUrls: ethBuilderUrls,
BlocksInTheFuture: blocksInTheFuture,
Expand Down
2 changes: 1 addition & 1 deletion internal/start/private.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func PrivateMode() {
rep := entities.New(db, eth, conf.ReputationConstants)

// Init Client
c := client.New(mem, ov, chain, conf.SupportedEntryPoints)
c := client.New(mem, ov, chain, conf.SupportedEntryPoints, conf.OpLookupLimit)
c.SetGetUserOpReceiptFunc(client.GetUserOpReceiptWithEthClient(eth))
c.SetGetGasPricesFunc(client.GetGasPricesWithEthClient(eth))
c.SetGetGasEstimateFunc(
Expand Down
2 changes: 1 addition & 1 deletion internal/start/searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func SearcherMode() {
rep := entities.New(db, eth, conf.ReputationConstants)

// Init Client
c := client.New(mem, ov, chain, conf.SupportedEntryPoints)
c := client.New(mem, ov, chain, conf.SupportedEntryPoints, conf.OpLookupLimit)
c.SetGetUserOpReceiptFunc(client.GetUserOpReceiptWithEthClient(eth))
c.SetGetGasPricesFunc(client.GetGasPricesWithEthClient(eth))
c.SetGetGasEstimateFunc(
Expand Down
7 changes: 5 additions & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Client struct {
getGasEstimate GetGasEstimateFunc
getUserOpByHash GetUserOpByHashFunc
getStakeFunc stake.GetStakeFunc
opLookupLimit uint64
}

// New initializes a new ERC-4337 client which can be extended with modules for validating UserOperations
Expand All @@ -42,6 +43,7 @@ func New(
ov *gas.Overhead,
chainID *big.Int,
supportedEntryPoints []common.Address,
opLookupLimit uint64,
) *Client {
return &Client{
mempool: mempool,
Expand All @@ -55,6 +57,7 @@ func New(
getGasEstimate: getGasEstimateNoop(),
getUserOpByHash: getUserOpByHashNoop(),
getStakeFunc: stake.GetStakeFuncNoop(),
opLookupLimit: opLookupLimit,
}
}

Expand Down Expand Up @@ -249,7 +252,7 @@ func (i *Client) GetUserOperationReceipt(
// Init logger
l := i.logger.WithName("eth_getUserOperationReceipt").WithValues("userop_hash", hash)

ev, err := i.getUserOpReceipt(hash, i.supportedEntryPoints[0])
ev, err := i.getUserOpReceipt(hash, i.supportedEntryPoints[0], i.opLookupLimit)
if err != nil {
l.Error(err, "eth_getUserOperationReceipt error")
return nil, err
Expand All @@ -265,7 +268,7 @@ func (i *Client) GetUserOperationByHash(hash string) (*filter.HashLookupResult,
// Init logger
l := i.logger.WithName("eth_getUserOperationByHash").WithValues("userop_hash", hash)

res, err := i.getUserOpByHash(hash, i.supportedEntryPoints[0], i.chainID)
res, err := i.getUserOpByHash(hash, i.supportedEntryPoints[0], i.chainID, i.opLookupLimit)
if err != nil {
l.Error(err, "eth_getUserOperationByHash error")
return nil, err
Expand Down
22 changes: 11 additions & 11 deletions pkg/client/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import (
"github.com/stackup-wallet/stackup-bundler/pkg/userop"
)

// GetUserOpReceiptFunc is a general interface for fetching a UserOperationReceipt given a userOpHash and
// EntryPoint address.
type GetUserOpReceiptFunc = func(hash string, ep common.Address) (*filter.UserOperationReceipt, error)
// GetUserOpReceiptFunc is a general interface for fetching a UserOperationReceipt given a userOpHash,
// EntryPoint address, and block range.
type GetUserOpReceiptFunc = func(hash string, ep common.Address, blkRange uint64) (*filter.UserOperationReceipt, error)

func getUserOpReceiptNoop() GetUserOpReceiptFunc {
return func(hash string, ep common.Address) (*filter.UserOperationReceipt, error) {
return func(hash string, ep common.Address, blkRange uint64) (*filter.UserOperationReceipt, error) {
return nil, nil
}
}

// GetUserOpReceiptWithEthClient returns an implementation of GetUserOpReceiptFunc that relies on an eth
// client to fetch a UserOperationReceipt.
func GetUserOpReceiptWithEthClient(eth *ethclient.Client) GetUserOpReceiptFunc {
return func(hash string, ep common.Address) (*filter.UserOperationReceipt, error) {
return filter.GetUserOperationReceipt(eth, hash, ep)
return func(hash string, ep common.Address, blkRange uint64) (*filter.UserOperationReceipt, error) {
return filter.GetUserOperationReceipt(eth, hash, ep, blkRange)
}
}

Expand Down Expand Up @@ -95,19 +95,19 @@ func GetGasEstimateWithEthClient(
}

// GetUserOpByHashFunc is a general interface for fetching a UserOperation given a userOpHash, EntryPoint
// address, and chain ID.
type GetUserOpByHashFunc func(hash string, ep common.Address, chain *big.Int) (*filter.HashLookupResult, error)
// address, chain ID, and block range.
type GetUserOpByHashFunc func(hash string, ep common.Address, chain *big.Int, blkRange uint64) (*filter.HashLookupResult, error)

func getUserOpByHashNoop() GetUserOpByHashFunc {
return func(hash string, ep common.Address, chain *big.Int) (*filter.HashLookupResult, error) {
return func(hash string, ep common.Address, chain *big.Int, blkRange uint64) (*filter.HashLookupResult, error) {
return nil, nil
}
}

// GetUserOpByHashWithEthClient returns an implementation of GetUserOpByHashFunc that relies on an eth client
// to fetch a UserOperation.
func GetUserOpByHashWithEthClient(eth *ethclient.Client) GetUserOpByHashFunc {
return func(hash string, ep common.Address, chain *big.Int) (*filter.HashLookupResult, error) {
return filter.GetUserOperationByHash(eth, hash, ep, chain)
return func(hash string, ep common.Address, chain *big.Int, blkRange uint64) (*filter.HashLookupResult, error) {
return filter.GetUserOperationByHash(eth, hash, ep, chain, blkRange)
}
}
7 changes: 4 additions & 3 deletions pkg/entrypoint/filter/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func filterUserOperationEvent(
eth *ethclient.Client,
userOpHash string,
entryPoint common.Address,
blkRange uint64,
) (*entrypoint.EntrypointUserOperationEventIterator, error) {
ep, err := entrypoint.NewEntrypoint(entryPoint, eth)
if err != nil {
Expand All @@ -25,9 +26,9 @@ func filterUserOperationEvent(
}
toBlk := big.NewInt(0).SetUint64(bn)
startBlk := big.NewInt(0)
sub10kBlk := big.NewInt(0).Sub(toBlk, big.NewInt(10000))
if sub10kBlk.Cmp(startBlk) > 0 {
startBlk = sub10kBlk
subBlkRange := big.NewInt(0).Sub(toBlk, big.NewInt(0).SetUint64(blkRange))
if subBlkRange.Cmp(startBlk) > 0 {
startBlk = subBlkRange
}

return ep.FilterUserOperationEvent(
Expand Down
3 changes: 2 additions & 1 deletion pkg/entrypoint/filter/opbyhash.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ func GetUserOperationByHash(
userOpHash string,
entryPoint common.Address,
chainID *big.Int,
blkRange uint64,
) (*HashLookupResult, error) {
if !IsValidUserOpHash(userOpHash) {
//lint:ignore ST1005 This needs to match the bundler test spec.
return nil, errors.New("Missing/invalid userOpHash")
}

it, err := filterUserOperationEvent(eth, userOpHash, entryPoint)
it, err := filterUserOperationEvent(eth, userOpHash, entryPoint, blkRange)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/entrypoint/filter/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ func GetUserOperationReceipt(
eth *ethclient.Client,
userOpHash string,
entryPoint common.Address,
blkRange uint64,
) (*UserOperationReceipt, error) {
if !IsValidUserOpHash(userOpHash) {
//lint:ignore ST1005 This needs to match the bundler test spec.
return nil, errors.New("Missing/invalid userOpHash")
}

it, err := filterUserOperationEvent(eth, userOpHash, entryPoint)
it, err := filterUserOperationEvent(eth, userOpHash, entryPoint, blkRange)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit e9c267a

Please sign in to comment.