-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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: rework binary encoding. BREAKING CHANGE #11646
Conversation
f611e0b
to
9e532ed
Compare
Codecov Report
@@ Coverage Diff @@
## master #11646 +/- ##
=========================================
- Coverage 82.1% 82.0% -0.1%
=========================================
Files 330 330
Lines 76198 76222 +24
=========================================
+ Hits 62560 62569 +9
- Misses 13638 13653 +15 |
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] | ||
#[serde(rename_all = "camelCase")] | ||
pub enum UiAccountEncoding { | ||
Binary, // SLOW! Avoid this encoding | ||
Binary, // Legacy. Retained for RPC backwards compatibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One day we can remove "binary" when it starts getting in the way. It's no longer documented
if let Some(ref mut account) = rpc_account { | ||
if let Binary(_) = &account.data { | ||
let tmp = Binary64(String::new()); | ||
match std::mem::replace(&mut account.data, tmp) { | ||
Binary(new_data) => account.data = Binary64(new_data), | ||
_ => panic!("should have gotten binary here."), | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with Binary(String)
and Binary64(String)
is visible here. Serde can't distinguish between the two on deserialization with the the untagged
attribute, so this workaround was previously needed for Rust RPC clients.
@@ -3119,24 +3122,27 @@ pub mod tests { | |||
bank.store_account(&address, &account); | |||
|
|||
let req = format!( | |||
r#"{{"jsonrpc":"2.0","id":1,"method":"getAccountInfo","params":["{}", {{"encoding":"binary64"}}]}}"#, | |||
r#"{{"jsonrpc":"2.0","id":1,"method":"getAccountInfo","params":["{}", {{"encoding":"base64"}}]}}"#, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this feels so much nicer. "binary64"? What's that! "base64"? Oh, that's base64.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes yes yes!! 🙌
This PR escalated quickly! It's a breaking change mostly for the newly added binary64 encoding, so the downstream users should still be few and I think the long-term benefits outweigh the minor inconvenience of adapting to the slightly different RPC request/responses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for wrangling this one! lgtm
* Add base64 (binary64) encoding for getConfirmedTransaction/getConfirmedBlock (cherry picked from commit b5f3ced) * decode-transaction now supports binary64 (cherry picked from commit 2ebc68a) # Conflicts: # cli/src/cli.rs * Rework UiAccountData encode/decode such that it works from Rust (cherry picked from commit 757e147) # Conflicts: # account-decoder/src/lib.rs # cli/src/cli.rs * Rename Binary64 to Base64. Establish Base58 encoding (cherry picked from commit adc984a) # Conflicts: # account-decoder/src/lib.rs * Remove "binary" encoding. Document "encoding" as required (cherry picked from commit e528115) * resolve conflicts Co-authored-by: Michael Vines <mvines@gmail.com>
* Add base64 (binary64) encoding for getConfirmedTransaction/getConfirmedBlock (cherry picked from commit b5f3ced) # Conflicts: # transaction-status/Cargo.toml * decode-transaction now supports binary64 (cherry picked from commit 2ebc68a) # Conflicts: # cli/src/cli.rs * Rework UiAccountData encode/decode such that it works from Rust (cherry picked from commit 757e147) # Conflicts: # cli/src/cli.rs * Rename Binary64 to Base64. Establish Base58 encoding (cherry picked from commit adc984a) * Remove "binary" encoding. Document "encoding" as required (cherry picked from commit e528115) * resolve conflicts Co-authored-by: Michael Vines <mvines@gmail.com>
…na-labs#11646) (solana-labs#11673)"" This reverts commit fb90fb3.
Problems:
Binary(String)
andBinary64(String)
enums, requiring RpcClient hacksChanges:
UiAccountData
for the "base58"/"base64" encoding now return an array of two elements,["encoded data", "encoding type"]
instead of just"encoded data"
. This allows serde_json to work. <-- BREAKING CHANGETODO