Skip to content

Commit

Permalink
BFT-474: Add min_batch_number
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh committed Jul 5, 2024
1 parent c90c71d commit ea6e227
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion node/actors/executor/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use anyhow::Context;
use zksync_concurrency::ctx;
use zksync_concurrency::time;
use zksync_consensus_network::gossip::BatchVotesPublisher;
use zksync_consensus_roles::attester::BatchNumber;
use zksync_consensus_storage::{BatchStore, BlockStore};

use crate::Attester;
Expand Down Expand Up @@ -38,6 +39,9 @@ impl AttesterRunner {
/// Poll the database for new L1 batches and publish our signature over the batch.
pub(super) async fn run(self, ctx: &ctx::Ctx) -> ctx::Result<()> {
let public_key = self.attester.key.public();
// The first batch number we want to publish our vote for. We don't have to re-publish a vote
// because once it enters the vote register even future peers can pull it from there.
let mut min_batch_number = BatchNumber(0);
loop {
// Pretend that the attesters can evolve.
let Some(attesters) = self.block_store.genesis().attesters.as_ref() else {
Expand All @@ -47,19 +51,31 @@ impl AttesterRunner {
continue;
}

let unsigned_batch_numbers = self
let mut unsigned_batch_numbers = self
.batch_store
.unsigned_batch_numbers(ctx)
.await
.context("unsigned_batch_numbers")?;

// Just to be sure we go from smaller to higher batches.
unsigned_batch_numbers.sort();

for bn in unsigned_batch_numbers {
// If we have already voted on this we can move on, no need to fetch the payload again.
// Batches appear in the store in order, even if we might have QC for a newer and not for an older batch,
// so once published our vote for a certain height, we can expect that we only have to vote on newer batches.
if bn < min_batch_number {
continue;
}

if let Some(batch) = self
.batch_store
.batch_to_sign(ctx, bn)
.await
.context("batch_to_sign")?
{
min_batch_number = batch.number.next();

self.publisher
.publish(attesters, &self.attester.key, batch)
.await
Expand Down

0 comments on commit ea6e227

Please sign in to comment.