Skip to content
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

fix(listener): fix batch request creation #2367

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions crates/chain-listener/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

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

if batch_requests.is_empty() {
tracing::debug!(target: "chain-listener", "No compute units to poll proofs for. Probably all CUs have reached max proofs count");
return Ok(());
}

let proof_batches = if self.is_epoch_ending() {
let last_known_proofs = batch_requests
.into_iter()
Expand Down Expand Up @@ -1419,17 +1424,19 @@ impl ChainListener {
let mut batch_request = HashMap::new();
for cu_id in self.cc_compute_units.keys() {
let sent_proofs_count = self.proof_tracker.get_proof_counter(cu_id);
let proofs_needed = U64::from(
self.max_proofs_per_epoch
.checked_add(-sent_proofs_count)
.unwrap_or(Uint::ZERO),
)
.as_limbs()[0] as usize;
let proofs_needed = self
.max_proofs_per_epoch
.checked_sub(sent_proofs_count)
.unwrap_or(Uint::ZERO)
.as_limbs()[0];

if proofs_needed > 0 {
let request = BatchRequest {
last_seen_proof_idx: self.proof_tracker.get_last_submitted_proof_id(cu_id),
proof_batch_size: min(proofs_needed, self.listener_config.max_proof_batch_size),
proof_batch_size: min(
proofs_needed as usize,
self.listener_config.max_proof_batch_size,
),
};

batch_request.insert(*cu_id, request);
Expand Down
Loading