Skip to content

Commit

Permalink
fmt + clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-mainardi committed Jan 3, 2025
1 parent 29126e3 commit 14d374b
Show file tree
Hide file tree
Showing 27 changed files with 887 additions and 699 deletions.
2 changes: 1 addition & 1 deletion inspect/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::repl::PayloadFormatter;
pub(crate) type IndexDb = MerkleTreeKvDb<
BlockTree,
IndexNode<BlockPrimaryIndex>,
PgsqlStorage<BlockTree, IndexNode<BlockPrimaryIndex>>,
PgsqlStorage<BlockTree, IndexNode<BlockPrimaryIndex>, false>,
>;

struct IndexPayloadFormatterDisplay {
Expand Down
9 changes: 6 additions & 3 deletions inspect/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use repl::Repl;
use rows::{RowDb, RowPayloadFormatter};
use ryhope::{
storage::pgsql::{SqlServerConnection, SqlStorageSettings, ToFromBytea},
UserEpoch, InitSettings,
InitSettings, UserEpoch,
};
use serde::Serialize;

Expand Down Expand Up @@ -77,6 +77,8 @@ async fn main() -> Result<()> {
SqlStorageSettings {
source: SqlServerConnection::NewConnection(args.db_uri.clone()),
table: args.db_table,
external_mapper: None, // not necessary even if there is an external epoch mapper,
// since we are initializing the tree with `InitSettings::MustExist`
},
)
.await?;
Expand All @@ -91,7 +93,7 @@ async fn main() -> Result<()> {

let mut repl = Repl::new(tree_db, payload_fmt).await?;
if let Some(epoch) = args.epoch {
repl.set_epoch(epoch)?;
repl.set_epoch(epoch).await?;
}
repl.run().await
}
Expand All @@ -101,6 +103,7 @@ async fn main() -> Result<()> {
SqlStorageSettings {
source: SqlServerConnection::NewConnection(args.db_uri.clone()),
table: args.db_table,
external_mapper: None,
},
)
.await?;
Expand All @@ -109,7 +112,7 @@ async fn main() -> Result<()> {

let mut repl = Repl::new(tree_db, payload_fmt).await?;
if let Some(epoch) = args.epoch {
repl.set_epoch(epoch)?;
repl.set_epoch(epoch).await?;
}
repl.run().await
}
Expand Down
16 changes: 8 additions & 8 deletions inspect/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ryhope::{
TreeStorage,
},
tree::{MutableTree, PrintableTree, TreeTopology},
UserEpoch, MerkleTreeKvDb, NodePayload,
MerkleTreeKvDb, NodePayload, UserEpoch,
};
use tabled::{builder::Builder, settings::Style};

