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

feat: add flag to enable/disable DA inclusion verification #2647

Merged
merged 7 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
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>,
/// Enable on-chain verification of the data availability.
// TODO: run a verification task to check if the L1 contract expects the inclusion proofs.
// Maybe even remove this value and use the L1 as a source of truth.
pub use_dummy_inclusion_data: Option<bool>,
dimazhornyk marked this conversation as resolved.
Show resolved Hide resolved
}

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 @@ -924,6 +924,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
Loading