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

Support Account Data for Seeds in Account Resolution #5182

Merged
merged 11 commits into from
Sep 25, 2023

Conversation

buffalojoec
Copy link
Contributor

@buffalojoec buffalojoec commented Aug 31, 2023

This PR adds support for account data as a seed configuration for a PDA stored
within validation data.

A dynamic program-derived address may depend on one or more seeds that are
actually taken from the inner data of some account in the list of accounts
provided to the program.

Reviewing this PR

  • Commit 1: Changes made to account resolution
  • Commit 2: Re-working tests and docs
  • Commit 3: Fixing the closure provided to a transfer hook test to return None for accounts that don't exist

@buffalojoec
Copy link
Contributor Author

buffalojoec commented Aug 31, 2023

Finally circled back to this bad boy. It's hilarious (and painful) how simple this change appears despite the tribulations it went through.

In any case, it's worth mentioning that there are a few things I dislike about the design.

RPC Fetch Abuse

Because not every address is known at the time add_to_instruction is invoked, it's not possible to use the RPC's get_multiple_accounts method over get_account.

I don't think there's anything we can do about this, but we are going to have a problem if people need to resolve a large number of accounts off-chain.

I propose three solutions:

  • Provide a fetch_account_data: bool switch (not the best).
  • Insert a new TLV entry in front of the ExtraAccountMetaList with length 0 that simply uses a discriminator to declare whether or not the extra account meta configuration requires the fetching of account data.
  • Leverage the TLV entry above to actually describe specifically which accounts must be fetched. For example, it could be a vector of u8 values describing each index of an account that must be fetched. We could also provide a helper for building ExtraAccountMetaList data that does this automatically based on seed configs (my favorite).
#[discriminator_hash_input("extra_account_metas:fetch_configs")]
pub struct FetchConfiigs {
    indices: Vec<u8>,
}

impl SplVariableLenPack for FetchConfigs {
    ...
}

@buffalojoec
Copy link
Contributor Author

buffalojoec commented Aug 31, 2023

In conclusion, I think the points raised above should become issues and solutions can be implemented later, but as long as nobody presses on their RPC endpoint rate limits with their list of extra metas, we should be OK for merging this.

As it stands right now, the most restrictive is https://api.devnet.solana.com at 100 requests per second. I don't think anyone using transfer hook will near 100 accounts for a while. Once they do, we will integrate a more robust solution.

@buffalojoec buffalojoec force-pushed the account-data-resolution branch 5 times, most recently from b6ed38f to b19cb57 Compare August 31, 2023 20:40
@buffalojoec buffalojoec marked this pull request as ready for review August 31, 2023 21:55
@buffalojoec buffalojoec force-pushed the account-data-resolution branch 3 times, most recently from 46281e6 to be2e6f0 Compare August 31, 2023 22:07
@buffalojoec buffalojoec requested a review from joncinque August 31, 2023 22:07
@buffalojoec buffalojoec added the do-not-close Add this tag to exempt a PR / issue from being closed automatically label Sep 1, 2023
Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Looks really great overall! Nothing big here, mostly nits, so this should be ready to go soon

libraries/tlv-account-resolution/src/state.rs Outdated Show resolved Hide resolved
libraries/tlv-account-resolution/src/state.rs Outdated Show resolved Hide resolved
libraries/tlv-account-resolution/src/state.rs Outdated Show resolved Hide resolved
libraries/tlv-account-resolution/src/account.rs Outdated Show resolved Hide resolved
libraries/tlv-account-resolution/src/account.rs Outdated Show resolved Hide resolved
libraries/tlv-account-resolution/src/state.rs Outdated Show resolved Hide resolved
libraries/tlv-account-resolution/src/account.rs Outdated Show resolved Hide resolved
libraries/tlv-account-resolution/src/state.rs Outdated Show resolved Hide resolved
libraries/tlv-account-resolution/src/state.rs Outdated Show resolved Hide resolved
libraries/tlv-account-resolution/src/state.rs Show resolved Hide resolved
joncinque
joncinque previously approved these changes Sep 22, 2023
Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Really great work! Just one little question, but otherwise this is ready to go from my side

libraries/tlv-account-resolution/src/state.rs Outdated Show resolved Hide resolved
@buffalojoec
Copy link
Contributor Author

buffalojoec commented Sep 22, 2023

Really great work! Just one little question, but otherwise this is ready to go from my side

Thanks Jon, appreciate the review & feedback.

I still have to address the Rust doc comment you had, which unfortunately may change a few of the future-based types.

Basically, I feel like RPC client is going to be one of the more popular off-chain provided "get account data" closures, so I'd better make sure it isn't a pain to package up for the resolution call.

That will be just one more commit. Also will rebase, which will (maybe?) fix audit 💪🏼

@joncinque
Copy link
Contributor

I still have to address the Rust doc comment you had, which unfortunately may change a few of the future-based types.

Ah right, my bad, this is why I shouldn't do reviews past a certain hour

@joncinque
Copy link
Contributor

Also will rebase, which will (maybe?) fix audit 💪🏼

And yeah we should be good

@mergify mergify bot dismissed joncinque’s stale review September 22, 2023 09:22

Pull request has been modified.

@buffalojoec buffalojoec force-pushed the account-data-resolution branch from 6c56437 to ff2c5e1 Compare September 22, 2023 09:23
@buffalojoec
Copy link
Contributor Author

@joncinque In my last commit "enable doctest", I set up a client with RPC very similar to the test client I use in state.rs. This configuration will work for anyone who uses ExtraAccountMetaList::add_to_instruction(..).

However, if they try to use a closure and just call an RPC client object directly, like below, the static lifetime requirements of futures will not allow you to pass an object and then return a future that depends on a reference to said object, even if you use move all over the place.

|address: Pubkey| {
   client
      .get_account(&address) // Temporary value
      .map_ok(|acct| Some(acct.data))
      .map_err(|e| Box::new(e) as AccountFetchError)
}

If the configuration I've written in the Rustdoc looks good to you, this is ready to roll.

joncinque
joncinque previously approved these changes Sep 22, 2023
Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Looks great! Just one last micro-nit and then this is good to go. I couldn't come up with anything better than your custom client

libraries/tlv-account-resolution/src/state.rs Outdated Show resolved Hide resolved
@buffalojoec buffalojoec force-pushed the account-data-resolution branch from ff2c5e1 to d578d10 Compare September 22, 2023 11:11
@mergify mergify bot dismissed joncinque’s stale review September 22, 2023 11:11

Pull request has been modified.

@buffalojoec
Copy link
Contributor Author

This should be good to go

Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Really great work, thanks!

@buffalojoec buffalojoec merged commit 199361b into solana-labs:master Sep 25, 2023
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-close Add this tag to exempt a PR / issue from being closed automatically
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants