Skip to content

Commit

Permalink
BFT-498: Remove common.proto
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh committed Jul 26, 2024
1 parent b835dff commit 412cf7b
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 18 deletions.
3 changes: 1 addition & 2 deletions node/actors/network/src/proto/consensus.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ syntax = "proto3";

package zksync.network.consensus;

import "zksync/roles/common.proto";
import "zksync/roles/validator.proto";
import "zksync/std.proto";

// First message exchanged in the encrypted session.
message Handshake {
optional roles.validator.Signed session_id = 1; // required
optional roles.common.GenesisHash genesis = 2; // required
optional roles.validator.GenesisHash genesis = 2; // required
}

message ConsensusReq {
Expand Down
3 changes: 1 addition & 2 deletions node/actors/network/src/proto/gossip.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ syntax = "proto3";

package zksync.network.gossip;

import "zksync/roles/common.proto";
import "zksync/roles/node.proto";
import "zksync/roles/validator.proto";
import "zksync/roles/attester.proto";

// First message exchanged in the encrypted session.
message Handshake {
optional roles.node.Signed session_id = 1; // required
optional roles.common.GenesisHash genesis = 3; // required
optional roles.validator.GenesisHash genesis = 3; // required
optional bool is_static = 2; // required
}

Expand Down
27 changes: 25 additions & 2 deletions node/libs/roles/src/attester/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ use zksync_consensus_crypto::ByteFmt;
use zksync_consensus_utils::enum_util::Variant;
use zksync_protobuf::{read_map, read_required, required, ProtoFmt};

// This is here because `attester::GenesisHash` is a type alias for `validator::GenesisHash`,
// and `validator::GenesisHash` serializes to the type in `validator.proto`. We can't import
// `validator.proto` into `attester.proto` because it would be circular, and we can't move
// `GenesisHash` to a separate `common.proto` file because the compatibility checker complains
// about the change in package name. This way the massaging from one type to another is limited
// to here, but in the domain model we can work with the same types.
struct GenesisHashWrapper(super::GenesisHash);

impl ProtoFmt for GenesisHashWrapper {
type Proto = proto::GenesisHash;
fn read(r: &Self::Proto) -> anyhow::Result<Self> {
let hash = super::GenesisHash(ByteFmt::decode(required(&r.keccak256)?)?);
Ok(Self(hash))
}
fn build(&self) -> Self::Proto {
Self::Proto {
keccak256: self.0.build().keccak256,
}
}
}

impl ProtoFmt for BatchHash {
type Proto = proto::BatchHash;
fn read(r: &Self::Proto) -> anyhow::Result<Self> {
Expand All @@ -29,14 +50,16 @@ impl ProtoFmt for Batch {
Ok(Self {
number: BatchNumber(*required(&r.number).context("number")?),
hash: read_required(&r.hash).context("hash")?,
genesis: read_required(&r.genesis).context("genesis")?,
genesis: read_required::<GenesisHashWrapper>(&r.genesis)
.context("genesis")?
.0,
})
}
fn build(&self) -> Self::Proto {
Self::Proto {
number: Some(self.number.0),
hash: Some(self.hash.build()),
genesis: Some(self.genesis.build()),
genesis: Some(GenesisHashWrapper(self.genesis).build()),
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions node/libs/roles/src/proto/attester.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ syntax = "proto3";
package zksync.roles.attester;

import "zksync/std.proto";
import "zksync/roles/common.proto";

message SyncBatch {
optional uint64 number = 1; // required
Expand All @@ -15,10 +14,14 @@ message BatchHash {
optional bytes keccak256 = 1; // required
}

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

message Batch {
optional uint64 number = 1; // required
optional BatchHash hash = 2; // required
optional common.GenesisHash genesis = 3; // required
optional GenesisHash genesis = 3; // required
}

message BatchQC {
Expand Down
7 changes: 0 additions & 7 deletions node/libs/roles/src/proto/common.proto

This file was deleted.

7 changes: 5 additions & 2 deletions node/libs/roles/src/proto/validator.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ syntax = "proto3";
package zksync.roles.validator;

import "zksync/std.proto";
import "zksync/roles/common.proto";
import "zksync/roles/attester.proto";

message Genesis {
Expand Down Expand Up @@ -38,6 +37,10 @@ message LeaderSelectionMode {
}
}

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

message PayloadHash {
optional bytes keccak256 = 1; // required
}
Expand All @@ -57,7 +60,7 @@ message FinalBlock {
message View {
reserved 1,2;
reserved "protocol_version","fork";
optional common.GenesisHash genesis = 4; // required
optional GenesisHash genesis = 4; // required
optional uint64 number = 3; // required; ViewNumber
}

Expand Down
2 changes: 1 addition & 1 deletion node/libs/roles/src/validator/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl ProtoFmt for Genesis {
}

impl ProtoFmt for GenesisHash {
type Proto = crate::proto::common::GenesisHash;
type Proto = proto::GenesisHash;
fn read(r: &Self::Proto) -> anyhow::Result<Self> {
Ok(Self(ByteFmt::decode(required(&r.keccak256)?)?))
}
Expand Down

0 comments on commit 412cf7b

Please sign in to comment.