rpc: rework binary encoding. BREAKING CHANGE#11646
rpc: rework binary encoding. BREAKING CHANGE#11646mvines merged 5 commits intosolana-labs:masterfrom
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 |
| #[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.
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.
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.
|
|
||
| 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.
Ah, this feels so much nicer. "binary64"? What's that! "base64"? Oh, that's base64.
|
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 |
CriesofCarrots
left a comment
There was a problem hiding this comment.
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:
UiAccountDatafor 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