Skip to content

Commit

Permalink
Fix struct size discrepancy by specifying enum representation #115 (#117
Browse files Browse the repository at this point in the history
)

* 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]>
  • Loading branch information
ali-bahjati and 0xBurbo authored Mar 13, 2024
1 parent 096432f commit 05ddf2b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/pyth-sdk-solana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ jobs:
run: sudo apt-get update && sudo apt-get install libudev-dev
- name: Install Solana Binaries
run: |
# Installing 1.17.x cli tools to have sbf instead of bpf. bpf does not work anymore.
sh -c "$(curl -sSfL https://release.solana.com/v1.18.1/install)"
sh -c "$(curl -sSfL https://release.solana.com/v1.18.4/install)"
echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Build BPF
run: cargo build-bpf --verbose
- name: Run BPF tests
run: cargo test-bpf --verbose
- name: Build SBF
run: cargo build-sbf --verbose
- name: Run SBF tests
run: cargo test-sbf --verbose
2 changes: 1 addition & 1 deletion pyth-sdk-solana/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyth-sdk-solana"
version = "0.10.0"
version = "0.10.1"
authors = ["Pyth Data Foundation"]
edition = "2018"
license = "Apache-2.0"
Expand Down
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
2 changes: 1 addition & 1 deletion pyth-sdk-solana/test-contract/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# This is only used for tests
[toolchain]
channel = "1.71.0"
channel = "1.76.0"
profile = "minimal"

0 comments on commit 05ddf2b

Please sign in to comment.