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

rpc: Support token-2022 in token-specific calls #25150

Merged
merged 2 commits into from
May 17, 2022

Conversation

joncinque
Copy link
Contributor

Problem

While running tests for solana-labs/solana-program-library#3071 against master, there were still issues recognizing token-2022 accounts for some of the token-specific RPC endpoints.

Summary of Changes

Support token-2022 in a few more places in RPC. Most of the changes are tests.

A few changes that you might disagree with, so I want to flag them:

  • the filter resolution logic for token-2022 is a bit tricky, since a token account can either have length 165 or data[165] == 2. if someone specifies one of those, should we assume that they actually want all token accounts or truly respect what they say?
  • added program_id to the UiTokenAccount types, which is helpful in the CLI when figuring out dynamically which program id the account belongs to
  • added ParsableAccount::SplToken2022, and the program name that comes out is "spl-token-2022"

@joncinque joncinque requested a review from CriesofCarrots May 11, 2022 21:36
account-decoder/src/parse_account_data.rs Show resolved Hide resolved
bytes: MemcmpEncodedBytes::Bytes(bytes),
..
}) => {
}) if *offset == account_packed_len && *program_id == inline_spl_token_2022::id() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about steering token-2022 users toward adding RpcFilterType::TokenAccountState instead of a token-2022-specific memcmp?

Then it would be something like:

let mut token_account_state_filter: bool = false;
...
match filter {
    RpcFilterType::TokenAccountState => {
        token_account_state_filter = true;
    }
    ...
}
if data_size_filter == Some(account_packed_len as u64) || token_account_state_filter {
    ...
}

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 that makes way more sense. If someone does search on just the 165th byte though and it's possible to use an index, is it worth supporting that? Or should it use the normal getProgramAccounts implementation?

Copy link
Contributor

@CriesofCarrots CriesofCarrots May 11, 2022

Choose a reason for hiding this comment

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

Yeah, I suppose there's no harm in supporting that (165th byte memcmp) filter for secondary indexes, and it does provide a way to use the secondary indexes to get only spl-token-2022 accounts, which could be useful.
So to be explicit regarding this...

if someone specifies one of those, should we assume that they actually want all token accounts or truly respect what they say?

I'm inclined to respect what they say, which is how your current code will work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My apologies, I hadn't read the whole thing and just assumed that it was simplifying the filter and not adding more filters. I added the token account state filter as you initially asked.

rpc/src/rpc.rs Show resolved Hide resolved
rpc/src/rpc.rs Show resolved Hide resolved
@codecov
Copy link

codecov bot commented May 13, 2022

Codecov Report

Merging #25150 (e0bdbca) into master (69a0ff9) will increase coverage by 0.0%.
The diff coverage is 83.6%.

@@            Coverage Diff            @@
##           master   #25150     +/-   ##
=========================================
  Coverage    82.0%    82.1%             
=========================================
  Files         598      610     +12     
  Lines      165882   168068   +2186     
=========================================
+ Hits       136125   138031   +1906     
- Misses      29757    30037    +280     

@joncinque
Copy link
Contributor Author

This is ready for another look, whenever you have a moment

Copy link
Contributor

@CriesofCarrots CriesofCarrots left a comment

Choose a reason for hiding this comment

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

Thanks, this lgtm!

@joncinque joncinque merged commit 0820065 into solana-labs:master May 17, 2022
@joncinque joncinque deleted the tk22-rpc branch May 17, 2022 19:02
mergify bot pushed a commit that referenced this pull request Jun 22, 2022
* rpc: Support token-2022 in token-specific calls

* Address feedback

(cherry picked from commit 0820065)

# Conflicts:
#	account-decoder/src/parse_token.rs
joncinque added a commit that referenced this pull request Jun 23, 2022
* rpc: Support token-2022 in token-specific calls

* Address feedback
mergify bot added a commit that referenced this pull request Jun 23, 2022
* rpc: Support token-2022 in token-specific calls

* Address feedback

Co-authored-by: Jon Cinque <jon.cinque@gmail.com>
jeffwashington pushed a commit to jeffwashington/solana that referenced this pull request Jun 29, 2022
* rpc: Support token-2022 in token-specific calls

* Address feedback
jeffwashington pushed a commit to jeffwashington/solana that referenced this pull request Jun 29, 2022
* rpc: Support token-2022 in token-specific calls

* Address feedback
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants