Skip to content

Commit

Permalink
Merge pull request #1581 from matter-labs/deniallugo-hardcode-initial…
Browse files Browse the repository at this point in the history
…-chain-id

hardcode initial chain id
  • Loading branch information
kelemeno committed Apr 5, 2024
2 parents bb287d6 + 3e59eb1 commit 930eb77
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
4 changes: 4 additions & 0 deletions core/lib/constants/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,7 @@ pub const MINT_AND_BURN_ADDRESS: H160 = H160::zero();

// The `storage_log.value` database value for a contract that was deployed in a failed transaction.
pub const FAILED_CONTRACT_DEPLOYMENT_BYTECODE_HASH: H256 = H256::zero();

// Default ERA_CHAIN_ID. All hyeprchains starts with this chain id and later on
// it will be changed to proper one
pub const DEFAULT_ERA_CHAIN_ID: u32 = 270;
13 changes: 7 additions & 6 deletions core/lib/zksync_core/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use zksync_contracts::{BaseSystemContracts, BaseSystemContractsHashes, SET_CHAIN
use zksync_dal::{Connection, ConnectionPool, Core, CoreDal, DalError};
use zksync_eth_client::{clients::QueryClient, EthInterface};
use zksync_merkle_tree::domain::ZkSyncTree;
use zksync_system_constants::PRIORITY_EXPIRATION;
use zksync_system_constants::{DEFAULT_ERA_CHAIN_ID, PRIORITY_EXPIRATION};
use zksync_types::{
block::{
BlockGasCount, DeployedContract, L1BatchHeader, L1BatchTreeData, MiniblockHasher,
Expand Down Expand Up @@ -205,7 +205,6 @@ pub async fn insert_genesis_batch(

create_genesis_l1_batch(
&mut transaction,
genesis_params.config.l2_chain_id,
genesis_params.protocol_version(),
genesis_params.base_system_contracts(),
genesis_params.system_contracts(),
Expand Down Expand Up @@ -342,9 +341,12 @@ async fn insert_base_system_contracts_to_factory_deps(
async fn insert_system_contracts(
storage: &mut Connection<'_, Core>,
contracts: &[DeployedContract],
chain_id: L2ChainId,
) -> Result<(), GenesisError> {
let system_context_init_logs = (H256::default(), get_system_context_init_logs(chain_id));
let system_context_init_logs = (
H256::default(),
// During the genesis all chains have the same id.
get_system_context_init_logs(L2ChainId::from(DEFAULT_ERA_CHAIN_ID)),
);

let known_code_storage_logs: Vec<_> = contracts
.iter()
Expand Down Expand Up @@ -470,7 +472,6 @@ async fn insert_system_contracts(
#[allow(clippy::too_many_arguments)]
pub(crate) async fn create_genesis_l1_batch(
storage: &mut Connection<'_, Core>,
chain_id: L2ChainId,
protocol_version: ProtocolVersionId,
base_system_contracts: &BaseSystemContracts,
system_contracts: &[DeployedContract],
Expand Down Expand Up @@ -534,7 +535,7 @@ pub(crate) async fn create_genesis_l1_batch(
.await?;

insert_base_system_contracts_to_factory_deps(&mut transaction, base_system_contracts).await?;
insert_system_contracts(&mut transaction, system_contracts, chain_id).await?;
insert_system_contracts(&mut transaction, system_contracts).await?;
add_eth_token(&mut transaction).await?;

transaction.commit().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use zksync_types::{
block::MiniblockHasher, ethabi::Token, fee::Fee, snapshots::SnapshotRecoveryStatus,
storage_writes_deduplicator::StorageWritesDeduplicator,
system_contracts::get_system_smart_contracts, utils::storage_key_for_standard_token_balance,
AccountTreeId, Address, Execute, L1BatchNumber, L2ChainId, MiniblockNumber, PriorityOpId,
AccountTreeId, Address, Execute, L1BatchNumber, MiniblockNumber, PriorityOpId,
ProtocolVersionId, StorageKey, StorageLog, Transaction, H256, L2_ETH_TOKEN_ADDRESS,
SYSTEM_CONTEXT_MINIMAL_BASE_FEE, U256,
};
Expand All @@ -39,7 +39,6 @@ use crate::{
};

const DEFAULT_GAS_PER_PUBDATA: u32 = 10000;
const CHAIN_ID: u32 = 270;

/// Representation of configuration parameters used by the state keeper.
/// Has sensible defaults for most tests, each of which can be overridden.
Expand Down Expand Up @@ -249,7 +248,6 @@ impl Tester {
if storage.blocks_dal().is_genesis_needed().await.unwrap() {
create_genesis_l1_batch(
&mut storage,
L2ChainId::from(CHAIN_ID),
ProtocolVersionId::latest(),
&BASE_SYSTEM_CONTRACTS,
&get_system_smart_contracts(),
Expand Down
1 change: 0 additions & 1 deletion core/lib/zksync_core/src/state_keeper/io/tests/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ impl Tester {
if storage.blocks_dal().is_genesis_needed().await.unwrap() {
create_genesis_l1_batch(
&mut storage,
L2ChainId::from(270),
ProtocolVersionId::latest(),
&self.base_system_contracts,
&get_system_smart_contracts(),
Expand Down
4 changes: 1 addition & 3 deletions infrastructure/zk/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ async function create_genesis(cmd: string) {
export async function genesisFromSources(options?: { setChainId: boolean }) {
const args = [options?.setChainId ? '--set-chain-id' : ''];
// we fix chainId as we need all chains to have the same chainId at genesis
await create_genesis(
'CHAIN_ETH_ZKSYNC_NETWORK_ID=270 cargo run --bin zksync_server --release -- --genesis ' + args.join(' ')
);
await create_genesis('cargo run --bin zksync_server --release -- --genesis ' + args.join(' '));
}

export async function genesisFromBinary() {
Expand Down

0 comments on commit 930eb77

Please sign in to comment.