Skip to content

Commit

Permalink
Merge branch 'main' of github.com:matter-labs/zksync-era into kl/fact…
Browse files Browse the repository at this point in the history
…ory-migration-fix-4
  • Loading branch information
kelemeno committed May 8, 2024
2 parents 4c3dc33 + 368aeea commit 2d65a96
Show file tree
Hide file tree
Showing 20 changed files with 949 additions and 92 deletions.
1 change: 1 addition & 0 deletions checks-config/era.dic
Expand Up @@ -673,6 +673,7 @@ crypto
callee
Subcalls
Vec
vec
vecs
L1Messenger
SystemL2ToL1Log
Expand Down
14 changes: 3 additions & 11 deletions core/lib/eth_client/src/clients/http/decl.rs
Expand Up @@ -30,25 +30,17 @@ pub(super) trait L1EthNamespace {
async fn get_transaction_count(
&self,
address: Address,
block: Option<web3::BlockNumber>,
block: web3::BlockNumber,
) -> RpcResult<U256>;

#[method(name = "gasPrice")]
async fn gas_price(&self) -> RpcResult<U256>;

#[method(name = "call")]
async fn call(
&self,
req: web3::CallRequest,
block: Option<web3::BlockId>,
) -> RpcResult<web3::Bytes>;
async fn call(&self, req: web3::CallRequest, block: web3::BlockId) -> RpcResult<web3::Bytes>;

#[method(name = "getBalance")]
async fn get_balance(
&self,
address: Address,
block: Option<web3::BlockNumber>,
) -> RpcResult<U256>;
async fn get_balance(&self, address: Address, block: web3::BlockNumber) -> RpcResult<U256>;

#[method(name = "getLogs")]
async fn get_logs(&self, filter: web3::Filter) -> RpcResult<Vec<web3::Log>>;
Expand Down
20 changes: 10 additions & 10 deletions core/lib/eth_client/src/clients/http/query.rs
Expand Up @@ -69,10 +69,7 @@ impl EthInterface for QueryClient {
) -> Result<U256, Error> {
COUNTERS.call[&(Method::NonceAtForAccount, self.component)].inc();
let latency = LATENCIES.direct[&Method::NonceAtForAccount].start();
let nonce = self
.web3
.get_transaction_count(account, Some(block))
.await?;
let nonce = self.web3.get_transaction_count(account, block).await?;
latency.observe();
Ok(nonce)
}
Expand Down Expand Up @@ -203,11 +200,10 @@ impl EthInterface for QueryClient {
access_list: None,
};

let err = self
.web3
.call(call_request, receipt.block_number.map(Into::into))
.await
.err();
let block_number = receipt
.block_number
.map_or_else(|| web3::BlockNumber::Latest.into(), Into::into);
let err = self.web3.call(call_request, block_number).await.err();

let failure_info = match err {
Some(ClientError::Call(call_err)) => {
Expand Down Expand Up @@ -246,6 +242,7 @@ impl EthInterface for QueryClient {
block: Option<web3::BlockId>,
) -> Result<web3::Bytes, Error> {
let latency = LATENCIES.direct[&Method::CallContractFunction].start();
let block = block.unwrap_or_else(|| web3::BlockNumber::Latest.into());
let output_bytes = self.web3.call(request, block).await?;
latency.observe();
Ok(output_bytes)
Expand All @@ -262,7 +259,10 @@ impl EthInterface for QueryClient {
async fn eth_balance(&self, address: Address) -> Result<U256, Error> {
COUNTERS.call[&(Method::EthBalance, self.component)].inc();
let latency = LATENCIES.direct[&Method::EthBalance].start();
let balance = self.web3.get_balance(address, None).await?;
let balance = self
.web3
.get_balance(address, web3::BlockNumber::Latest)
.await?;
latency.observe();
Ok(balance)
}
Expand Down
4 changes: 2 additions & 2 deletions core/node/node_framework/src/service/runnables.rs
Expand Up @@ -27,8 +27,8 @@ pub(super) struct Runnables {

impl fmt::Debug for Runnables {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Macro that iterates over a `Vec`, invokes `.name()` method and collects the results into a Vec<String>.
// Returns a reference to created vector to satisfy the `.field` method signature.
// Macro that iterates over a `Vec`, invokes `.name()` method and collects the results into a `Vec<String>`.
// Returns a reference to created `Vec` to satisfy the `.field` method signature.
macro_rules! names {
($vec:expr) => {
&$vec.iter().map(|x| x.name()).collect::<Vec<_>>()
Expand Down
1 change: 1 addition & 0 deletions docker/local-node/Dockerfile
Expand Up @@ -70,4 +70,5 @@ RUN mkdir /etc/env/l1-inits && mkdir /etc/env/l2-inits

# setup entrypoint script
COPY ./docker/local-node/entrypoint.sh /usr/bin/

ENTRYPOINT ["entrypoint.sh"]
41 changes: 31 additions & 10 deletions docker/local-node/entrypoint.sh
Expand Up @@ -44,6 +44,16 @@ until psql ${DATABASE_URL%/*} -c '\q'; do
sleep 5
done

if [ -z "$MASTER_URL" ]; then
echo "Running as zksync master"
else
# If running in slave mode - wait for the master to be up and running.
echo "Waiting for zksync master to init hyperchain"
until curl --fail ${MASTER_HEALTH_URL}; do
>&2 echo "Master zksync not ready yet, sleeping"
sleep 5
done
fi

# Normally, the /etc/env and /var/lib/zksync/data should be mapped to volumes
# so that they are persisted between docker restarts - which would allow even faster starts.
Expand All @@ -66,19 +76,28 @@ else
update_config "/etc/env/base/database.toml" "state_keeper_db_path" "/var/lib/zksync/data/state_keeper"
update_config "/etc/env/base/database.toml" "backup_path" "/var/lib/zksync/data/backups"


if [ -z "$MASTER_URL" ]; then
echo "Starting with hyperchain"
else
# Updates all the stuff (from the '/etc/master_env') - it assumes that it is mapped via docker compose.
zk f yarn --cwd /infrastructure/local-setup-preparation join
fi

zk config compile

zk db reset

# Perform initialization

zk contract deploy-verifier
zk run deploy-erc20 dev # (created etc/tokens/localhost)

## init bridgehub state transition
zk contract deploy # (deploy L1)
zk contract initialize-governance
zk contract initialize-validator
# Perform initialization (things needed to be done only if you're running in the master mode)
if [ -z "$MASTER_URL" ]; then
zk contract deploy-verifier
zk run deploy-erc20 dev # (created etc/tokens/localhost)

## init bridgehub state transition
zk contract deploy # (deploy L1)
zk contract initialize-governance
zk contract initialize-validator
fi

## init hyperchain
zk contract register-hyperchain
Expand All @@ -87,7 +106,9 @@ else

zk contract deploy-l2-through-l1

zk f yarn --cwd /infrastructure/local-setup-preparation start
if [ -z "$MASTER_URL" ]; then
zk f yarn --cwd /infrastructure/local-setup-preparation start
fi

# Create init file.
echo "System initialized. Please remove this file if you want to reset the system" > $INIT_FILE
Expand Down
3 changes: 2 additions & 1 deletion infrastructure/local-setup-preparation/package.json
Expand Up @@ -13,6 +13,7 @@
"@types/node": "^18.19.15"
},
"scripts": {
"start": "ts-node ./src/index.ts"
"start": "ts-node ./src/index.ts",
"join": "ts-node ./src/join_hyperchain.ts"
}
}
86 changes: 86 additions & 0 deletions infrastructure/local-setup-preparation/src/join_hyperchain.ts
@@ -0,0 +1,86 @@
import fs from 'fs';
import path from 'path';
import { ethers } from 'ethers';
import { getEthersProvider, getWalletKeys } from './utils';
import assert from 'assert';

async function joinHyperchain() {
const chainId = process.env.CHAIN_ETH_ZKSYNC_NETWORK_ID!;
assert(chainId != '270', `Your chain id is set to 270 - are you sure`);

const ethProvider = getEthersProvider();
const operatorWallet = ethers.Wallet.createRandom();
console.log(`Operator: ${operatorWallet.address}`);
const blobOperatorWallet = ethers.Wallet.createRandom();
console.log(`Blob Operator: ${blobOperatorWallet.address}`);

const allWalletKeys = getWalletKeys();

const richWalletKey = allWalletKeys[allWalletKeys.length - 1];

const richAccount = new ethers.Wallet(richWalletKey.privateKey, ethProvider);

for (const addr of [operatorWallet.address, blobOperatorWallet.address]) {
const tx = {
to: addr,
// Convert Ether to Wei
value: ethers.utils.parseEther('100')
};
await richAccount.sendTransaction(tx);
}
console.log(`Eth sent to operator accounts`);

const inputFilePath = process.env.MASTER_ENV_FILE!;
const outputFilePath = path.resolve('/etc/env/l1-inits', '.init.env');
const varsToKeep = [
'CONTRACTS_BRIDGEHUB_PROXY_ADDR',
'CONTRACTS_STATE_TRANSITION_PROXY_ADDR',
'CONTRACTS_ADMIN_FACET_ADDR',
'CONTRACTS_MAILBOX_FACET_ADDR',
'CONTRACTS_EXECUTOR_FACET_ADDR',
'CONTRACTS_GETTERS_FACET_ADDR',
'CONTRACTS_DIAMOND_INIT_ADDR',
'CONTRACTS_BLOB_VERSIONED_HASH_RETRIEVER_ADDR',
'CONTRACTS_VERIFIER_ADDR',
'CONTRACTS_L1_MULTICALL3_ADDR',
'CONTRACTS_VALIDATOR_TIMELOCK_ADDR',
'CONTRACTS_GOVERNANCE_ADDR'
];

try {
const data = fs.readFileSync(inputFilePath, 'utf8');

const lines = data.split(/\r?\n/);
// Filter and map lines to keep only specified variables
const filteredEnvVars = lines.filter((line) => {
const key = line.split('=')[0];
return varsToKeep.includes(key);
});

filteredEnvVars.push(`ETH_SENDER_SENDER_OPERATOR_PRIVATE_KEY=${operatorWallet.privateKey}`);
filteredEnvVars.push(`ETH_SENDER_SENDER_OPERATOR_COMMIT_ETH_ADDR=${operatorWallet.address}`);
filteredEnvVars.push(`ETH_SENDER_SENDER_OPERATOR_BLOBS_PRIVATE_KEY=${blobOperatorWallet.privateKey}`);
filteredEnvVars.push(`ETH_SENDER_SENDER_OPERATOR_BLOBS_ETH_ADDR=${blobOperatorWallet.address}`);

// Prepare the content to write to the output file
const outputContent = filteredEnvVars.join('\n');

// Write the filtered environment variables to the output file
fs.writeFileSync(outputFilePath, outputContent, 'utf8');
console.log('Filtered environment variables have been written to the output file.');
} catch (error) {
console.error('Failed to process environment variables:', error);
}
}

async function main() {
await joinHyperchain();
}

main()
.then(() => {
console.log('Successfully joined hyperchain!');
})
.catch((e) => {
console.log(`Execution failed with error ${e}`);
});

0 comments on commit 2d65a96

Please sign in to comment.