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

storage: refactor and rocksdb implementation #123

Merged
merged 20 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
110 changes: 109 additions & 1 deletion Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ members = [
"crates/groth16",
"crates/errors",
"crates/sp1",
"crates/storage",
]
default-members = [
"crates/prism",
"crates/common",
"crates/nova",
"crates/groth16",
"crates/errors",
"crates/storage",
]
resolver = "2"

Expand Down Expand Up @@ -78,10 +80,12 @@ bincode = "1.3.3"
sp1-zkvm = { version = "1.2.0" }
sp1-sdk = { version = "1.2.0" }
prism-common = { path = "crates/common" }
prism-storage = { path = "crates/storage" }
prism-nova = { path = "crates/nova" }
prism-errors = { path = "crates/errors" }
prism-main = { path = "crates/prism" }
prism-groth16 = { path = "crates/groth16" }
rocksdb = "0.21.0"

[patch.crates-io]
sha2-v0-10-8 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha2", branch = "patch-sha2-v0.10.8" }
Expand Down
1 change: 1 addition & 0 deletions crates/prism/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jmt = { workspace = true }
sha2 = { workspace = true }
auto_impl = { workspace = true }
prism-common = { workspace = true }
prism-storage = { workspace = true }
prism-errors = { workspace = true }
prism-groth16 = { workspace = true }
sp1-sdk = { workspace = true }
Expand Down
15 changes: 2 additions & 13 deletions crates/prism/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use serde::{Deserialize, Serialize};
use std::{fs, path::Path, sync::Arc};

use crate::da::{celestia::CelestiaConnection, DataAvailabilityLayer};
use prism_storage::RedisConfig;

#[derive(Clone, Debug, Subcommand, Deserialize)]
pub enum Commands {
Expand Down Expand Up @@ -97,18 +98,6 @@ impl Default for WebServerConfig {
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct RedisConfig {
pub connection_string: String,
}

impl Default for RedisConfig {
fn default() -> Self {
RedisConfig {
connection_string: "redis://127.0.0.1/".to_string(),
}
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct CelestiaConfig {
Expand Down Expand Up @@ -300,7 +289,7 @@ pub async fn initialize_da_layer(
unreachable!() // This line should never be reached due to the return in the last iteration
}
DALayerOption::InMemory => {
let (da_layer, _height_rx, _block_rx) = InMemoryDataAvailabilityLayer::new(1);
let (da_layer, _height_rx, _block_rx) = InMemoryDataAvailabilityLayer::new(30);
distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved
Ok(Arc::new(da_layer) as Arc<dyn DataAvailabilityLayer + 'static>)
distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved
}
DALayerOption::None => Err(anyhow!(PrismError::ConfigError(
Expand Down
1 change: 0 additions & 1 deletion crates/prism/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pub mod cfg;
pub mod consts;
pub mod da;
pub mod node_types;
pub mod storage;
pub mod utils;
pub mod webserver;
#[macro_use]
Expand Down
3 changes: 1 addition & 2 deletions crates/prism/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ mod cfg;
pub mod consts;
pub mod da;
mod node_types;
pub mod storage;
mod utils;
mod webserver;

Expand All @@ -13,7 +12,7 @@ use keystore_rs::{KeyChain, KeyStore, KeyStoreType};
use crate::cfg::{CommandLineArgs, Commands};
use node_types::{lightclient::LightClient, sequencer::Sequencer, NodeType};
use std::sync::Arc;
use storage::RedisConnection;
use prism_storage::RedisConnection;

#[macro_use]
extern crate log;
Expand Down
5 changes: 3 additions & 2 deletions crates/prism/src/node_types/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ use crate::{
consts::{CHANNEL_BUFFER_SIZE, DA_RETRY_COUNT, DA_RETRY_INTERVAL},
da::{DataAvailabilityLayer, FinalizedEpoch},
node_types::NodeType,
storage::Database,
webserver::{OperationInput, WebServer},
};

use prism_storage::Database;
use prism_common::{
hashchain::{Hashchain, HashchainEntry},
operation::{AccountSource, Operation},
Expand Down Expand Up @@ -470,8 +471,8 @@ mod tests {
use crate::{
cfg::{Config, RedisConfig},
da::memory::InMemoryDataAvailabilityLayer,
storage::RedisConnection,
};
use prism_storage::RedisConnection;
use base64::{engine::general_purpose::STANDARD as engine, Engine as _};
use keystore_rs::create_signing_key;
use serial_test::serial;
Expand Down
30 changes: 30 additions & 0 deletions crates/storage/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "prism-storage"
version.workspace = true
authors.workspace = true
edition.workspace = true
description.workspace = true
homepage.workspace = true
repository.workspace = true
license.workspace = true
keywords.workspace = true
readme.workspace = true

[dependencies]
serde = { workspace = true }
serde_json = { workspace = true }
redis = { workspace = true }
mockall = { workspace = true }
tokio = { workspace = true }
log = { workspace = true }
anyhow = { workspace = true }
bincode = { workspace = true }
hex = { workspace = true }
jmt = { workspace = true }
pretty_env_logger = { workspace = true }
config = { workspace = true }
thiserror = { workspace = true }
prism-errors = { workspace = true }
prism-common = { workspace = true }
auto_impl = {workspace = true}
rocksdb = {workspace = true}
distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved
29 changes: 29 additions & 0 deletions crates/storage/src/database.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use anyhow::Result;
use auto_impl::auto_impl;
use jmt::storage::{TreeReader, TreeWriter};
use prism_common::{
hashchain::{Hashchain, HashchainEntry},
operation::Operation,
tree::Digest,
};
use prism_errors::{DatabaseError, PrismError};

#[auto_impl(&, Box, Arc)]
pub trait Database: Send + Sync + TreeReader + TreeWriter {
distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved
fn get_hashchain(&self, key: &str) -> Result<Hashchain>;
fn set_hashchain(&self, incoming_operation: &Operation, value: &[HashchainEntry])
-> Result<()>;

fn get_commitment(&self, epoch: &u64) -> Result<String>;
fn set_commitment(&self, epoch: &u64, commitment: &Digest) -> Result<()>;
distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved

fn get_epoch(&self) -> Result<u64>;
fn set_epoch(&self, epoch: &u64) -> Result<()>;

#[cfg(test)]
fn flush_database(&self) -> Result<()>;
distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved
}
distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved

pub fn convert_to_connection_error(e: redis::RedisError) -> PrismError {
PrismError::Database(DatabaseError::ConnectionError(e.to_string()))
}
distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions crates/storage/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod database;
pub mod redis;
pub mod rocksdb;
distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved

pub use crate::database::Database;
pub use crate::redis::{RedisConfig, RedisConnection};
Loading