diff --git a/node/actors/network/src/proto/consensus.proto b/node/actors/network/src/proto/consensus.proto index 4414ada1..919b6d57 100644 --- a/node/actors/network/src/proto/consensus.proto +++ b/node/actors/network/src/proto/consensus.proto @@ -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 { diff --git a/node/actors/network/src/proto/gossip.proto b/node/actors/network/src/proto/gossip.proto index 757989e9..33e3d16a 100644 --- a/node/actors/network/src/proto/gossip.proto +++ b/node/actors/network/src/proto/gossip.proto @@ -2,7 +2,6 @@ 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"; @@ -10,7 +9,7 @@ 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 } diff --git a/node/libs/roles/src/attester/conv.rs b/node/libs/roles/src/attester/conv.rs index 7eb3c065..60d04102 100644 --- a/node/libs/roles/src/attester/conv.rs +++ b/node/libs/roles/src/attester/conv.rs @@ -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 { + 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 { @@ -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::(&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()), } } } diff --git a/node/libs/roles/src/proto/attester.proto b/node/libs/roles/src/proto/attester.proto index 49db5d31..bd30f4f5 100644 --- a/node/libs/roles/src/proto/attester.proto +++ b/node/libs/roles/src/proto/attester.proto @@ -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 @@ -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 { diff --git a/node/libs/roles/src/proto/common.proto b/node/libs/roles/src/proto/common.proto deleted file mode 100644 index 2d396fe6..00000000 --- a/node/libs/roles/src/proto/common.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; - -package zksync.roles.common; - -message GenesisHash { - optional bytes keccak256 = 1; // required -} \ No newline at end of file diff --git a/node/libs/roles/src/proto/validator.proto b/node/libs/roles/src/proto/validator.proto index 14108306..e3bab662 100644 --- a/node/libs/roles/src/proto/validator.proto +++ b/node/libs/roles/src/proto/validator.proto @@ -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 { @@ -38,6 +37,10 @@ message LeaderSelectionMode { } } +message GenesisHash { + optional bytes keccak256 = 1; // required +} + message PayloadHash { optional bytes keccak256 = 1; // required } @@ -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 } diff --git a/node/libs/roles/src/validator/conv.rs b/node/libs/roles/src/validator/conv.rs index 4609860c..8d6703b0 100644 --- a/node/libs/roles/src/validator/conv.rs +++ b/node/libs/roles/src/validator/conv.rs @@ -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 { Ok(Self(ByteFmt::decode(required(&r.keccak256)?)?)) }