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

rpc: add context toggle to getProgramAccounts #17399

Merged
merged 4 commits into from
May 22, 2021

Conversation

00nktk
Copy link
Contributor

@00nktk 00nktk commented May 21, 2021

Problem

There is no way in current implementation to get getProgramAccounts response with context.

Summary of Changes

Added an optional flag (with_context) in getProgramAccounts config to set the format of the response. The implementation is simple: if it is present and is true, the response will be wrapped in RpcResponse, otherwise it defaults to array. While it feels like returning RpcResponse should be the default behavior, there is a big chance that someone relies on the current format of the API. This might seem like not the most elegant solution, but it's backwards compatible.

@00nktk 00nktk force-pushed the get-program-accs-with-ctx branch from 8d4976f to d575af4 Compare May 21, 2021 23:56
Copy link
Member

@mvines mvines left a comment

Choose a reason for hiding this comment

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

This is a nice improvement, thank you!

@@ -1681,6 +1681,7 @@ pub fn process_show_stakes(
encoding: Some(solana_account_decoder::UiAccountEncoding::Base64),
..RpcAccountInfoConfig::default()
},
with_context: None,
Copy link
Member

Choose a reason for hiding this comment

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

How about this instead:
..RpcProgramAccountsConfig::default()
so we don't need to touch all these places the next time a new field is added. In some cases it looks like doing so would allow us to remove filters: None, too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Fixed

@00nktk 00nktk force-pushed the get-program-accs-with-ctx branch from d575af4 to 76daa23 Compare May 22, 2021 00:14
@00nktk 00nktk force-pushed the get-program-accs-with-ctx branch from 76daa23 to 745ec5c Compare May 22, 2021 00:18
@CriesofCarrots
Copy link
Contributor

Nice, I bet there are a few other rpc methods that could take advantage of OptionalContext

core/src/rpc.rs Outdated Show resolved Hide resolved
Co-authored-by: Michael Vines <[email protected]>
mvines
mvines previously approved these changes May 22, 2021
Copy link
Member

@mvines mvines left a comment

Choose a reason for hiding this comment

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

lgtm with my documentation nits picked

@mvines mvines added the v1.6 label May 22, 2021
Co-authored-by: Michael Vines <[email protected]>
@mergify mergify bot dismissed mvines’s stale review May 22, 2021 00:45

Pull request has been modified.

@00nktk
Copy link
Contributor Author

00nktk commented May 22, 2021

Nice, I bet there are a few other rpc methods that could take advantage of OptionalContext

Thanks! Glad to help!

@mvines mvines added the automerge Merge this Pull Request automatically once CI passes label May 22, 2021
@mergify mergify bot removed the automerge Merge this Pull Request automatically once CI passes label May 22, 2021
@mergify
Copy link
Contributor

mergify bot commented May 22, 2021

automerge label removed due to a CI failure

@mvines
Copy link
Member

mvines commented May 22, 2021

Downstream projects build fix landing via https://github.com/solana-labs/solana-program-library/pull/1766/files, once it does I'll retrigger the failed build here

@mvines mvines added the automerge Merge this Pull Request automatically once CI passes label May 22, 2021
@codecov
Copy link

codecov bot commented May 22, 2021

Codecov Report

Merging #17399 (c9ed7d6) into master (ff0e623) will decrease coverage by 0.0%.
The diff coverage is 80.9%.

@@            Coverage Diff            @@
##           master   #17399     +/-   ##
=========================================
- Coverage    82.8%    82.7%   -0.1%     
=========================================
  Files         424      424             
  Lines      118541   118554     +13     
=========================================
- Hits        98205    98150     -55     
- Misses      20336    20404     +68     

@mergify mergify bot merged commit d41266e into solana-labs:master May 22, 2021
mergify bot pushed a commit that referenced this pull request May 22, 2021
* fix(rpc): return context in get_program_accounts

* doc(rpc): document withContext flag

* fix(rpc): fix comment

Co-authored-by: Michael Vines <[email protected]>

* fix(rpc): fix doc

Co-authored-by: Michael Vines <[email protected]>

Co-authored-by: Michael Vines <[email protected]>
(cherry picked from commit d41266e)
mergify bot added a commit that referenced this pull request May 22, 2021
* fix(rpc): return context in get_program_accounts

* doc(rpc): document withContext flag

* fix(rpc): fix comment

Co-authored-by: Michael Vines <[email protected]>

* fix(rpc): fix doc

Co-authored-by: Michael Vines <[email protected]>

Co-authored-by: Michael Vines <[email protected]>
(cherry picked from commit d41266e)

Co-authored-by: Nikita <[email protected]>
@brooksprumo brooksprumo mentioned this pull request Aug 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this Pull Request automatically once CI passes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants