diff --git a/core/client/eth/client.go b/core/client/eth/client.go index 1872fa9748..1abfbeb028 100644 --- a/core/client/eth/client.go +++ b/core/client/eth/client.go @@ -67,7 +67,12 @@ func Dial(ctx context.Context, cfg Config) (*Client, error) { return nil, fmt.Errorf("couldn't instantiate Ethereum client: %w", err) } - return &Client{ETHClient: newEthClientWrapper(ethClient), cfg: cfg}, nil + wrappedClient, err := newEthClientWrapper(ethClient) + if err != nil { + return nil, fmt.Errorf("could not instantiate lru cache: %w", err) + } + + return &Client{ETHClient: wrappedClient, cfg: cfg}, nil } func (c *Client) UpdateEthereumConfig(ethConfig *types.EthereumConfig) error { diff --git a/core/client/eth/client_wrapper.go b/core/client/eth/client_wrapper.go index 645a0b2339..77045916f0 100644 --- a/core/client/eth/client_wrapper.go +++ b/core/client/eth/client_wrapper.go @@ -3,14 +3,13 @@ package eth import ( "context" "math/big" - "time" "code.vegaprotocol.io/vega/core/metrics" "github.com/ethereum/go-ethereum" ethcommon "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/hashicorp/golang-lru/v2/expirable" + lru "github.com/hashicorp/golang-lru/v2" ) // ETHClient ... @@ -53,17 +52,19 @@ type ETHClient interface { //revive:disable:exported type ethClientWrapper struct { clt ETHClient - headerByNumberCache *expirable.LRU[string, *ethtypes.Header] + headerByNumberCache *lru.Cache[string, *ethtypes.Header] } -func newEthClientWrapper(clt ETHClient) *ethClientWrapper { - return ðClientWrapper{ - clt: clt, - // arbitrary size of 100 blocks, kept for at most 10 minutes, - // let see later how to make this less hardcoded - headerByNumberCache: expirable.NewLRU[string, *ethtypes.Header](100, nil, 10*time.Minute), +func newEthClientWrapper(clt ETHClient) (*ethClientWrapper, error) { + cache, err := lru.New[string, *ethtypes.Header](1000) + if err != nil { + return nil, err } + return ðClientWrapper{ + clt: clt, + headerByNumberCache: cache, + }, nil } func (c *ethClientWrapper) ChainID(ctx context.Context) (*big.Int, error) {