Skip to content

Commit

Permalink
Merge branch 'alin/fewer-Serialize-derives' into 'master'
Browse files Browse the repository at this point in the history
chore: Don't unnecessarily derive Serialize/Deserialize for all types protos

Only a handful of proto types need to derive Serialize or Deserialize. 

See merge request dfinity-lab/public/ic!19586
  • Loading branch information
alin-at-dfinity committed Jun 1, 2024
2 parents 285ad88 + 426e9cf commit 5e86ee7
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 366 deletions.
13 changes: 12 additions & 1 deletion rs/protobuf/generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,18 @@ fn build_state_proto(def: &Path, out: &Path) {
/// Generates Rust structs from types Protobuf messages.
fn build_types_proto(def: &Path, out: &Path) {
let mut config = base_config(out, "types");
config.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]");
for path in [
".types.v1.CanisterId",
".types.v1.CatchUpPackage",
".types.v1.NiDkgId",
".types.v1.NodeId",
".types.v1.PrincipalId",
".types.v1.SubnetId",
".types.v1.ThresholdSignature",
".types.v1.ThresholdSignatureShare",
] {
config.type_attribute(path, "#[derive(serde::Serialize, serde::Deserialize)]");
}
config.type_attribute(".types.v1.CatchUpPackage", "#[derive(Eq, Hash)]");
config.type_attribute(".types.v1.SubnetId", "#[derive(Eq, Hash)]");
config.type_attribute(".types.v1.NiDkgId", "#[derive(Eq, Hash)]");
Expand Down
32 changes: 1 addition & 31 deletions rs/protobuf/src/gen/types/bitcoin.v1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Transaction {
Expand All @@ -11,7 +10,6 @@ pub struct Transaction {
#[prost(message, repeated, tag = "4")]
pub output: ::prost::alloc::vec::Vec<TxOut>,
}
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct TxIn {
Expand All @@ -24,7 +22,6 @@ pub struct TxIn {
#[prost(bytes = "vec", repeated, tag = "4")]
pub witness: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec<u8>>,
}
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct TxOut {
Expand All @@ -33,7 +30,6 @@ pub struct TxOut {
#[prost(bytes = "vec", tag = "2")]
pub script_pubkey: ::prost::alloc::vec::Vec<u8>,
}
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct OutPoint {
Expand All @@ -42,7 +38,6 @@ pub struct OutPoint {
#[prost(uint32, tag = "2")]
pub vout: u32,
}
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BlockHeader {
Expand All @@ -59,7 +54,6 @@ pub struct BlockHeader {
#[prost(uint32, tag = "6")]
pub nonce: u32,
}
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Block {
Expand All @@ -68,7 +62,6 @@ pub struct Block {
#[prost(message, repeated, tag = "2")]
pub txdata: ::prost::alloc::vec::Vec<Transaction>,
}
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SendTransactionRequest {
Expand All @@ -77,12 +70,10 @@ pub struct SendTransactionRequest {
#[prost(bytes = "vec", tag = "2")]
pub transaction: ::prost::alloc::vec::Vec<u8>,
}
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SendTransactionResponse {}
/// Wraps the different types of requests to the Bitcoin Adapter.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BitcoinAdapterRequestWrapper {
Expand All @@ -91,7 +82,6 @@ pub struct BitcoinAdapterRequestWrapper {
}
/// Nested message and enum types in `BitcoinAdapterRequestWrapper`.
pub mod bitcoin_adapter_request_wrapper {
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum R {
Expand All @@ -102,7 +92,6 @@ pub mod bitcoin_adapter_request_wrapper {
}
}
/// Wraps the different types of responses from the Bitcoin Adapter.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BitcoinAdapterResponseWrapper {
Expand All @@ -111,7 +100,6 @@ pub struct BitcoinAdapterResponseWrapper {
}
/// Nested message and enum types in `BitcoinAdapterResponseWrapper`.
pub mod bitcoin_adapter_response_wrapper {
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum R {
Expand All @@ -127,7 +115,6 @@ pub mod bitcoin_adapter_response_wrapper {
}
/// A Bitcoin Adapter request, used to store the requests in the
/// `ReplicatedState`.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BitcoinAdapterRequest {
Expand All @@ -141,7 +128,6 @@ pub struct BitcoinAdapterRequest {
}
/// A Bitcoin Adapter response, used to store the responses in the
/// `ReplicatedState`.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BitcoinAdapterResponse {
Expand All @@ -154,7 +140,6 @@ pub struct BitcoinAdapterResponse {
pub callback_id: u64,
}
/// A request to retrieve new blocks from the specified Bitcoin network.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetSuccessorsRequestInitial {
Expand All @@ -166,7 +151,6 @@ pub struct GetSuccessorsRequestInitial {
pub anchor: ::prost::alloc::vec::Vec<u8>,
}
/// A response containing new successor blocks from the Bitcoin network.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetSuccessorsResponseComplete {
Expand All @@ -176,7 +160,6 @@ pub struct GetSuccessorsResponseComplete {
pub next: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec<u8>>,
}
/// A `GetSucceessors` reject response containing additional information about the rejection.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetSuccessorsReject {
Expand All @@ -186,7 +169,6 @@ pub struct GetSuccessorsReject {
pub message: ::prost::alloc::string::String,
}
/// A `SendTransaction` reject response containing additional information about the rejection.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SendTransactionReject {
Expand All @@ -195,19 +177,7 @@ pub struct SendTransactionReject {
#[prost(string, tag = "2")]
pub message: ::prost::alloc::string::String,
}
#[derive(
serde::Serialize,
serde::Deserialize,
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration,
)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum Network {
Unspecified = 0,
Expand Down
4 changes: 0 additions & 4 deletions rs/protobuf/src/gen/types/messaging.xnet.v1.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/// State tree root hash.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CertificationContent {
#[prost(bytes = "vec", tag = "2")]
pub hash: ::prost::alloc::vec::Vec<u8>,
}
/// Certification of state tree root hash.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Certification {
Expand All @@ -19,7 +17,6 @@ pub struct Certification {
pub signature: ::core::option::Option<super::super::super::types::v1::ThresholdSignature>,
}
/// Certification signed by a single replica
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CertificationShare {
Expand All @@ -31,7 +28,6 @@ pub struct CertificationShare {
pub signature: ::core::option::Option<super::super::super::types::v1::ThresholdSignatureShare>,
}
/// XNet stream slice with certification and matching Merkle proof.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CertifiedStreamSlice {
Expand Down
50 changes: 3 additions & 47 deletions rs/protobuf/src/gen/types/registry.crypto.v1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// A list of subnets that can sign with this ECDSA key.
/// This allows replicas to route their signing requests to the right subnets.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EcdsaSigningSubnetList {
Expand All @@ -9,15 +8,13 @@ pub struct EcdsaSigningSubnetList {
}
/// A list of subnets that can sign with a given chain key.
/// This allows replicas to route their signing requests to the right subnets.
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ChainKeySigningSubnetList {
#[prost(message, repeated, tag = "1")]
pub subnets: ::prost::alloc::vec::Vec<super::super::super::types::v1::SubnetId>,
}
/// A public key. Described by its `AlgorithmId`, the key's value and proof data holding, e.g., a proof of possession (PoP).
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PublicKey {
Expand All @@ -34,14 +31,12 @@ pub struct PublicKey {
pub timestamp: ::core::option::Option<u64>,
}
/// DER-encoded X509 public key certificate
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct X509PublicKeyCert {
#[prost(bytes = "vec", tag = "1")]
pub certificate_der: ::prost::alloc::vec::Vec<u8>,
}
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EcdsaKeyId {
Expand All @@ -50,7 +45,6 @@ pub struct EcdsaKeyId {
#[prost(string, tag = "2")]
pub name: ::prost::alloc::string::String,
}
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SchnorrKeyId {
Expand All @@ -59,7 +53,6 @@ pub struct SchnorrKeyId {
#[prost(string, tag = "2")]
pub name: ::prost::alloc::string::String,
}
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct MasterPublicKeyId {
Expand All @@ -68,7 +61,6 @@ pub struct MasterPublicKeyId {
}
/// Nested message and enum types in `MasterPublicKeyId`.
pub mod master_public_key_id {
#[derive(serde::Serialize, serde::Deserialize)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum KeyId {
Expand All @@ -79,19 +71,7 @@ pub mod master_public_key_id {
}
}
/// An algorithm ID. This is used to specify the signature algorithm associated with a public key.
#[derive(
serde::Serialize,
serde::Deserialize,
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration,
)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum AlgorithmId {
Unspecified = 0,
Expand Down Expand Up @@ -172,19 +152,7 @@ impl AlgorithmId {
}
}
/// Types of curves that can be used for ECDSA signatures.
#[derive(
serde::Serialize,
serde::Deserialize,
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration,
)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum EcdsaCurve {
Unspecified = 0,
Expand All @@ -211,19 +179,7 @@ impl EcdsaCurve {
}
}
/// Types of curves that can be used for Schnorr signatures.
#[derive(
serde::Serialize,
serde::Deserialize,
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration,
)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum SchnorrAlgorithm {
Unspecified = 0,
Expand Down
Loading

0 comments on commit 5e86ee7

Please sign in to comment.