Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(): index storage scaffolding & rocksdb implementation #47

Merged
merged 23 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 88 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license-file = "LICENSE"
repository = "https://github.com/eigerco/polka-storage"

[workspace]
members = ["node", "runtime"]
members = ["node", "runtime", "storage/file-storage"]
resolver = "2"

# FIXME(#@jmg-duarte,#7,14/5/24): remove the patch once something >1.11.0 is released
Expand All @@ -18,6 +18,8 @@ litep2p = "0.3.0"
substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" }
substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" }

ciborium = "0.2.2"
cid = { version = "0.11.1" }
clap = { version = "4.5.3" }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
color-print = "0.3.4"
Expand All @@ -29,6 +31,7 @@ polkavm = "0.9.3"
polkavm-derive = "0.9.1"
polkavm-linker = "0.9.2"
quote = { version = "1.0.33" }
rocksdb = { version = "0.21" }
scale-info = { version = "2.11.1", default-features = false }
serde = { version = "1.0.197", default-features = false }
serde-big-array = { version = "0.3.2" }
Expand Down
Empty file removed storage/file-storage/.gitkeep
Empty file.
21 changes: 21 additions & 0 deletions storage/file-storage/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
authors.workspace = true
edition.workspace = true
homepage.workspace = true
license-file.workspace = true
name = "file-storage"
repository.workspace = true
version = "0.1.0"

[dependencies]
ciborium = { workspace = true }
cid = { workspace = true, features = ["serde"] }
rocksdb = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
tempfile = "3.10.1"
cernicc marked this conversation as resolved.
Show resolved Hide resolved

[lints]
workspace = true
1 change: 1 addition & 0 deletions storage/file-storage/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod piecestore;
3 changes: 3 additions & 0 deletions storage/file-storage/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
cernicc marked this conversation as resolved.
Show resolved Hide resolved
}
69 changes: 69 additions & 0 deletions storage/file-storage/src/piecestore/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use std::collections::HashMap;

use cid::Cid;
use rocksdb::RocksDBError;
use thiserror::Error;

use self::types::{BlockLocation, CidInfo, DealInfo, PieceInfo};

pub mod rocksdb;
mod types;

pub trait PieceStore {
/// Implementation-specific configuration.
type Config;

/// Initialize a new store.
fn new(config: Self::Config) -> Result<Self, PieceStoreError>
where
Self: Sized;

/// Store deal_info in the PieceStore with key piece_cid.
fn add_deal_for_piece(
&self,
piece_cid: &Cid,
deal_info: DealInfo,
) -> Result<(), PieceStoreError>;

/// Store the map of block_locations in the PieceStore's CidInfo store, with
/// key piece_cid.
///
/// Note: If a piece block location is already present in the CidInfo, it
/// will be ignored.
fn add_piece_block_locations(
&self,
piece_cid: &Cid,
block_locations: &HashMap<Cid, BlockLocation>,
) -> Result<(), PieceStoreError>;

/// List all piece CIDs stored in the PieceStore.
fn list_piece_info_keys(&self) -> Result<Vec<Cid>, PieceStoreError>;

/// List all CIDInfo keys stored in the PieceStore.
fn list_cid_info_keys(&self) -> Result<Vec<Cid>, PieceStoreError>;

/// Retrieve the PieceInfo for a given piece CID.
fn get_piece_info(&self, cid: &Cid) -> Result<Option<PieceInfo>, PieceStoreError>;

/// Retrieve the CidInfo associated with piece CID.
fn get_cid_info(&self, cid: &Cid) -> Result<Option<CidInfo>, PieceStoreError>;
}

/// Error that can occur when interacting with the PieceStore.
#[derive(Debug, Error)]
pub enum PieceStoreError {
#[error("Initialization error: {0}")]
Initialization(String),

#[error("Deal already exists")]
DealExists,

#[error("Serialization error: {0}")]
Serialization(String),

#[error("Deserialization error: {0}")]
Deserialization(String),

#[error(transparent)]
StoreError(#[from] RocksDBError),
}
Loading