Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ lru = { workspace = true }
min-max-heap = { workspace = true }
num_cpus = { workspace = true }
num_enum = { workspace = true }
parking_lot = { workspace = true }
prio-graph = { workspace = true }
qualifier_attr = { workspace = true }
quinn = { workspace = true }
Expand Down
42 changes: 38 additions & 4 deletions core/src/block_creation_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
banking_trace::BankingTracer,
replay_stage::{Finalizer, ReplayStage},
},
crossbeam_channel::Receiver,
crossbeam_channel::{Receiver, Sender},
solana_clock::Slot,
solana_entry::block_component::BlockFooterV1,
solana_gossip::cluster_info::ClusterInfo,
Expand All @@ -32,7 +32,12 @@ use {
block_component_processor::BlockComponentProcessor,
},
solana_version::version,
solana_votor::{common::block_timeout, event::LeaderWindowInfo},
solana_votor::{
common::block_timeout,
consensus_rewards::{BuildRewardCertsRequest, BuildRewardCertsResponse},
event::LeaderWindowInfo,
},
solana_votor_messages::rewards_certificate::{NotarRewardCertificate, SkipRewardCertificate},
stats::{BlockCreationLoopMetrics, SlotMetrics},
std::{
sync::{
Expand Down Expand Up @@ -91,6 +96,9 @@ pub struct BlockCreationLoopConfig {
// Channel to receive RecordReceiver from PohService
pub record_receiver_receiver: Receiver<RecordReceiver>,
pub optimistic_parent_receiver: Receiver<LeaderWindowInfo>,

pub build_reward_certs_sender: Sender<BuildRewardCertsRequest>,
pub reward_certs_receiver: Receiver<BuildRewardCertsResponse>,
}

struct LeaderContext {
Expand All @@ -108,6 +116,8 @@ struct LeaderContext {
slot_status_notifier: Option<SlotStatusNotifier>,
banking_tracer: Arc<BankingTracer>,
replay_highest_frozen: Arc<ReplayHighestFrozen>,
build_reward_certs_sender: Sender<BuildRewardCertsRequest>,
reward_certs_receiver: Receiver<BuildRewardCertsResponse>,

// Metrics
metrics: BlockCreationLoopMetrics,
Expand Down Expand Up @@ -159,6 +169,8 @@ fn start_loop(config: BlockCreationLoopConfig) {
replay_highest_frozen,
highest_parent_ready,
optimistic_parent_receiver,
build_reward_certs_sender,
reward_certs_receiver,
} = config;

// Similar to Votor, if this loop dies kill the validator
Expand Down Expand Up @@ -196,6 +208,8 @@ fn start_loop(config: BlockCreationLoopConfig) {
replay_highest_frozen,
metrics: BlockCreationLoopMetrics::default(),
slot_metrics: SlotMetrics::default(),
build_reward_certs_sender,
reward_certs_receiver,
};

// Setup poh
Expand Down Expand Up @@ -316,6 +330,8 @@ fn produce_window(
if let Err(e) = record_and_complete_block(
ctx.poh_recorder.as_ref(),
&mut ctx.record_receiver,
&ctx.build_reward_certs_sender,
&ctx.reward_certs_receiver,
skip_timer,
timeout,
) {
Expand Down Expand Up @@ -369,7 +385,11 @@ fn skew_block_producer_time_nanos(

/// Produces a block footer with the current timestamp and version information.
/// The bank_hash field is left as default and will be filled in after the bank freezes.
fn produce_block_footer(bank: Arc<Bank>) -> BlockFooterV1 {
fn produce_block_footer(
bank: Arc<Bank>,
skip_reward_certificate: Option<SkipRewardCertificate>,
notar_reward_certificate: Option<NotarRewardCertificate>,
) -> BlockFooterV1 {
let mut block_producer_time_nanos = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Misconfigured system clock; couldn't measure block producer time.")
Expand All @@ -396,6 +416,8 @@ fn produce_block_footer(bank: Arc<Bank>) -> BlockFooterV1 {
bank_hash: Hash::default(),
block_producer_time_nanos: block_producer_time_nanos as u64,
block_user_agent: format!("agave/{}", version!()).into_bytes(),
skip_reward_certificate,
notar_reward_certificate,
}
}

Expand All @@ -409,9 +431,16 @@ fn produce_block_footer(bank: Arc<Bank>) -> BlockFooterV1 {
fn record_and_complete_block(
poh_recorder: &RwLock<PohRecorder>,
record_receiver: &mut RecordReceiver,
build_reward_certs_sender: &Sender<BuildRewardCertsRequest>,
cert_receiver: &Receiver<BuildRewardCertsResponse>,
block_timer: Instant,
block_timeout: Duration,
) -> Result<(), PohRecorderError> {
// XXX: how to look up the slot.
let slot = u64::MAX;
build_reward_certs_sender
.send(BuildRewardCertsRequest { slot })
.unwrap();
loop {
let remaining_slot_time = block_timeout.saturating_sub(block_timer.elapsed());
if remaining_slot_time.is_zero() {
Expand Down Expand Up @@ -462,7 +491,12 @@ fn record_and_complete_block(

// Produce the footer with the current timestamp
let working_bank = w_poh_recorder.working_bank().unwrap();
let footer = produce_block_footer(working_bank.bank.clone_without_scheduler());
let resp = cert_receiver.recv().unwrap();
let footer = produce_block_footer(
working_bank.bank.clone_without_scheduler(),
resp.skip,
resp.notar,
);

BlockComponentProcessor::update_bank_with_footer(
working_bank.bank.clone_without_scheduler(),
Expand Down
43 changes: 36 additions & 7 deletions core/src/bls_sigverify/bls_sigverifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ use {
solana_runtime::{bank::Bank, bank_forks::SharableBanks, epoch_stakes::BLSPubkeyToRankMap},
solana_signer_store::{decode, DecodeError},
solana_streamer::packet::PacketBatch,
solana_votor::consensus_metrics::{ConsensusMetricsEvent, ConsensusMetricsEventSender},
solana_votor::{
consensus_metrics::{ConsensusMetricsEvent, ConsensusMetricsEventSender},
consensus_rewards::{AddVoteEntry, AddVoteMessage},
},
solana_votor_messages::{
consensus_message::{Certificate, CertificateType, ConsensusMessage, VoteMessage},
vote::Vote,
Expand Down Expand Up @@ -84,6 +87,7 @@ enum CertVerifyError {

pub struct BLSSigVerifier {
verified_votes_sender: VerifiedVoteSender,
reward_votes_sender: Sender<AddVoteMessage>,
message_sender: Sender<ConsensusMessage>,
sharable_banks: SharableBanks,
stats: BLSSigVerifierStats,
Expand Down Expand Up @@ -172,8 +176,11 @@ impl BLSSigVerifier {
id: *solana_pubkey,
vote: vote_message.vote,
});
// Only need votes newer than root slot

// consensus pool does not need votes for slots other than root slot however the rewards container may still need them.
if vote_message.vote.slot() <= root_bank.slot() {
// XXX: actually verify and send the votes. The verification and sending should happen off the critical path.

self.stats.received_old.fetch_add(1, Ordering::Relaxed);
packet.meta_mut().set_discard(true);
continue;
Expand Down Expand Up @@ -219,8 +226,8 @@ impl BLSSigVerifier {
|| self.verify_and_send_certificates(certs_to_verify, &root_bank),
);

votes_result?;
certs_result?;
let rewards_votes = votes_result?;
let () = certs_result?;

// Send to RPC service for last voted tracking
self.alpenglow_last_voted
Expand All @@ -235,6 +242,21 @@ impl BLSSigVerifier {
warn!("could not send consensus metrics, receive side of channel is closed");
}

let votes = rewards_votes
.into_iter()
.filter_map(|v| {
get_key_to_rank_map(&root_bank, v.vote.slot()).map(|rank_map| AddVoteEntry {
max_validators: rank_map.len(),
vote: v,
})
})
.collect();
let msg = AddVoteMessage {
root_slot: root_bank.slot(),
votes,
};
self.reward_votes_sender.send(msg).unwrap();

self.stats.maybe_report_stats();

Ok(())
Expand All @@ -245,13 +267,15 @@ impl BLSSigVerifier {
pub fn new(
sharable_banks: SharableBanks,
verified_votes_sender: VerifiedVoteSender,
reward_votes_sender: Sender<AddVoteMessage>,
message_sender: Sender<ConsensusMessage>,
consensus_metrics_sender: ConsensusMetricsEventSender,
alpenglow_last_voted: Arc<AlpenglowLastVoted>,
) -> Self {
Self {
sharable_banks,
verified_votes_sender,
reward_votes_sender,
message_sender,
stats: BLSSigVerifierStats::new(),
verified_certs: RwLock::new(HashSet::new()),
Expand All @@ -262,11 +286,16 @@ impl BLSSigVerifier {
}
}

/// Verifies votes and sends verified votes to the consensus pool.
/// Also returns a copy of the verified votes that the rewards container is interested is so that the caller can send them to it.
fn verify_and_send_votes(
&self,
votes_to_verify: Vec<VoteToVerify>,
) -> Result<(), BLSSigVerifyServiceError<ConsensusMessage>> {
) -> Result<Vec<VoteMessage>, BLSSigVerifyServiceError<ConsensusMessage>> {
let verified_votes = self.verify_votes(votes_to_verify);
// XXX: call consensus_rewards::wants_vote() to do some additional filtering here.
let reward_votes = verified_votes.iter().map(|v| v.vote_message).collect();

self.stats
.total_valid_packets
.fetch_add(verified_votes.len() as u64, Ordering::Relaxed);
Expand All @@ -285,7 +314,7 @@ impl BLSSigVerifier {
}
}

// Send the BLS vote messaage to certificate pool
// Send the votes to the consensus pool
match self
.message_sender
.try_send(ConsensusMessage::Vote(vote.vote_message))
Expand Down Expand Up @@ -319,7 +348,7 @@ impl BLSSigVerifier {
}
}

Ok(())
Ok(reward_votes)
}

fn verify_votes(&self, votes_to_verify: Vec<VoteToVerify>) -> Vec<VoteToVerify> {
Expand Down
10 changes: 10 additions & 0 deletions core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ use {
solana_vote::vote_transaction::VoteTransaction,
solana_votor::{
consensus_metrics::{ConsensusMetricsEventReceiver, ConsensusMetricsEventSender},
consensus_rewards::{AddVoteMessage, BuildRewardCertsRequest, BuildRewardCertsResponse},
event::{
CompletedBlock, LeaderWindowInfo, VotorEvent, VotorEventReceiver, VotorEventSender,
},
Expand Down Expand Up @@ -299,6 +300,9 @@ pub struct ReplayStageConfig {
pub consensus_metrics_sender: ConsensusMetricsEventSender,
pub consensus_metrics_receiver: ConsensusMetricsEventReceiver,
pub migration_status: Arc<MigrationStatus>,
pub reward_certs_sender: Sender<BuildRewardCertsResponse>,
pub reward_votes_receiver: Receiver<AddVoteMessage>,
pub build_reward_certs_receiver: Receiver<BuildRewardCertsRequest>,
}

pub struct ReplaySenders {
Expand Down Expand Up @@ -620,6 +624,9 @@ impl ReplayStage {
consensus_metrics_sender,
consensus_metrics_receiver,
migration_status,
reward_certs_sender,
reward_votes_receiver,
build_reward_certs_receiver,
} = config;

let ReplaySenders {
Expand Down Expand Up @@ -694,6 +701,9 @@ impl ReplayStage {
consensus_metrics_sender,
consensus_metrics_receiver,
migration_status: migration_status.clone(),
reward_certs_sender,
reward_votes_receiver,
build_reward_certs_receiver,
};
let votor = Votor::new(votor_config);

Expand Down
10 changes: 9 additions & 1 deletion core/src/tvu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ use {
},
solana_turbine::{retransmit_stage::RetransmitStage, xdp::XdpSender},
solana_votor::{
consensus_rewards::{BuildRewardCertsRequest, BuildRewardCertsResponse},
event::{LeaderWindowInfo, VotorEventReceiver, VotorEventSender},
vote_history::VoteHistory,
vote_history_storage::VoteHistoryStorage,
Expand Down Expand Up @@ -216,6 +217,8 @@ impl Tvu {
key_notifiers: Arc<RwLock<KeyUpdaters>>,
alpenglow_last_voted: Arc<AlpenglowLastVoted>,
migration_status: Arc<MigrationStatus>,
reward_certs_sender: Sender<BuildRewardCertsResponse>,
build_reward_certs_receiver: Receiver<BuildRewardCertsRequest>,
) -> Result<Self, String> {
let (consensus_message_sender, consensus_message_receiver) =
bounded(MAX_ALPENGLOW_PACKET_NUM);
Expand Down Expand Up @@ -268,11 +271,13 @@ impl Tvu {
alpenglow_quic_server_config,
)
.unwrap();
let (reward_votes_sender, reward_votes_receiver) = unbounded();
let alpenglow_sigverify_service = {
let sharable_banks = bank_forks.read().unwrap().sharable_banks();
let verifier = BLSSigVerifier::new(
sharable_banks,
verified_vote_sender.clone(),
reward_votes_sender,
consensus_message_sender.clone(),
consensus_metrics_sender.clone(),
alpenglow_last_voted.clone(),
Expand Down Expand Up @@ -449,6 +454,9 @@ impl Tvu {
consensus_metrics_sender: consensus_metrics_sender.clone(),
consensus_metrics_receiver,
migration_status,
reward_certs_sender,
reward_votes_receiver,
build_reward_certs_receiver,
};

let voting_service = VotingService::new(
Expand Down Expand Up @@ -597,7 +605,7 @@ pub mod tests {
solana_signer::Signer,
solana_streamer::socket::SocketAddrSpace,
solana_tpu_client::tpu_client::{DEFAULT_TPU_CONNECTION_POOL_SIZE, DEFAULT_VOTE_USE_QUIC},
solana_votor::vote_history_storage::FileVoteHistoryStorage,
solana_votor::{consensus_metrics, vote_history_storage::FileVoteHistoryStorage},
std::sync::atomic::{AtomicU64, Ordering},
};

Expand Down
7 changes: 7 additions & 0 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,9 @@ impl Validator {

let (optimistic_parent_sender, optimistic_parent_receiver) = unbounded();

let (build_reward_certs_sender, build_reward_certs_receiver) = bounded(1);
let (reward_certs_sender, reward_certs_receiver) = bounded(1);

let block_creation_loop_config = BlockCreationLoopConfig {
exit: exit.clone(),
bank_forks: bank_forks.clone(),
Expand All @@ -1447,6 +1450,8 @@ impl Validator {
replay_highest_frozen: replay_highest_frozen.clone(),
highest_parent_ready: highest_parent_ready.clone(),
optimistic_parent_receiver: optimistic_parent_receiver.clone(),
build_reward_certs_sender,
reward_certs_receiver,
};
let block_creation_loop = BlockCreationLoop::new(block_creation_loop_config);

Expand Down Expand Up @@ -1703,6 +1708,8 @@ impl Validator {
key_notifiers.clone(),
alpenglow_last_voted.clone(),
migration_status.clone(),
reward_certs_sender,
build_reward_certs_receiver,
)
.map_err(ValidatorError::Other)?;

Expand Down
Loading