Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Conversation

buffalojoec
Copy link
Contributor

@buffalojoec buffalojoec commented Jan 9, 2024

This PR refactors the accounts schema to allow for providing specific account
data encoding only when requesting the data field, which is always going to
be a string of encoded data.

Accounts are queried from the RPC as jsonParsed by default, so when this field
is provided with an explicit encoding, it will return the account's data in
the requested encoding in the data field.

Note this means it's now possible to query multiple data encodings on accounts,
as depicted in the tests.

For more context, here's a review comment by @steveluscher on a previous PR:

#1837 (comment)

Important Note: This change will cause programAccounts queries to spam
the RPC for each account, as the resolver is called from each account's context.
This is remedied in the next commit in the stack.

Copy link
Contributor Author

buffalojoec commented Jan 9, 2024

@mergify mergify bot added the community label Jan 9, 2024
@buffalojoec buffalojoec force-pushed the 01-08-refactor_experimental_provide_account_encoding_on_the_data_field branch from 450582d to ca5cf6d Compare January 9, 2024 03:42
@buffalojoec buffalojoec force-pushed the 01-08-refactor_experimental_provide_account_encoding_on_the_data_field branch from ca5cf6d to d8547c8 Compare January 9, 2024 03:45
Copy link
Contributor

@steveluscher steveluscher left a comment

Choose a reason for hiding this comment

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

I think what this code is doing is:

  • unconditionally doing one account.load with no encoding
  • doing account.loads with whatever encoding is on zero or more data fields in the subselection

What I hope we can make happen is stuff like this:

  • If there are no data fields, fetch the account with the fastest-to-fetch encoding
  • If there is one data field set to Y encoding, then both fetches in resolveAccount and in resolveAccountData should use Y encoding

Back to your queue for comments!

@@ -13,3 +13,19 @@ export const resolveAccount = (fieldName: string) => {
) =>
parent[fieldName] === null ? null : context.loaders.account.load({ ...args, address: parent[fieldName] }, info);
Copy link
Contributor

@steveluscher steveluscher Jan 9, 2024

Choose a reason for hiding this comment

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

Maybe this is what you mean by ‘This is remedied in the next commit in the stack,’ but what should happen here is:

  1. The account resolver introspects the query itself, and looks into its own subselection for direct child data fields.
    a. If there are no data fields, fetch the account with whatever encoding is lightest on the RPC.
    b. If there are data fields, fetch the account with one of those encodings (to ensure a cache hit between the fetch for the account and the fetch for at least one of the data fields).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was going to tackle this in the next commit, but I guess now that I think of it there's no reason for this one then. 😅

@buffalojoec
Copy link
Contributor Author

What I hope we can make happen is stuff like this:

  • If there are no data fields, fetch the account with the fastest-to-fetch encoding
  • If there is one data field set to Y encoding, then both fetches in resolveAccount and in resolveAccountData should use Y encoding

I think this is probably a good approach. I can latch into this to help with programAccounts, which would be complete spam city with this implementation. I might walk this one back.

@buffalojoec
Copy link
Contributor Author

Closing to pull this off the current stack and introduce a new stack for schema revisions.

Copy link
Contributor

Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants