Skip to content

Comments

StakeStakeV2 zero copy api [wincode]#222

Open
grod220 wants to merge 23 commits intomainfrom
wincode-state
Open

StakeStakeV2 zero copy api [wincode]#222
grod220 wants to merge 23 commits intomainfrom
wincode-state

Conversation

@grod220
Copy link
Member

@grod220 grod220 commented Dec 19, 2025

Adds a new zero‑copy state API backed by wincode.

Key Changes

  • Adds p-stake-interface crate (#![no_std] compatible)
  • Integrates alignment-1 POD types for safe zero-copy from unaligned slices
  • New API via StakeStateV2:
    • StakeStateV2::from_bytes(&[u8]) -> Result<&StakeStateV2, StakeStateError> for read-only access
    • StakeStateV2::from_bytes_mut(&mut [u8]) -> Result<&mut StakeStateV2, StakeStateError> for
      mutations
    • Tag-checked accessors: meta(), stake(), meta_mut(), stake_mut()
    • State transitions: initialize(), delegate()
  • Maintains full ABI compatibility with legacy bincode-encoded stake accounts

Motivation

Deserialization via bincode/borsh is computationally expensive for programs that only need to access specific fields or verify the state. This zero-copy approach allows for significantly lower compute unit (CU) usage when interacting with stake accounts.

@grod220 grod220 changed the title Wincode spike StakeStakeV2 zero copy api [wincode] Jan 12, 2026
@grod220 grod220 force-pushed the wincode-state branch 2 times, most recently from e0471c2 to 3b7d1b1 Compare January 12, 2026 18:11
@grod220 grod220 marked this pull request as ready for review January 12, 2026 18:27
@grod220 grod220 requested review from febo and joncinque January 12, 2026 18:27
@grod220 grod220 requested a review from febo January 16, 2026 16:06
Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall! Mostly small things on my side

Copy link
Contributor

@febo febo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got a few more small comments.

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.

3 participants