Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(zk_toolbox): added support for setting attester committee defined in a separate file #2992

Merged
merged 17 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ jobs:

- name: Setup attester committee for the consensus chain
run: |
ci_run zk_inception consensus set-attester-committee --chain consensus &> ${{ env.INTEGRATION_TESTS_LOGS_DIR }}/consensus.log
ci_run zk_inception consensus set-attester-committee --chain consensus --from-genesis &> ${{ env.INTEGRATION_TESTS_LOGS_DIR }}/consensus.log

- name: Run integration tests
run: |
Expand Down
20 changes: 0 additions & 20 deletions Cargo.lock

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

9 changes: 4 additions & 5 deletions core/lib/protobuf_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,16 @@ pub fn read_optional_repr<P: ProtoRepr>(field: &Option<P>) -> Option<P::Type> {
.flatten()
}

pub fn decode_yaml_repr<T: ProtoRepr>(
/// Reads a yaml file.
pub fn read_yaml_repr<T: ProtoRepr>(
path: &PathBuf,
deny_unknown_fields: bool,
) -> anyhow::Result<T::Type> {
let yaml = std::fs::read_to_string(path).with_context(|| path.display().to_string())?;
let d = serde_yaml::Deserializer::from_str(&yaml);
let this: T = zksync_protobuf::serde::Deserialize {
zksync_protobuf::serde::Deserialize {
deny_unknown_fields,
}
.proto(d)?;
this.read()
.proto_repr_from_yaml::<T>(&yaml)
}

pub fn encode_yaml_repr<T: ProtoRepr>(value: &T::Type) -> anyhow::Result<Vec<u8>> {
Expand Down
17 changes: 7 additions & 10 deletions core/lib/protobuf_config/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{path::PathBuf, str::FromStr};

use zksync_protobuf::testonly::{test_encode_all_formats, ReprConv};

use crate::{decode_yaml_repr, proto};
use crate::{proto, read_yaml_repr};

/// Tests config <-> proto (boilerplate) conversions.
#[test]
Expand Down Expand Up @@ -60,14 +60,11 @@ fn test_encoding() {
#[test]
fn verify_file_parsing() {
let base_path = PathBuf::from_str("../../../etc/env/file_based/").unwrap();
decode_yaml_repr::<proto::general::GeneralConfig>(&base_path.join("general.yaml"), true)
.unwrap();
read_yaml_repr::<proto::general::GeneralConfig>(&base_path.join("general.yaml"), true).unwrap();
// It's allowed to have unknown fields in wallets, e.g. we keep private key for fee account
decode_yaml_repr::<proto::wallets::Wallets>(&base_path.join("wallets.yaml"), false).unwrap();
decode_yaml_repr::<proto::genesis::Genesis>(&base_path.join("genesis.yaml"), true).unwrap();
decode_yaml_repr::<proto::contracts::Contracts>(&base_path.join("contracts.yaml"), true)
.unwrap();
decode_yaml_repr::<proto::secrets::Secrets>(&base_path.join("secrets.yaml"), true).unwrap();
decode_yaml_repr::<proto::en::ExternalNode>(&base_path.join("external_node.yaml"), true)
.unwrap();
read_yaml_repr::<proto::wallets::Wallets>(&base_path.join("wallets.yaml"), false).unwrap();
read_yaml_repr::<proto::genesis::Genesis>(&base_path.join("genesis.yaml"), true).unwrap();
read_yaml_repr::<proto::contracts::Contracts>(&base_path.join("contracts.yaml"), true).unwrap();
read_yaml_repr::<proto::secrets::Secrets>(&base_path.join("secrets.yaml"), true).unwrap();
read_yaml_repr::<proto::en::ExternalNode>(&base_path.join("external_node.yaml"), true).unwrap();
}
34 changes: 22 additions & 12 deletions zk_toolbox/Cargo.lock

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

3 changes: 3 additions & 0 deletions zk_toolbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ zksync_protobuf_config = { path = "../core/lib/protobuf_config" }
zksync_basic_types = { path = "../core/lib/basic_types" }
zksync_consensus_roles = "=0.3.0"
zksync_consensus_crypto = "=0.3.0"
zksync_consensus_utils = "=0.3.0"
zksync_protobuf = "=0.3.0"
zksync_protobuf_build = "=0.3.0"

# External dependencies
anyhow = "1.0.82"
Expand All @@ -49,6 +51,7 @@ futures = "0.3.30"
human-panic = "2.0"
lazy_static = "1.4.0"
once_cell = "1.19.0"
prost = "0.12.1"
rand = "0.8.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions zk_toolbox/crates/config/src/consensus_secrets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use std::path::Path;

use xshell::Shell;
use zksync_config::configs::consensus::ConsensusSecrets;
use zksync_protobuf_config::decode_yaml_repr;
use zksync_protobuf_config::read_yaml_repr;

use crate::traits::ReadConfig;

impl ReadConfig for ConsensusSecrets {
fn read(shell: &Shell, path: impl AsRef<Path>) -> anyhow::Result<Self> {
let path = shell.current_dir().join(path);
decode_yaml_repr::<zksync_protobuf_config::proto::secrets::ConsensusSecrets>(&path, false)
read_yaml_repr::<zksync_protobuf_config::proto::secrets::ConsensusSecrets>(&path, false)
}
}
10 changes: 5 additions & 5 deletions zk_toolbox/crates/config/src/ecosystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,20 @@ impl EcosystemConfig {
.unwrap_or(self.default_chain.as_ref())
}

pub fn load_chain(&self, name: Option<String>) -> Option<ChainConfig> {
pub fn load_chain(&self, name: Option<String>) -> anyhow::Result<ChainConfig> {
let name = name.unwrap_or(self.default_chain.clone());
self.load_chain_inner(&name)
}

pub fn load_current_chain(&self) -> Option<ChainConfig> {
pub fn load_current_chain(&self) -> anyhow::Result<ChainConfig> {
self.load_chain_inner(self.current_chain())
}

fn load_chain_inner(&self, name: &str) -> Option<ChainConfig> {
fn load_chain_inner(&self, name: &str) -> anyhow::Result<ChainConfig> {
let path = self.chains.join(name).join(CONFIG_NAME);
let config = ChainConfigInternal::read(self.get_shell(), path.clone()).ok()?;
let config = ChainConfigInternal::read(self.get_shell(), path.clone())?;

Some(ChainConfig {
Ok(ChainConfig {
id: config.id,
name: config.name,
chain_id: config.chain_id,
Expand Down
4 changes: 2 additions & 2 deletions zk_toolbox/crates/config/src/external_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::Path;

use xshell::Shell;
pub use zksync_config::configs::en_config::ENConfig;
use zksync_protobuf_config::{decode_yaml_repr, encode_yaml_repr};
use zksync_protobuf_config::{encode_yaml_repr, read_yaml_repr};

use crate::{
consts::EN_CONFIG_FILE,
Expand All @@ -23,6 +23,6 @@ impl SaveConfig for ENConfig {
impl ReadConfig for ENConfig {
fn read(shell: &Shell, path: impl AsRef<Path>) -> anyhow::Result<Self> {
let path = shell.current_dir().join(path);
decode_yaml_repr::<zksync_protobuf_config::proto::en::ExternalNode>(&path, false)
read_yaml_repr::<zksync_protobuf_config::proto::en::ExternalNode>(&path, false)
}
}
4 changes: 2 additions & 2 deletions zk_toolbox/crates/config/src/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use url::Url;
use xshell::Shell;
use zksync_config::configs::object_store::ObjectStoreMode;
pub use zksync_config::configs::GeneralConfig;
use zksync_protobuf_config::{decode_yaml_repr, encode_yaml_repr};
use zksync_protobuf_config::{encode_yaml_repr, read_yaml_repr};

use crate::{
consts::GENERAL_FILE,
Expand Down Expand Up @@ -137,7 +137,7 @@ impl SaveConfig for GeneralConfig {
impl ReadConfig for GeneralConfig {
fn read(shell: &Shell, path: impl AsRef<Path>) -> anyhow::Result<Self> {
let path = shell.current_dir().join(path);
decode_yaml_repr::<zksync_protobuf_config::proto::general::GeneralConfig>(&path, false)
read_yaml_repr::<zksync_protobuf_config::proto::general::GeneralConfig>(&path, false)
}
}

Expand Down
4 changes: 2 additions & 2 deletions zk_toolbox/crates/config/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::Path;
use xshell::Shell;
use zksync_basic_types::L1ChainId;
pub use zksync_config::GenesisConfig;
use zksync_protobuf_config::{decode_yaml_repr, encode_yaml_repr};
use zksync_protobuf_config::{encode_yaml_repr, read_yaml_repr};

use crate::{
consts::GENESIS_FILE,
Expand Down Expand Up @@ -32,6 +32,6 @@ impl SaveConfig for GenesisConfig {
impl ReadConfig for GenesisConfig {
fn read(shell: &Shell, path: impl AsRef<Path>) -> anyhow::Result<Self> {
let path = shell.current_dir().join(path);
decode_yaml_repr::<zksync_protobuf_config::proto::genesis::Genesis>(&path, false)
read_yaml_repr::<zksync_protobuf_config::proto::genesis::Genesis>(&path, false)
}
}
2 changes: 1 addition & 1 deletion zk_toolbox/crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub use manipulations::*;
pub use secrets::*;
pub use wallet_creation::*;
pub use wallets::*;
pub use zksync_protobuf_config::{decode_yaml_repr, encode_yaml_repr};
pub use zksync_protobuf_config::{encode_yaml_repr, read_yaml_repr};

mod apps;
mod chain;
Expand Down
4 changes: 2 additions & 2 deletions zk_toolbox/crates/config/src/secrets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use common::db::DatabaseConfig;
use xshell::Shell;
use zksync_basic_types::url::SensitiveUrl;
pub use zksync_config::configs::Secrets as SecretsConfig;
use zksync_protobuf_config::{decode_yaml_repr, encode_yaml_repr};
use zksync_protobuf_config::{encode_yaml_repr, read_yaml_repr};

use crate::{
consts::SECRETS_FILE,
Expand Down Expand Up @@ -59,6 +59,6 @@ impl SaveConfig for SecretsConfig {
impl ReadConfig for SecretsConfig {
fn read(shell: &Shell, path: impl AsRef<Path>) -> anyhow::Result<Self> {
let path = shell.current_dir().join(path);
decode_yaml_repr::<zksync_protobuf_config::proto::secrets::Secrets>(&path, false)
read_yaml_repr::<zksync_protobuf_config::proto::secrets::Secrets>(&path, false)
}
}
Loading
Loading