Skip to content

Commit e8ee2f8

Browse files
authored
fix(listener): fix batch request creation (#2367)
1 parent 949222e commit e8ee2f8

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

crates/chain-listener/src/listener.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/
1919

20-
use alloy_primitives::{Address, FixedBytes, Uint, U256, U64};
20+
use alloy_primitives::{Address, FixedBytes, Uint, U256};
2121
use alloy_sol_types::SolEvent;
2222
use backoff::Error::Permanent;
2323
use std::cmp::min;
@@ -1131,6 +1131,11 @@ impl ChainListener {
11311131
if let Some(ref ccp_client) = self.ccp_client {
11321132
let batch_requests = self.get_batch_request();
11331133

1134+
if batch_requests.is_empty() {
1135+
tracing::debug!(target: "chain-listener", "No compute units to poll proofs for. Probably all CUs have reached max proofs count");
1136+
return Ok(());
1137+
}
1138+
11341139
let proof_batches = if self.is_epoch_ending() {
11351140
let last_known_proofs = batch_requests
11361141
.into_iter()
@@ -1419,17 +1424,19 @@ impl ChainListener {
14191424
let mut batch_request = HashMap::new();
14201425
for cu_id in self.cc_compute_units.keys() {
14211426
let sent_proofs_count = self.proof_tracker.get_proof_counter(cu_id);
1422-
let proofs_needed = U64::from(
1423-
self.max_proofs_per_epoch
1424-
.checked_add(-sent_proofs_count)
1425-
.unwrap_or(Uint::ZERO),
1426-
)
1427-
.as_limbs()[0] as usize;
1427+
let proofs_needed = self
1428+
.max_proofs_per_epoch
1429+
.checked_sub(sent_proofs_count)
1430+
.unwrap_or(Uint::ZERO)
1431+
.as_limbs()[0];
14281432

14291433
if proofs_needed > 0 {
14301434
let request = BatchRequest {
14311435
last_seen_proof_idx: self.proof_tracker.get_last_submitted_proof_id(cu_id),
1432-
proof_batch_size: min(proofs_needed, self.listener_config.max_proof_batch_size),
1436+
proof_batch_size: min(
1437+
proofs_needed as usize,
1438+
self.listener_config.max_proof_batch_size,
1439+
),
14331440
};
14341441

14351442
batch_request.insert(*cu_id, request);

0 commit comments

Comments
 (0)