Skip to content

Commit

Permalink
Fix struct size discrepancy by specifying enum representation
Browse files Browse the repository at this point in the history
This commit resolves a size discrepancy issue observed with structs
derived from the Pyth SDK when executed on Solana's runtime vs off-chain.
The use of `#[repr(C)]` in enum definitions, leading to an unexpected
increase in struct sizes when compiled for the Solana BPF target,
causing the SDK to fail deserialization.
The account size for std::mem::size_of::<SolanaPriceAccount>() returned 3840, when the correct size is 3312.

By changing the enum representation from `#[repr(C)]` to `#[repr(u8)]`,
we ensure a consistent and minimal size for the enums across both
execution environments.
  • Loading branch information
0xBurbo committed Mar 5, 2024
1 parent 096432f commit 8cddc15
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pyth-sdk-solana/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub const PROD_ATTR_SIZE: usize = PROD_ACCT_SIZE - PROD_HDR_SIZE;
serde::Serialize,
serde::Deserialize,
)]
#[repr(C)]
#[repr(u8)]
pub enum AccountType {
Unknown,
Mapping,
Expand All @@ -74,7 +74,7 @@ impl Default for AccountType {
serde::Serialize,
serde::Deserialize,
)]
#[repr(C)]
#[repr(u8)]
pub enum CorpAction {
NoCorpAct,
}
Expand All @@ -98,7 +98,7 @@ impl Default for CorpAction {
serde::Serialize,
serde::Deserialize,
)]
#[repr(C)]
#[repr(u8)]
pub enum PriceType {
Unknown,
Price,
Expand All @@ -122,7 +122,7 @@ impl Default for PriceType {
serde::Serialize,
serde::Deserialize,
)]
#[repr(C)]
#[repr(u8)]
pub enum PriceStatus {
/// The price feed is not currently updating for an unknown reason.
Unknown,
Expand Down

0 comments on commit 8cddc15

Please sign in to comment.