Skip to content

Commit

Permalink
BFT-496: Change AttesterStatusClient to return AttesterStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh committed Aug 1, 2024
1 parent 9373b83 commit 7e6647d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
23 changes: 11 additions & 12 deletions node/actors/executor/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::Context;
use std::sync::Arc;
use zksync_concurrency::{ctx, sync, time};
use zksync_consensus_network::gossip::{
AttestationStatusReceiver, AttestationStatusWatch, BatchVotesPublisher,
AttestationStatus, AttestationStatusReceiver, AttestationStatusWatch, BatchVotesPublisher,
};
use zksync_consensus_roles::attester;
use zksync_consensus_storage::{BatchStore, BlockStore};
Expand Down Expand Up @@ -123,10 +123,7 @@ pub trait AttestationStatusClient: 'static + Send + Sync {
///
/// The genesis hash is returned along with the new batch number to facilitate detecting reorgs
/// on the main node as soon as possible and prevent inconsistent state from entering the system.
async fn attestation_status(
&self,
ctx: &ctx::Ctx,
) -> ctx::Result<Option<(attester::GenesisHash, attester::BatchNumber)>>;
async fn attestation_status(&self, ctx: &ctx::Ctx) -> ctx::Result<Option<AttestationStatus>>;
}

/// Use an [AttestationStatusClient] to periodically poll the main node and update the [AttestationStatusWatch].
Expand Down Expand Up @@ -200,8 +197,10 @@ impl AttestationStatusRunner {
async fn poll_until_some(&mut self, ctx: &ctx::Ctx) -> ctx::Result<()> {
loop {
match self.client.attestation_status(ctx).await {
Ok(Some((genesis, batch_number))) => {
self.status.update(genesis, batch_number).await?;
Ok(Some(status)) => {
self.status
.update(status.genesis, status.next_batch_to_attest)
.await?;
return Ok(());
}
Ok(None) => {
Expand Down Expand Up @@ -229,11 +228,11 @@ struct LocalAttestationStatusClient {

#[async_trait::async_trait]
impl AttestationStatusClient for LocalAttestationStatusClient {
async fn attestation_status(
&self,
ctx: &ctx::Ctx,
) -> ctx::Result<Option<(attester::GenesisHash, attester::BatchNumber)>> {
async fn attestation_status(&self, ctx: &ctx::Ctx) -> ctx::Result<Option<AttestationStatus>> {
let batch_number = self.batch_store.next_batch_to_attest(ctx).await?;
Ok(batch_number.map(|n| (self.genesis, n)))
Ok(batch_number.map(|n| AttestationStatus {
genesis: self.genesis,
next_batch_to_attest: n,
}))
}
}
16 changes: 10 additions & 6 deletions node/actors/executor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use rand::Rng as _;
use tracing::Instrument as _;
use zksync_concurrency::{sync, testonly::abort_on_panic};
use zksync_consensus_bft as bft;
use zksync_consensus_network::testonly::{new_configs, new_fullnode};
use zksync_consensus_network::{
gossip::AttestationStatus,
testonly::{new_configs, new_fullnode},
};
use zksync_consensus_roles::validator::{testonly::Setup, BlockNumber};
use zksync_consensus_storage::{
testonly::{in_memory, TestMemoryStorage},
Expand Down Expand Up @@ -342,7 +345,7 @@ async fn test_attestation_status_runner() {
async fn attestation_status(
&self,
_ctx: &ctx::Ctx,
) -> ctx::Result<Option<(attester::GenesisHash, attester::BatchNumber)>> {
) -> ctx::Result<Option<AttestationStatus>> {
let curr = self
.batch_number
.fetch_add(1u64, std::sync::atomic::Ordering::Relaxed);
Expand All @@ -351,10 +354,11 @@ async fn test_attestation_status_runner() {
Ok(None)
} else {
// The first actual result will be 1 on the 2nd poll.
Ok(Some((
*self.genesis.lock().unwrap(),
attester::BatchNumber(curr),
)))
let status = AttestationStatus {
genesis: *self.genesis.lock().unwrap(),
next_batch_to_attest: attester::BatchNumber(curr),
};
Ok(Some(status))
}
}
}
Expand Down

0 comments on commit 7e6647d

Please sign in to comment.