0

I would like to deserialize VoteState account in Solana on-chain program. https://github.com/solana-labs/solana/blob/v1.17.10/sdk/program/src/vote/state/mod.rs#L285

From what I can see it's not possible to be done with VoteState::deserialize as the deserialize is not implemented for sbf compilation (if I understand correctly). https://github.com/solana-labs/solana/blob/v1.17.10/sdk/program/src/vote/state/mod.rs#L358

I found an issue related to that https://github.com/solana-labs/solana/pull/30515

While I do not understand if there is some simple way to get deserialized data or not and some manual deserialization is needed.

Would you somebody know?

1 Answer 1

1

You did all the right research! The VoteState struct is too big to deserialize on-chain because its size is greater than the stack size of any function in the VM, as evidenced by the error:

Stack offset of 6344 exceeded max offset of 4096 by 2248 bytes, please minimize large stack variables

Your best bet is to write a limited deserializer just for the fields that you care about. For example, if you want to fetch the authorized_withdrawer in the account, you'll need to get bytes 36-68 in the account (4 bytes for the enum discriminant, then 4 bytes for the node_pubkey), which would mean:

let authorized_withdrawer = Pubkey::try_from(&vote_account_data[36..68]).unwrap();

The current VoteState is defined at: https://github.com/solana-labs/solana/blob/8330dee95d025dcf6e75a3d5ac538bda9a3d9e70/sdk/program/src/vote/state/mod.rs#L290

1
  • Perfect, I see, thanks for the confirmation.
    – chalda
    Jan 4 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.