Skip to content

Commit f09087b

Browse files
authored
feat: pubdata type changes from sync-layer-stable (#3425)
## What ❔ Changes to PubdataType from sync-layer-stable: Validium variant is removed and specific DAs are added. This change is breaking but - for DB only `Rollup` is used for pre-gateway and this variant wasn't changed - for consensus protobuf `pubdata_params` is null for pre-gateway so it should be good. Changes to allow reading system bytecodes from L2 upgrade tx factory deps. Fix `metadata[3]` in eth watcher processor. ## Why ❔ Reduce sync-layer-stable diff ## 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 `zkstack dev fmt` and `zkstack dev lint`.
1 parent 3037ee6 commit f09087b

File tree

26 files changed

+344
-240
lines changed

26 files changed

+344
-240
lines changed

core/bin/zksync_server/src/node_builder.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ use zksync_node_framework::{
7272
service::{ZkStackService, ZkStackServiceBuilder},
7373
};
7474
use zksync_types::{
75-
pubdata_da::PubdataSendingMode, settlement::SettlementMode, SHARED_BRIDGE_ETHER_TOKEN_ADDRESS,
75+
commitment::{L1BatchCommitmentMode, PubdataType},
76+
pubdata_da::PubdataSendingMode,
77+
settlement::SettlementMode,
78+
SHARED_BRIDGE_ETHER_TOKEN_ADDRESS,
7679
};
7780
use zksync_vlog::prometheus::PrometheusExporterConfig;
7881

@@ -118,6 +121,24 @@ impl MainNodeBuilder {
118121
self.node.runtime_handle()
119122
}
120123

124+
pub fn get_pubdata_type(&self) -> PubdataType {
125+
if self.genesis_config.l1_batch_commit_data_generator_mode == L1BatchCommitmentMode::Rollup
126+
{
127+
return PubdataType::Rollup;
128+
}
129+
130+
let Some(da_client_config) = self.configs.da_client_config.clone() else {
131+
return PubdataType::NoDA;
132+
};
133+
134+
match da_client_config {
135+
DAClientConfig::Avail(_) => PubdataType::Avail,
136+
DAClientConfig::Celestia(_) => PubdataType::Celestia,
137+
DAClientConfig::Eigen(_) => PubdataType::Eigen,
138+
DAClientConfig::ObjectStore(_) => PubdataType::ObjectStore,
139+
}
140+
}
141+
121142
fn add_sigint_handler_layer(mut self) -> anyhow::Result<Self> {
122143
self.node.add_layer(SigintHandlerLayer);
123144
Ok(self)
@@ -252,7 +273,7 @@ impl MainNodeBuilder {
252273
try_load_config!(self.configs.mempool_config),
253274
try_load_config!(wallets.state_keeper),
254275
self.contracts_config.l2_da_validator_addr,
255-
self.genesis_config.l1_batch_commit_data_generator_mode,
276+
self.get_pubdata_type(),
256277
);
257278
let db_config = try_load_config!(self.configs.db_config);
258279
let experimental_vm_config = self

core/lib/basic_types/src/commitment.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,35 @@ impl FromStr for L1BatchCommitmentMode {
5858
}
5959
}
6060

61+
#[derive(Default, Copy, Debug, Clone, PartialEq, Serialize, Deserialize, Display)]
62+
pub enum PubdataType {
63+
#[default]
64+
Rollup,
65+
NoDA,
66+
Avail,
67+
Celestia,
68+
Eigen,
69+
ObjectStore,
70+
}
71+
72+
impl FromStr for PubdataType {
73+
type Err = &'static str;
74+
75+
fn from_str(s: &str) -> Result<Self, Self::Err> {
76+
match s {
77+
"Rollup" => Ok(Self::Rollup),
78+
"NoDA" => Ok(Self::NoDA),
79+
"Avail" => Ok(Self::Avail),
80+
"Celestia" => Ok(Self::Celestia),
81+
"Eigen" => Ok(Self::Eigen),
82+
"ObjectStore" => Ok(Self::ObjectStore),
83+
_ => Err("Incorrect DA client type; expected one of `Rollup`, `NoDA`, `Avail`, `Celestia`, `Eigen`, `ObjectStore`"),
84+
}
85+
}
86+
}
87+
6188
#[derive(Default, Copy, Debug, Clone, PartialEq, Serialize, Deserialize)]
6289
pub struct PubdataParams {
6390
pub l2_da_validator_address: Address,
64-
pub pubdata_type: L1BatchCommitmentMode,
91+
pub pubdata_type: PubdataType,
6592
}

core/lib/dal/src/consensus/conv.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use zksync_consensus_roles::{attester, node};
55
use zksync_protobuf::{read_optional_repr, read_required, required, ProtoFmt, ProtoRepr};
66
use zksync_types::{
77
abi,
8-
commitment::{L1BatchCommitmentMode, PubdataParams},
8+
commitment::{PubdataParams, PubdataType},
99
ethabi,
1010
fee::Fee,
1111
h256_to_u256,
@@ -112,8 +112,8 @@ impl ProtoRepr for proto::PubdataParams {
112112
l2_da_validator_address: required(&self.l2_da_validator_address)
113113
.and_then(|a| parse_h160(a))
114114
.context("l2_da_validator_address")?,
115-
pubdata_type: required(&self.pubdata_type)
116-
.and_then(|x| Ok(proto::L1BatchCommitDataGeneratorMode::try_from(*x)?))
115+
pubdata_type: required(&self.pubdata_info)
116+
.and_then(|x| Ok(proto::PubdataType::try_from(*x)?))
117117
.context("pubdata_type")?
118118
.parse(),
119119
})
@@ -122,9 +122,7 @@ impl ProtoRepr for proto::PubdataParams {
122122
fn build(this: &Self::Type) -> Self {
123123
Self {
124124
l2_da_validator_address: Some(this.l2_da_validator_address.as_bytes().into()),
125-
pubdata_type: Some(
126-
proto::L1BatchCommitDataGeneratorMode::new(&this.pubdata_type) as i32,
127-
),
125+
pubdata_info: Some(this.pubdata_type as i32),
128126
}
129127
}
130128
}
@@ -572,18 +570,15 @@ impl ProtoRepr for proto::AttesterCommittee {
572570
}
573571
}
574572

