Skip to content
This repository was archived by the owner on Sep 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 18 additions & 30 deletions program/src/bls_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ use {

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Copy, Debug, PartialEq)]
/// BLS message vote data, we need rank to look up pubkey
pub struct BLSMessageVoteData {
/// BLS vote message, we need rank to look up pubkey
pub struct VoteMessage {
/// The vote
pub vote: Vote,
/// The signature
pub signature: BLSSignature,
/// The rank of the validator
pub rank: u16,
}
Expand All @@ -27,33 +29,21 @@ pub struct BLSMessageVoteData {
#[derive(Clone, Debug, PartialEq)]
#[allow(clippy::large_enum_variant)]
/// BLS message data in Alpenglow
pub enum BLSMessageData {
pub enum BLSMessage {
/// Vote message, with the vote and the rank of the validator.
Vote(BLSMessageVoteData),
Vote(VoteMessage),
/// Certificate message
Certificate(Certificate),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent, do you want to rename Certificate(Certificate) to Certificate(CertificateMessage) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I divided Certificate into Certificate excluding the signature and bit vector and then CertificateMessage, which includes them. I think this is the most consistent with Vote. Let me know what you think.

I did realize that we would ultimately need to make additional modifications to the Certificate format for the fallback certificates where we use a base3 encoding to signify the validators that signed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, can we just pack the base3 encoding into the bitvec? Do we need other data structures?

Copy link
Collaborator Author

@samkim-crypto samkim-crypto May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the encoding itself will be the same. At the end of the day, BitVec is just encoded in the same way as Vec<u8> (in bincode, length prefix followed by bytes). A base3 encoding should also be encoded the same in binary.

We will probably need to replace BitVec with a dedicated type for base3 encoding though so that we have a nice interface to easily add/remove base3 elements and to also check which elements have been added. This is just for fallback/skip certificates.

Alternatively, we can replace BitVec with just Vec<u8> here. Then in consumer logic (in alpenglow), we can just interpret/convert Vec<u8> into a base3 encoding type before we do logic.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0x0ece what do you think? Which is more convenient for Firedancer? I think Vec is probably easier?

}

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, PartialEq)]
/// BLS message to be sent all to all in Alpenglow
pub struct BLSMessage {
/// The message data
pub message_data: BLSMessageData,
/// The signature of the message
pub signature: BLSSignature,
}

impl BLSMessage {
/// Create a new vote message
pub fn new_vote(vote: Vote, my_rank: u16, signature: BLSSignature) -> Self {
Self {
message_data: BLSMessageData::Vote(BLSMessageVoteData {
vote,
rank: my_rank,
}),
pub fn new_vote(vote: Vote, signature: BLSSignature, rank: u16) -> Self {
Self::Vote(VoteMessage {
vote,
signature,
}
rank,
})
}

/// Create a new certificate message
Expand All @@ -65,16 +55,14 @@ impl BLSMessage {
bitmap: BitVec<u8, Lsb0>,
signature: BLSSignature,
) -> Self {
Self {
message_data: BLSMessageData::Certificate(Certificate {
certificate_type,
slot,
block_id,
replayed_bank_hash,
bitmap,
}),
Self::Certificate(Certificate {
certificate_type,
slot,
block_id,
replayed_bank_hash,
signature,
}
bitmap,
})
}

#[cfg(feature = "serde")]
Expand Down
7 changes: 6 additions & 1 deletion program/src/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use {bitvec::prelude::*, solana_hash::Hash, solana_program::clock::Slot};
use {
bitvec::prelude::*, solana_bls::Signature as BLSSignature, solana_hash::Hash,
solana_program::clock::Slot,
};

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