Skip to content

Commit

Permalink
Merge branch 'main' into bh/ci-test
Browse files Browse the repository at this point in the history
  • Loading branch information
benceharomi authored Jul 5, 2024
2 parents ec1a1c1 + 217a4ba commit d5d2273
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 51 deletions.
10 changes: 5 additions & 5 deletions core/lib/config/src/configs/wallets.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use zksync_basic_types::{Address, H160, H256};
use zksync_crypto_primitives::K256PrivateKey;

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct AddressWallet {
address: Address,
}
Expand All @@ -16,7 +16,7 @@ impl AddressWallet {
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct Wallet {
address: Address,
private_key: K256PrivateKey,
Expand Down Expand Up @@ -58,18 +58,18 @@ impl Wallet {
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct EthSender {
pub operator: Wallet,
pub blob_operator: Option<Wallet>,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct StateKeeper {
pub fee_account: AddressWallet,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct Wallets {
pub eth_sender: Option<EthSender>,
pub state_keeper: Option<StateKeeper>,
Expand Down
64 changes: 59 additions & 5 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use zksync_basic_types::{
L1BatchNumber, L1ChainId, L2ChainId,
};
use zksync_consensus_utils::EncodeDist;
use zksync_crypto_primitives::K256PrivateKey;

use crate::configs::{self, eth_sender::PubdataSendingMode};

Expand Down Expand Up @@ -682,11 +683,11 @@ impl Distribution<configs::GenesisConfig> for EncodeDist {
.unwrap(),
patch: VersionPatch(rng.gen()),
}),
genesis_root_hash: rng.gen(),
rollup_last_leaf_index: self.sample(rng),
genesis_commitment: rng.gen(),
bootloader_hash: rng.gen(),
default_aa_hash: rng.gen(),
genesis_root_hash: Some(rng.gen()),
rollup_last_leaf_index: Some(self.sample(rng)),
genesis_commitment: Some(rng.gen()),
bootloader_hash: Some(rng.gen()),
default_aa_hash: Some(rng.gen()),
fee_account: rng.gen(),
l1_chain_id: L1ChainId(self.sample(rng)),
l2_chain_id: L2ChainId::default(),
Expand Down Expand Up @@ -805,3 +806,56 @@ impl Distribution<configs::secrets::Secrets> for EncodeDist {
}
}
}

impl Distribution<configs::wallets::Wallet> for EncodeDist {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> configs::wallets::Wallet {
configs::wallets::Wallet::new(K256PrivateKey::from_bytes(rng.gen()).unwrap())
}
}

impl Distribution<configs::wallets::AddressWallet> for EncodeDist {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> configs::wallets::AddressWallet {
configs::wallets::AddressWallet::from_address(rng.gen())
}
}

impl Distribution<configs::wallets::StateKeeper> for EncodeDist {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> configs::wallets::StateKeeper {
configs::wallets::StateKeeper {
fee_account: self.sample(rng),
}
}
}

impl Distribution<configs::wallets::EthSender> for EncodeDist {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> configs::wallets::EthSender {
configs::wallets::EthSender {
operator: self.sample(rng),
blob_operator: self.sample_opt(|| self.sample(rng)),
}
}
}

impl Distribution<configs::wallets::Wallets> for EncodeDist {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> configs::wallets::Wallets {
configs::wallets::Wallets {
state_keeper: self.sample_opt(|| self.sample(rng)),
eth_sender: self.sample_opt(|| self.sample(rng)),
}
}
}

impl Distribution<configs::en_config::ENConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> configs::en_config::ENConfig {
configs::en_config::ENConfig {
l2_chain_id: L2ChainId::default(),
l1_chain_id: L1ChainId(rng.gen()),
main_node_url: format!("localhost:{}", rng.gen::<u16>()).parse().unwrap(),
l1_batch_commit_data_generator_mode: match rng.gen_range(0..2) {
0 => L1BatchCommitmentMode::Rollup,
_ => L1BatchCommitmentMode::Validium,
},
main_node_rate_limit_rps: self.sample_opt(|| rng.gen()),
}
}
}
2 changes: 1 addition & 1 deletion core/lib/crypto_primitives/src/ecdsa_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Public = H512;
///
/// Provides a safe to use `Debug` implementation (outputting the address corresponding to the key).
/// The key is zeroized on drop.
#[derive(Clone)]
#[derive(Clone, PartialEq)]
pub struct K256PrivateKey(SecretKey);

impl fmt::Debug for K256PrivateKey {
Expand Down

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

This file was deleted.

10 changes: 4 additions & 6 deletions core/lib/dal/src/vm_runner_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@ pub struct VmRunnerDal<'c, 'a> {
impl VmRunnerDal<'_, '_> {
pub async fn get_protective_reads_latest_processed_batch(
&mut self,
default_batch: L1BatchNumber,
) -> DalResult<L1BatchNumber> {
) -> DalResult<Option<L1BatchNumber>> {
let row = sqlx::query!(
r#"
SELECT
COALESCE(MAX(l1_batch_number), $1) AS "last_processed_l1_batch!"
MAX(l1_batch_number) AS "last_processed_l1_batch"
FROM
vm_runner_protective_reads
"#,
default_batch.0 as i32
"#
)
.instrument("get_protective_reads_latest_processed_batch")
.report_latency()
.fetch_one(self.storage)
.await?;
Ok(L1BatchNumber(row.last_processed_l1_batch as u32))
Ok(row.last_processed_l1_batch.map(|n| L1BatchNumber(n as u32)))
}

pub async fn get_protective_reads_last_ready_batch(
Expand Down
2 changes: 1 addition & 1 deletion core/lib/protobuf_config/src/en.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl ProtoRepr for proto::ExternalNode {
)
.into(),
),
main_node_rate_limit_rps: this.main_node_rate_limit_rps.map(|a| a.get() as u32),
main_node_rate_limit_rps: this.main_node_rate_limit_rps.map(|a| a.get() as u64),
}
}
}
1 change: 0 additions & 1 deletion core/lib/protobuf_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ mod secrets;
mod snapshots_creator;

mod snapshot_recovery;
pub mod testonly;
#[cfg(test)]
mod tests;
mod utils;
Expand Down
2 changes: 1 addition & 1 deletion core/lib/protobuf_config/src/proto/config/en.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ message ExternalNode {
optional string main_node_url = 1; // required
optional uint64 l2_chain_id = 2; // required
optional uint64 l1_chain_id = 3; // required
optional uint32 main_node_rate_limit_rps = 6; // optional
optional uint64 main_node_rate_limit_rps = 6; // optional
optional config.genesis.L1BatchCommitDataGeneratorMode l1_batch_commit_data_generator_mode = 7; // optional, default to rollup
}
1 change: 0 additions & 1 deletion core/lib/protobuf_config/src/testonly.rs

This file was deleted.

3 changes: 3 additions & 0 deletions core/lib/protobuf_config/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ fn test_encoding() {
test_encode_all_formats::<ReprConv<proto::prover::ProofDataHandler>>(rng);
test_encode_all_formats::<ReprConv<proto::snapshot_creator::SnapshotsCreator>>(rng);
test_encode_all_formats::<ReprConv<proto::observability::Observability>>(rng);
test_encode_all_formats::<ReprConv<proto::wallets::Wallets>>(rng);
test_encode_all_formats::<ReprConv<proto::genesis::Genesis>>(rng);
test_encode_all_formats::<ReprConv<proto::en::ExternalNode>>(rng);
}

#[test]
Expand Down
12 changes: 10 additions & 2 deletions core/lib/protobuf_config/src/wallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,20 @@ impl ProtoRepr for proto::Wallets {
.as_ref()
.map(|blob| proto::PrivateKeyWallet {
address: Some(format!("{:?}", blob.address())),
private_key: Some(format!("{:?}", blob.private_key())),
private_key: Some(hex::encode(
blob.private_key().expose_secret().secret_bytes(),
)),
});
(
Some(proto::PrivateKeyWallet {
address: Some(format!("{:?}", eth_sender.operator.address())),
private_key: Some(format!("{:?}", eth_sender.operator.private_key())),
private_key: Some(hex::encode(
eth_sender
.operator
.private_key()
.expose_secret()
.secret_bytes(),
)),
}),
blob,
)
Expand Down
3 changes: 2 additions & 1 deletion core/node/metadata_calculator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,10 @@ async fn expected_tree_hash(pool: &ConnectionPool<Core>, sealed_protective_reads
} else {
storage
.vm_runner_dal()
.get_protective_reads_latest_processed_batch(L1BatchNumber(0))
.get_protective_reads_latest_processed_batch()
.await
.unwrap()
.unwrap_or_default()
};
let mut all_logs = vec![];
for i in 0..=processed_l1_batch_number.0 {
Expand Down
8 changes: 5 additions & 3 deletions core/node/metadata_calculator/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,10 @@ impl TreeUpdater {
} else {
storage
.vm_runner_dal()
.get_protective_reads_latest_processed_batch(L1BatchNumber(0))
.get_protective_reads_latest_processed_batch()
.await
.context("failed loading latest L1 batch number with protective reads")?
.unwrap_or_default()
};
drop(storage);

Expand Down Expand Up @@ -423,8 +424,9 @@ impl AsyncTree {

let current_db_batch = storage
.vm_runner_dal()
.get_protective_reads_latest_processed_batch(L1BatchNumber(0))
.await?;
.get_protective_reads_latest_processed_batch()
.await?
.unwrap_or_default();
let last_l1_batch_with_tree_data = storage
.blocks_dal()
.get_last_l1_batch_number_with_tree_data()
Expand Down
5 changes: 3 additions & 2 deletions core/node/vm_runner/src/impls/protective_reads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ impl VmRunnerIo for ProtectiveReadsIo {
) -> anyhow::Result<L1BatchNumber> {
Ok(conn
.vm_runner_dal()
.get_protective_reads_latest_processed_batch(self.first_processed_batch)
.await?)
.get_protective_reads_latest_processed_batch()
.await?
.unwrap_or(self.first_processed_batch))
}

async fn last_ready_to_be_loaded_batch(
Expand Down

0 comments on commit d5d2273

Please sign in to comment.