v0.3.1-pre.004

This commit is contained in:
2026-08-29 08:20:16 +02:00
parent afd4c770f9
commit 28ca5bdac5
11 changed files with 843 additions and 70 deletions

View File

@@ -0,0 +1,231 @@
// file: crates/ksp-store-api/src/model/raw_account.rs
// version: 1
/// Durable backend-independent identity of one canonical RAW account state.
///
/// The content hash is part of the identity because one account can be written more than once
/// inside the same slot while standard HTTP/WebSocket surfaces do not expose Yellowstone's
/// `write_version`. Multiple observations of the same complete state therefore converge on the
/// same reference without making a provider-specific write ordinal part of the common model.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct RawAccountStateReference {
network: crate::RawNetworkId,
pubkey: ksp_core_lib::Pubkey,
slot: u64,
state_hash: crate::RawContentHash,
}
impl RawAccountStateReference {
/// Creates one durable account-state identity from network, account, slot and canonical state digest.
#[must_use]
pub fn new(network: crate::RawNetworkId, pubkey: ksp_core_lib::Pubkey, slot: u64, state_hash: crate::RawContentHash) -> Self {
return Self { network, pubkey, slot, state_hash };
}
/// Returns the logical Solana network/cluster identifier.
#[must_use]
pub fn network(&self) -> &crate::RawNetworkId {
return &self.network;
}
/// Returns the account public key.
#[must_use]
pub const fn pubkey(&self) -> &ksp_core_lib::Pubkey {
return &self.pubkey;
}
/// Returns the slot associated with this complete account state.
#[must_use]
pub const fn slot(&self) -> u64 {
return self.slot;
}
/// Returns the producer-supplied digest of the complete canonical account state.
#[must_use]
pub const fn state_hash(&self) -> crate::RawContentHash {
return self.state_hash;
}
}
/// Canonical complete N1 RAW account state independent from HTTP, WebSocket or gRPC acquisition.
///
/// Only complete raw account bytes are admissible. A transport response using `jsonParsed`, a
/// request-side data slice, or a response without a durable slot context must be normalized or
/// reacquired before this model is constructed.
pub struct RawAccountState {
data: std::boxed::Box<[u8]>,
executable: bool,
lamports: u64,
owner: ksp_core_lib::Pubkey,
reference: crate::RawAccountStateReference,
rent_epoch: u64,
}
impl RawAccountState {
/// Creates one complete canonical RAW account state after Store-owned admission checks.
pub fn try_new(
reference: crate::RawAccountStateReference,
lamports: u64,
owner: ksp_core_lib::Pubkey,
executable: bool,
rent_epoch: u64,
data: std::boxed::Box<[u8]>,
) -> ksp_core_lib::Result<Self> {
if data.len() > crate::MAX_RAW_ACCOUNT_DATA_BYTES {
return std::result::Result::Err(
ksp_core_lib::Error::new(crate::ERROR_CODE_RAW_MODEL_INVALID, "invalid backend-agnostic RAW Store model")
.with_context("field", "account_data")
.with_context("actual_len", data.len().to_string())
.with_context("maximum_len", crate::MAX_RAW_ACCOUNT_DATA_BYTES.to_string()),
);
}
return std::result::Result::Ok(Self { data, executable, lamports, owner, reference, rent_epoch });
}
/// Returns the exact complete account bytes used by future decoders.
#[must_use]
pub fn data(&self) -> &[u8] {
return self.data.as_ref();
}
/// Returns the complete account-data length in bytes.
#[must_use]
pub fn data_len(&self) -> usize {
return self.data.len();
}
/// Returns whether the account is executable.
#[must_use]
pub const fn executable(&self) -> bool {
return self.executable;
}
/// Returns the account lamport balance.
#[must_use]
pub const fn lamports(&self) -> u64 {
return self.lamports;
}
/// Returns the account owner program public key.
#[must_use]
pub const fn owner(&self) -> &ksp_core_lib::Pubkey {
return &self.owner;
}
/// Returns the durable source-independent account-state identity.
#[must_use]
pub fn reference(&self) -> &crate::RawAccountStateReference {
return &self.reference;
}
/// Returns the rent epoch reported for this account state.
#[must_use]
pub const fn rent_epoch(&self) -> u64 {
return self.rent_epoch;
}
}
impl std::fmt::Debug for RawAccountState {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
return formatter
.debug_struct("RawAccountState")
.field("reference", &self.reference)
.field("lamports", &self.lamports)
.field("owner", &self.owner)
.field("executable", &self.executable)
.field("rent_epoch", &self.rent_epoch)
.field("data_len", &self.data.len())
.finish();
}
}
/// Persistable acquisition observation linked to one complete canonical RAW account state.
///
/// Yellowstone-only metadata remains optional observation detail and never changes the canonical
/// account state itself. HTTP/WS acquisitions therefore use the same observation type without
/// inventing a `write_version`, transaction signature or startup flag.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct RawAccountObservation {
account: crate::RawAccountStateReference,
is_startup: std::option::Option<bool>,
observation_key: crate::RawObservationKey,
provenance: crate::RawAcquisitionProvenance,
transaction_signature: std::option::Option<crate::RawTransactionSignature>,
write_version: std::option::Option<u64>,
}
impl RawAccountObservation {
/// Creates one successful observation of a complete canonical RAW account state.
#[must_use]
pub fn new(observation_key: crate::RawObservationKey, account: crate::RawAccountStateReference, provenance: crate::RawAcquisitionProvenance) -> Self {
return Self {
account,
is_startup: std::option::Option::None,
observation_key,
provenance,
transaction_signature: std::option::Option::None,
write_version: std::option::Option::None,
};
}
/// Attaches a provider-reported startup/replay marker when the source exposes one.
#[must_use]
pub fn with_is_startup(mut self, value: bool) -> Self {
self.is_startup = std::option::Option::Some(value);
return self;
}
/// Attaches the transaction signature associated with the account write when exposed by the source.
#[must_use]
pub fn with_transaction_signature(mut self, value: crate::RawTransactionSignature) -> Self {
self.transaction_signature = std::option::Option::Some(value);
return self;
}
/// Attaches the source-specific account write version when the source exposes one.
#[must_use]
pub fn with_write_version(mut self, value: u64) -> Self {
self.write_version = std::option::Option::Some(value);
return self;
}
/// Returns the durable account-state identity observed by this acquisition.
#[must_use]
pub fn account(&self) -> &crate::RawAccountStateReference {
return &self.account;
}
/// Returns the optional source-reported startup/replay marker.
#[must_use]
pub const fn is_startup(&self) -> std::option::Option<bool> {
return self.is_startup;
}
/// Returns the deterministic producer-owned observation idempotence key.
#[must_use]
pub const fn observation_key(&self) -> crate::RawObservationKey {
return self.observation_key;
}
/// Returns safe source-independent acquisition provenance.
#[must_use]
pub fn provenance(&self) -> &crate::RawAcquisitionProvenance {
return &self.provenance;
}
/// Returns the optional transaction signature associated with this account write.
#[must_use]
pub const fn transaction_signature(&self) -> std::option::Option<crate::RawTransactionSignature> {
return self.transaction_signature;
}
/// Returns the optional source-specific account write version.
#[must_use]
pub const fn write_version(&self) -> std::option::Option<u64> {
return self.write_version;
}
}
#[cfg(test)]
#[path = "../../unit_tests/model/raw_account.rs"]
mod tests;

View File

@@ -1,6 +1,10 @@
// file: crates/ksp-store-api/src/model/raw_primitives.rs
// version: 1
// version: 2
/// Maximum complete RAW account-data length admitted by the Store API.
///
/// This is a Store admission guard, not a Solana protocol-size claim.
pub const MAX_RAW_ACCOUNT_DATA_BYTES: usize = 16 * 1024 * 1024;
/// Maximum UTF-8 byte length accepted for one safe logical RAW/provenance code.
pub const MAX_RAW_CODE_BYTES: usize = 128;
/// Maximum KSP-owned canonical RAW payload admitted by the Store API.