Skip to content

Commit

Permalink
Document memstore
Browse files Browse the repository at this point in the history
  • Loading branch information
gianbelinche committed Nov 4, 2024
1 parent f892e99 commit 22fd8a2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/node/da_clients/src/eigen/memstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct MemStoreData {
key_starts: HashMap<String, Instant>,
}

/// This struct represents a memory store for blobs.
/// It should be used for testing purposes only.
#[derive(Clone, Debug)]
pub struct MemStore {
config: MemStoreConfig,
Expand All @@ -62,6 +64,7 @@ impl MemStore {
memstore
}

/// Saves a blob to the memory store, it harcodes the blob info, since we don't care about it in a memory based store
pub async fn put_blob(self: Arc<Self>, value: Vec<u8>) -> Result<String, MemStoreError> {
tokio::time::sleep(Duration::from_millis(self.config.put_latency)).await;
if value.len() as u64 > self.config.max_blob_size_bytes {
Expand Down Expand Up @@ -134,6 +137,7 @@ impl MemStore {
Ok(hex::encode(cert_bytes))
}

/// It returns the inclusion proof
pub async fn get_inclusion_data(
self: Arc<Self>,
blob_id: &str,
Expand All @@ -152,6 +156,7 @@ impl MemStore {
}))
}

/// This function is only used on tests, it returns the blob data
#[cfg(test)]
pub async fn get_blob_data(
self: Arc<Self>,
Expand Down Expand Up @@ -188,6 +193,7 @@ impl MemStore {
}
}

/// After some time has passed, blobs are removed from the store
async fn prune_expired(self: Arc<Self>) {
let mut data = self.data.write().unwrap();
let mut to_remove = vec![];
Expand All @@ -202,6 +208,7 @@ impl MemStore {
}
}

/// Loop used to prune expired blobs
async fn pruning_loop(self: Arc<Self>) {
let mut interval = interval(Duration::from_secs(self.config.blob_expiration));

Expand Down

0 comments on commit 22fd8a2

Please sign in to comment.