Commit bc5e060e authored by clabby's avatar clabby

Add flag to `op-node`

parent 80d619ab
......@@ -82,6 +82,12 @@ var (
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{
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.",
......@@ -304,6 +310,7 @@ var optionalFlags = []cli.Flag{
RollupHalt,
RollupLoadProtocolVersions,
CanyonOverrideFlag,
L1RethDBPath,
}
// Flags contains the list of configuration options available to the binary.
......
......@@ -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 context.CancelCauseFunc
// [OPTIONAL] The reth DB path to read receipts from
RethDBPath *string
}
type RPCConfig struct {
......
......@@ -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)
}
rpcCfg.EthClientConfig.RethDBPath = cfg.RethDBPath
n.l1Source, err = sources.NewL1Client(
client.NewInstrumentedRPC(l1Node, n.metrics), n.log, n.metrics.L1SourceCache, rpcCfg)
if err != nil {
......
......@@ -71,6 +71,11 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*node.Config, error) {
haltOption = ""
}
var rethDBPath *string
if rdb := ctx.String(flags.L1RethDBPath.Name); rdb != "" {
rethDBPath = &rdb
}
cfg := &node.Config{
L1: l1Endpoint,
L2: l2Endpoint,
......@@ -104,6 +109,7 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*node.Config, error) {
ConfigPersistence: configPersistence,
Sync: *syncConfig,
RollupHalt: haltOption,
RethDBPath: rethDBPath,
}
if err := cfg.LoadPersisted(log); err != nil {
......
......@@ -62,6 +62,9 @@ type EthClientConfig struct {
// 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.
MethodResetDuration time.Duration
// [OPTIONAL] The reth DB path to fetch receipts from
RethDBPath *string
}
func (c *EthClientConfig) Check() error {
......@@ -132,6 +135,9 @@ type EthClient struct {
// methodResetDuration defines how long we take till we reset lastMethodsReset
methodResetDuration time.Duration
// [OPTIONAL] The reth DB path to fetch receipts from
rethDbPath *string
}
func (s *EthClient) PickReceiptsMethod(txCount uint64) ReceiptsFetchingMethod {
......@@ -179,6 +185,7 @@ func NewEthClient(client client.RPC, log log.Logger, metrics caching.Metrics, co
availableReceiptMethods: AvailableReceiptsFetchingMethods(config.RPCProviderKind),
lastMethodsReset: time.Now(),
methodResetDuration: config.MethodResetDuration,
rethDbPath: config.RethDBPath,
}, nil
}
......@@ -357,7 +364,7 @@ func (s *EthClient) FetchReceipts(ctx context.Context, blockHash common.Hash) (e
job = v
} else {
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)
}
receipts, err := job.Fetch(ctx)
......
......@@ -281,7 +281,7 @@ const (
// - Reth: array of RLP-encoded receipts
// See:
// - reth's DB crate documentation: https://github.com/paradigmxyz/reth/blob/main/docs/crates/db.md
RethGetBlockReceiptsMDBX
RethGetBlockReceipts
// Other:
// - 250 credits, not supported, strictly worse than other options. In quicknode price-table.
......@@ -318,7 +318,7 @@ func AvailableReceiptsFetchingMethods(kind RPCProviderKind) ReceiptsFetchingMeth
case RPCKindStandard:
return EthGetBlockReceipts | EthGetTransactionReceiptBatch
case RPCKindRethDB:
return RethGetBlockReceiptsMDBX
return RethGetBlockReceipts
default:
return EthGetTransactionReceiptBatch
}
......@@ -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
// lower than fetching transactions one by one with the standard receipts RPC method.
if kind == RPCKindRethDB {
return RethGetBlockReceiptsMDBX
return RethGetBlockReceipts
} else if kind == RPCKindAlchemy {
if available&AlchemyGetTransactionReceipts != 0 && txCount > 250/15 {
return AlchemyGetTransactionReceipts
......@@ -389,11 +389,14 @@ type receiptsFetchingJob struct {
fetcher *IterativeBatchCall[common.Hash, *types.Receipt]
// [OPTIONAL] RethDB path to fetch receipts from
rethDbPath *string
result types.Receipts
}
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{
requester: requester,
client: client,
......@@ -401,6 +404,7 @@ func NewReceiptsFetchingJob(requester ReceiptsRequester, client rpcClient, maxBa
block: block,
receiptHash: receiptHash,
txHashes: txHashes,
rethDbPath: rethDb,
}
}
......@@ -478,8 +482,11 @@ func (job *receiptsFetchingJob) runAltMethod(ctx context.Context, m ReceiptsFetc
err = job.client.CallContext(ctx, &result, "eth_getBlockReceipts", job.block.Hash)
case ErigonGetBlockReceiptsByBlockHash:
err = job.client.CallContext(ctx, &result, "erigon_getBlockReceiptsByBlockHash", job.block.Hash)
case RethGetBlockReceiptsMDBX:
res, err := FetchRethReceipts("placeholder", &job.block.Hash)
case RethGetBlockReceipts:
if job.rethDbPath == nil {
return fmt.Errorf("reth_db path not set")
}
res, err := FetchRethReceipts(*job.rethDbPath, &job.block.Hash)
if err != nil {
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