Skip to content

Commit

Permalink
feat: add flag to enable/disable DA inclusion verification (#2647)
Browse files Browse the repository at this point in the history
## What ❔

<!-- What are the changes this PR brings about? -->
<!-- Example: This PR adds a PR template to the repo. -->
<!-- (For bigger PRs adding more context is appreciated) -->

This PR adds a config to explicitly enable/disable DA verification
onchain.

## Why ❔

Without this feature, any chain using custom DA had to wait for full
inclusion before they could commit a batch even if they were not doing
the onchain verification.

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
  • Loading branch information
dimazhornyk authored Aug 27, 2024
1 parent 951d5f2 commit b425561
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
11 changes: 11 additions & 0 deletions core/lib/config/src/configs/da_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use serde::Deserialize;
pub const DEFAULT_POLLING_INTERVAL_MS: u32 = 5000;
pub const DEFAULT_MAX_ROWS_TO_DISPATCH: u32 = 100;
pub const DEFAULT_MAX_RETRIES: u16 = 5;
pub const DEFAULT_USE_DUMMY_INCLUSION_DATA: bool = false;

#[derive(Debug, Clone, PartialEq, Deserialize)]
pub struct DADispatcherConfig {
Expand All @@ -14,6 +15,10 @@ pub struct DADispatcherConfig {
pub max_rows_to_dispatch: Option<u32>,
/// The maximum number of retries for the dispatch of a blob.
pub max_retries: Option<u16>,
/// Use dummy value as inclusion proof instead of getting it from the client.
// TODO: run a verification task to check if the L1 contract expects the inclusion proofs to
// avoid the scenario where contracts expect real proofs, and server is using dummy proofs.
pub use_dummy_inclusion_data: Option<bool>,
}

impl DADispatcherConfig {
Expand All @@ -22,6 +27,7 @@ impl DADispatcherConfig {
polling_interval_ms: Some(DEFAULT_POLLING_INTERVAL_MS),
max_rows_to_dispatch: Some(DEFAULT_MAX_ROWS_TO_DISPATCH),
max_retries: Some(DEFAULT_MAX_RETRIES),
use_dummy_inclusion_data: Some(DEFAULT_USE_DUMMY_INCLUSION_DATA),
}
}

Expand All @@ -40,4 +46,9 @@ impl DADispatcherConfig {
pub fn max_retries(&self) -> u16 {
self.max_retries.unwrap_or(DEFAULT_MAX_RETRIES)
}

pub fn use_dummy_inclusion_data(&self) -> bool {
self.use_dummy_inclusion_data
.unwrap_or(DEFAULT_USE_DUMMY_INCLUSION_DATA)
}
}
1 change: 1 addition & 0 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@ impl Distribution<configs::da_dispatcher::DADispatcherConfig> for EncodeDist {
polling_interval_ms: self.sample(rng),
max_rows_to_dispatch: self.sample(rng),
max_retries: self.sample(rng),
use_dummy_inclusion_data: self.sample(rng),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions core/lib/env_config/src/da_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod tests {
polling_interval_ms: Some(interval),
max_rows_to_dispatch: Some(rows_limit),
max_retries: Some(max_retries),
use_dummy_inclusion_data: Some(true),
}
}

Expand All @@ -36,6 +37,7 @@ mod tests {
DA_DISPATCHER_POLLING_INTERVAL_MS=5000
DA_DISPATCHER_MAX_ROWS_TO_DISPATCH=60
DA_DISPATCHER_MAX_RETRIES=7
DA_DISPATCHER_USE_DUMMY_INCLUSION_DATA="true"
"#;
lock.set_env(config);
let actual = DADispatcherConfig::from_env().unwrap();
Expand Down
2 changes: 2 additions & 0 deletions core/lib/protobuf_config/src/da_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ impl ProtoRepr for proto::DataAvailabilityDispatcher {
polling_interval_ms: self.polling_interval_ms,
max_rows_to_dispatch: self.max_rows_to_dispatch,
max_retries: self.max_retries.map(|x| x as u16),
use_dummy_inclusion_data: self.use_dummy_inclusion_data,
})
}

Expand All @@ -19,6 +20,7 @@ impl ProtoRepr for proto::DataAvailabilityDispatcher {
polling_interval_ms: this.polling_interval_ms,
max_rows_to_dispatch: this.max_rows_to_dispatch,
max_retries: this.max_retries.map(Into::into),
use_dummy_inclusion_data: this.use_dummy_inclusion_data,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ syntax = "proto3";

package zksync.config.da_dispatcher;

import "zksync/config/object_store.proto";

message DataAvailabilityDispatcher {
optional uint32 polling_interval_ms = 1;
optional uint32 max_rows_to_dispatch = 2;
optional uint32 max_retries = 3;
optional bool use_dummy_inclusion_data = 4;
}
30 changes: 19 additions & 11 deletions core/node/da_dispatcher/src/da_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use chrono::Utc;
use rand::Rng;
use tokio::sync::watch::Receiver;
use zksync_config::DADispatcherConfig;
use zksync_da_client::{types::DAError, DataAvailabilityClient};
use zksync_da_client::{
types::{DAError, InclusionData},
DataAvailabilityClient,
};
use zksync_dal::{ConnectionPool, Core, CoreDal};
use zksync_types::L1BatchNumber;

Expand Down Expand Up @@ -133,16 +136,21 @@ impl DataAvailabilityDispatcher {
return Ok(());
};

let inclusion_data = self
.client
.get_inclusion_data(blob_info.blob_id.as_str())
.await
.with_context(|| {
format!(
"failed to get inclusion data for blob_id: {}, batch_number: {}",
blob_info.blob_id, blob_info.l1_batch_number
)
})?;
let inclusion_data = if self.config.use_dummy_inclusion_data() {
self.client
.get_inclusion_data(blob_info.blob_id.as_str())
.await
.with_context(|| {
format!(
"failed to get inclusion data for blob_id: {}, batch_number: {}",
blob_info.blob_id, blob_info.l1_batch_number
)
})?
} else {
// if the inclusion verification is disabled, we don't need to wait for the inclusion
// data before committing the batch, so simply return an empty vector
Some(InclusionData { data: vec![] })
};

let Some(inclusion_data) = inclusion_data else {
return Ok(());
Expand Down

0 comments on commit b425561

Please sign in to comment.