575-
impl proto::L1BatchCommitDataGeneratorMode {
576-
pub(crate) fn new(n: &L1BatchCommitmentMode) -> Self {
577-
match n {
578-
L1BatchCommitmentMode::Rollup => Self::Rollup,
579-
L1BatchCommitmentMode::Validium => Self::Validium,
580-
}
581-
}
582-
583-
pub(crate) fn parse(&self) -> L1BatchCommitmentMode {
573+
impl proto::PubdataType {
574+
pub(crate) fn parse(&self) -> PubdataType {
584575
match self {
585-
Self::Rollup => L1BatchCommitmentMode::Rollup,
586-
Self::Validium => L1BatchCommitmentMode::Validium,
576+
Self::Rollup => PubdataType::Rollup,
577+
Self::NoDa => PubdataType::NoDA,
578+
Self::Avail => PubdataType::Avail,
579+
Self::Celestia => PubdataType::Celestia,
580+
Self::Eigen => PubdataType::Eigen,
581+
Self::ObjectStore => PubdataType::ObjectStore,
587582
}
588583
}
589584
}

core/lib/dal/src/consensus/proto/mod.proto

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ message Payload {
3131

3232
message PubdataParams {
3333
optional bytes l2_da_validator_address = 1; // required; H160
34-
optional L1BatchCommitDataGeneratorMode pubdata_type = 2; // required
34+
optional PubdataType pubdata_info = 3; // required
35+
reserved 2; reserved "pubdata_type";
3536
}
3637

3738
message L1Transaction {
@@ -149,7 +150,11 @@ message AttestationStatus {
149150
optional uint64 next_batch_to_attest = 2; // required
150151
}
151152

152-
enum L1BatchCommitDataGeneratorMode {
153+
enum PubdataType {
153154
Rollup = 0;
154-
Validium = 1;
155+
NoDA = 1;
156+
Avail = 2;
157+
Celestia = 3;
158+
Eigen = 4;
159+
ObjectStore = 5;
155160
}

core/lib/dal/src/consensus/tests.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use zksync_protobuf::{
99
};
1010
use zksync_test_contracts::Account;
1111
use zksync_types::{
12-
commitment::{L1BatchCommitmentMode, PubdataParams},
12+
commitment::{PubdataParams, PubdataType},
1313
web3::Bytes,
1414
Execute, ExecuteTransactionCommon, L1BatchNumber, ProtocolVersionId, Transaction,
1515
};
@@ -58,8 +58,12 @@ fn payload(rng: &mut impl Rng, protocol_version: ProtocolVersionId) -> Payload {
5858
} else {
5959
PubdataParams {
6060
pubdata_type: match rng.gen_range(0..2) {
61-
0 => L1BatchCommitmentMode::Rollup,
62-
_ => L1BatchCommitmentMode::Validium,
61+
0 => PubdataType::Rollup,
62+
1 => PubdataType::NoDA,
63+
2 => PubdataType::Avail,
64+
3 => PubdataType::Celestia,
65+
4 => PubdataType::Eigen,
66+
_ => PubdataType::ObjectStore,
6367
},
6468
l2_da_validator_address: rng.gen(),
6569
}

core/lib/dal/src/factory_deps_dal.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,39 +89,36 @@ impl FactoryDepsDal<'_, '_> {
8989
.map(|row| row.bytecode))
9090
}
9191

92-
pub async fn get_base_system_contracts(
92+
pub async fn get_base_system_contracts_from_factory_deps(
9393
&mut self,
9494
bootloader_hash: H256,
9595
default_aa_hash: H256,
9696
evm_emulator_hash: Option<H256>,
97-
) -> anyhow::Result<BaseSystemContracts> {
97+
) -> anyhow::Result<Option<BaseSystemContracts>> {
9898
let bootloader_bytecode = self
9999
.get_sealed_factory_dep(bootloader_hash)
100100
.await
101-
.context("failed loading bootloader code")?
102-
.with_context(|| format!("bootloader code with hash {bootloader_hash:?} should be present in the database"))?;
103-
let bootloader_code = SystemContractCode {
104-
code: bootloader_bytecode,
105-
hash: bootloader_hash,
106-
};
101+
.context("failed loading bootloader code")?;
107102

108103
let default_aa_bytecode = self
109104
.get_sealed_factory_dep(default_aa_hash)
110105
.await
111-
.context("failed loading default account code")?
112-
.with_context(|| format!("default account code with hash {default_aa_hash:?} should be present in the database"))?;
106+
.context("failed loading default account code")?;
113107

114-
let default_aa_code = SystemContractCode {
115-
code: default_aa_bytecode,
116-
hash: default_aa_hash,
108+
let (Some(bootloader_bytecode), Some(default_aa_bytecode)) =
109+
(bootloader_bytecode, default_aa_bytecode)
110+
else {
111+
return Ok(None);
117112
};
118113

119114
let evm_emulator_code = if let Some(evm_emulator_hash) = evm_emulator_hash {
120115
let evm_emulator_bytecode = self
121116
.get_sealed_factory_dep(evm_emulator_hash)
122117
.await
123-
.context("failed loading EVM emulator code")?
124-
.with_context(|| format!("EVM emulator code with hash {evm_emulator_hash:?} should be present in the database"))?;
118+
.context("failed loading EVM emulator code")?;
119+
let Some(evm_emulator_bytecode) = evm_emulator_bytecode else {
120+
return Ok(None);
121+
};
125122

126123
Some(SystemContractCode {
127124
code: evm_emulator_bytecode,
@@ -131,11 +128,20 @@ impl FactoryDepsDal<'_, '_> {
131128
None
132129
};
133130

134-
Ok(BaseSystemContracts {
131+
let bootloader_code = SystemContractCode {
132+
code: bootloader_bytecode,
133+
hash: bootloader_hash,
134+
};
135+
136+
let default_aa_code = SystemContractCode {
137+
code: default_aa_bytecode,
138+
hash: default_aa_hash,
139+
};
140+
Ok(Some(BaseSystemContracts {
135141
bootloader: bootloader_code,
136142
default_aa: default_aa_code,
137143
evm_emulator: evm_emulator_code,
138-
})
144+
}))
139145
}
140146

141147
/// Returns bytecodes for factory deps with the specified `hashes`.

core/lib/dal/src/models/storage_block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use zksync_contracts::BaseSystemContractsHashes;
77
use zksync_types::{
88
api,
99
block::{L1BatchHeader, L2BlockHeader, UnsealedL1BatchHeader},
10-
commitment::{L1BatchCommitmentMode, L1BatchMetaParameters, L1BatchMetadata, PubdataParams},
10+
commitment::{L1BatchMetaParameters, L1BatchMetadata, PubdataParams, PubdataType},
1111
fee_model::{BatchFeeInput, L1PeggedBatchFeeModelInput, PubdataIndependentBatchFeeModelInput},
1212
l2_to_l1_log::{L2ToL1Log, SystemL2ToL1Log, UserL2ToL1Log},
1313
Address, Bloom, L1BatchNumber, L2BlockNumber, ProtocolVersionId, SLChainId, H256,
@@ -556,7 +556,7 @@ impl From<StorageL2BlockHeader> for L2BlockHeader {
556556
.unwrap_or_default(),
557557
pubdata_params: PubdataParams {
558558
l2_da_validator_address: Address::from_slice(&row.l2_da_validator_address),
559-
pubdata_type: L1BatchCommitmentMode::from_str(&row.pubdata_type).unwrap(),
559+
pubdata_type: PubdataType::from_str(&row.pubdata_type).unwrap(),
560560
},
561561
}
562562
}

core/lib/dal/src/models/storage_sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use zksync_contracts::BaseSystemContractsHashes;
44
use zksync_db_connection::error::SqlxContext;
55
use zksync_types::{
66
api::en,
7-
commitment::{L1BatchCommitmentMode, PubdataParams},
7+
commitment::{PubdataParams, PubdataType},
88
parse_h160, parse_h256, parse_h256_opt, Address, L1BatchNumber, L2BlockNumber,
99
ProtocolVersionId, Transaction, H256,
1010
};
@@ -97,7 +97,7 @@ impl TryFrom<StorageSyncBlock> for SyncBlock {
9797
hash: parse_h256(&block.hash).decode_column("hash")?,
9898
protocol_version: parse_protocol_version(block.protocol_version)?,
9999
pubdata_params: PubdataParams {
100-
pubdata_type: L1BatchCommitmentMode::from_str(&block.pubdata_type)
100+
pubdata_type: PubdataType::from_str(&block.pubdata_type)
101101
.decode_column("Invalid pubdata type")?,
102102
l2_da_validator_address: parse_h160(&block.l2_da_validator_address)
103103
.decode_column("l2_da_validator_address")?,

core/lib/dal/src/protocol_versions_dal.rs

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::convert::TryInto;
22

33
use anyhow::Context as _;
4-
use zksync_contracts::{BaseSystemContracts, BaseSystemContractsHashes};
4+
use zksync_contracts::BaseSystemContractsHashes;
55
use zksync_db_connection::{
66
connection::Connection,
77
error::DalResult,
@@ -200,12 +200,10 @@ impl ProtocolVersionsDal<'_, '_> {
200200
ProtocolVersionId::try_from(row.id as u16).map_err(|err| sqlx::Error::Decode(err.into()))
201201
}
202202

203-
/// Returns base system contracts' hashes. Prefer `load_base_system_contracts_by_version_id` if
204-
/// you also want to load the contracts themselves AND expect the contracts to be in the DB
205-
/// already.
203+
/// Returns base system contracts' hashes.
206204
pub async fn get_base_system_contract_hashes_by_version_id(
207205
&mut self,
208-
version_id: u16,
206+
version_id: ProtocolVersionId,
209207
) -> anyhow::Result<Option<BaseSystemContractsHashes>> {
210208
let row = sqlx::query!(
211209
r#"
@@ -218,10 +216,10 @@ impl ProtocolVersionsDal<'_, '_> {
218216
WHERE
219217
id = $1
220218
"#,
221-
i32::from(version_id)
219+
i32::from(version_id as u16)
222220
)
223221
.instrument("get_base_system_contract_hashes_by_version_id")
224-
.with_arg("version_id", &version_id)
222+
.with_arg("version_id", &(version_id as u16))
225223
.fetch_optional(self.storage)
226224
.await
227225
.context("cannot fetch system contract hashes")?;
@@ -237,45 +235,6 @@ impl ProtocolVersionsDal<'_, '_> {
237235
})
238236
}
239237

240-
pub async fn load_base_system_contracts_by_version_id(
241-
&mut self,
242-
version_id: u16,
243-
) -> anyhow::Result<Option<BaseSystemContracts>> {
244-
let row = sqlx::query!(
245-
r#"
246-
SELECT
247-
bootloader_code_hash,
248-
default_account_code_hash,
249-
evm_emulator_code_hash
250-
FROM
251-
protocol_versions
252-
WHERE
253-
id = $1
254-
"#,
255-
i32::from(version_id)
256-
)
257-
.instrument("load_base_system_contracts_by_version_id")
258-
.with_arg("version_id", &version_id)
259-
.fetch_optional(self.storage)
260-
.await
261-
.context("cannot fetch system contract hashes")?;
262-
263-
Ok(if let Some(row) = row {
264-
let contracts = self
265-
.storage
266-
.factory_deps_dal()
267-
.get_base_system_contracts(
268-
H256::from_slice(&row.bootloader_code_hash),
269-
H256::from_slice(&row.default_account_code_hash),
270-
row.evm_emulator_code_hash.as_deref().map(H256::from_slice),
271-
)
272-
.await?;
273-
Some(contracts)
274-
} else {
275-
None
276-
})
277-
}
278-
279238
pub async fn get_protocol_version_with_latest_patch(
280239
&mut self,
281240
version_id: ProtocolVersionId,

core/lib/env_config/src/genesis.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ impl FromEnv for GenesisConfig {
8484
bootloader_hash: state_keeper.bootloader_hash,
8585
default_aa_hash: state_keeper.default_aa_hash,
8686
evm_emulator_hash: state_keeper.evm_emulator_hash,
87-
// TODO(EVM-676): for now, the settlement layer is always the same as the L1 network
8887
l1_chain_id: L1ChainId(network_config.network.chain_id().0),
8988
l2_chain_id: network_config.zksync_network_id,
9089
snark_wrapper_vk_hash: contracts_config.snark_wrapper_vk_hash,

0 commit comments

Comments
 (0)