Commit bc5e060e authored by clabby's avatar clabby

Add flag to `op-node`

parent 80d619ab
...@@ -82,6 +82,12 @@ var ( ...@@ -82,6 +82,12 @@ var (
return &out return &out
}(), }(),
} }
L1RethDBPath = &cli.StringFlag{
Name: "l1.rethdb",
Usage: "The L1 RethDB path, used to fetch receipts for L1 blocks. Only applicable when using the `reth_db` RPC kind with `l1.rpckind`.",
EnvVars: prefixEnvVars("L1_RETHDB"),
Required: false,
}
L1RPCRateLimit = &cli.Float64Flag{ L1RPCRateLimit = &cli.Float64Flag{
Name: "l1.rpc-rate-limit", Name: "l1.rpc-rate-limit",
Usage: "Optional self-imposed global rate-limit on L1 RPC requests, specified in requests / second. Disabled if set to 0.", Usage: "Optional self-imposed global rate-limit on L1 RPC requests, specified in requests / second. Disabled if set to 0.",
...@@ -304,6 +310,7 @@ var optionalFlags = []cli.Flag{ ...@@ -304,6 +310,7 @@ var optionalFlags = []cli.Flag{
RollupHalt, RollupHalt,
RollupLoadProtocolVersions, RollupLoadProtocolVersions,
CanyonOverrideFlag, CanyonOverrideFlag,
L1RethDBPath,
} }
// Flags contains the list of configuration options available to the binary. // Flags contains the list of configuration options available to the binary.
......
...@@ -60,6 +60,9 @@ type Config struct { ...@@ -60,6 +60,9 @@ type Config struct {
// Cancel to request a premature shutdown of the node itself, e.g. when halting. This may be nil. // Cancel to request a premature shutdown of the node itself, e.g. when halting. This may be nil.
Cancel context.CancelCauseFunc Cancel context.CancelCauseFunc
// [OPTIONAL] The reth DB path to read receipts from
RethDBPath *string
} }
type RPCConfig struct { type RPCConfig struct {
......
...@@ -156,6 +156,8 @@ func (n *OpNode) initL1(ctx context.Context, cfg *Config) error { ...@@ -156,6 +156,8 @@ func (n *OpNode) initL1(ctx context.Context, cfg *Config) error {
return fmt.Errorf("failed to get L1 RPC client: %w", err) return fmt.Errorf("failed to get L1 RPC client: %w", err)
} }
rpcCfg.EthClientConfig.RethDBPath = cfg.RethDBPath
n.l1Source, err = sources.NewL1Client( n.l1Source, err = sources.NewL1Client(
client.NewInstrumentedRPC(l1Node, n.metrics), n.log, n.metrics.L1SourceCache, rpcCfg) client.NewInstrumentedRPC(l1Node, n.metrics), n.log, n.metrics.L1SourceCache, rpcCfg)
if err != nil { if err != nil {
......
...@@ -71,6 +71,11 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*node.Config, error) { ...@@ -71,6 +71,11 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*node.Config, error) {
haltOption = "" haltOption = ""
} }
var rethDBPath *string
if rdb := ctx.String(flags.L1RethDBPath.Name); rdb != "" {
rethDBPath = &rdb
}
cfg := &node.Config{ cfg := &node.Config{
L1: l1Endpoint, L1: l1Endpoint,
L2: l2Endpoint, L2: l2Endpoint,
...@@ -104,6 +109,7 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*node.Config, error) { ...@@ -104,6 +109,7 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*node.Config, error) {
ConfigPersistence: configPersistence, ConfigPersistence: configPersistence,
Sync: *syncConfig, Sync: *syncConfig,
RollupHalt: haltOption, RollupHalt: haltOption,
RethDBPath: rethDBPath,
} }
if err := cfg.LoadPersisted(log); err != nil { if err := cfg.LoadPersisted(log); err != nil {
......
...@@ -62,6 +62,9 @@ type EthClientConfig struct { ...@@ -62,6 +62,9 @@ type EthClientConfig struct {
// till we re-attempt the user-preferred methods. // till we re-attempt the user-preferred methods.
// If this is 0 then the client does not fall back to less optimal but available methods. // If this is 0 then the client does not fall back to less optimal but available methods.
MethodResetDuration time.Duration MethodResetDuration time.Duration
// [OPTIONAL] The reth DB path to fetch receipts from
RethDBPath *string
} }
func (c *EthClientConfig) Check() error { func (c *EthClientConfig) Check() error {
...@@ -132,6 +135,9 @@ type EthClient struct { ...@@ -132,6 +135,9 @@ type EthClient struct {
// methodResetDuration defines how long we take till we reset lastMethodsReset // methodResetDuration defines how long we take till we reset lastMethodsReset
methodResetDuration time.Duration methodResetDuration time.Duration
// [OPTIONAL] The reth DB path to fetch receipts from
rethDbPath *string
} }
func (s *EthClient) PickReceiptsMethod(txCount uint64) ReceiptsFetchingMethod { func (s *EthClient) PickReceiptsMethod(txCount uint64) ReceiptsFetchingMethod {
...@@ -179,6 +185,7 @@ func NewEthClient(client client.RPC, log log.Logger, metrics caching.Metrics, co ...@@ -179,6 +185,7 @@ func NewEthClient(client client.RPC, log log.Logger, metrics caching.Metrics, co
availableReceiptMethods: AvailableReceiptsFetchingMethods(config.RPCProviderKind), availableReceiptMethods: AvailableReceiptsFetchingMethods(config.RPCProviderKind),
lastMethodsReset: time.Now(), lastMethodsReset: time.Now(),
methodResetDuration: config.MethodResetDuration, methodResetDuration: config.MethodResetDuration,
rethDbPath: config.RethDBPath,
}, nil }, nil
} }
...@@ -357,7 +364,7 @@ func (s *EthClient) FetchReceipts(ctx context.Context, blockHash common.Hash) (e ...@@ -357,7 +364,7 @@ func (s *EthClient) FetchReceipts(ctx context.Context, blockHash common.Hash) (e
job = v job = v
} else { } else {
txHashes := eth.TransactionsToHashes(txs) txHashes := eth.TransactionsToHashes(txs)
job = NewReceiptsFetchingJob(s, s.client, s.maxBatchSize, eth.ToBlockID(info), info.ReceiptHash(), txHashes) job = NewReceiptsFetchingJob(s, s.client, s.maxBatchSize, eth.ToBlockID(info), info.ReceiptHash(), txHashes, s.rethDbPath)
s.receiptsCache.Add(blockHash, job) s.receiptsCache.Add(blockHash, job)
} }
receipts, err := job.Fetch(ctx) receipts, err := job.Fetch(ctx)
......
...@@ -281,7 +281,7 @@ const ( ...@@ -281,7 +281,7 @@ const (
// - Reth: array of RLP-encoded receipts // - Reth: array of RLP-encoded receipts
// See: // See:
// - reth's DB crate documentation: https://github.com/paradigmxyz/reth/blob/main/docs/crates/db.md // - reth's DB crate documentation: https://github.com/paradigmxyz/reth/blob/main/docs/crates/db.md
RethGetBlockReceiptsMDBX RethGetBlockReceipts
// Other: // Other:
// - 250 credits, not supported, strictly worse than other options. In quicknode price-table. // - 250 credits, not supported, strictly worse than other options. In quicknode price-table.
...@@ -318,7 +318,7 @@ func AvailableReceiptsFetchingMethods(kind RPCProviderKind) ReceiptsFetchingMeth ...@@ -318,7 +318,7 @@ func AvailableReceiptsFetchingMethods(kind RPCProviderKind) ReceiptsFetchingMeth
case RPCKindStandard: case RPCKindStandard:
return EthGetBlockReceipts | EthGetTransactionReceiptBatch return EthGetBlockReceipts | EthGetTransactionReceiptBatch
case RPCKindRethDB: case RPCKindRethDB:
return RethGetBlockReceiptsMDBX return RethGetBlockReceipts
default: default:
return EthGetTransactionReceiptBatch return EthGetTransactionReceiptBatch
} }
...@@ -330,7 +330,7 @@ func PickBestReceiptsFetchingMethod(kind RPCProviderKind, available ReceiptsFetc ...@@ -330,7 +330,7 @@ func PickBestReceiptsFetchingMethod(kind RPCProviderKind, available ReceiptsFetc
// If we have optimized methods available, it makes sense to use them, but only if the cost is // If we have optimized methods available, it makes sense to use them, but only if the cost is
// lower than fetching transactions one by one with the standard receipts RPC method. // lower than fetching transactions one by one with the standard receipts RPC method.
if kind == RPCKindRethDB { if kind == RPCKindRethDB {
return RethGetBlockReceiptsMDBX return RethGetBlockReceipts
} else if kind == RPCKindAlchemy { } else if kind == RPCKindAlchemy {
if available&AlchemyGetTransactionReceipts != 0 && txCount > 250/15 { if available&AlchemyGetTransactionReceipts != 0 && txCount > 250/15 {
return AlchemyGetTransactionReceipts return AlchemyGetTransactionReceipts
...@@ -389,11 +389,14 @@ type receiptsFetchingJob struct { ...@@ -389,11 +389,14 @@ type receiptsFetchingJob struct {
fetcher *IterativeBatchCall[common.Hash, *types.Receipt] fetcher *IterativeBatchCall[common.Hash, *types.Receipt]
// [OPTIONAL] RethDB path to fetch receipts from
rethDbPath *string
result types.Receipts result types.Receipts
} }
func NewReceiptsFetchingJob(requester ReceiptsRequester, client rpcClient, maxBatchSize int, block eth.BlockID, func NewReceiptsFetchingJob(requester ReceiptsRequester, client rpcClient, maxBatchSize int, block eth.BlockID,
receiptHash common.Hash, txHashes []common.Hash) *receiptsFetchingJob { receiptHash common.Hash, txHashes []common.Hash, rethDb *string) *receiptsFetchingJob {
return &receiptsFetchingJob{ return &receiptsFetchingJob{
requester: requester, requester: requester,
client: client, client: client,
...@@ -401,6 +404,7 @@ func NewReceiptsFetchingJob(requester ReceiptsRequester, client rpcClient, maxBa ...@@ -401,6 +404,7 @@ func NewReceiptsFetchingJob(requester ReceiptsRequester, client rpcClient, maxBa
block: block, block: block,
receiptHash: receiptHash, receiptHash: receiptHash,
txHashes: txHashes, txHashes: txHashes,
rethDbPath: rethDb,
} }
} }
...@@ -478,8 +482,11 @@ func (job *receiptsFetchingJob) runAltMethod(ctx context.Context, m ReceiptsFetc ...@@ -478,8 +482,11 @@ func (job *receiptsFetchingJob) runAltMethod(ctx context.Context, m ReceiptsFetc
err = job.client.CallContext(ctx, &result, "eth_getBlockReceipts", job.block.Hash) err = job.client.CallContext(ctx, &result, "eth_getBlockReceipts", job.block.Hash)
case ErigonGetBlockReceiptsByBlockHash: case ErigonGetBlockReceiptsByBlockHash:
err = job.client.CallContext(ctx, &result, "erigon_getBlockReceiptsByBlockHash", job.block.Hash) err = job.client.CallContext(ctx, &result, "erigon_getBlockReceiptsByBlockHash", job.block.Hash)
case RethGetBlockReceiptsMDBX: case RethGetBlockReceipts:
res, err := FetchRethReceipts("placeholder", &job.block.Hash) if job.rethDbPath == nil {
return fmt.Errorf("reth_db path not set")
}
res, err := FetchRethReceipts(*job.rethDbPath, &job.block.Hash)
if err != nil { if err != nil {
return err return err
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment