Skip to content

Commit

Permalink
fix(chain-listener): reset proof counters on new epoch in refresh [NE…
Browse files Browse the repository at this point in the history
  • Loading branch information
justprosh authored May 14, 2024
1 parent 15a803a commit da8f4c7
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions crates/chain-listener/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,17 @@ impl ChainListener {
err
})?;

tracing::info!(target: "chain-listener","Commitment initial params: difficulty {}, global nonce {}, init_timestamp {}, epoch_duration {}, current_epoch {}, min_proofs_per_epoch {}, max_proofs_per_epoch {}", init_params.difficulty, init_params.global_nonce, init_params.init_timestamp, init_params.epoch_duration, init_params.current_epoch, init_params.min_proofs_per_epoch, init_params.max_proofs_per_epoch);

self.difficulty = init_params.difficulty;
self.init_timestamp = init_params.init_timestamp;
self.global_nonce = init_params.global_nonce;
self.epoch_duration = init_params.epoch_duration;
self.current_epoch = init_params.current_epoch;
self.min_proofs_per_epoch = init_params.min_proofs_per_epoch;
self.max_proofs_per_epoch = init_params.max_proofs_per_epoch;

tracing::info!(target: "chain-listener","Commitment initial params: difficulty {}, global nonce {}, init_timestamp {}, epoch_duration {}, current_epoch {}, min_proofs_per_epoch {}, max_proofs_per_epoch {}", init_params.difficulty, init_params.global_nonce, init_params.init_timestamp, init_params.epoch_duration, init_params.current_epoch, init_params.min_proofs_per_epoch, init_params.max_proofs_per_epoch);
self.set_current_epoch(init_params.current_epoch);

Ok(())
}

Expand Down Expand Up @@ -359,6 +361,7 @@ impl ChainListener {
}

async fn reset_proof_id(&mut self) -> eyre::Result<()> {
tracing::info!(target: "chain-listener", "Resetting proof id counter");
self.set_proof_id(ProofIdx::zero()).await
}

Expand Down Expand Up @@ -657,7 +660,6 @@ impl ChainListener {

if epoch_changed {
// TODO: add epoch_number to metrics
tracing::info!(target: "chain-listener", "Epoch changed, new epoch number: {epoch_number}");

// nonce changes every epoch
self.global_nonce = self.chain_connector.get_global_nonce().await?;
Expand All @@ -666,10 +668,8 @@ impl ChainListener {
self.global_nonce
);

self.current_epoch = epoch_number;
tracing::info!(target: "chain-listener", "Resetting proof id counter");
self.set_current_epoch(epoch_number);
self.reset_proof_id().await?;
self.proof_counter.clear();

if let Some(status) = self.get_commitment_status().await? {
tracing::info!(target: "chain-listener", "Current commitment status: {status:?}");
Expand Down Expand Up @@ -1321,6 +1321,14 @@ impl ChainListener {
Ok(())
}

fn set_current_epoch(&mut self, epoch_number: U256) {
if self.current_epoch != epoch_number {
tracing::info!(target: "chain-listener", "Epoch changed, was {}, new epoch number is {epoch_number}", self.current_epoch);
self.current_epoch = epoch_number;
self.proof_counter.clear();
}
}

fn observe<F>(&self, f: F)
where
F: FnOnce(&ChainListenerMetrics),
Expand Down

0 comments on commit da8f4c7

Please sign in to comment.