Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 401
refactor: remove_proofs_from_queue called after submit is OK#1507
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
Closed
uri-99
wants to merge
11
commits into
staging
from
1505-refactor-batcher-shouldnt-remove-submitted-proofs-from-queue-until-they-are-accepted-on-chain
Uh oh!
There was an error while loading. Please reload this page.
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a2cd9bc
refactor: remove_proofs_from_queue called after submit is OK
uri-99 3ff65a5
chore: fmt and clippy
uri-99 ceb3d38
chore: comment for better understanding the .remove
uri-99 c5f7cfb
fix: clippy impl error, len >0 is !empty
uri-99 153f615
Update batcher/aligned-batcher/src/lib.rs
uri-99 fde4824
Update batcher/aligned-batcher/src/lib.rs
uri-99 241f629
feat: add error log
avilagaston9 30c18c4
refactor: better removing of items
uri-99 b928c7b
Update batcher/aligned-batcher/src/lib.rs
uri-99 db3e048
Update batcher/aligned-batcher/src/lib.rs
uri-99 36dda1d
Update batcher/aligned-batcher/src/lib.rs
uri-99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1115,12 +1115,13 @@ impl Batcher { | ||
| /// an empty batch, even if the block interval has been reached. | ||
| /// Once the batch meets the conditions for submission, the finalized batch is then passed to the | ||
| /// `finalize_batch` function. | ||
| /// This function doesn't remove the proofs from the queue. | ||
| async fn is_batch_ready( | ||
| &self, | ||
| block_number: u64, | ||
| gas_price: U256, | ||
| ) -> Option<Vec<BatchQueueEntry>> { | ||
| let mut batch_state_lock = self.batch_state.lock().await; | ||
| let batch_state_lock = self.batch_state.lock().await; | ||
| let current_batch_len = batch_state_lock.batch_queue.len(); | ||
| let last_uploaded_batch_block_lock = self.last_uploaded_batch_block.lock().await; | ||
| @@ -1152,7 +1153,7 @@ impl Batcher { | ||
| // Set the batch posting flag to true | ||
| *batch_posting = true; | ||
| let batch_queue_copy = batch_state_lock.batch_queue.clone(); | ||
| let (resulting_batch_queue, finalized_batch) = batch_queue::try_build_batch( | ||
| let finalized_batch = batch_queue::try_build_batch( | ||
| batch_queue_copy, | ||
| gas_price, | ||
| self.max_batch_byte_size, | ||
| @@ -1172,7 +1173,26 @@ impl Batcher { | ||
| }) | ||
| .ok()?; | ||
| batch_state_lock.batch_queue = resulting_batch_queue; | ||
| Some(finalized_batch) | ||
| } | ||
| /// Takes the submitted proofs and removes them from the queue. | ||
| /// This function should be called only AFTER the submission was confirmed onchain | ||
| async fn remove_proofs_from_queue( | ||
| &self, | ||
| finalized_batch: Vec<BatchQueueEntry>, | ||
| ) -> Result<(), BatcherError> { | ||
| info!("Removing proofs from queue..."); | ||
| let mut batch_state_lock = self.batch_state.lock().await; | ||
| finalized_batch.iter().for_each(|entry| { | ||
| if batch_state_lock.batch_queue.remove(entry).is_none() { | ||
| // If this happens, we have a bug in our code | ||
| error!("Some proofs were not found in the queue. This should not happen."); | ||
| } | ||
| }); | ||
| // now we calculate the new user_states | ||
| let new_user_states = // proofs, max_fee_limit, total_fees_in_queue | ||
| batch_state_lock.calculate_new_user_states_data(); | ||
| @@ -1188,17 +1208,33 @@ impl Batcher { | ||
| // informative error. | ||
| // Now we update the user states related to the batch (proof count in batch and min fee in batch) | ||
| batch_state_lock.update_user_proof_count(addr, *proof_count)?; | ||
| batch_state_lock.update_user_max_fee_limit(addr, *max_fee_limit)?; | ||
| batch_state_lock.update_user_total_fees_in_queue(addr, *total_fees_in_queue)?; | ||
| batch_state_lock | ||
| .update_user_proof_count(addr, *proof_count) | ||
| .ok_or(BatcherError::QueueRemoveError( | ||
| "Could not update_user_proof_count".into(), | ||
| ))?; | ||
| batch_state_lock | ||
| .update_user_max_fee_limit(addr, *max_fee_limit) | ||
| .ok_or(BatcherError::QueueRemoveError( | ||
| "Could not update_user_max_fee_limit".into(), | ||
| ))?; | ||
| batch_state_lock | ||
| .update_user_total_fees_in_queue(addr, *total_fees_in_queue) | ||
| .ok_or(BatcherError::QueueRemoveError( | ||
| "Could not update_user_total_fees_in_queue".into(), | ||
| ))?; | ||
| } | ||
| Some(finalized_batch) | ||
| Ok(()) | ||
| } | ||
| /// Takes the finalized batch as input and builds the merkle tree, posts verification data batch | ||
| /// to s3, creates new task in Aligned contract and sends responses to all clients that added proofs | ||
| /// to the batch. The last uploaded batch block is updated once the task is created in Aligned. | ||
| /// Takes the finalized batch as input and: | ||
| /// builds the merkle tree | ||
| /// posts verification data batch to s3 | ||
| /// creates new task in Aligned contract | ||
| /// removes the proofs from the queue, once they are succesfully submitted on-chain | ||
| /// sends responses to all clients that added proofs to the batch. | ||
| /// The last uploaded batch block is updated once the task is created in Aligned. | ||
| async fn finalize_batch( | ||
| &self, | ||
| block_number: u64, | ||
| @@ -1256,6 +1292,7 @@ impl Batcher { | ||
| warn!("Failed to initialize task trace on telemetry: {:?}", e); | ||
| } | ||
| // Here we submit the batch on-chain | ||
| if let Err(e) = self | ||
| .submit_batch( | ||
| &batch_bytes, | ||
| @@ -1295,6 +1332,12 @@ impl Batcher { | ||
| return Err(e); | ||
uri-99 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }; | ||
| // Once the submit is succesfull, we remove the submitted proofs from the queue | ||
| // TODO handle error case: | ||
| if let Err(e) = self.remove_proofs_from_queue(finalized_batch.clone()).await { | ||
| error!("Unexpected error while updating queue: {:?}", e); | ||
| } | ||
| connection::send_batch_inclusion_data_responses(finalized_batch, &batch_merkle_tree).await | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this process leave a consistent state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1520