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

refactor: more ergonomic WorkplanItem #383

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 10 additions & 10 deletions devenv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"devenv": {
"locked": {
"dir": "src/modules",
"lastModified": 1728993896,
"lastModified": 1729857292,
"owner": "cachix",
"repo": "devenv",
"rev": "dc7ebaf872306526ea6dcbb2122acca792680701",
"rev": "d9156ba99fed6f4bc4d84b8ff1b442f04a98210a",
"type": "github"
},
"original": {
Expand All @@ -24,10 +24,10 @@
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1728973961,
"lastModified": 1729838036,
"owner": "nix-community",
"repo": "fenix",
"rev": "d6a9ff4d1e60c347a23bc96ccdb058d37a810541",
"rev": "c9f079dab2456bd75da8539b7129f8aaea9d4a2d",
"type": "github"
},
"original": {
Expand Down Expand Up @@ -88,10 +88,10 @@
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1728740863,
"lastModified": 1729691686,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "a3f9ad65a0bf298ed5847629a57808b97e6e8077",
"rev": "32e940c7c420600ef0d1ef396dc63b04ee9cad37",
"type": "github"
},
"original": {
Expand All @@ -111,10 +111,10 @@
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1728778939,
"lastModified": 1729104314,
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "ff68f91754be6f3427e4986d7949e6273659be1d",
"rev": "3c3e88f0f544d6bb54329832616af7eb971b6be6",
"type": "github"
},
"original": {
Expand All @@ -134,10 +134,10 @@
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1728921748,
"lastModified": 1729792465,
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "0319586ef2a2636f6d6b891690b7ebebf4337c85",
"rev": "6a67a4d3cd480dbbc3b1dec461a31b1bea1dfba4",
"type": "github"
},
"original": {
Expand Down
2 changes: 1 addition & 1 deletion mp2-v1/tests/common/cases/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ where
// closure performing all the operations necessary beofre jumping to the next iteration
let mut end_iteration = |proven_nodes: &mut HashSet<K>| -> Result<()> {
proven_nodes.insert(k.clone());
workplan.done(&wk)?;
workplan.done(wk.k())?;
Ok(())
};
// since epoch starts at genesis now, we can directly give the value of the block
Expand Down
2 changes: 1 addition & 1 deletion mp2-v1/tests/common/celltree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl TestContext {
.unwrap()
)
);
workplan.done(&wk).unwrap();
workplan.done(wk.k()).unwrap();
}
let root = tree.root().await.unwrap();
let root_data = tree.root_data().await.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion mp2-v1/tests/common/index_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl TestContext {
.store_proof(ProofKey::Index(proof_key), proof)
.expect("unable to store index tree proof");

workplan.done(&wk).unwrap();
workplan.done(wk.k()).unwrap();
}
let root = t.root().await.unwrap();
let root_proof_key = IndexProofIdentifier {
Expand Down
2 changes: 1 addition & 1 deletion mp2-v1/tests/common/rowtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl TestContext {
new_proof_key,
hex::encode(extract_hash_from_proof(&proof).unwrap().to_bytes())
);
workplan.done(&wk).unwrap();
workplan.done(wk.k()).unwrap();
}
let root = t.root().await.unwrap();
let row = table.row.fetch(&root).await;
Expand Down
2 changes: 0 additions & 2 deletions recursion-framework/src/circuit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ pub(crate) mod tests {
}

impl<
'a,
F: SerializableRichField<D>,
const D: usize,
const NUM_VERIFIERS: usize,
Expand Down Expand Up @@ -457,7 +456,6 @@ pub(crate) mod tests {
}

impl<
'a,
F: SerializableRichField<D>,
const D: usize,
const NUM_VERIFIERS: usize,
Expand Down
2 changes: 1 addition & 1 deletion ryhope/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ where

let mut payload = self.storage.data().fetch(item.k()).await;
payload.aggregate(child_data.into_iter());
plan.done(&item)?;
plan.done(item.k())?;
self.storage
.data_mut()
.store(item.k().to_owned(), payload)
Expand Down
36 changes: 24 additions & 12 deletions ryhope/src/storage/updatetree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,22 @@ impl<K: Clone + Hash + Eq + Debug> WorkplanItem<K> {
WorkplanItem::Subtree { k, .. } | WorkplanItem::Node { k, .. } => k,
}
}

pub fn as_subtree(&self) -> &UpdateTree<K> {
if let WorkplanItem::Subtree { subtree, .. } = self {
subtree
} else {
unreachable!()
}
}

pub fn as_node(&self) -> bool {
if let WorkplanItem::Node { is_path_end, .. } = self {
*is_path_end
} else {
unreachable!()
}
}
}

/// An update plan to recompute all the hashes of the touched nodes stored in a
Expand Down Expand Up @@ -419,15 +435,11 @@ impl<T: Debug + Clone + Hash + Eq> UpdatePlan<T> {

/// Mark the given item as having been completed. Its dependent will not be
/// generated by the iterator until the item has been marked as completed.
pub fn done(&mut self, item: &WorkplanItem<T>) -> Result<()> {
let i = *self
.t
.idx
.get(item.k())
.ok_or_else(|| anyhow!("unknwown key"))?;
pub fn done(&mut self, k: &T) -> Result<()> {
let i = *self.t.idx.get(k).ok_or_else(|| anyhow!("unknwown key"))?;

// May happen when restarting a plan
self.anchors.retain(|k| k != item.k());
self.anchors.retain(|_k| _k != k);

// Root node is hardcoded to 0
if i == 0 {
Expand Down Expand Up @@ -541,14 +553,14 @@ mod tests {

loop {
let mut done = vec![];
while let Some(Next::Ready(k)) = workplan.next() {
println!("Doing {}", k.k());
done.push(k);
while let Some(Next::Ready(item)) = workplan.next() {
println!("Doing {}", item.k());
done.push(item);
workplan.t.print();
}

for d in done.iter() {
workplan.done(d).unwrap();
workplan.done(d.k()).unwrap();
}
if done.is_empty() {
break;
Expand Down Expand Up @@ -599,7 +611,7 @@ mod tests {
count_done += 1;
}
}
workplan.done(&item).unwrap();
workplan.done(item.k()).unwrap();
}

assert_eq!(count_done, mt.nodes.len());
Expand Down
Loading