Skip to content

Commit 27f46a9

Browse files
committed
Add try_push mock
1 parent 9bc03de commit 27f46a9

2 files changed

Lines changed: 30 additions & 18 deletions

File tree

batcher/aligned-batcher/src/lib.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use aligned_sdk::communication::serialization::{cbor_deserialize, cbor_serialize};
2+
use aws_sdk_s3::operation::list_bucket_intelligent_tiering_configurations::builders::ListBucketIntelligentTieringConfigurationsFluentBuilder;
23
use config::NonPayingConfig;
34
use connection::{send_message, WsMessageSink};
45
use dotenvy::dotenv;
@@ -16,7 +17,7 @@ use tokio::time::{timeout, Instant};
1617
use types::batch_state::BatchState;
1718
use types::user_state::UserState;
1819

19-
use batch_queue::calculate_batch_size;
20+
use batch_queue::{calculate_batch_size, try_push_to_queue};
2021
use std::collections::HashMap;
2122
use std::env;
2223
use std::net::SocketAddr;
@@ -1047,23 +1048,10 @@ impl Batcher {
10471048
let verification_data_comm = verification_data.clone().into();
10481049
info!("Adding verification data to batch...");
10491050

1050-
let mut queue_len = batch_state_lock.batch_queue.len();
1051-
let mut queue_size_bytes = calculate_batch_size(&batch_state_lock.batch_queue)?;
1052-
1053-
if let Ok(verification_data_bytes) =
1054-
cbor_serialize(&verification_data.verification_data)
1055-
{
1056-
if queue_len + 1 > self.max_batch_proof_qty ||
1057-
queue_size_bytes + verification_data_bytes.len() + CBOR_ARRAY_MAX_OVERHEAD > self.max_batch_byte_size
1058-
{
1059-
// do something
1060-
}
1061-
}
1062-
1063-
10641051
let max_fee = verification_data.max_fee;
10651052
let nonce = verification_data.nonce;
1066-
batch_state_lock.batch_queue.push(
1053+
try_push_to_queue(
1054+
&mut batch_state_lock.batch_queue,
10671055
BatchQueueEntry::new(
10681056
verification_data,
10691057
verification_data_comm,
@@ -1072,11 +1060,14 @@ impl Batcher {
10721060
proof_submitter_addr,
10731061
),
10741062
BatchQueueEntryPriority::new(max_fee, nonce),
1063+
self.max_batch_byte_size,
1064+
self.max_batch_proof_qty,
10751065
);
10761066

10771067
// Update metrics
1078-
queue_len = batch_state_lock.batch_queue.len();
1079-
queue_size_bytes = calculate_batch_size(&batch_state_lock.batch_queue)?;
1068+
let queue_len = batch_state_lock.batch_queue.len();
1069+
let queue_size_bytes = calculate_batch_size(&batch_state_lock.batch_queue)?;
1070+
10801071
self.metrics
10811072
.update_queue_metrics(queue_len as i64, queue_size_bytes as i64);
10821073

batcher/aligned-batcher/src/types/batch_queue.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,27 @@ fn calculate_fee_per_proof(batch_len: usize, gas_price: U256, constant_gas_cost:
212212
U256::from(gas_per_proof) * gas_price
213213
}
214214

215+
pub(crate) fn try_push_to_queue(
216+
batch_queue: &mut BatchQueue,
217+
item: BatchQueueEntry,
218+
priority: BatchQueueEntryPriority,
219+
max_batch_byte_size: usize,
220+
max_batch_proof_qty: usize,
221+
) -> Result<(), ()> {
222+
// if let Ok(verification_data_bytes) =
223+
// cbor_serialize(&verification_data.verification_data)
224+
// {
225+
// if queue_len + 1 > self.max_batch_proof_qty ||
226+
// queue_size_bytes + verification_data_bytes.len() + CBOR_ARRAY_MAX_OVERHEAD > self.max_batch_byte_size
227+
// {
228+
// let mut lowest_fee;
229+
230+
// }
231+
// }
232+
233+
batch_queue.push(item, priority);
234+
Ok(())
235+
}
215236
#[cfg(test)]
216237
mod test {
217238
use aligned_sdk::core::constants::DEFAULT_CONSTANT_GAS_COST;

0 commit comments

Comments
 (0)