Skip to main content

CompressionInfo

Struct CompressionInfo 

Source
#[repr(C)]
pub struct CompressionInfo { pub last_claimed_slot: u64, pub lamports_per_write: u32, pub config_version: u16, pub state: CompressionState, pub _padding: u8, pub rent_config: RentConfig, }
Expand description

SDK CompressionInfo - a compact 24-byte struct for custom zero-copy PDAs.

This is the lightweight version of compression info used in the SDK. CToken has its own compression handling via light_compressible::CompressionInfo.

§Memory Layout (24 bytes with #[repr(C)])

  • last_claimed_slot: u64 @ offset 0 (8 bytes, 8-byte aligned)
  • lamports_per_write: u32 @ offset 8 (4 bytes)
  • config_version: u16 @ offset 12 (2 bytes)
  • state: CompressionState @ offset 14 (1 byte)
  • _padding: u8 @ offset 15 (1 byte)
  • rent_config: RentConfig @ offset 16 (8 bytes, 2-byte aligned)

Fields are ordered for optimal alignment to achieve exactly 24 bytes.

Fields§

§last_claimed_slot: u64

Slot when rent was last claimed (epoch boundary accounting).

§lamports_per_write: u32

Lamports to top up on each write (from config, stored per-account to avoid passing config on every write)

§config_version: u16

Version of the compressible config used to initialize this account.

§state: CompressionState

Account compression state.

§_padding: u8§rent_config: RentConfig

Rent function parameters for determining compressibility/claims.

Implementations§

Source§

impl CompressionInfo

Source

pub fn compressed() -> CompressionInfo

Source

pub fn new_from_config(cfg: &LightConfig, current_slot: u64) -> CompressionInfo

Create a new CompressionInfo initialized from a compressible config.

Rent sponsor is always the config’s rent_sponsor (not stored per-account). This means rent always flows to the protocol’s rent pool upon compression, regardless of who paid for account creation.

Source

pub fn new_decompressed(current_slot: u64) -> CompressionInfo

Backward-compat constructor; initializes minimal fields. Rent will flow to config’s rent_sponsor upon compression.

Source

pub fn bump_last_claimed_slot(&mut self, current_slot: u64)

Update last_claimed_slot to the given slot.

Source

pub fn set_last_claimed_slot(&mut self, slot: u64)

Explicitly set last_claimed_slot.

Source

pub fn last_claimed_slot(&self) -> u64

Get last_claimed_slot.

Source

pub fn set_compressed(&mut self)

Source

pub fn is_compressed(&self) -> bool

Source§

impl CompressionInfo

Source

pub fn calculate_top_up_lamports( &self, num_bytes: u64, current_slot: u64, current_lamports: u64, rent_exemption_lamports: u64, ) -> u64

Calculate top-up lamports required for a write.

Logic (same as CTokens):

  • If account is compressible (can’t pay current + next epoch): return lamports_per_write + deficit
  • If account has >= max_funded_epochs: return 0 (no top-up needed)
  • Otherwise: return lamports_per_write (maintenance mode)
Source

pub fn top_up_rent<AI>( &self, account_info: &AI, payer_info: &AI, ) -> Result<(), LightSdkTypesError>
where AI: AccountInfoTrait,

Top up rent on write if needed and transfer lamports from payer to account. This is the standard pattern for all write operations on compressible PDAs. Generic over AccountInfoTrait to work with both solana and pinocchio.

§Arguments
  • account_info - The PDA account to top up
  • payer_info - The payer account (will be debited)

Trait Implementations§

Source§

impl BorshDeserialize for CompressionInfo

Source§

fn deserialize_reader<R>(reader: &mut R) -> Result<CompressionInfo, Error>
where R: Read,

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

Source§

impl BorshSerialize for CompressionInfo

Source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write,

Source§

fn try_to_vec(&self) -> Result<Vec<u8>, Error>

Serialize this instance into a vector of bytes.
Source§

impl Clone for CompressionInfo

Source§

fn clone(&self) -> CompressionInfo

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CompressionInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for CompressionInfo

Source§

fn default() -> CompressionInfo

Returns the “default value” for a type. Read more
Source§

impl PartialEq for CompressionInfo

Source§

fn eq(&self, other: &CompressionInfo) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Space for CompressionInfo

Source§

impl Zeroable for CompressionInfo

Source§

fn zeroed() -> Self

Source§

impl Copy for CompressionInfo

Source§

impl Pod for CompressionInfo

Source§

impl StructuralPartialEq for CompressionInfo

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HashToFieldSize for T
where T: BorshSerialize,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> AnyBitPattern for T
where T: Pod,

Source§

impl<T> NoUninit for T
where T: Pod,