diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b4b8e3..b3daefb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,6 +44,8 @@ jobs: steps: - uses: actions/checkout@v2 - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} + - name: Install Dependencies + run: sudo apt install protobuf-compiler - name: Cargo test run: cargo test --release --verbose diff --git a/Cargo.lock b/Cargo.lock index 43a6987..06908ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1854,7 +1854,6 @@ dependencies = [ "eyre", "futures", "jsonrpsee", - "kvdb-memorydb", "log", "pretty_assertions", "prost", @@ -3256,25 +3255,6 @@ dependencies = [ "sha3-asm", ] -[[package]] -name = "kvdb" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7d770dcb02bf6835887c3a979b5107a04ff4bbde97a5f0928d27404a155add9" -dependencies = [ - "smallvec", -] - -[[package]] -name = "kvdb-memorydb" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf7a85fe66f9ff9cd74e169fdd2c94c6e1e74c412c99a73b4df3200b5d3760b2" -dependencies = [ - "kvdb", - "parking_lot 0.12.1", -] - [[package]] name = "lazy_static" version = "1.4.0" diff --git a/Cargo.toml b/Cargo.toml index 89ad748..995d2c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,6 @@ reth-blockchain-tree = { git = "https://github.com/0xEigenLabs/reth", package = # Database reth-libmdbx = { git = "https://github.com/0xEigenLabs/reth", package = "reth-libmdbx", rev = "8cffebd72" } -kvdb-memorydb = "0.13.0" #reth-payload-builder = { path = "../reth/crates/payload/builder" } #reth-basic-payload-builder = { path = "../reth/crates/payload/basic" } diff --git a/src/da/ethereum/mod.rs b/src/da/ethereum/mod.rs index 9d0f028..8b13789 100644 --- a/src/da/ethereum/mod.rs +++ b/src/da/ethereum/mod.rs @@ -1 +1 @@ -//! + diff --git a/src/db/db_utils/libmdbx.rs b/src/db/db_utils/libmdbx.rs index a88e5c2..8b13789 100644 --- a/src/db/db_utils/libmdbx.rs +++ b/src/db/db_utils/libmdbx.rs @@ -1,61 +1 @@ -use reth_libmdbx::*; -use db::Database as EigenDB; -use crate::db; -pub struct Bd(Database); - -impl EigenDB for Bd { - fn get(&self, key: &[u8]) -> Option> { - self.0.get(key).unwrap() - } - - fn put(&mut self, key: Vec, value: Vec) { - self.0.put(key, value).unwrap() - } - - fn del(&mut self, key: Vec) { - self.0.del(key).unwrap() - } - - fn commit(&mut self, transaction: db::Transaction) { - for change in transaction.0 { - match change { - db::ChangeOpt::Put(key, value) => self.put(key, value), - db::ChangeOpt::Del(key) => self.del(key), - } - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - - fn test_open() { - let dir = "/tmp/eigen-reth2"; - let env = Environment::builder() - .open(std::path::Path::new(dir)) - .unwrap(); - let txn = env.begin_rw_txn().unwrap(); - let db = txn.open_db(None).unwrap(); - txn.put(db.dbi(), b"key1", b"val1", WriteFlags::empty()) - .unwrap(); - txn.put(db.dbi(), b"key2", b"val2", WriteFlags::empty()) - .unwrap(); - txn.put(db.dbi(), b"key3", b"val3", WriteFlags::empty()) - .unwrap(); - txn.commit().unwrap(); - - let txn = env.begin_rw_txn().unwrap(); - let db = txn.open_db(None).unwrap(); - assert_eq!(txn.get(db.dbi(), b"key1").unwrap(), Some(*b"val1")); - assert_eq!(txn.get(db.dbi(), b"key2").unwrap(), Some(*b"val2")); - assert_eq!(txn.get(db.dbi(), b"key3").unwrap(), Some(*b"val3")); - assert_eq!(txn.get::<()>(db.dbi(), b"key").unwrap(), None); - - txn.del(db.dbi(), b"key1", None).unwrap(); - assert_eq!(txn.get::<()>(db.dbi(), b"key1").unwrap(), None); - txn.commit().unwrap(); - } - -} diff --git a/src/db/db_utils/mem.rs b/src/db/db_utils/mem.rs new file mode 100644 index 0000000..037ae80 --- /dev/null +++ b/src/db/db_utils/mem.rs @@ -0,0 +1,19 @@ +use crate::db::Database as EigenDB; +use std::collections::HashMap; + +#[derive(Default)] +pub struct Db(HashMap, Vec>); + +impl EigenDB for Db { + fn get(&self, key: &[u8]) -> Option> { + self.0.get(key).cloned() + } + + fn put(&mut self, key: Vec, value: Vec) { + self.0.insert(key, value); + } + + fn del(&mut self, key: Vec) -> Option> { + self.0.remove(&key) + } +} diff --git a/src/db/db_utils/memory_kvdb.rs b/src/db/db_utils/memory_kvdb.rs deleted file mode 100644 index 9b795dc..0000000 --- a/src/db/db_utils/memory_kvdb.rs +++ /dev/null @@ -1,34 +0,0 @@ -use kvdb_memorydb::InMemory; - -use crate::db::Database as EigenDB; - -/* -pub struct InMemory { - columns: RwLock, DBValue>>>, -} - */ - -pub struct Db(InMemory); - -impl EigenDB for Db { - fn get(&self, key: &[u8]) -> Option> { - self.0.get(key).unwrap() - } - - fn put(&mut self, key: Vec, value: Vec) { - self.0.put(key, value).unwrap() - } - - fn del(&mut self, key: Vec) { - self.0.del(key).unwrap() - } - - fn commit(&mut self, transaction: db::Transaction) { - for change in transaction.0 { - match change { - db::ChangeOpt::Put(key, value) => self.put(key, value), - db::ChangeOpt::Del(key) => self.del(key), - } - } - } -} \ No newline at end of file diff --git a/src/db/db_utils/mod.rs b/src/db/db_utils/mod.rs index c5b6c0e..27b3d1f 100644 --- a/src/db/db_utils/mod.rs +++ b/src/db/db_utils/mod.rs @@ -1,35 +1,32 @@ -mod memory_kvdb; -mod libmdbx; +// TODO: Fix me +#![allow(dead_code)] -use std::path::PathBuf; +mod libmdbx; +mod mem; -use db::Database as EigenDB; use crate::db; +use db::Database as EigenDB; pub(crate) enum DBConfig { /// memory kv-database Memory, /// libmdbx database - MDBX { + Mdbx { /// Path to the mdbx database - path: PathBuf, - // path: String, + // path: PathBuf, + path: String, }, } -// TODO: - - -pub(crate) fn open_db(config: &DBConfig) -> Result { - +pub(crate) fn open_db(config: &DBConfig) -> Result, ()> { + match config { + DBConfig::Memory => open_memory_db(), + DBConfig::Mdbx { .. } => { + unimplemented!("open_mdbx_db") + } + } } - -fn open_mdbx_db(path: &PathBuf) -> Result { - let db = libmdbx::Database::open(path); - Ok(EigenDB::MDBX(db)) +fn open_memory_db() -> Result, ()> { + Ok(Box::new(mem::Db::default())) } - -// -// fn open_memory_db() -> Result { -// } \ No newline at end of file diff --git a/src/db/mod.rs b/src/db/mod.rs index f53081d..8fb2fa2 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -1,36 +1,13 @@ +// TODO: Fix me +#![allow(dead_code)] + mod data_availability_db; mod db_utils; -/// TODO: we need a trait to abstract the database operations in order to support multiple databases? - -pub enum ChangeOpt { - Put(Vec, Vec), - Del(Vec), -} - -pub struct Transaction(pub Vec); - -impl Transaction { -pub fn new() -> Self { - Transaction(Vec::new()) - } - - pub fn put(&mut self, key: Vec, value: Vec) { - self.0.push(ChangeOpt::Put(key, value)); - } - - pub fn del(&mut self, key: Vec) { - self.0.push(ChangeOpt::Del(key)); - } -} +/// TODO: we need a trait to abstract the database operations in order to support multiple databases pub trait Database { fn get(&self, key: &[u8]) -> Option>; fn put(&mut self, key: Vec, value: Vec); - fn del(&mut self, key: Vec); - fn commit(&mut self, transaction: Transaction); + fn del(&mut self, key: Vec) -> Option>; } -/// key prefixes for different databases -pub(crate) mod columns{ - pub const NUM_COLUMNS: u8 = 0; -} \ No newline at end of file diff --git a/src/prover/provider.rs b/src/prover/provider.rs index cb6ead1..928bac9 100644 --- a/src/prover/provider.rs +++ b/src/prover/provider.rs @@ -4,13 +4,15 @@ //! the proof generation request to proof network; //! 2) Keep polling if the task is finished. //! 3) If the task is finished, update the status into proof database, hence the extended RPC module will fetch this and return it to SDK. +// TODO: Fix me +#![allow(dead_code)] use crate::prover::provider::prover_service::prover_request::RequestType; use crate::prover::provider::prover_service::prover_response::ResponseType; use crate::prover::provider::prover_service::prover_service_client::ProverServiceClient; use crate::prover::provider::prover_service::{ Batch, GenAggregatedProofRequest, GenBatchProofRequest, GenFinalProofRequest, - ProofResultStatus, ProverRequest, ProverResponse, + ProofResultStatus, ProverRequest, }; use tokio::sync::mpsc; use tokio::sync::mpsc::{Receiver, Sender}; @@ -58,7 +60,7 @@ pub struct ProveSMT { /// the endpoint to communicate with the prover endpoint: ProverEndpoint, - /// + /// used to receive response from the endpoint response_receiver: Receiver, } @@ -113,7 +115,7 @@ impl ProveSMT { loop { self.step = match &self.step { ProveStep::Start => { - let batch = self.current_batch.unwrap().clone(); + let batch = self.current_batch.unwrap(); ProveStep::Batch(batch) } @@ -209,9 +211,15 @@ impl ProveSMT { { ProveStep::End } else { + // TODO: return error + log::error!( + "gen final proof failed, error: {:?}", + gen_final_proof_response.error_message + ); ProveStep::End } } else { + log::error!("gen final proof failed, no response"); ProveStep::End } } @@ -252,7 +260,7 @@ pub struct ProverEndpoint { /// listen to the stop signal, and stop the endpoint loop stop_endpoint_rx: Receiver<()>, - /// + /// used to send response to the ProveSMT response_sender: Sender, } diff --git a/src/settlement/ethereum/client.rs b/src/settlement/ethereum/client.rs index ec82c45..8b13789 100644 --- a/src/settlement/ethereum/client.rs +++ b/src/settlement/ethereum/client.rs @@ -1,3 +1 @@ -//! -//! -//! +