Skip to content

Commit

Permalink
Update committee data types
Browse files Browse the repository at this point in the history
  • Loading branch information
moshababo committed Jul 28, 2024
1 parent 0d27fcf commit 435cd05
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 10 deletions.
27 changes: 23 additions & 4 deletions node/libs/roles/src/attester/conv.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -142,6 +139,28 @@ impl ProtoFmt for WeightedAttester {
}
}

impl ProtoFmt for AttesterCommittee {
type Proto = proto::AttesterCommittee;

fn read(r: &Self::Proto) -> anyhow::Result<Self> {
Ok(Self {
members: r
.members
.iter()
.map(ProtoFmt::read)
.collect::<Result<_, _>>()
.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;

Expand Down
5 changes: 5 additions & 0 deletions node/libs/roles/src/attester/messages/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,8 @@ pub struct WeightedAttester {

/// Voting weight.
pub type Weight = u64;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AttesterCommittee {
pub members: Vec<WeightedAttester>
}
4 changes: 4 additions & 0 deletions node/libs/roles/src/proto/attester.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions node/libs/roles/src/proto/validator.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
31 changes: 25 additions & 6 deletions node/libs/roles/src/validator/conv.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -525,13 +520,37 @@ 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")?,
})
}

fn build(&self) -> Self::Proto {
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<Self> {
Ok(Self {
members: r
.members
.iter()
.map(ProtoFmt::read)
.collect::<Result<_, _>>()
.context("members")?,
})
}

fn build(&self) -> Self::Proto {
Self::Proto {
members: self.members.iter().map(|x| x.build()).collect(),
}
}
}

8 changes: 8 additions & 0 deletions node/libs/roles/src/validator/messages/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WeightedValidator>
}

3 changes: 3 additions & 0 deletions node/libs/roles/src/validator/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -173,6 +174,7 @@ impl From<SetupSpec> for Setup {
WeightedValidator {
key: k.public(),
weight: *w,
pop: Signature::decode(&vec![]).unwrap(), // TODO(moshababo): implement
}
}))
.unwrap(),
Expand Down Expand Up @@ -437,6 +439,7 @@ impl Distribution<Committee> 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()
}
Expand Down

0 comments on commit 435cd05

Please sign in to comment.