Skip to content

Commit

Permalink
Add protobuf related functions for new message
Browse files Browse the repository at this point in the history
  • Loading branch information
IAvecilla committed Mar 14, 2024
1 parent 93732c4 commit cbc7790
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
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 @@ -144,11 +144,16 @@ message NetAddress {
optional std.Timestamp timestamp = 3; // required
}

message L1BatchSignature {
optional bytes signature = 1; // required
}

message Msg {
oneof t { // required
ConsensusMsg consensus = 1;
bytes session_id = 2;
NetAddress net_address = 3;
L1BatchSignature l1_batch_signature = 4;
}
}

Expand Down
25 changes: 22 additions & 3 deletions node/libs/roles/src/validator/conv.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use super::{
AggregateSignature, BlockHeader, BlockHeaderHash, BlockNumber, CommitQC, ConsensusMsg,
FinalBlock, Fork, ForkNumber, Genesis, GenesisHash, LeaderCommit, LeaderPrepare, Msg, MsgHash,
NetAddress, Payload, PayloadHash, Phase, PrepareQC, ProtocolVersion, PublicKey, ReplicaCommit,
ReplicaPrepare, Signature, Signed, Signers, ValidatorSet, View, ViewNumber,
FinalBlock, Fork, ForkNumber, Genesis, GenesisHash, L1BatchSignature, LeaderCommit,
LeaderPrepare, Msg, MsgHash, NetAddress, Payload, PayloadHash, Phase, PrepareQC,
ProtocolVersion, PublicKey, ReplicaCommit, ReplicaPrepare, Signature, Signed, Signers,
ValidatorSet, View, ViewNumber,
};
use crate::{node::SessionId, proto::validator as proto};
use anyhow::Context as _;
Expand Down Expand Up @@ -355,6 +356,20 @@ impl ProtoFmt for NetAddress {
}
}

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

fn read(r: &Self::Proto) -> anyhow::Result<Self> {
Ok(Self(ByteFmt::decode(required(&r.signature)?)?))
}

fn build(&self) -> Self::Proto {
Self::Proto {
signature: Some(self.0.encode()),
}
}
}

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

Expand All @@ -364,6 +379,9 @@ impl ProtoFmt for Msg {
T::Consensus(r) => Self::Consensus(ProtoFmt::read(r).context("Consensus")?),
T::SessionId(r) => Self::SessionId(SessionId(r.clone())),
T::NetAddress(r) => Self::NetAddress(ProtoFmt::read(r).context("NetAddress")?),
T::L1BatchSignature(r) => {
Self::L1BatchSignature(ProtoFmt::read(r).context("L1BatchSignature")?)
}
})
}

Expand All @@ -374,6 +392,7 @@ impl ProtoFmt for Msg {
Self::Consensus(x) => T::Consensus(x.build()),
Self::SessionId(x) => T::SessionId(x.0.clone()),
Self::NetAddress(x) => T::NetAddress(x.build()),
Self::L1BatchSignature(x) => T::L1BatchSignature(x.build()),
};

Self::Proto { t: Some(t) }
Expand Down

0 comments on commit cbc7790

Please sign in to comment.