Storage Canister

The storage canister is responsible for K-V storage and retrieval of blobs.

Canister Types

/// Storage Canister
// Canister Get Blob Types
struct Blob {
    data: Vec<u8>, // blob data
    next: Option<usize>, // next slice index: u64
}

/// Save Blob Argument
/// To manage subnet storage pressure, blobs are uploaded serially in slices.
struct BlobChunk {
    index: usize,          // Segmented upload index
    digest: [u8; 32],      // Sha256 digest of the blob in hex format
    timestamp: u128,       // Time since epoch in nanoseconds
    total: usize,          // Total blob size in bytes
    data: Vec<u8>,         // Blob slice (a piece of the Blob)
}

// Storage Canister Configuration
struct Config {
    signature_canister: Principal,      // Principal authorized to upload blobs
    owner: Principal,                   // Principal managing confirmations and signatures
    query_response_size: usize,         // Adjusted for efficient blob retrieval
    canister_storage_threshold: u32,   // Maximum blobs stored (7-day period recommended)
}

enum Result {
    Ok(),
    Err(String),
}

Canister Services

// Retrieve the first slice of a Blob (if slicing is required, returns the first slice)
fn get_blob(digest: [u8; 32]) -> Blob {}

// Retrieve subsequent slices of a Blob by index
fn get_blob_with_index(digest: [u8; 32], index: usize) -> Blob {}

// Save a Blob slice
fn save_blob(chunk: BlobChunk) -> Result<(), String> {}

Candid Interfaces

type Blob = record { data : blob; next : opt nat64 };
type BlobChunk = record {
  total : nat64;
  data : blob;
  timestamp : nat;
  digest : blob;
  index : nat64;
};
type Config = record {
  owner : vec principal;
  signature_canister : principal;
  query_response_size : nat64;
  chunk_size : nat64;
  canister_storage_threshold : nat32;
};
type Result = variant { Ok; Err : text };
service : {
  get_blob : (blob) -> (Blob) query;
  get_blob_with_index : (blob, nat64) -> (Blob) query;
  notify_generate_confirmation : (blob) -> ();
  save_blob : (BlobChunk) -> (Result);
  update_config : (Config) -> ();
}

Last updated