From 435cd05ee12c0edc62685d75f160ad19e396a069 Mon Sep 17 00:00:00 2001 From: Moshe Shababo <17073733+moshababo@users.noreply.github.com> Date: Sun, 28 Jul 2024 16:17:35 -0700 Subject: [PATCH] Update committee data types --- node/libs/roles/src/attester/conv.rs | 27 +++++++++++++--- node/libs/roles/src/attester/messages/msg.rs | 5 +++ node/libs/roles/src/proto/attester.proto | 4 +++ node/libs/roles/src/proto/validator.proto | 5 +++ node/libs/roles/src/validator/conv.rs | 31 +++++++++++++++---- .../roles/src/validator/messages/consensus.rs | 8 +++++ node/libs/roles/src/validator/testonly.rs | 3 ++ 7 files changed, 73 insertions(+), 10 deletions(-) diff --git a/node/libs/roles/src/attester/conv.rs b/node/libs/roles/src/attester/conv.rs index e3beec41..6321a67f 100644 --- a/node/libs/roles/src/attester/conv.rs +++ b/node/libs/roles/src/attester/conv.rs @@ -1,7 +1,4 @@ -use super::{ - AggregateSignature, Batch, BatchHash, BatchNumber, BatchQC, Msg, MsgHash, MultiSig, PublicKey, - Signature, Signed, Signers, SyncBatch, WeightedAttester, -}; +use super::{AggregateSignature, AttesterCommittee, Batch, BatchHash, BatchNumber, BatchQC, Msg, MsgHash, MultiSig, PublicKey, Signature, Signed, Signers, SyncBatch, WeightedAttester}; use crate::{ proto::attester::{self as proto, Attestation}, validator::Payload, @@ -142,6 +139,28 @@ impl ProtoFmt for WeightedAttester { } } +impl ProtoFmt for AttesterCommittee { + type Proto = proto::AttesterCommittee; + + fn read(r: &Self::Proto) -> anyhow::Result { + Ok(Self { + members: r + .members + .iter() + .map(ProtoFmt::read) + .collect::>() + .context("members")?, + }) + } + + fn build(&self) -> Self::Proto { + Self::Proto { + members: self.members.iter().map(|x| x.build()).collect(), + } + } +} + + impl ProtoFmt for Signers { type Proto = zksync_protobuf::proto::std::BitVector; diff --git a/node/libs/roles/src/attester/messages/msg.rs b/node/libs/roles/src/attester/messages/msg.rs index cdf8b1e6..9ffd6d66 100644 --- a/node/libs/roles/src/attester/messages/msg.rs +++ b/node/libs/roles/src/attester/messages/msg.rs @@ -276,3 +276,8 @@ pub struct WeightedAttester { /// Voting weight. pub type Weight = u64; + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct AttesterCommittee { + pub members: Vec +} diff --git a/node/libs/roles/src/proto/attester.proto b/node/libs/roles/src/proto/attester.proto index 38743353..e5abc1db 100644 --- a/node/libs/roles/src/proto/attester.proto +++ b/node/libs/roles/src/proto/attester.proto @@ -62,6 +62,10 @@ message WeightedAttester { optional uint64 weight = 2; // required } +message AttesterCommittee { + repeated WeightedAttester members = 1; // required +} + message Attestation { optional PublicKey key = 1; // required optional Signature sig = 2; // required diff --git a/node/libs/roles/src/proto/validator.proto b/node/libs/roles/src/proto/validator.proto index 969705c6..26f85353 100644 --- a/node/libs/roles/src/proto/validator.proto +++ b/node/libs/roles/src/proto/validator.proto @@ -198,4 +198,9 @@ message AggregateSignature { message WeightedValidator { optional PublicKey key = 1; // required optional uint64 weight = 2; // required + optional Signature pop = 3; // required +} + +message ValidatorCommittee { + repeated WeightedValidator members = 1; // required } diff --git a/node/libs/roles/src/validator/conv.rs b/node/libs/roles/src/validator/conv.rs index 8d6703b0..2a0d656b 100644 --- a/node/libs/roles/src/validator/conv.rs +++ b/node/libs/roles/src/validator/conv.rs @@ -1,9 +1,4 @@ -use super::{ - AggregateSignature, BlockHeader, BlockNumber, ChainId, CommitQC, Committee, ConsensusMsg, - FinalBlock, ForkNumber, Genesis, GenesisHash, GenesisRaw, LeaderCommit, LeaderPrepare, Msg, - MsgHash, NetAddress, Payload, PayloadHash, Phase, PrepareQC, ProtocolVersion, PublicKey, - ReplicaCommit, ReplicaPrepare, Signature, Signed, Signers, View, ViewNumber, WeightedValidator, -}; +use super::{AggregateSignature, BlockHeader, BlockNumber, ChainId, CommitQC, Committee, ConsensusMsg, FinalBlock, ForkNumber, Genesis, GenesisHash, GenesisRaw, LeaderCommit, LeaderPrepare, Msg, MsgHash, NetAddress, Payload, PayloadHash, Phase, PrepareQC, ProtocolVersion, PublicKey, ReplicaCommit, ReplicaPrepare, Signature, Signed, Signers, ValidatorCommittee, View, ViewNumber, WeightedValidator}; use crate::{ attester::{self, WeightedAttester}, node::SessionId, @@ -525,6 +520,7 @@ impl ProtoFmt for WeightedValidator { Ok(Self { key: read_required(&r.key).context("key")?, weight: *required(&r.weight).context("weight")?, + pop: read_required(&r.pop).context("pop")?, }) } @@ -532,6 +528,29 @@ impl ProtoFmt for WeightedValidator { Self::Proto { key: Some(self.key.build()), weight: Some(self.weight), + pop: Some(self.pop.build()), + } + } +} + +impl ProtoFmt for ValidatorCommittee { + type Proto = proto::ValidatorCommittee; + + fn read(r: &Self::Proto) -> anyhow::Result { + Ok(Self { + members: r + .members + .iter() + .map(ProtoFmt::read) + .collect::>() + .context("members")?, + }) + } + + fn build(&self) -> Self::Proto { + Self::Proto { + members: self.members.iter().map(|x| x.build()).collect(), } } } + diff --git a/node/libs/roles/src/validator/messages/consensus.rs b/node/libs/roles/src/validator/messages/consensus.rs index 71738790..d1f4c7ec 100644 --- a/node/libs/roles/src/validator/messages/consensus.rs +++ b/node/libs/roles/src/validator/messages/consensus.rs @@ -528,7 +528,15 @@ pub struct WeightedValidator { pub key: validator::PublicKey, /// Validator weight inside the Committee. pub weight: Weight, + /// Proof-of-possession (PoP) of the validator's public key (a signature over the public key) + pub pop: validator::Signature, } /// Voting weight; pub type Weight = u64; + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ValidatorCommittee { + pub members: Vec +} + diff --git a/node/libs/roles/src/validator/testonly.rs b/node/libs/roles/src/validator/testonly.rs index f4ce2b35..5a8a6bf9 100644 --- a/node/libs/roles/src/validator/testonly.rs +++ b/node/libs/roles/src/validator/testonly.rs @@ -17,6 +17,7 @@ use rand::{ }; use std::sync::Arc; use zksync_concurrency::time; +use zksync_consensus_crypto::ByteFmt; use zksync_consensus_utils::enum_util::Variant; /// Test setup specification. @@ -173,6 +174,7 @@ impl From for Setup { WeightedValidator { key: k.public(), weight: *w, + pop: Signature::decode(&vec![]).unwrap(), // TODO(moshababo): implement } })) .unwrap(), @@ -437,6 +439,7 @@ impl Distribution for Standard { let public_keys = (0..count).map(|_| WeightedValidator { key: rng.gen(), weight: 1, + pop: Signature::decode(&vec![]).unwrap(), // TODO(moshababo): implement }); Committee::new(public_keys).unwrap() }