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 20 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ target/

# reproducible local environment
.direnv

# Visual Studio Code
.vscode/
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.

6 changes: 5 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/polka-index"]
resolver = "2"

# FIXME(#@jmg-duarte,#7,14/5/24): remove the patch once something >1.11.0 is released
Expand All @@ -28,6 +28,8 @@ panic = 'abort' # Use abort on panic to reduce binary size
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 @@ -39,6 +41,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 All @@ -47,6 +50,7 @@ serde_json = { version = "1.0.114", default-features = false }
serde_yaml = { version = "0.9" }
smallvec = "1.11.0"
syn = { version = "2.0.53" }
tempfile = "3.10.1"
thiserror = { version = "1.0.48" }
tracing-subscriber = { version = "0.3.18" }

Expand Down
Empty file removed storage/polka-index/.gitkeep
Empty file.
21 changes: 21 additions & 0 deletions storage/polka-index/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 = "polka-index"
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 = { workspace = true }

[lints]
workspace = true
1 change: 1 addition & 0 deletions storage/polka-index/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/polka-index/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please add the crate level doc with text from the readme?

The piecestore module is a simple encapsulation of two data stores, one for PieceInfo and
another for CidInfo.

println!("Hello, world!");
}
67 changes: 67 additions & 0 deletions storage/polka-index/src/piecestore/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use std::collections::HashMap;

use cid::Cid;
use thiserror::Error;

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

mod types;

pub trait PieceStore {
th7nder marked this conversation as resolved.
Show resolved Hide resolved
/// 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.
cernicc marked this conversation as resolved.
Show resolved Hide resolved
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] rocksdb::Error),
}
Loading