Skip to main content

Module account

Module account 

Source
Expand description

Account memory architecture.

Hopper supports four account memory styles:

  1. Fixed Layout – Classic zero-copy #[repr(C)] overlay with a 16-byte header.
  2. Overlay Layout – Multiple typed views over different regions of one account.
  3. Segmented Layout – Fixed prefix + dynamic typed segments with a segment table.
  4. Arena Layout – Accounts as typed storage arenas (slab allocators, ring buffers).

All styles share the same 16-byte header format for self-description.

Re-exports§

pub use registry::segment_id;
pub use registry::SegmentEntry;
pub use registry::SegmentId;
pub use registry::SegmentRegistry;
pub use registry::SegmentRegistryMut;
pub use registry::MAX_REGISTRY_SEGMENTS;
pub use registry::REGISTRY_HEADER_SIZE;
pub use registry::REGISTRY_OFFSET;
pub use registry::SEGMENT_ENTRY_SIZE;
pub use registry::SEG_FLAG_DYNAMIC;
pub use registry::SEG_FLAG_FROZEN;
pub use registry::SEG_FLAG_LOCKED;
pub use segment_role::SegmentRole;
pub use segment_role::SEG_ROLE_AUDIT;
pub use segment_role::SEG_ROLE_CACHE;
pub use segment_role::SEG_ROLE_CORE;
pub use segment_role::SEG_ROLE_EXTENSION;
pub use segment_role::SEG_ROLE_INDEX;
pub use segment_role::SEG_ROLE_JOURNAL;
pub use segment_role::SEG_ROLE_SHARD;

Modules§

registry
Segmented Accounts for Hopper.
segment_role
Segment roles – typed semantic classification for account segments.

Structs§

AccountHeader
The 16-byte account header, overlay-safe.
AccountReader
Header-aware read-only account reader.
DataWriter
Sequential write cursor over a mutable byte slice.
DynamicView
An inline dynamic view that caches offsets for O(1) field access.
DynamicViewMut
Mutable inline dynamic view for writing dynamic fields.
ReallocGuard
Per-instruction realloc budget guard.
SegmentDescriptor
A single segment descriptor.
SegmentSlice
Type-safe immutable slice over a segment’s elements.
SegmentSliceMut
Type-safe mutable slice over a segment’s elements.
SegmentTable
Read-only segment table.
SegmentTableMut
Mutable segment table.
SliceCursor
Sequential read cursor over a byte slice.
VerifiedAccount
Immutable verified account – proof that validation passed.
VerifiedAccountMut
Mutable verified account – proof that validation passed, with write access.

Constants§

CLOSE_SENTINEL
Sentinel byte written to byte 0 when an account is closed. Prevents account revival attacks.
HEADER_FORMAT
Header format version. Bump only if the header wire format itself changes.
HEADER_LEN
Header length in bytes.
MAX_SEGMENTS
Maximum number of segments per account.
SEGMENT_DESC_SIZE
Size of one segment descriptor in bytes.

Traits§

FixedLayout
Trait for types with a compile-time known wire size.
Pod
Marker for types that can be safely overlaid on raw account bytes.

Functions§

cast_unchecked
Raw unchecked cast from bytes to an immutable reference.
cast_unchecked_mut
Raw unchecked cast from bytes to a mutable reference.
check_header
Validate the header against expected values.
overlay
Overlay immutable reference to a Pod type at the start of a byte slice.
overlay_mut
Overlay mutable reference to a Pod type at the start of a byte slice.
pod_from_bytes
Zero-copy cast from bytes to an immutable reference.
pod_from_bytes_mut
Zero-copy cast from bytes to a mutable reference.
pod_read
Copy a Pod value from bytes (alignment-safe).
pod_write
Write a Pod value to bytes (alignment-safe).
read_discriminator
Read the discriminator byte from raw account data.
read_dynamic_u8
Read a u8-prefixed dynamic field: returns (data_slice, next_offset).
read_dynamic_u16
Read a u16-prefixed dynamic field.
read_dynamic_u32
Read a u32-prefixed dynamic field.
read_header_flags
Read the flags field as u16.
read_layout_id
Read the 8-byte layout_id.
read_version
Read the version byte.
safe_close
Safely close an account by draining all lamports to destination.
safe_close_with_sentinel
Close with sentinel – writes CLOSE_SENTINEL to byte 0 after zeroing.
safe_realloc
Reallocate an account to a new size.
write_dynamic_u8
Write a u8-prefixed dynamic field. Returns next offset after written data.
write_dynamic_u16
Write a u16-prefixed dynamic field.
write_dynamic_u32
Write a u32-prefixed dynamic field.
write_header
Write a complete header to the beginning of data.
zero_init
Zero-initialize a byte slice. Must be called before write_header.