Skip to content

Commit

Permalink
Merge branch 'develop' into feat/25/car-implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jmg-duarte committed May 31, 2024
2 parents e43ff4b + 9362c82 commit 575f23f
Show file tree
Hide file tree
Showing 11 changed files with 618 additions and 2 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/
51 changes: 51 additions & 0 deletions Cargo.lock

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

10 changes: 8 additions & 2 deletions 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", "storage/mater"]
members = ["node", "runtime", "storage/mater", "storage/polka-index"]
resolver = "2"

# FIXME(#@jmg-duarte,#7,14/5/24): remove the patch once something >1.11.0 is released
Expand All @@ -32,6 +32,8 @@ async-stream = "0.3.5"
bitflags = "2.5.0"
byteorder = "1.5.0"
bytes = "1.6.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 @@ -51,6 +53,7 @@ polkavm-linker = "0.9.2"
quick-protobuf = "0.8.1"
quote = { version = "1.0.33" }
rand = "0.8.5"
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 @@ -61,6 +64,7 @@ serde_yaml = { version = "0.9" }
sha2 = "0.10.8"
smallvec = "1.11.0"
syn = { version = "2.0.53" }
tempfile = "3.10.1"
thiserror = { version = "1.0.48" }
tokio = "1.37.0"
tokio-stream = "0.1.15"
Expand Down Expand Up @@ -109,7 +113,9 @@ substrate-prometheus-endpoint = { git = "https://github.com/paritytech/polkadot-

# Polkadot
pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false }
polkadot-cli = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", features = ["rococo-native"] }
polkadot-cli = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", features = [
"rococo-native",
] }
polkadot-parachain-primitives = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" }
polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false }
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 575f23f

Please sign in to comment.