Skip to content

Commit

Permalink
refactor(workspace): extracting crates and modifying project structure (
Browse files Browse the repository at this point in the history
#137)

* refactor(common): extract keys to own module

* refactor(prism): moving node_types/sequencer to own crate

* refactor(prism): extract node_types/lightclient into own crate

* restructuring

* refactor(prism): renaming prism-main to bin

* refactor(sequencer): renaming sequencer to prover

* fix(prover): sync loop

* fix(justfile): sp1 build dir
  • Loading branch information
distractedm1nd authored Oct 9, 2024
1 parent 1f81adb commit 787bbaf
Show file tree
Hide file tree
Showing 77 changed files with 785 additions and 832 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
cargo-

- name: Run non-integration tests
run: cargo test --lib --release --features mock_prover -- --skip test_light_client_sequencer_talking
run: cargo test --lib --release --features mock_prover -- --skip test_light_client_prover_talking

integration-test:
runs-on: ubuntu-latest
Expand Down
115 changes: 68 additions & 47 deletions Cargo.lock

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

18 changes: 12 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@ readme = "README.md"

[workspace]
default-members = [
"crates/prism",
"crates/bin",
"crates/node_types/prover",
"crates/node_types/lightclient",
"crates/common",
"crates/errors",
"crates/storage",
"crates/da",
]

members = [
"crates/prism",
"crates/bin",
"crates/node_types/prover",
"crates/node_types/lightclient",
"crates/common",
"crates/errors",
"crates/sp1",
"crates/zk/sp1",
"crates/storage",
"crates/da",
]
Expand Down Expand Up @@ -80,11 +84,13 @@ 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-nova = { path = "crates/zk/nova" }
prism-da = { path = "crates/da" }
prism-errors = { path = "crates/errors" }
prism-main = { path = "crates/prism" }
prism-groth16 = { path = "crates/groth16" }
prism-bin = { path = "crates/bin" }
prism-groth16 = { path = "crates/zk/groth16" }
prism-prover = { path = "crates/node_types/prover" }
prism-lightclient = { path = "crates/node_types/lightclient" }
rocksdb = { version = "0.21.0", features = ["multi-threaded-cf"] }


Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ Redis serves as a powerful in-memory database that is used to store the label-va

A DA layer such as Celestia is an important component for data security and availability. It stores the cryptographic commitments and parameters of the zkSNARKs and ideally enables them to be verified. Follow the instructions [here](https://github.com/celestiaorg/apollo) to deploy a local testnet.

### Starting the sequencer
### Starting the prover

If Redis is installed and the local devnet is running, Prism can be started. Prism can be started in two different ways, as a sequencer (service provider and proof generator) or as a light-client (to verify the proofs posted on Celestia using the cryptographic commitments). To start the sequencer, run the following command:
If Redis is installed and the local devnet is running, Prism can be started. Prism can be started in two different ways, as a prover (service provider and proof generator) or as a light-client (to verify the proofs posted on Celestia using the cryptographic commitments). To start the prover, run the following command:

```bash
cargo run sequencer
cargo run prover
```

to start the light-client, run the following command:
Expand Down
6 changes: 4 additions & 2 deletions crates/prism/Cargo.toml → crates/bin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "prism-main"
name = "prism-bin"
version.workspace = true
edition.workspace = true
license.workspace = true
Expand All @@ -25,7 +25,6 @@ redis = { workspace = true }
ed25519-dalek = { workspace = true }
base64 = { workspace = true }
tokio = { workspace = true }
bellman = { workspace = true }
bincode = { workspace = true }
bls12_381 = { workspace = true }
hex = { workspace = true }
Expand All @@ -45,9 +44,12 @@ auto_impl = { workspace = true }
prism-common = { workspace = true, features = ["test_utils"] }
prism-storage = { workspace = true }
prism-errors = { workspace = true }
prism-prover = { workspace = true }
prism-lightclient = { workspace = true }
prism-da = { workspace = true }
sp1-sdk = { workspace = true }
rand = { workspace = true }

[[test]]
name = "integration_tests"
path = "tests/integration_tests.rs"
Expand Down
20 changes: 3 additions & 17 deletions crates/prism/src/cfg.rs → crates/bin/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use dirs::home_dir;
use dotenvy::dotenv;
use log::{error, warn};
use prism_errors::{DataAvailabilityError, GeneralError, PrismError};
use prism_prover::webserver::WebServerConfig;
use prism_storage::redis::RedisConfig;
use serde::{Deserialize, Serialize};
use std::{fs, path::Path, sync::Arc};
Expand All @@ -19,7 +20,7 @@ use prism_da::{
#[derive(Clone, Debug, Subcommand, Deserialize)]
pub enum Commands {
LightClient,
Sequencer,
Prover,
}

#[derive(Parser, Clone, Debug, Deserialize)]
Expand Down Expand Up @@ -85,21 +86,6 @@ pub enum DALayerOption {
None,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct WebServerConfig {
pub host: String,
pub port: u16,
}

impl Default for WebServerConfig {
fn default() -> Self {
WebServerConfig {
host: "127.0.0.1".to_string(),
port: 8089,
}
}
}

impl Default for Config {
fn default() -> Self {
Config {
Expand Down Expand Up @@ -137,7 +123,7 @@ pub fn load_config(args: CommandLineArgs) -> Result<Config> {
let final_config = apply_command_line_args(merged_config, args);

if final_config.verifying_key.is_none() {
warn!("sequencer's public key was not provided. this is not recommended and epoch signatures will not be verified.");
warn!("prover's public key was not provided. this is not recommended and epoch signatures will not be verified.");
}

Ok(final_config)
Expand Down
2 changes: 2 additions & 0 deletions crates/bin/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod cfg;
pub mod node_types;
21 changes: 11 additions & 10 deletions crates/prism/src/main.rs → crates/bin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
mod cfg;
mod node_types;
mod utils;
mod webserver;

use cfg::{initialize_da_layer, load_config, CommandLineArgs, Commands};
use clap::Parser;
use ed25519_dalek::VerifyingKey as Ed25519VerifyingKey;
use keystore_rs::{KeyChain, KeyStore, KeyStoreType};
use prism_common::operation::VerifyingKey;
use prism_common::keys::VerifyingKey;

use node_types::{lightclient::LightClient, sequencer::Sequencer, NodeType};
use node_types::NodeType;
use prism_lightclient::LightClient;
use prism_prover::Prover;
use prism_storage::RedisConnection;
use std::sync::Arc;

Expand Down Expand Up @@ -38,16 +38,16 @@ async fn main() -> std::io::Result<()> {
)
})?;

let sequencer_vk = config
let prover_vk = config
.verifying_key
.and_then(|s| s.try_into().ok())
.and_then(|vk: VerifyingKey| {
Ed25519VerifyingKey::from_bytes(vk.as_bytes().try_into().unwrap()).ok()
});

Arc::new(LightClient::new(da, celestia_config, sequencer_vk))
Arc::new(LightClient::new(da, celestia_config, prover_vk))
}
Commands::Sequencer {} => {
Commands::Prover {} => {
let redis_config = config.clone().redis_config.ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::NotFound,
Expand All @@ -62,14 +62,15 @@ async fn main() -> std::io::Result<()> {
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;

Arc::new(
Sequencer::new(
Prover::new(
Arc::new(Box::new(redis_connections)),
da,
config,
config.webserver.unwrap(),
config.celestia_config.unwrap().start_height,
signing_key,
)
.map_err(|e| {
error!("error initializing sequencer: {}", e);
error!("error initializing prover: {}", e);
std::io::Error::new(std::io::ErrorKind::Other, e.to_string())
})?,
)
Expand Down
23 changes: 23 additions & 0 deletions crates/bin/src/node_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use anyhow::Result;
use async_trait::async_trait;
use std::{self, sync::Arc};

#[async_trait]
pub trait NodeType {
async fn start(self: Arc<Self>) -> Result<()>;
// async fn stop(&self) -> Result<(), String>;
}

#[async_trait]
impl NodeType for prism_prover::Prover {
async fn start(self: Arc<Self>) -> Result<()> {
self.run().await
}
}

#[async_trait]
impl NodeType for prism_lightclient::LightClient {
async fn start(self: Arc<Self>) -> Result<()> {
self.run().await
}
}
Loading

0 comments on commit 787bbaf

Please sign in to comment.