From 95c934f4b4a504de8ca8064b11005b966ba5738c Mon Sep 17 00:00:00 2001 From: welkin22 Date: Wed, 31 Jul 2024 18:15:21 +0800 Subject: [PATCH 1/4] feat(op-node): add l1 cache size config --- op-chain-ops/cmd/check-derivation/main.go | 2 +- op-node/flags/flags.go | 8 ++++++++ op-node/node/client.go | 14 ++++++++++++++ op-node/service.go | 1 + op-service/sources/l1_client.go | 4 +++- 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/op-chain-ops/cmd/check-derivation/main.go b/op-chain-ops/cmd/check-derivation/main.go index 499b128f87..dd5d631942 100644 --- a/op-chain-ops/cmd/check-derivation/main.go +++ b/op-chain-ops/cmd/check-derivation/main.go @@ -114,7 +114,7 @@ func newClientsFromContext(cliCtx *cli.Context) (*ethclient.Client, *sources.Eth MethodResetDuration: time.Minute, } cl := ethclient.NewClient(clients.L2RpcClient) - ethCl, err := sources.NewEthClient(client.NewBaseRPCClient(clients.L2RpcClient), log.Root(), nil, ðClCfg) + ethCl, err := sources.NewEthClient(client.NewBaseRPCClient(clients.L2RpcClient), log.Root(), nil, ðClCfg, false) if err != nil { return nil, nil, err } diff --git a/op-node/flags/flags.go b/op-node/flags/flags.go index a6037d1ce9..f19a68ce82 100644 --- a/op-node/flags/flags.go +++ b/op-node/flags/flags.go @@ -180,6 +180,13 @@ var ( Value: 20, Category: L1RPCCategory, } + L1RPCMaxCacheSize = &cli.IntFlag{ + Name: "l1.rpc-max-cache-size", + Usage: "The maximum cache size of the L1 client. it should be greater than or equal to the max lag of unsafe and safe block heights. Must be greater than or equal to 1", + EnvVars: prefixEnvVars("L1_RPC_MAX_CACHE_SIZE"), + Value: 1000, + Category: L1RPCCategory, + } L1HTTPPollInterval = &cli.DurationFlag{ Name: "l1.http-poll-interval", Usage: "Polling interval for latest-block subscription when using an HTTP RPC provider. Ignored for other types of RPC endpoints.", @@ -417,6 +424,7 @@ var optionalFlags = []cli.Flag{ L1RPCProviderKind, L1RPCRateLimit, L1RPCMaxBatchSize, + L1RPCMaxCacheSize, L1RPCMaxConcurrency, L1HTTPPollInterval, L1ArchiveBlobRpcAddr, diff --git a/op-node/node/client.go b/op-node/node/client.go index 3f2bf80b05..77790a8222 100644 --- a/op-node/node/client.go +++ b/op-node/node/client.go @@ -117,6 +117,9 @@ type L1EndpointConfig struct { // BatchSize specifies the maximum batch-size, which also applies as L1 rate-limit burst amount (if set). BatchSize int + // CacheSize specifies the maximum cache size of l1 client. it should be greater than or equal to the max lag of unsafe and safe block heights. + CacheSize int + // MaxConcurrency specifies the maximum number of concurrent requests to the L1 RPC. MaxConcurrency int @@ -133,6 +136,9 @@ func (cfg *L1EndpointConfig) Check() error { if cfg.BatchSize < 1 || cfg.BatchSize > 500 { return fmt.Errorf("batch size is invalid or unreasonable: %d", cfg.BatchSize) } + if cfg.CacheSize < 1 { + return fmt.Errorf("cache size is invalid or unreasonable: %d", cfg.CacheSize) + } if cfg.RateLimit < 0 { return fmt.Errorf("rate limit cannot be negative") } @@ -163,6 +169,10 @@ func (cfg *L1EndpointConfig) Setup(ctx context.Context, log log.Logger, rollupCf rpcCfg := sources.L1ClientDefaultConfig(rollupCfg, cfg.L1TrustRPC, cfg.L1RPCKind) rpcCfg.MaxRequestsPerBatch = cfg.BatchSize rpcCfg.MaxConcurrentRequests = cfg.MaxConcurrency + rpcCfg.ReceiptsCacheSize = cfg.CacheSize + rpcCfg.HeadersCacheSize = cfg.CacheSize + rpcCfg.TransactionsCacheSize = cfg.CacheSize + rpcCfg.PayloadsCacheSize = cfg.CacheSize return l1Node, rpcCfg, nil } @@ -177,6 +187,10 @@ func fallbackClientWrap(ctx context.Context, logger log.Logger, urlList []string rpcCfg := sources.L1ClientDefaultConfig(rollupCfg, cfg.L1TrustRPC, cfg.L1RPCKind) rpcCfg.MaxRequestsPerBatch = cfg.BatchSize rpcCfg.MaxConcurrentRequests = cfg.MaxConcurrency + rpcCfg.ReceiptsCacheSize = cfg.CacheSize + rpcCfg.HeadersCacheSize = cfg.CacheSize + rpcCfg.TransactionsCacheSize = cfg.CacheSize + rpcCfg.PayloadsCacheSize = cfg.CacheSize return l1Node, rpcCfg, nil } diff --git a/op-node/service.go b/op-node/service.go index 8602baa7e5..7d850ed91d 100644 --- a/op-node/service.go +++ b/op-node/service.go @@ -158,6 +158,7 @@ func NewL1EndpointConfig(ctx *cli.Context) *node.L1EndpointConfig { L1RPCKind: sources.RPCProviderKind(strings.ToLower(ctx.String(flags.L1RPCProviderKind.Name))), RateLimit: ctx.Float64(flags.L1RPCRateLimit.Name), BatchSize: ctx.Int(flags.L1RPCMaxBatchSize.Name), + CacheSize: ctx.Int(flags.L1RPCMaxCacheSize.Name), HttpPollInterval: ctx.Duration(flags.L1HTTPPollInterval.Name), MaxConcurrency: ctx.Int(flags.L1RPCMaxConcurrency.Name), } diff --git a/op-service/sources/l1_client.go b/op-service/sources/l1_client.go index a347a17272..67faa259b4 100644 --- a/op-service/sources/l1_client.go +++ b/op-service/sources/l1_client.go @@ -206,7 +206,9 @@ func (s *L1Client) GoOrUpdatePreFetchReceipts(ctx context.Context, l1Start uint6 continue } if !isSuccess { - s.log.Debug("pre fetch receipts fail without error,need retry", "blockHash", blockInfo.Hash, "blockNumber", blockNumber) + s.log.Debug("The receipts cache may be full. "+ + "please ensure the difference between the safe block height and the unsafe block height is less than or equal to the cache size.", + "blockHash", blockInfo.Hash, "blockNumber", blockNumber) time.Sleep(1 * time.Second) continue } From 6aaee80f514ff38a58a1bf706f83924ec5bcbc85 Mon Sep 17 00:00:00 2001 From: welkin22 Date: Wed, 31 Jul 2024 21:01:00 +0800 Subject: [PATCH 2/4] modify code comments --- op-node/flags/flags.go | 2 +- op-node/node/client.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/op-node/flags/flags.go b/op-node/flags/flags.go index f19a68ce82..742e4f9efc 100644 --- a/op-node/flags/flags.go +++ b/op-node/flags/flags.go @@ -182,7 +182,7 @@ var ( } L1RPCMaxCacheSize = &cli.IntFlag{ Name: "l1.rpc-max-cache-size", - Usage: "The maximum cache size of the L1 client. it should be greater than or equal to the max lag of unsafe and safe block heights. Must be greater than or equal to 1", + Usage: "The maximum cache size of the L1 client. it should be greater than or equal to the maximum height difference between the L1 blocks corresponding to the unsafe block height and the safe block height. Must be greater than or equal to 1", EnvVars: prefixEnvVars("L1_RPC_MAX_CACHE_SIZE"), Value: 1000, Category: L1RPCCategory, diff --git a/op-node/node/client.go b/op-node/node/client.go index 77790a8222..6873bb5cc4 100644 --- a/op-node/node/client.go +++ b/op-node/node/client.go @@ -117,7 +117,8 @@ type L1EndpointConfig struct { // BatchSize specifies the maximum batch-size, which also applies as L1 rate-limit burst amount (if set). BatchSize int - // CacheSize specifies the maximum cache size of l1 client. it should be greater than or equal to the max lag of unsafe and safe block heights. + // CacheSize specifies the maximum cache size of l1 client. + // it should be greater than or equal to the maximum height difference between the L1 blocks corresponding to the unsafe block height and the safe block height. CacheSize int // MaxConcurrency specifies the maximum number of concurrent requests to the L1 RPC. From e05d35a3f55fe3f13bd3bb5a6f035fc6dc6b4926 Mon Sep 17 00:00:00 2001 From: welkin22 Date: Wed, 31 Jul 2024 21:03:11 +0800 Subject: [PATCH 3/4] modify the log --- op-service/sources/l1_client.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/op-service/sources/l1_client.go b/op-service/sources/l1_client.go index 67faa259b4..e2359a843a 100644 --- a/op-service/sources/l1_client.go +++ b/op-service/sources/l1_client.go @@ -207,7 +207,8 @@ func (s *L1Client) GoOrUpdatePreFetchReceipts(ctx context.Context, l1Start uint6 } if !isSuccess { s.log.Debug("The receipts cache may be full. "+ - "please ensure the difference between the safe block height and the unsafe block height is less than or equal to the cache size.", + "please ensure the maximum height difference between the L1 blocks "+ + "corresponding to the unsafe block height and the safe block height is less than or equal to the cache size.", "blockHash", blockInfo.Hash, "blockNumber", blockNumber) time.Sleep(1 * time.Second) continue From 8f7737ab0d4455ccaa2f3e1a0496edaafcafa7dc Mon Sep 17 00:00:00 2001 From: welkin22 Date: Thu, 1 Aug 2024 10:19:47 +0800 Subject: [PATCH 4/4] fix e2e case --- op-e2e/setup.go | 1 + 1 file changed, 1 insertion(+) diff --git a/op-e2e/setup.go b/op-e2e/setup.go index 0be50744c2..f0ebe03f1a 100644 --- a/op-e2e/setup.go +++ b/op-e2e/setup.go @@ -923,6 +923,7 @@ func configureL1(rollupNodeCfg *rollupNode.Config, l1Node EthInstance) { BatchSize: 20, HttpPollInterval: time.Millisecond * 100, MaxConcurrency: 10, + CacheSize: 1000, } }