|
1 | | -use aligned_sdk::{ |
2 | | - common::{ |
3 | | - constants::CBOR_ARRAY_MAX_OVERHEAD, |
4 | | - types::{NoncedVerificationData, VerificationDataCommitment}, |
5 | | - }, |
6 | | - communication::serialization::cbor_serialize, |
| 1 | +use aligned_sdk::common::{ |
| 2 | + constants::CBOR_ARRAY_MAX_OVERHEAD, |
| 3 | + types::{NoncedVerificationData, VerificationDataCommitment}, |
7 | 4 | }; |
8 | 5 | use ethers::types::{Address, Signature, U256}; |
9 | 6 | use priority_queue::PriorityQueue; |
@@ -124,14 +121,9 @@ pub(crate) type BatchQueue = PriorityQueue<BatchQueueEntry, BatchQueueEntryPrior |
124 | 121 | /// Calculates the size of the batch represented by the given batch queue. |
125 | 122 | pub(crate) fn calculate_batch_size(batch_queue: &BatchQueue) -> Result<usize, BatcherError> { |
126 | 123 | let folded_result = batch_queue.iter().try_fold(0, |acc, (entry, _)| { |
127 | | - if let Ok(verification_data_bytes) = |
128 | | - cbor_serialize(&entry.nonced_verification_data.verification_data) |
129 | | - { |
130 | | - let current_batch_size = acc + verification_data_bytes.len(); |
131 | | - ControlFlow::Continue(current_batch_size) |
132 | | - } else { |
133 | | - ControlFlow::Break(()) |
134 | | - } |
| 124 | + let verification_data_size = entry.nonced_verification_data.cbor_size_upper_bound(); |
| 125 | + let current_batch_size = acc + verification_data_size; |
| 126 | + ControlFlow::<usize, usize>::Continue(current_batch_size) |
135 | 127 | }); |
136 | 128 |
|
137 | 129 | if let ControlFlow::Continue(batch_size) = folded_result { |
@@ -178,12 +170,7 @@ pub(crate) fn try_build_batch( |
178 | 170 | // * Subtract this entry size to the size of the batch size. |
179 | 171 | // * Push the current entry to the resulting batch queue. |
180 | 172 |
|
181 | | - // It is safe to call `.unwrap()` here since any serialization error should have been caught |
182 | | - // when calculating the total size of the batch with the `calculate_batch_size` function |
183 | | - let verification_data_size = |
184 | | - cbor_serialize(&entry.nonced_verification_data.verification_data) |
185 | | - .unwrap() |
186 | | - .len(); |
| 173 | + let verification_data_size = entry.nonced_verification_data.cbor_size_upper_bound(); |
187 | 174 | batch_size -= verification_data_size; |
188 | 175 |
|
189 | 176 | finalized_batch.pop(); |
|
0 commit comments