Skip to content

Commit

Permalink
Fix after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-mainardi committed Feb 3, 2025
1 parent 737079d commit 1298394
Show file tree
Hide file tree
Showing 17 changed files with 467 additions and 362 deletions.
6 changes: 2 additions & 4 deletions inspect/src/repl.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use anyhow::{anyhow, bail};
use anyhow::{Result, anyhow, bail};
use colored::Colorize;
use dialoguer::{console, theme::ColorfulTheme, FuzzySelect, Input};
use itertools::Itertools;
use ryhope::{
storage::{
FromSettings, MetaOperations, PayloadStorage, RoEpochKvStorage, TransactionalStorage,
TreeStorage,
},
tree::{MutableTree, PrintableTree, TreeTopology},
MerkleTreeKvDb, NodePayload, UserEpoch,
}, tree::{MutableTree, PrintableTree, TreeTopology}, MerkleTreeKvDb, NodePayload, UserEpoch
};
use std::io::Write;
use tabled::{builder::Builder, settings::Style};
Expand Down
2 changes: 0 additions & 2 deletions mp2-v1/src/indexing/row.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashSet;

use super::{block::BlockPrimaryIndex, cell::CellTreeKey, ColumnID};
use alloy::primitives::U256;
use anyhow::Result;
Expand Down
2 changes: 1 addition & 1 deletion mp2-v1/src/query/batching_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async fn generate_chunks<const CHUNK_SIZE: usize, C: ContextProvider>(
let proven_node = non_existence_inputs
.find_row_node_for_non_existence(index_value)
.await
.unwrap_or_else(|_| {
.unwrap_or_else(|e| {
panic!("node for non-existence not found for index value {index_value}: {e:?}")
});
let row_input = compute_input_for_row(
Expand Down
4 changes: 3 additions & 1 deletion mp2-v1/tests/common/cases/indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl TableIndexing {
columns,
row_unique_id,
)
.await;
.await?;
Ok((
Self {
value_column,
Expand Down Expand Up @@ -959,6 +959,7 @@ async fn build_mapping_table(
row_unique_id,
)
.await
.unwrap()
}

/// Build the mapping of mappings table.
Expand Down Expand Up @@ -1071,6 +1072,7 @@ async fn build_mapping_of_mappings_table(
row_unique_id,
)
.await
.unwrap()
}

#[derive(Clone, Debug)]
Expand Down
5 changes: 4 additions & 1 deletion mp2-v1/tests/common/index_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ impl TestContext {
// here we are simply proving the new updated nodes from the new node to
// the root. We fetch the same node but at the previous version of the
// tree to prove the update.
let previous_node = t.try_fetch_at(k, t.current_epoch().await.unwrap() - 1).await?.unwrap();
let previous_node = t
.try_fetch_at(k, t.current_epoch().await.unwrap() - 1)
.await?
.unwrap();
let left_key = context.left.expect("should always be a left child");
let left_node = t.try_fetch(&left_key).await?.unwrap();
// this should be one of the nodes we just proved in this loop before
Expand Down
29 changes: 14 additions & 15 deletions mp2-v1/tests/common/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ use futures::{
};
use itertools::Itertools;
use log::debug;
use mp2_v1::indexing::{
block::{BlockPrimaryIndex, BlockTreeKey, MerkleIndexTree},
build_trees,
cell::{self, Cell, CellTreeKey, MerkleCell, MerkleCellTree},
index::IndexNode,
load_trees,
row::{CellCollection, MerkleRowTree, Row, RowTreeKey},
ColumnID,
use mp2_v1::{
indexing::{
block::{BlockPrimaryIndex, BlockTreeKey, MerkleIndexTree},
build_trees,
cell::{self, Cell, CellTreeKey, MerkleCell, MerkleCellTree},
index::IndexNode,
load_trees,
row::{CellCollection, MerkleRowTree, Row, RowTreeKey},
ColumnID,
},
values_extraction::gadgets::column_info::ColumnInfo,
};
use parsil::symbols::{ColumnKind, ContextProvider, ZkColumn, ZkTable};
use plonky2::field::types::PrimeField64;
Expand Down Expand Up @@ -209,7 +212,7 @@ impl Table {
row_table_name(&public_name),
)
.await?;
let genesis = index_tree.storage_state().await.shift;
let genesis = index_tree.storage_state().await?.shift;
columns.self_assert();

Ok(Self {
Expand All @@ -232,15 +235,11 @@ impl Table {
}

pub async fn new(

genesis_block: u64,

root_table_name: String,

columns: TableColumns,
row_unique_id: TableRowUniqueID,
,
) -> Self {
) -> Result<Self> {
let db_url = std::env::var("DB_URL").unwrap_or("host=localhost dbname=storage".to_string());
let (index_tree, row_tree) = build_trees(
db_url.as_str(),
Expand Down Expand Up @@ -449,7 +448,7 @@ impl Table {
{
// debugging
println!("\n+++++++++++++++++++++++++++++++++\n");
let root = self.row.root_data().await.unwrap();
let root = self.row.root_data().await?.unwrap();
println!(
" ++ After row update, row cell tree root tree proof hash = {:?}",
hex::encode(root.cell_root_hash.unwrap().0)
Expand Down
10 changes: 7 additions & 3 deletions parsil/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ enum Command {
to_keys: bool,
},
Core {
/// The query to execute if tree_type is "row", or the table name if
/// tree_type is "index"
#[arg(long, short = 'Q')]
request: String,

Expand Down Expand Up @@ -217,9 +219,11 @@ fn main() -> Result<()> {
// todo!(),
// )?
}
"index" => {
core_keys_for_index_tree(epoch, (min_block as NodeIdx, max_block as NodeIdx))?
}
"index" => core_keys_for_index_tree(
epoch,
(min_block as NodeIdx, max_block as NodeIdx),
&request,
)?,
_ => unreachable!(),
};

Expand Down
12 changes: 12 additions & 0 deletions ryhope/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use thiserror::Error;
use tokio_postgres::error::Error as PgError;

use crate::IncrementalEpoch;

#[derive(Error, Debug)]
pub enum RyhopeError {
/// An error that occured while interacting with the DB.
Expand Down Expand Up @@ -34,6 +36,12 @@ pub enum RyhopeError {

#[error("key not found in tree")]
KeyNotFound,

#[error("Current epoch is undefined: internal epoch is {0}, but no corresponding user epoch was found")]
CurrenEpochUndefined(IncrementalEpoch),

#[error("Error in epoch mapper operation: {0}")]
EpochMapperError(String),
}
impl RyhopeError {
pub fn from_db<S: AsRef<str>>(msg: S, err: PgError) -> Self {
Expand Down Expand Up @@ -64,6 +72,10 @@ impl RyhopeError {
pub fn fatal<S: AsRef<str>>(msg: S) -> Self {
RyhopeError::Fatal(msg.as_ref().to_string())
}

pub fn epoch_error<S: AsRef<str>>(msg: S) -> Self {
RyhopeError::EpochMapperError(msg.as_ref().to_string())
}
}

pub fn ensure<S: AsRef<str>>(cond: bool, msg: S) -> Result<(), RyhopeError> {
Expand Down
25 changes: 8 additions & 17 deletions ryhope/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,9 @@ where
}

pub async fn node_context_at(

&self,

k: &T::Key,

epoch: UserEpoch,
,
) -> Result<Option<NodeContext<T::Key>>, RyhopeError> {
self.tree
.node_context(k, &self.storage.view_at(epoch))
Expand Down Expand Up @@ -381,7 +377,10 @@ where

/// Return the update tree generated by the transaction defining the given
/// epoch.
pub async fn diff_at(&self, epoch: UserEpoch) -> Result<Option<UpdateTree<T::Key>>, RyhopeError> {
pub async fn diff_at(
&self,
epoch: UserEpoch,
) -> Result<Option<UpdateTree<T::Key>>, RyhopeError> {
let current_epoch = self.current_epoch().await?;
Ok(if epoch <= current_epoch {
let dirtied = self.storage.born_at(epoch).await;
Expand All @@ -395,7 +394,7 @@ where
}

let ut = UpdateTree::from_paths(paths, epoch);
Ok(Some(ut))
Some(ut)
} else {
None
})
Expand Down Expand Up @@ -462,23 +461,15 @@ impl<
self.storage.data().initial_epoch()
}

fn current_epoch(&self) -> impl Future<Output = Result<UserEpoch>> + Send {
fn current_epoch(&self) -> impl Future<Output = Result<UserEpoch, RyhopeError>> + Send {
self.storage.data().current_epoch()
}

async fn fetch_at(&self, k: &T::Key, timestamp: UserEpoch) -> V {
self.storage.data().fetch_at(k, timestamp).await
}

async fn fetch(&self, k: &T::Key) -> V {
self.storage.data().fetch(k).await
}

async fn try_fetch_at(&self, k: &T::Key, epoch: UserEpoch) -> Result<Option<V>, RyhopeError> {
self.storage.data().try_fetch_at(k, epoch).await
}

async fn try_fetch(&self, k: &T::Key) -> Option<V> {
async fn try_fetch(&self, k: &T::Key) -> Result<Option<V>, RyhopeError> {
self.storage.data().try_fetch(k).await
}

Expand Down Expand Up @@ -552,7 +543,7 @@ impl<
self.storage.rollback_to(epoch).await
}

async fn rollback(&mut self) -> Result<()> {
async fn rollback(&mut self) -> Result<(), RyhopeError> {
trace!("[MerkleTreeKvDb] rolling back");
self.storage.rollback().await
}
Expand Down
Loading

0 comments on commit 1298394

Please sign in to comment.