Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into lyova-merge-main-into…
Browse files Browse the repository at this point in the history
…-boojum
  • Loading branch information
ly0va committed Oct 9, 2023
2 parents 742ec84 + fa71650 commit ab384c2
Show file tree
Hide file tree
Showing 81 changed files with 1,510 additions and 788 deletions.
2 changes: 1 addition & 1 deletion .github/release-please/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk/zksync-web3.js": "0.15.4",
"sdk/zksync-rs": "0.4.0",
"core": "15.1.0",
"core": "15.1.1",
"prover": "7.1.1"
}
21 changes: 3 additions & 18 deletions .github/workflows/build-prover-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,14 @@ on:
required: false

jobs:
era-bellman-cuda:
name: Get era-bellman-cuda release URLs.
runs-on: [ubuntu-latest]
outputs:
source: ${{ steps.release.outputs.source }}
binary: ${{ steps.release.outputs.binary }}
steps:
- id: release
run: |
release=($(curl -v --silent https://api.github.com/repos/matter-labs/era-bellman-cuda/releases/tags/${{ inputs.ERA_BELLMAN_CUDA_RELEASE }} | jq -r ".name, .tarball_url, .assets[0].browser_download_url"))
echo "source=${release[1]}" >> "$GITHUB_OUTPUT"
echo "binary=${release[2]}" >> "$GITHUB_OUTPUT"
build-images:
name: Build and Push Docker Images
env:
image_tag: ${{ inputs.image_tag }}
IMAGE_TAG_SUFFIX: ${{ inputs.image_tag_suffix }}
RUNNER_COMPOSE_FILE: "docker-compose-runner-nightly.yml"
ERA_BELLMAN_CUDA_RELEASE: ${{ inputs.ERA_BELLMAN_CUDA_RELEASE }}
runs-on: [matterlabs-ci-runner]
needs: [era-bellman-cuda]
strategy:
matrix:
component:
Expand All @@ -65,9 +52,6 @@ jobs:
with:
submodules: "recursive"

- name: Prepare bellman-cuda directory
run: etc/scripts/prepare_era_bellman_cuda.sh ${{ needs.era-bellman-cuda.outputs.source }} ${{ needs.era-bellman-cuda.outputs.binary }}

- name: setup-env
run: |
echo ZKSYNC_HOME=$(pwd) >> $GITHUB_ENV
Expand Down Expand Up @@ -113,7 +97,7 @@ jobs:
"proof-fri-compressor"
)
run: |
nightly_components=${{env.RUST_NIGHTLY_COMPONENTS}}
nightly_components=${{ env.RUST_NIGHTLY_COMPONENTS }}
ci_run docker login -u ${{ secrets.DOCKERHUB_USER }} -p ${{ secrets.DOCKERHUB_TOKEN }}
ci_run gcloud auth configure-docker us-docker.pkg.dev,asia-docker.pkg.dev -q
Expand All @@ -130,6 +114,7 @@ jobs:
ci_run echo [workspace] > Cargo.toml
ci_run echo members = [\"prover/${underscored_name}\"] >> Cargo.toml
ci_run cp prover/Cargo.lock Cargo.lock
PASSED_ENV_VARS="ERA_BELLMAN_CUDA_RELEASE" \
ci_run zk docker $DOCKER_ACTION $COMPONENT
else
ci_run zk docker $DOCKER_ACTION $COMPONENT
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
id: release
uses: google-github-actions/release-please-action@v3
with:
token: ${{ secrets.RELEASE_TOKEN }}
command: manifest
config-file: .github/release-please/config.json
manifest-file: .github/release-please/manifest.json
Expand Down
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion bin/ci_run
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,16 @@
# Runs the command from within CI docker-compose environment.
cd $ZKSYNC_HOME
compose_file="${RUNNER_COMPOSE_FILE:-docker-compose-runner.yml}"
docker-compose -f $compose_file exec -T zk $@

# Pass environment variables explicitly if specified
if [ ! -z "$PASSED_ENV_VARS" ]; then
env_vars_option=""
IFS=',' read -ra ADDR <<<"$PASSED_ENV_VARS"
for var in "${ADDR[@]}"; do
value=$(eval echo \$$var)
env_vars_option="${env_vars_option} -e ${var}=${value}"
done
docker-compose -f $compose_file exec -T $env_vars_option zk $@
else
docker-compose -f $compose_file exec -T zk $@
fi
7 changes: 7 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [15.1.1](https://github.com/matter-labs/zksync-era/compare/core-v15.1.0...core-v15.1.1) (2023-10-05)


### Bug Fixes

* use gauge instead histogram for replication lag metric ([#159](https://github.com/matter-labs/zksync-era/issues/159)) ([0d952d4](https://github.com/matter-labs/zksync-era/commit/0d952d43a021c2fbf18920da3e7d770a6309d990))

## [15.1.0](https://github.com/matter-labs/zksync-era/compare/core-v15.0.2...core-v15.1.0) (2023-10-03)


Expand Down
15 changes: 8 additions & 7 deletions core/bin/external_node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ impl RemoteENConfig {
.get_main_contract()
.await
.context("Failed to fetch L1 contract address")?;
let l2_chain_id = L2ChainId(
let l2_chain_id = L2ChainId::try_from(
client
.chain_id()
.await
.context("Failed to fetch L2 chain ID")?
.as_u64() as u16,
);
.as_u64(),
)
.unwrap();
let l1_chain_id = L1ChainId(
client
.l1_chain_id()
Expand Down Expand Up @@ -396,14 +397,14 @@ impl ExternalNodeConfig {
.await
.context("Unable to check L1 chain ID through the configured L1 client")?;

let l2_chain_id: u16 = env_var("EN_L2_CHAIN_ID");
let l2_chain_id: L2ChainId = env_var("EN_L2_CHAIN_ID");
let l1_chain_id: u64 = env_var("EN_L1_CHAIN_ID");
if l2_chain_id != remote.l2_chain_id.0 {
if l2_chain_id != remote.l2_chain_id {
anyhow::bail!(
"Configured L2 chain id doesn't match the one from main node.
Make sure your configuration is correct and you are corrected to the right main node.
Main node L2 chain id: {}. Local config value: {}",
remote.l2_chain_id.0, l2_chain_id
Main node L2 chain id: {:?}. Local config value: {:?}",
remote.l2_chain_id, l2_chain_id
);
}
if l1_chain_id != remote.l1_chain_id.0 {
Expand Down
2 changes: 1 addition & 1 deletion core/bin/system-constants-generator/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub(super) fn get_l2_tx(contract_address: Address, signer: &H256, pubdata_price:
gas_per_pubdata_limit: pubdata_price.into(),
},
U256::from(0),
L2ChainId(270),
L2ChainId::from(270),
signer,
None,
Default::default(),
Expand Down
1 change: 1 addition & 0 deletions core/lib/basic_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ categories = ["cryptography"]
[dependencies]
web3 = { version= "0.19.0", default-features = false, features = ["http-rustls-tls", "test", "signing"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
162 changes: 149 additions & 13 deletions core/lib/basic_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod macros;

pub mod network;

use serde::{Deserialize, Serialize};
use serde::{de, Deserialize, Deserializer, Serialize};
use std::convert::{Infallible, TryFrom, TryInto};
use std::fmt;
use std::num::ParseIntError;
Expand Down Expand Up @@ -76,6 +76,85 @@ impl TryFrom<U256> for AccountTreeId {
}
}

/// ChainId in the ZkSync network.
#[derive(Copy, Clone, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct L2ChainId(u64);

impl<'de> Deserialize<'de> for L2ChainId {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let s: String = Deserialize::deserialize(deserializer)?;
s.parse().map_err(de::Error::custom)
}
}

impl FromStr for L2ChainId {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
// Parse the string as a U64
// try to parse as decimal first
let number = match U64::from_dec_str(s) {
Ok(u) => u,
Err(_) => {
// try to parse as hex
s.parse::<U64>()
.map_err(|err| format!("Failed to parse L2ChainId: Err {err}"))?
}
};

if number.as_u64() > L2ChainId::max().0 {
return Err(format!("Too big chain ID. MAX: {}", L2ChainId::max().0));
}
Ok(L2ChainId(number.as_u64()))
}
}

impl L2ChainId {
/// The maximum value of the L2 chain ID.
// 2^53 - 1 is a max safe integer in JS. In ethereum JS libs chain ID should be the safe integer.
// Next arithmetic operation: subtract 36 and divide by 2 comes from `v` calculation:
// v = 2*chainId + 36, that should be save integer as well.
const MAX: u64 = ((1 << 53) - 1 - 36) / 2;

pub fn max() -> Self {
Self(Self::MAX)
}

pub fn as_u64(&self) -> u64 {
self.0
}
}

impl Default for L2ChainId {
fn default() -> Self {
Self(270)
}
}

impl TryFrom<u64> for L2ChainId {
type Error = String;

fn try_from(val: u64) -> Result<Self, Self::Error> {
if val > L2ChainId::max().0 {
return Err(format!(
"Cannot convert given value {} into L2ChainId. It's greater than MAX: {},",
val,
L2ChainId::max().0,
));
}
Ok(Self(val))
}
}

impl From<u32> for L2ChainId {
fn from(value: u32) -> Self {
Self(value as u64)
}
}

basic_type!(
/// zkSync network block sequential index.
MiniblockNumber,
Expand Down Expand Up @@ -112,12 +191,6 @@ basic_type!(
u64
);

basic_type!(
/// ChainId in the ZkSync network.
L2ChainId,
u16
);

#[allow(clippy::derivable_impls)]
impl Default for MiniblockNumber {
fn default() -> Self {
Expand All @@ -139,15 +212,78 @@ impl Default for L1BlockNumber {
}
}

impl Default for L2ChainId {
fn default() -> Self {
Self(270)
}
}

#[allow(clippy::derivable_impls)]
impl Default for PriorityOpId {
fn default() -> Self {
Self(0)
}
}

#[cfg(test)]
mod tests {
use super::*;
use serde_json::from_str;

#[test]
fn test_from_str_valid_decimal() {
let input = "42";
let result = L2ChainId::from_str(input);
assert_eq!(result.unwrap().as_u64(), 42);
}

#[test]
fn test_from_str_valid_hexadecimal() {
let input = "0x2A";
let result = L2ChainId::from_str(input);
assert_eq!(result.unwrap().as_u64(), 42);
}

#[test]
fn test_from_str_too_big_chain_id() {
let input = "18446744073709551615"; // 2^64 - 1
let result = L2ChainId::from_str(input);
assert_eq!(
result,
Err(format!("Too big chain ID. MAX: {}", L2ChainId::max().0))
);
}

#[test]
fn test_from_str_invalid_input() {
let input = "invalid"; // Invalid input that cannot be parsed as a number
let result = L2ChainId::from_str(input);

assert!(result.is_err());
assert!(result
.unwrap_err()
.contains("Failed to parse L2ChainId: Err "));
}

#[test]
fn test_deserialize_valid_decimal() {
let input_json = "\"42\"";

let result: Result<L2ChainId, _> = from_str(input_json);
assert_eq!(result.unwrap().as_u64(), 42);
}

#[test]
fn test_deserialize_valid_hex() {
let input_json = "\"0x2A\"";

let result: Result<L2ChainId, _> = from_str(input_json);
assert_eq!(result.unwrap().as_u64(), 42);
}

#[test]
fn test_deserialize_invalid() {
let input_json = "\"invalid\"";

let result: Result<L2ChainId, serde_json::Error> = from_str(input_json);
assert!(result.is_err());
assert!(result
.unwrap_err()
.to_string()
.contains("Failed to parse L2ChainId: Err Invalid character "));
}
}
6 changes: 3 additions & 3 deletions core/lib/config/src/configs/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::Deserialize;
use std::time::Duration;
// Local uses
use zksync_basic_types::network::Network;
use zksync_basic_types::{Address, H256};
use zksync_basic_types::{Address, L2ChainId, H256};
use zksync_contracts::BaseSystemContractsHashes;

use super::envy_load;
Expand Down Expand Up @@ -47,7 +47,7 @@ pub struct NetworkConfig {
pub zksync_network: String,
/// ID of current zkSync network treated as ETH network ID.
/// Used to distinguish zkSync from other Web3-capable networks.
pub zksync_network_id: u16,
pub zksync_network_id: L2ChainId,
}

impl NetworkConfig {
Expand Down Expand Up @@ -202,7 +202,7 @@ mod tests {
network: NetworkConfig {
network: "localhost".parse().unwrap(),
zksync_network: "localhost".to_string(),
zksync_network_id: 270,
zksync_network_id: L2ChainId::from(270),
},
state_keeper: StateKeeperConfig {
transaction_slots: 50,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE prover_jobs_fri ADD CONSTRAINT prover_jobs_fri_l1_batch_number_fkey
FOREIGN KEY (l1_batch_number) REFERENCES l1_batches (number);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE prover_jobs_fri DROP CONSTRAINT IF EXISTS prover_jobs_fri_l1_batch_number_fkey;
Loading

0 comments on commit ab384c2

Please sign in to comment.