Skip to content
This repository was archived by the owner on Sep 24, 2025. It is now read-only.

Commit 58cd654

Browse files
authored
Add bls signature and rank to vote (#87)
* Rename BlsMessage to BLSMessage to be consistent. * We need pubkey and signature for all BLS messages. * Add serialize and deserialize.
1 parent bc0203e commit 58cd654

File tree

2 files changed

+55
-20
lines changed

2 files changed

+55
-20
lines changed

program/src/bls_message.rs

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
2747
impl 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
}

program/src/certificate.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
#[cfg(feature = "serde")]
33
use serde::{Deserialize, Serialize};
44

5-
use {
6-
bitvec::prelude::*, solana_bls::Signature as BLSSignature, solana_hash::Hash,
7-
solana_program::clock::Slot,
8-
};
5+
use {bitvec::prelude::*, solana_hash::Hash, solana_program::clock::Slot};
96

107
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
118
#[derive(Clone, Copy, Debug, PartialEq)]
@@ -35,8 +32,6 @@ pub struct Certificate {
3532
pub block_id: Option<Hash>,
3633
/// The bank hash of the block
3734
pub replayed_bank_hash: Option<Hash>,
38-
/// The signature
39-
pub signature: BLSSignature,
4035
/// The bitmap for validators, little endian byte order
4136
pub bitmap: BitVec<u8, Lsb0>,
4237
}

0 commit comments

Comments
 (0)