Skip to content

Commit

Permalink
Merge pull request #47 from eigerco/feat/41/index_storage_scaffolding
Browse files Browse the repository at this point in the history
feat(): index storage scaffolding & rocksdb implementation
  • Loading branch information
cernicc authored May 31, 2024
2 parents ab04704 + ab4a730 commit 9362c82
Show file tree
Hide file tree
Showing 11 changed files with 652 additions and 17 deletions.
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() {
println!("Hello, world!");
}
4 changes: 4 additions & 0 deletions storage/polka-index/src/piecestore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# piecestore

The piecestore module is a simple encapsulation of two data stores, one for `PieceInfo` and
another for `CidInfo`.
69 changes: 69 additions & 0 deletions storage/polka-index/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;
pub 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 [`DealInfo`] 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 [`BlockLocation`] 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 [`Cid`]s stored in the [`PieceStore`].
fn list_piece_info_keys(&self) -> Result<Vec<Cid>, PieceStoreError>;

/// List all [`CidInfo`]s 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

0 comments on commit 9362c82

Please sign in to comment.