Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix struct size discrepancy by specifying enum representation #115

Closed
wants to merge 1 commit into from

Conversation

0xBurbo
Copy link
Contributor

@0xBurbo 0xBurbo commented Mar 5, 2024

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::() 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.

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.
@0xBurbo 0xBurbo closed this Mar 5, 2024
@0xBurbo 0xBurbo reopened this Mar 5, 2024
@ali-bahjati
Copy link
Collaborator

I couldn't push to this PR. Closing it and opening another one with my changes on top of it.

ali-bahjati added a commit that referenced this pull request Mar 13, 2024
)

* 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]>
@ali-bahjati
Copy link
Collaborator

@0xBurbo thanks a lot for collaborating! We've made a new release with your fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants