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

improve rpc request result performance #1586

Open
wants to merge 39 commits into
base: kjs/sync-store
Choose a base branch
from

Conversation

kyscott18
Copy link
Collaborator

Description

Improved several performance characteristics surrounding cached rpc requests

  • Dropped request column from rpc_request_results table
  • Added index to support pruneRpcRequestResults
  • Granular cache for multicall requests
  • Stopped caching "0x" rpc responses, which are sometimes wrongly sent by degraded rpc

async () => {
const requestHashes = requests.map((request) =>
crypto.createHash("md5").update(request).digest("hex"),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@typedarray Need to be very careful that this matches the previous hashes that we generated by postgres. I added a test for this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems good, but we should double check

  • Make sure any pre-processing we're doing (casing, sorting keys?) is the same as before
  • Casing, we're storing this in a TEXT column
  • Any possibility that the strings were changed by the driver before making it to PG (in the old imp)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The request is preprocessed before making it to this function.

})).map((request) =>
toLowerCase(JSON.stringify(orderObject(request))),
);

Comment on lines +139 to +142
// Note: we don't cache request that failed or returned "0x". See more about "0x" below.
.filter(
({ result }) => result?.success && result.returnData !== "0x",
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@typedarray I don't think we should cache failed requests and just re-request them

Copy link
Collaborator

Choose a reason for hiding this comment

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

Brilliant

@kyscott18 kyscott18 changed the title import rpc request result performance improve rpc request result performance Mar 7, 2025
@kyscott18 kyscott18 linked an issue Mar 12, 2025 that may be closed by this pull request
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.

context.client.readContract occasionally returns 0x
2 participants