Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 401
fix: flush batcher queue only when needed#1512
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
Merged
JuArce
merged 26 commits into
staging
from
1510-fix-flush-batcher-queue-only-when-neededNov 29, 2024
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
5136bf3
Parse error codes from ethereum contract on createNewTask
dbf168c
Remove wrong comment
4c4aa4d
remove comments
avilagaston9 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 5801b51
chore: better comments on flush-or-not
uri-99 241f629
feat: add error log
avilagaston9 30c18c4
refactor: better removing of items
uri-99 34c5980
feat: only flush in defined cases
uri-99 f9cf53a
Merge branch 'staging' into 1510-fix-flush-batcher-queue-only-when-ne…
uri-99 e775ddc
Merge branch '1505-refactor-batcher-shouldnt-remove-submitted-proofs-…
MarcosNicolau 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 24ed6f8
Merge branch '1505-refactor-batcher-shouldnt-remove-submitted-proofs-…
uri-99 8561c94
Merge branch 'staging' into 1510-fix-flush-batcher-queue-only-when-ne…
b65b9f8
refactor: rename func to send_task_creation_error_messages
uri-99 23b290b
remove: flush in generic error
uri-99 6093de6
remove: send message when flushing queue, as flush queue already send…
uri-99 fbed8b7
Merge branch 'staging' into 1510-fix-flush-batcher-queue-only-when-ne…
uri-99 afa517d
chore: fmt
MarcosNicolau b019a36
test: assert that batche_queue len remains the same
MarcosNicolau 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
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 |
|---|---|---|
| @@ -134,27 +134,25 @@ pub(crate) fn calculate_batch_size(batch_queue: &BatchQueue) -> Result<usize, Ba | ||
| } | ||
| /// This function tries to build a batch to be submitted to Aligned. | ||
| /// Given a copy of the current batch queue, , and applyies an algorithm to find the biggest batch | ||
| /// Given the current batch queue applies the following algorithm to find the biggest batch | ||
| /// of proofs from users that are willing to pay for it: | ||
| /// 1. Traverse each batch priority queue, starting from the one with minimum max fee. | ||
| /// 2. Calculate the `fee_per_proof` for the whole batch and compare with the `max_fee` of the entry. | ||
| /// 3. If `fee_per_proof` is less than the `max_fee` of the current entry, submit the batch. If not, pop this entry | ||
| /// from the queue and push it to `resulting_priority_queue`, then repeat step 1. | ||
| /// from the queue. then repeat step 1. | ||
| /// | ||
| /// `resulting_priority_queue` will be the batch queue composed of all entries that were not willing to pay for the batch. | ||
| /// This is outputted in along with the finalized batch. | ||
| /// Returns the finalized batch. | ||
| pub(crate) fn try_build_batch( | ||
| batch_queue: BatchQueue, | ||
| gas_price: U256, | ||
| max_batch_byte_size: usize, | ||
| max_batch_proof_qty: usize, | ||
| ) -> Result<(BatchQueue, Vec<BatchQueueEntry>), BatcherError> { | ||
| let mut batch_queue = batch_queue; | ||
| let mut batch_size = calculate_batch_size(&batch_queue)?; | ||
| let mut resulting_priority_queue = BatchQueue::new(); | ||
| ) -> Result<Vec<BatchQueueEntry>, BatcherError> { | ||
| let mut finalized_batch = batch_queue; | ||
| let mut batch_size = calculate_batch_size(&finalized_batch)?; | ||
| while let Some((entry, _)) = batch_queue.peek() { | ||
| let batch_len = batch_queue.len(); | ||
| while let Some((entry, _)) = finalized_batch.peek() { | ||
| let batch_len = finalized_batch.len(); | ||
| let fee_per_proof = calculate_fee_per_proof(batch_len, gas_price); | ||
| if batch_size > max_batch_byte_size | ||
| @@ -173,8 +171,7 @@ pub(crate) fn try_build_batch( | ||
| .len(); | ||
| batch_size -= verification_data_size; | ||
| let (not_working_entry, not_working_priority) = batch_queue.pop().unwrap(); | ||
| resulting_priority_queue.push(not_working_entry, not_working_priority); | ||
| finalized_batch.pop(); | ||
| continue; | ||
| } | ||
| @@ -183,16 +180,13 @@ pub(crate) fn try_build_batch( | ||
| break; | ||
| } | ||
| // If `batch_queue_copy` is empty, this means that all the batch queue was traversed and we didn't find | ||
| // If `finalized_batch` is empty, this means that all the batch queue was traversed and we didn't find | ||
| // any user willing to pay fot the fee per proof. | ||
| if batch_queue.is_empty() { | ||
| if finalized_batch.is_empty() { | ||
| return Err(BatcherError::BatchCostTooHigh); | ||
| } | ||
| Ok(( | ||
| resulting_priority_queue, | ||
| batch_queue.clone().into_sorted_vec(), | ||
| )) | ||
| Ok(finalized_batch.clone().into_sorted_vec()) | ||
| } | ||
| fn calculate_fee_per_proof(batch_len: usize, gas_price: U256) -> U256 { | ||
| @@ -301,14 +295,20 @@ mod test { | ||
| batch_queue.push(entry_3, batch_priority_3); | ||
| let gas_price = U256::from(1); | ||
| let (resulting_batch_queue, batch) = | ||
| try_build_batch(batch_queue, gas_price, 5000000, 50).unwrap(); | ||
| let finalized_batch = try_build_batch(batch_queue, gas_price, 5000000, 50).unwrap(); | ||
| assert!(resulting_batch_queue.is_empty()); | ||
| assert_eq!(batch[0].nonced_verification_data.max_fee, max_fee_3); | ||
| assert_eq!(batch[1].nonced_verification_data.max_fee, max_fee_2); | ||
| assert_eq!(batch[2].nonced_verification_data.max_fee, max_fee_1); | ||
| assert_eq!( | ||
| finalized_batch[0].nonced_verification_data.max_fee, | ||
| max_fee_3 | ||
| ); | ||
| assert_eq!( | ||
| finalized_batch[1].nonced_verification_data.max_fee, | ||
| max_fee_2 | ||
| ); | ||
| assert_eq!( | ||
| finalized_batch[2].nonced_verification_data.max_fee, | ||
| max_fee_1 | ||
| ); | ||
| } | ||
| #[test] | ||
| @@ -404,13 +404,11 @@ mod test { | ||
| batch_queue.push(entry_3, batch_priority_3); | ||
| let gas_price = U256::from(1); | ||
| let (resulting_batch_queue, finalized_batch) = | ||
| try_build_batch(batch_queue, gas_price, 5000000, 50).unwrap(); | ||
| let finalized_batch = try_build_batch(batch_queue.clone(), gas_price, 5000000, 50).unwrap(); | ||
| // The resulting batch queue (entries from the old batch queue that were not willing to pay | ||
| // in this batch), should be empty and hence, all entries from the batch queue should be in | ||
| // All entries from the batch queue should be in | ||
| // the finalized batch. | ||
| assert!(resulting_batch_queue.is_empty()); | ||
| assert_eq!(batch_queue.len(), 3); | ||
| assert_eq!(finalized_batch.len(), 3); | ||
| assert_eq!( | ||
| finalized_batch[0].nonced_verification_data.max_fee, | ||
| @@ -515,14 +513,10 @@ mod test { | ||
| batch_queue.push(entry_3, batch_priority_3); | ||
| let gas_price = U256::from(1); | ||
| let (resulting_batch_queue, finalized_batch) = | ||
| try_build_batch(batch_queue, gas_price, 5000000, 50).unwrap(); | ||
| // The resulting batch queue (entries from the old batch queue that were not willing to pay | ||
| // in this batch), should be empty and hence, all entries from the batch queue should be in | ||
| // the finalized batch. | ||
| let finalized_batch = try_build_batch(batch_queue.clone(), gas_price, 5000000, 50).unwrap(); | ||
| assert_eq!(resulting_batch_queue.len(), 1); | ||
| // All but one entries from the batch queue should be in the finalized batch. | ||
| assert_eq!(batch_queue.len(), 3); | ||
| assert_eq!(finalized_batch.len(), 2); | ||
| assert_eq!( | ||
| finalized_batch[0].nonced_verification_data.max_fee, | ||
| @@ -628,10 +622,10 @@ mod test { | ||
| // The max batch len is 2, so the algorithm should stop at the second entry. | ||
| let max_batch_proof_qty = 2; | ||
| let (resulting_batch_queue, finalized_batch) = | ||
| try_build_batch(batch_queue, gas_price, 5000000, max_batch_proof_qty).unwrap(); | ||
| let finalized_batch = | ||
| try_build_batch(batch_queue.clone(), gas_price, 5000000, max_batch_proof_qty).unwrap(); | ||
| assert_eq!(resulting_batch_queue.len(), 1); | ||
MarcosNicolau marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| assert_eq!(batch_queue.len(), 3); | ||
| assert_eq!(finalized_batch.len(), 2); | ||
| assert_eq!( | ||
| finalized_batch[0].nonced_verification_data.max_fee, | ||
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.
Uh oh!
There was an error while loading. Please reload this page.