Skip to content

Commit 05ddf2b

Browse files
ali-bahjati0xBurbo
andauthored
Fix struct size discrepancy by specifying enum representation #115 (#117)
* 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. --------- Co-authored-by: Burbo <[email protected]>
1 parent 096432f commit 05ddf2b

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

.github/workflows/pyth-sdk-solana.yml

+5-6
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@ jobs:
3434
run: sudo apt-get update && sudo apt-get install libudev-dev
3535
- name: Install Solana Binaries
3636
run: |
37-
# Installing 1.17.x cli tools to have sbf instead of bpf. bpf does not work anymore.
38-
sh -c "$(curl -sSfL https://release.solana.com/v1.18.1/install)"
37+
sh -c "$(curl -sSfL https://release.solana.com/v1.18.4/install)"
3938
echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
4039
- name: Build
4140
run: cargo build --verbose
4241
- name: Run tests
4342
run: cargo test --verbose
44-
- name: Build BPF
45-
run: cargo build-bpf --verbose
46-
- name: Run BPF tests
47-
run: cargo test-bpf --verbose
43+
- name: Build SBF
44+
run: cargo build-sbf --verbose
45+
- name: Run SBF tests
46+
run: cargo test-sbf --verbose

pyth-sdk-solana/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-sdk-solana"
3-
version = "0.10.0"
3+
version = "0.10.1"
44
authors = ["Pyth Data Foundation"]
55
edition = "2018"
66
license = "Apache-2.0"

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,
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

22
# This is only used for tests
33
[toolchain]
4-
channel = "1.71.0"
4+
channel = "1.76.0"
55
profile = "minimal"

0 commit comments

Comments
 (0)