@@ -13,21 +13,47 @@ use {
1313 solana_program:: clock:: Slot ,
1414} ;
1515
16+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
17+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
18+ /// BLS message vote data, we need rank to look up pubkey
19+ pub struct BLSMessageVoteData {
20+ /// The vote
21+ pub vote : Vote ,
22+ /// The rank of the validator
23+ pub rank : u16 ,
24+ }
25+
1626#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1727#[ derive( Clone , Debug , PartialEq ) ]
1828#[ allow( clippy:: large_enum_variant) ]
19- /// BLS message type in Alpenglow
20- pub enum BLSMessage {
21- /// Vote message
22- Vote ( Vote ) ,
29+ /// BLS message data in Alpenglow
30+ pub enum BLSMessageData {
31+ /// Vote message, with the vote and the rank of the validator.
32+ Vote ( BLSMessageVoteData ) ,
2333 /// Certificate message
2434 Certificate ( Certificate ) ,
2535}
2636
37+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
38+ #[ derive( Clone , Debug , PartialEq ) ]
39+ /// BLS message to be sent all to all in Alpenglow
40+ pub struct BLSMessage {
41+ /// The message data
42+ pub message_data : BLSMessageData ,
43+ /// The signature of the message
44+ pub signature : BLSSignature ,
45+ }
46+
2747impl BLSMessage {
2848 /// Create a new vote message
29- pub fn new_vote ( vote : Vote ) -> Self {
30- Self :: Vote ( vote)
49+ pub fn new_vote ( vote : Vote , my_rank : u16 , signature : BLSSignature ) -> Self {
50+ Self {
51+ message_data : BLSMessageData :: Vote ( BLSMessageVoteData {
52+ vote,
53+ rank : my_rank,
54+ } ) ,
55+ signature,
56+ }
3157 }
3258
3359 /// Create a new certificate message
@@ -36,16 +62,30 @@ impl BLSMessage {
3662 slot : Slot ,
3763 block_id : Option < Hash > ,
3864 replayed_bank_hash : Option < Hash > ,
39- signature : BLSSignature ,
4065 bitmap : BitVec < u8 , Lsb0 > ,
66+ signature : BLSSignature ,
4167 ) -> Self {
42- Self :: Certificate ( Certificate {
43- certificate_type,
44- slot,
45- block_id,
46- replayed_bank_hash,
68+ Self {
69+ message_data : BLSMessageData :: Certificate ( Certificate {
70+ certificate_type,
71+ slot,
72+ block_id,
73+ replayed_bank_hash,
74+ bitmap,
75+ } ) ,
4776 signature,
48- bitmap,
49- } )
77+ }
78+ }
79+
80+ #[ cfg( feature = "serde" ) ]
81+ /// Deserialize a BLS message from bytes
82+ pub fn deserialize ( bls_message_in_bytes : & [ u8 ] ) -> Self {
83+ bincode:: deserialize ( bls_message_in_bytes) . unwrap ( )
84+ }
85+
86+ #[ cfg( feature = "serde" ) ]
87+ /// Serialize a BLS message to bytes
88+ pub fn serialize ( & self ) -> Vec < u8 > {
89+ bincode:: serialize ( self ) . unwrap ( )
5090 }
5191}
0 commit comments