Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Try to lessen Linea finalizer RPC burden #1740

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pxrl
Copy link
Contributor

@pxrl pxrl commented Aug 9, 2024

The Linea SDK implements some unfortunate RPC queries that are not well-suited to being called in parallel. This seems to be resulting in errors being returned by upstream RPC providers. Serialise some queries, with a longer delay on retry, in order to try to lessen the load and reduce the error rate. This will inevitably lead to a longer execution time, but might help to save the bot from throwing.

The Linea SDK implements some unfortunate RPC queries that are not
well-suited to being called in parallel. This seems to be resulting in
errors being returned by upstream RPC providers. Serialise some queries,
with a longer delay on retry, in order to try to lessen the load and
reduce the error rate. This will inevitably lead to a longer execution
time, but might help to save the bot from throwing.
@pxrl pxrl requested a review from bmzig August 9, 2024 20:42
@james-a-morris
Copy link
Contributor

Side thought: we can just override the rpc provider that is set in the constructor. Here's what the constructor SDK looks like in JS:

    constructor(options) {
        this.network = options.network;
        this.mode = options.mode;
        this.l2MessageTreeDepth = options.l2MessageTreeDepth ?? constants_1.DEFAULT_L2_MESSAGE_TREE_DEPTH;
        if (options.mode === "read-write") {
            this.l1SignerPrivateKey = options.l1SignerPrivateKey;
            this.l2SignerPrivateKey = options.l2SignerPrivateKey;
            this.maxFeePerGas = options.feeEstimatorOptions?.maxFeePerGas;
            this.gasFeeEstimationPercentile = options.feeEstimatorOptions?.gasFeeEstimationPercentile;
        }
        this.l1Provider = new ProviderService_1.default(options.l1RpcUrl);
        this.l2Provider = new ProviderService_1.default(options.l2RpcUrl);
    }

and ProviderService is:

import { ethers } from "ethers";
import { JsonRpcProvider } from "@ethersproject/providers";
export default class ProviderService {
    provider: JsonRpcProvider;
    constructor(rpcUrl: string);
    getSigner(privateKey: string): ethers.Signer;
}

with it's JS being:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ethers_1 = require("ethers");
const providers_1 = require("@ethersproject/providers");
class ProviderService {
    constructor(rpcUrl) {
        this.provider = new providers_1.JsonRpcProvider(rpcUrl);
    }
    getSigner(privateKey) {
        try {
            return new ethers_1.Wallet(privateKey, this.provider);
        }
        catch (e) {
            throw new Error("Something went wrong when trying to generate Wallet. Please check your private key and the provider url.");
        }
    }
}
exports.default = ProviderService;

We can probably create a class identical to ProviderService, create two instances of it and override the state set by the constructor with:

    (sdk as unknown as Record<string, unknown>)["l1Provider"] = new ProviderService( <- with our RPC provider)`

Copy link
Contributor

@james-a-morris james-a-morris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants