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

Added support for splitting proto packages into multiple files #162

Merged
merged 6 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ serde_json = "1.0.95"
serde_yaml = "0.9"
sha3 = "0.10.8"
snow = "0.9.3"
syn = "2.0.17"
syn = { version = "2.0.17", features = ["extra-traits"] }
tempfile = "3"
test-casing = "0.1.0"
thiserror = "1.0.40"
Expand Down
3 changes: 1 addition & 2 deletions node/actors/network/src/gossip/batch_votes.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//! Global state distributed by active attesters, observed by all the nodes in the network.
use super::metrics;
use crate::watch::Watch;
use std::{collections::HashSet, fmt, sync::Arc};
use zksync_concurrency::sync;
use zksync_consensus_roles::attester;

use super::metrics;

#[derive(Debug, Default)]
pub(super) struct BatchUpdateStats {
num_added: usize,
Expand Down
20 changes: 18 additions & 2 deletions node/libs/protobuf_build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ impl Config {
.join(RustName::ident("prost"));
config.prost_path(prost_path.to_string());
config.skip_protoc_run();
let mut extern_paths = HashMap::new();
for (root_path, manifest) in self.dependencies.iter().zip(&dependency_manifests) {
let descriptor = &direct_dependency_descriptors[&manifest.descriptor_path];
// ^ Indexing is safe by construction.
Expand All @@ -329,15 +330,30 @@ impl Config {
.relative_to(&manifest.proto_root.to_name()?)
.unwrap();
let rust_path = root_path.clone().join(proto_rel.to_rust_module()?);
config.extern_path(format!(".{}", file.package()), rust_path.to_string());
match extern_paths.insert(file.package(), rust_path.clone()) {
// If missing, add to config.
None => {
config.extern_path(format!(".{}", file.package()), rust_path.to_string());
}
// If already present, make sure that it is the same.
Some(old) => anyhow::ensure!(
rust_path == old,
"ambiguous rust path for proto package {}",
file.package()
),
}
}
}
let module = prost_build::Module::from_parts([""]);
for file in &descriptor.file {
let code = config
.generate(vec![(module.clone(), file.clone())])
.context("generation failed")?;
let code = &code[&module];
// It may happen that the proto package is empty,
// in which case no code gets generated.
let Some(code) = code.get(&module) else {
continue;
};
let code = syn::parse_str(code).with_context(|| {
format!("prost_build generated invalid code for {}", file.name())
})?;
Expand Down
2 changes: 1 addition & 1 deletion node/libs/protobuf_build/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl fmt::Display for ProtoPath {
/// generated code is location agnostic (it can be embedded in an arbitrary module within the crate),
/// you need to manually (in the Config) specify the rust modules containing the generated code
/// of the dependencies, so that it can be referenced from the newly generated code.
#[derive(Clone)]
#[derive(Clone, PartialEq)]
pub struct RustName(syn::Path);

impl RustName {
Expand Down
83 changes: 2 additions & 81 deletions node/libs/roles/src/proto/attester.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,5 @@ syntax = "proto3";

package zksync.roles.attester;

import "zksync/std.proto";

message SyncBatch {
optional uint64 number = 1; // required
repeated bytes payloads = 2; // required
optional bytes proof = 3; // required
}

message BatchHash {
optional bytes keccak256 = 1; // required
}


message Batch {
optional uint64 number = 1; // required
optional BatchHash hash = 2; // required
}

message BatchQC {
reserved 2, 3;
reserved "signers", "sig";

// TODO: de-deprecate these when we move back to using BLS aggregates,
// or consider the ones at the bottom.
// optional std.BitVector signers = 2; // required
// optional AggregateSignature sig = 3; // required

optional Batch msg = 1; // required
repeated Attestation signatures = 4;
}

message Msg {
oneof t { // required
Batch batch = 4;
}
}

message Signed {
optional Msg msg = 1; // required
optional PublicKey key = 2; // required
optional Signature sig = 3; // required
}

message PublicKey {
reserved 1;
reserved "bn254";
optional bytes secp256k1 = 2; // required
}

message Signature {
reserved 1;
reserved "bn254";
optional bytes secp256k1 = 2; // required
}

message WeightedAttester {
optional PublicKey key = 1; // required
optional uint64 weight = 2; // required
}

message Attestation {
optional PublicKey key = 1; // required
optional Signature sig = 2; // required
}

message MsgHash {
optional bytes keccak256 = 1; // required
}

// TODO: Placeholder for EIP-2537
message AggregateSignature {
reserved 1, 2;
reserved "bn254", "secp256k1";
optional bytes bls12_381 = 3; // required
}

// TODO: Placeholder for EIP-2537
message AggregateMultiSig {
optional std.BitVector signers = 1; // required
optional AggregateSignature sig = 2; // required
}
import public "zksync/roles/attester/keys.proto";
import public "zksync/roles/attester/messages.proto";
40 changes: 40 additions & 0 deletions node/libs/roles/src/proto/attester/keys.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
syntax = "proto3";

package zksync.roles.attester;

import "zksync/std.proto";

message PublicKey {
reserved 1;
reserved "bn254";
optional bytes secp256k1 = 2; // required
}

message Signature {
reserved 1;
reserved "bn254";
optional bytes secp256k1 = 2; // required
}

// TODO: Placeholder for EIP-2537
message AggregateSignature {
reserved 1, 2;
reserved "bn254", "secp256k1";
optional bytes bls12_381 = 3; // required
}

// TODO: Placeholder for EIP-2537
message AggregateMultiSig {
optional std.BitVector signers = 1; // required
optional AggregateSignature sig = 2; // required
}

message WeightedAttester {
optional PublicKey key = 1; // required
optional uint64 weight = 2; // required
}

message Attestation {
optional PublicKey key = 1; // required
optional Signature sig = 2; // required
}
50 changes: 50 additions & 0 deletions node/libs/roles/src/proto/attester/messages.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
syntax = "proto3";

package zksync.roles.attester;

import "zksync/roles/attester/keys.proto";
import "zksync/roles/validator/genesis.proto";

message SyncBatch {
optional uint64 number = 1; // required
repeated bytes payloads = 2; // required
optional bytes proof = 3; // required
}

message BatchHash {
optional bytes keccak256 = 1; // required
}

message Batch {
optional uint64 number = 1; // required
optional BatchHash hash = 2; // required
}

message BatchQC {
reserved 2, 3;
reserved "signers", "sig";

// TODO: de-deprecate these when we move back to using BLS aggregates,
// or consider using `AggregateMultiSig`
// optional std.BitVector signers = 2; // required
// optional AggregateSignature sig = 3; // required

optional Batch msg = 1; // required
repeated Attestation signatures = 4;
}

message Msg {
oneof t { // required
Batch batch = 4;
}
}

message Signed {
optional Msg msg = 1; // required
optional PublicKey key = 2; // required
optional Signature sig = 3; // required
}

message MsgHash {
optional bytes keccak256 = 1; // required
}
Loading
Loading