Expand Down Expand Up @@ -78,7 +78,7 @@ impl<
{
pub async fn new(db: MerkleTreeKvDb<T, V, S>, payload_fmt: F) -> Result<Self> {
let current_key = db.root().await.ok_or(anyhow!("tree is empty"))?;
let current_epoch = db.current_epoch();
let current_epoch = db.current_epoch().await?;

Ok(Self {
current_key,
Expand Down Expand Up @@ -106,19 +106,19 @@ impl<
.unwrap();
}

pub fn set_epoch(&mut self, epoch: UserEpoch) -> Result<()> {
if epoch < self.db.initial_epoch() {
pub async fn set_epoch(&mut self, epoch: UserEpoch) -> Result<()> {
if epoch < self.db.initial_epoch().await {
bail!(
"epoch `{}` is older than initial epoch `{}`",
epoch,
self.db.initial_epoch()
self.db.initial_epoch().await
);
}
if epoch > self.db.current_epoch() {
if epoch > self.db.current_epoch().await? {
bail!(
"epoch `{}` is newer than latest epoch `{}`",
epoch,
self.db.current_epoch()
self.db.current_epoch().await?
);
}

Expand Down Expand Up @@ -150,7 +150,7 @@ impl<
loop {
let epoch: UserEpoch = Input::new().with_prompt("target epoch:").interact_text()?;

self.set_epoch(epoch)?;
self.set_epoch(epoch).await?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion inspect/src/rows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::repl::PayloadFormatter;
pub(crate) type RowDb = MerkleTreeKvDb<
RowTree,
RowPayload<BlockPrimaryIndex>,
PgsqlStorage<RowTree, RowPayload<BlockPrimaryIndex>>,
PgsqlStorage<RowTree, RowPayload<BlockPrimaryIndex>, true>,
>;

struct RowPayloadFormatterDisplay {
Expand Down
6 changes: 5 additions & 1 deletion mp2-v1/src/indexing/block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
//! Module to handle the block number as a primary index
use ryhope::{storage::pgsql::PgsqlStorage, tree::{sbbst, TreeTopology}, MerkleTreeKvDb};
use ryhope::{
storage::pgsql::PgsqlStorage,
tree::{sbbst, TreeTopology},
MerkleTreeKvDb,
};

use super::index::IndexNode;

Expand Down
29 changes: 16 additions & 13 deletions mp2-v1/src/indexing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ use alloy::primitives::U256;
use block::MerkleIndexTree;
use mp2_common::types::HashOutput;
use row::MerkleRowTree;
use ryhope::{storage::pgsql::{SqlServerConnection, SqlStorageSettings}, tree::scapegoat, InitSettings, UserEpoch};
use ryhope::{
storage::pgsql::{SqlServerConnection, SqlStorageSettings},
tree::scapegoat,
InitSettings, UserEpoch,
};

pub mod block;
pub mod cell;
Expand All @@ -14,7 +18,7 @@ pub mod row;

pub type ColumnID = u64;

/// Build `MerkleIndexTree` and `MerkleRowTree` trees from tables
/// Build `MerkleIndexTree` and `MerkleRowTree` trees from tables
/// `index_table_name` and `row_table_name` in the DB with URL `db_url`.
pub async fn load_trees(
db_url: &str,
Expand All @@ -40,14 +44,12 @@ pub async fn load_trees(
)
.await?;

Ok(
(index_tree, row_tree)
)
Ok((index_tree, row_tree))
}

/// Build `MerkleIndexTree` and `MerkleRowTree` trees starting from
/// Build `MerkleIndexTree` and `MerkleRowTree` trees starting from
/// `genesis_block`. The tables employed in the DB with URL `db_url`
/// to store the trees are `index_table_name` and `row_table_name`,
/// to store the trees are `index_table_name` and `row_table_name`,
/// respectively. The following additional parameters are required:
/// - `alpha`: Parameter of the Scapegoat tree employed for the `MerkleRowTree`
/// - `reset_if_exist`: if true, an existing tree would be deleted
Expand All @@ -70,8 +72,12 @@ pub async fn build_trees(
external_mapper: Some(index_table_name),
};

let index_tree = ryhope::new_index_tree(genesis_block as UserEpoch, db_settings_index, reset_if_exist)
.await?;
let index_tree = ryhope::new_index_tree(
genesis_block as UserEpoch,
db_settings_index,
reset_if_exist,
)
.await?;
let row_tree = ryhope::new_row_tree(
genesis_block as UserEpoch,
alpha,
Expand All @@ -80,10 +86,7 @@ pub async fn build_trees(
)
.await?;

Ok(
(index_tree, row_tree)
)

Ok((index_tree, row_tree))
}

// NOTE this might be good to have on public API ?
Expand Down
6 changes: 5 additions & 1 deletion mp2-v1/src/indexing/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ use plonky2::{
hash::hash_types::HashOut,
plonk::config::{GenericHashOut, Hasher},
};
use ryhope::{storage::pgsql::{PgsqlStorage, ToFromBytea}, tree::scapegoat, MerkleTreeKvDb, NodePayload};
use ryhope::{
storage::pgsql::{PgsqlStorage, ToFromBytea},
tree::scapegoat,
MerkleTreeKvDb, NodePayload,
};
use serde::{Deserialize, Deserializer, Serialize, Serializer};

pub type RowTree = scapegoat::Tree<RowTreeKey>;
Expand Down
13 changes: 8 additions & 5 deletions mp2-v1/src/query/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ use mp2_common::types::HashOutput;
use parsil::{bracketer::bracket_secondary_index, symbols::ContextProvider, ParsilSettings};
use ryhope::{
storage::{
pgsql::ToFromBytea,
updatetree::UpdateTree,
FromSettings, PayloadStorage, TransactionalStorage, TreeStorage, WideLineage,
pgsql::ToFromBytea, updatetree::UpdateTree, FromSettings, PayloadStorage,
TransactionalStorage, TreeStorage, WideLineage,
},
tree::{MutableTree, NodeContext, TreeTopology},
UserEpoch, MerkleTreeKvDb, NodePayload,
MerkleTreeKvDb, NodePayload, UserEpoch,
};
use std::{fmt::Debug, future::Future};
use tokio_postgres::{row::Row as PsqlRow, types::ToSql, NoTls};
Expand Down Expand Up @@ -349,7 +348,11 @@ where
{
const IS_WIDE_LINEAGE: bool = true;

async fn fetch_ctx_and_payload_at(&self, k: &K, epoch: UserEpoch) -> Option<(NodeContext<K>, V)> {
async fn fetch_ctx_and_payload_at(
&self,
k: &K,
epoch: UserEpoch,
) -> Option<(NodeContext<K>, V)> {
self.ctx_and_payload_at(epoch, k)
}
}
Expand Down
20 changes: 13 additions & 7 deletions mp2-v1/tests/common/cases/query/aggregated_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,15 @@ pub(crate) async fn prove_query(
metadata: MetadataHash,
planner: &mut QueryPlanner<'_>,
) -> Result<()> {
println!("Row cache query: {}", &core_keys_for_row_tree(
&planner.query.query,
planner.settings,
&planner.pis.bounds,
&planner.query.placeholders,
)?);
println!(
"Row cache query: {}",
&core_keys_for_row_tree(
&planner.query.query,
planner.settings,
&planner.pis.bounds,
&planner.query.placeholders,
)?
);
let row_cache = planner
.table
.row
Expand Down Expand Up @@ -801,7 +804,10 @@ pub(crate) async fn find_longest_lived_key(
Ok((longest_key.clone(), (min_block, max_block)))
}

async fn collect_all_at(tree: &MerkleRowTree, at: UserEpoch) -> Result<Vec<Row<BlockPrimaryIndex>>> {
async fn collect_all_at(
tree: &MerkleRowTree,
at: UserEpoch,
) -> Result<Vec<Row<BlockPrimaryIndex>>> {
let root_key = tree.root_at(at).await.unwrap();
let (ctx, payload) = tree.try_fetch_with_context_at(&root_key, at).await.unwrap();
let root_row = Row {
Expand Down
2 changes: 1 addition & 1 deletion mp2-v1/tests/common/cases/query/simple_select_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use parsil::{
};
use ryhope::{
storage::{pgsql::ToFromBytea, RoEpochKvStorage},
UserEpoch, NodePayload,
NodePayload, UserEpoch,
};
use sqlparser::ast::Query;
use std::{fmt::Debug, hash::Hash};
Expand Down
5 changes: 4 additions & 1 deletion mp2-v1/tests/common/ivc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use super::{
};
use anyhow::Result;
use mp2_common::{proof::ProofWithVK, types::HashOutput, F};
use mp2_v1::{api, indexing::block::{BlockPrimaryIndex, MerkleIndexTree}};
use mp2_v1::{
api,
indexing::block::{BlockPrimaryIndex, MerkleIndexTree},
};
use plonky2::{hash::hash_types::HashOut, plonk::config::GenericHashOut};
use verifiable_db::ivc::PublicInputs;

Expand Down
4 changes: 2 additions & 2 deletions mp2-v1/tests/common/rowtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use mp2_v1::{
};
use plonky2::plonk::config::GenericHashOut;
use ryhope::storage::{
updatetree::{Next, UpdateTree},
RoEpochKvStorage,
updatetree::{Next, UpdateTree},
RoEpochKvStorage,
};
use serde::{Deserialize, Serialize};
use verifiable_db::{cells_tree, row_tree::extract_hash_from_proof};
Expand Down
43 changes: 26 additions & 17 deletions mp2-v1/tests/common/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,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
block::{BlockPrimaryIndex, BlockTreeKey, MerkleIndexTree},
build_trees,
cell::{self, Cell, CellTreeKey, MerkleCell, MerkleCellTree},
index::IndexNode,
load_trees,
row::{CellCollection, MerkleRowTree, Row, RowTreeKey},
ColumnID,
};
use parsil::symbols::{ColumnKind, ContextProvider, ZkColumn, ZkTable};
use ryhope::{
storage::{
updatetree::UpdateTree,
EpochKvStorage, RoEpochKvStorage, TreeTransactionalStorage,
},
storage::{updatetree::UpdateTree, EpochKvStorage, RoEpochKvStorage, TreeTransactionalStorage},
tree::scapegoat::Alpha,
UserEpoch,
};
Expand Down Expand Up @@ -171,10 +174,11 @@ impl Table {
pub async fn load(public_name: String, columns: TableColumns) -> Result<Self> {
let db_url = std::env::var("DB_URL").unwrap_or("host=localhost dbname=storage".to_string());
let (index_tree, row_tree) = load_trees(
db_url.as_str(),
index_table_name(&public_name),
row_table_name(&public_name)
).await?;
db_url.as_str(),
index_table_name(&public_name),
row_table_name(&public_name),
)
.await?;
let genesis = index_tree.storage_state().await.shift;
columns.self_assert();

Expand All @@ -192,16 +196,21 @@ impl Table {
row_table_name(&self.public_name)
}

pub async fn new(genesis_block: u64, root_table_name: String, columns: TableColumns) -> Result<Self> {
pub async fn new(
genesis_block: u64,
root_table_name: String,
columns: TableColumns,
) -> 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(),
index_table_name(&root_table_name),
row_table_name(&root_table_name),
genesis_block as UserEpoch,
Alpha::new(0.8),
true
).await?;
db_url.as_str(),
index_table_name(&root_table_name),
row_table_name(&root_table_name),
genesis_block as UserEpoch,
Alpha::new(0.8),
true,
)
.await?;
columns.self_assert();
Ok(Self {
db_pool: new_db_pool(&db_url)
Expand Down
6 changes: 4 additions & 2 deletions parsil/src/bracketer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use alloy::primitives::U256;
use ryhope::{mapper_table_name, KEY, PAYLOAD, VALID_FROM, VALID_UNTIL, USER_EPOCH, INCREMENTAL_EPOCH};
use ryhope::{
mapper_table_name, INCREMENTAL_EPOCH, KEY, PAYLOAD, USER_EPOCH, VALID_FROM, VALID_UNTIL,
};
use verifiable_db::query::utils::QueryBounds;

use crate::{symbols::ContextProvider, ParsilSettings};
Expand Down Expand Up @@ -36,7 +38,7 @@ pub(crate) fn _bracket_secondary_index<C: ContextProvider>(
) -> (Option<String>, Option<String>) {
let zk_table = settings.context.fetch_table(table_name).unwrap();
let zktable_name = &zk_table.zktable_name;
let mapper_table_name = mapper_table_name(&zktable_name);
let mapper_table_name = mapper_table_name(zktable_name);
let sec_ind_column = zk_table.secondary_index_column().id;

// A simple alias for the sec. ind. values
Expand Down
Loading

0 comments on commit 14d374b

Please sign in to comment.