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

Commit 21f0fa1

Browse files
Organize BLS message into two types and reorder signature (#91)
* include `BLSSignature` inside `VoteMessage` and `Certificate` for easier organization * rename `Certificate` to `CertificateMessage` * divide `Certificate` into `Certificate` and `CertificateMessage`
1 parent 58cd654 commit 21f0fa1

File tree

2 files changed

+31
-44
lines changed

2 files changed

+31
-44
lines changed

program/src/bls_message.rs

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,67 @@
33
use serde::{Deserialize, Serialize};
44

55
use {
6-
crate::{
7-
certificate::{Certificate, CertificateType},
8-
vote::Vote,
9-
},
6+
crate::{certificate::Certificate, vote::Vote},
107
bitvec::prelude::*,
118
solana_bls::Signature as BLSSignature,
12-
solana_hash::Hash,
13-
solana_program::clock::Slot,
149
};
1510

1611
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1712
#[derive(Clone, Copy, Debug, PartialEq)]
18-
/// BLS message vote data, we need rank to look up pubkey
19-
pub struct BLSMessageVoteData {
13+
/// BLS vote message, we need rank to look up pubkey
14+
pub struct VoteMessage {
2015
/// The vote
2116
pub vote: Vote,
17+
/// The signature
18+
pub signature: BLSSignature,
2219
/// The rank of the validator
2320
pub rank: u16,
2421
}
2522

2623
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2724
#[derive(Clone, Debug, PartialEq)]
28-
#[allow(clippy::large_enum_variant)]
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),
33-
/// Certificate message
34-
Certificate(Certificate),
25+
/// BLS vote message, we need rank to look up pubkey
26+
pub struct CertificateMessage {
27+
/// The certificate
28+
pub certificate: Certificate,
29+
/// The signature
30+
pub signature: BLSSignature,
31+
/// The bitmap for validators, little endian byte order
32+
pub bitmap: BitVec<u8, Lsb0>,
3533
}
3634

3735
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3836
#[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,
37+
#[allow(clippy::large_enum_variant)]
38+
/// BLS message data in Alpenglow
39+
pub enum BLSMessage {
40+
/// Vote message, with the vote and the rank of the validator.
41+
Vote(VoteMessage),
42+
/// Certificate message
43+
Certificate(CertificateMessage),
4544
}
4645

4746
impl BLSMessage {
4847
/// Create a new vote message
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-
}),
48+
pub fn new_vote(vote: Vote, signature: BLSSignature, rank: u16) -> Self {
49+
Self::Vote(VoteMessage {
50+
vote,
5551
signature,
56-
}
52+
rank,
53+
})
5754
}
5855

5956
/// Create a new certificate message
6057
pub fn new_certificate(
61-
certificate_type: CertificateType,
62-
slot: Slot,
63-
block_id: Option<Hash>,
64-
replayed_bank_hash: Option<Hash>,
58+
certificate: Certificate,
6559
bitmap: BitVec<u8, Lsb0>,
6660
signature: BLSSignature,
6761
) -> Self {
68-
Self {
69-
message_data: BLSMessageData::Certificate(Certificate {
70-
certificate_type,
71-
slot,
72-
block_id,
73-
replayed_bank_hash,
74-
bitmap,
75-
}),
62+
Self::Certificate(CertificateMessage {
63+
certificate,
7664
signature,
77-
}
65+
bitmap,
66+
})
7867
}
7968

8069
#[cfg(feature = "serde")]

program/src/certificate.rs

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

5-
use {bitvec::prelude::*, solana_hash::Hash, solana_program::clock::Slot};
5+
use {solana_hash::Hash, solana_program::clock::Slot};
66

77
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
88
#[derive(Clone, Copy, Debug, PartialEq)]
@@ -32,6 +32,4 @@ pub struct Certificate {
3232
pub block_id: Option<Hash>,
3333
/// The bank hash of the block
3434
pub replayed_bank_hash: Option<Hash>,
35-
/// The bitmap for validators, little endian byte order
36-
pub bitmap: BitVec<u8, Lsb0>,
3735
}

0 commit comments

Comments
 (0)