Skip to content

Commit 8cddc15

Browse files
committed
Fix struct size discrepancy by specifying enum representation
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.
1 parent 096432f commit 8cddc15

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pyth-sdk-solana/src/state.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub const PROD_ATTR_SIZE: usize = PROD_ACCT_SIZE - PROD_HDR_SIZE;
4747
serde::Serialize,
4848
serde::Deserialize,
4949
)]
50-
#[repr(C)]
50+
#[repr(u8)]
5151
pub enum AccountType {
5252
Unknown,
5353
Mapping,
@@ -74,7 +74,7 @@ impl Default for AccountType {
7474
serde::Serialize,
7575
serde::Deserialize,
7676
)]
77-
#[repr(C)]
77+
#[repr(u8)]
7878
pub enum CorpAction {
7979
NoCorpAct,
8080
}
@@ -98,7 +98,7 @@ impl Default for CorpAction {
9898
serde::Serialize,
9999
serde::Deserialize,
100100
)]
101-
#[repr(C)]
101+
#[repr(u8)]
102102
pub enum PriceType {
103103
Unknown,
104104
Price,
@@ -122,7 +122,7 @@ impl Default for PriceType {
122122
serde::Serialize,
123123
serde::Deserialize,
124124
)]
125-
#[repr(C)]
125+
#[repr(u8)]
126126
pub enum PriceStatus {
127127
/// The price feed is not currently updating for an unknown reason.
128128
Unknown,

0 commit comments

Comments
 (0)