Repository navigation
account-info: Switch account data helpers to wincode under a feature - #1077
Conversation
Problem
`AccountInfo` serializes and deserializes account data only through bincode, so solana-program can't drop bincode without losing these helpers.
Summary of Changes
- add a `wincode` feature that replaces the implementation of `AccountInfo::{serialize_data, deserialize_data}`, while the `bincode` feature provides them only when `wincode` is off
- export `WincodeConfig` and `WINCODE_CONFIG`, which keep the bincode wire format and raise the preallocation limit to the max account data length, matching solana-account
Problem solana-account and solana-account-info define the same wincode config separately, so the two copies can drift apart. Summary of Changes Add a test-only compile-time check that `WINCODE_CONFIG` has the type of `solana_account_info::WincodeConfig`.
| .with_preallocation_size_limit::<WINCODE_PREALLOC_LIMIT>( | ||
| ); | ||
| #[cfg(all(test, feature = "wincode"))] | ||
| const _: solana_account_info::WincodeConfig = WINCODE_CONFIG; |
There was a problem hiding this comment.
once we do account breaking release we can replace the config in this crate with alises to solana_account_info instead of this test
There was a problem hiding this comment.
We actually plan to deprecate solana_account_info and remove, so may as well leave this 😅
There was a problem hiding this comment.
ok, removed, since we now use different limits
joncinque
left a comment
There was a problem hiding this comment.
Looks great, just a few questions
| T: for<'de> wincode::SchemaRead<'de, WincodeConfig, Dst = T>, | ||
| { | ||
| wincode::config::deserialize(&self.data.borrow(), WINCODE_CONFIG) | ||
| } |
There was a problem hiding this comment.
This deserialization creates a whole new instance, correct? In that case, the current WINCODE_CONFIG limit will be way too big.
The stack only gives you 4KiB, and the heap defaults to 32KiB, so we can probably make the number much smaller.
It would only work on a 10MiB account if it used a zero-copy deserialization. Is that possible using this function? If not, let's reduce the limit to 32KiB.
There was a problem hiding this comment.
Ok, I lowered the limit, though I suppose we should use the max allowed heap size not default:
agave/program-runtime/src/execution_budget.rs:35 has pub const MAX_HEAP_FRAME_BYTES: u32 = 256 * 1024
?
|
|
||
| [dev-dependencies] | ||
| solana-address = { workspace = true, features = ["atomic"] } | ||
| wincode = { workspace = true, features = ["alloc"] } |
There was a problem hiding this comment.
Can we enable the wincode feature on the crate in dev-dependencies? That way we'll always run the wincode test
| .with_preallocation_size_limit::<WINCODE_PREALLOC_LIMIT>( | ||
| ); | ||
| #[cfg(all(test, feature = "wincode"))] | ||
| const _: solana_account_info::WincodeConfig = WINCODE_CONFIG; |
There was a problem hiding this comment.
We actually plan to deprecate solana_account_info and remove, so may as well leave this 😅
Problem - `AccountInfo::deserialize_data` decodes an owned value, so a 10 MiB preallocation limit admits collections far larger than any program heap. - The solana-account check pins its wincode config to the account-info one, although runtime accounts need the 10 MiB limit. - The wincode tests run only when the `wincode` feature is enabled explicitly. Summary of Changes - lower the account-info wincode preallocation limit to 256 KiB, the largest heap frame a program can request - drop the solana-account check that pins the two wincode configs together - enable the `wincode` feature through a dev-dependency on the crate itself, so the wincode tests always run
Problem
AccountInfoserializes and deserializes account data only through bincode, so solana-program can't drop bincode without losing these helpers.Summary of Changes
wincodefeature that replaces the implementation ofAccountInfo::{serialize_data, deserialize_data}, while thebincodefeature provides them only whenwincodeis offWincodeConfigandWINCODE_CONFIG, which keep the bincode wire format and raise the preallocation limit to the max account data length, matching solana-accountWINCODE_CONFIGhas the type ofsolana_account_info::WincodeConfig.