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: forester: batch ops #1453

Merged
merged 18 commits into from
Jan 9, 2025
Merged

refactor: forester: batch ops #1453

merged 18 commits into from
Jan 9, 2025

Conversation

sergeytimoshin
Copy link
Contributor

No description provided.

@sergeytimoshin sergeytimoshin changed the title forester batch ops refactored refactor: forester: batch ops Jan 5, 2025
@sergeytimoshin sergeytimoshin marked this pull request as ready for review January 5, 2025 20:11
Comment on lines 47 to 52
TreeType::BatchedState => {
info!("Processing state batch");
state::process_batch(&self.context).await
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to distinguish between an input(nullifier) queue batch being ready and an output queue batch being ready. The current implementation assumes that both are always ready at the same time which will fail in many cases.

}
}

async fn verify_batch_ready(&self) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't cover the output queue whichs batches are independent of input queue batches.

The input queue is part of the Merkle tree account since we usually need access to Merkle tree roots to prove inclusion (except if the account hash wasn't inserted into the tree yet then we need the output queue to proof inclusion by index in the value array).

The output queue is a separate account with separate batches. You can check whether an output queue batch is ready with the same logic used for trees the data structure is similar.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The address Merkle tree doesn't have an output queue hence the current implementation conceptually works for address trees as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks!

@sergeytimoshin sergeytimoshin force-pushed the sergey/foresters-batch-ops branch from a3c5f20 to 61346cb Compare January 6, 2025 15:58
forester/package.json Outdated Show resolved Hide resolved
Comment on lines 107 to 111
if self.verify_input_queue_batch_ready(&mut rpc).await {
BatchReadyState::ReadyForNullify
} else if self.verify_output_queue_batch_ready(&mut rpc).await {
BatchReadyState::ReadyForAppend
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two thoughts:

  1. what about switching this checking verify_output_queue_batch_ready with priority since I expect more output state creation than input state creation?
  2. There could be a case where the forester isn't fast enough and one queue is filled so fast that the forester neglects the other queue. Probably not the right time to focus on this right now but makes sense to keep this in mind.

Comment on lines 327 to 334
assert!(
merkle_tree
.get_metadata()
.queue_metadata
.next_full_batch_index
> 0,
"No batches were processed"
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert!(
merkle_tree
.get_metadata()
.queue_metadata
.next_full_batch_index
> 0,
"No batches were processed"
);
assert_eq!(
merkle_tree
.get_metadata()
.queue_metadata
.next_full_batch_index
,1,
"No batches were processed"
);

Comment on lines 336 to 352
assert!(
final_metadata.sequence_number > initial_sequence_number,
"Sequence number should have increased"
);

let post_root = merkle_tree.get_root().unwrap();
assert_ne!(pre_root, post_root, "Roots are the same");

assert_ne!(
pre_root,
merkle_tree.get_root().unwrap(),
"Root should have changed"
);
assert!(
merkle_tree.root_history.len() > 1,
"Root history should contain multiple roots"
);
Copy link
Contributor

@ananas-block ananas-block Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be better to assert exact numbers so that we can detect if the forester starts to behave differently.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we don't assert the root of the test indexer just that the root is not equal.
(The same for address tree asserts.)

@ananas-block ananas-block merged commit 9fc0542 into main Jan 9, 2025
20 checks passed
@ananas-block ananas-block deleted the sergey/foresters-batch-ops branch January 9, 2025 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants