uses enum instead of trait for VoteTransaction (#22019)
Box<dyn Trait> involves runtime dispatch, has significant overhead and is slow. It also requires hacky boilerplate code for implementing Clone or other basic traits: https://github.com/solana-labs/solana/blob/e92a81b74/programs/vote/src/vote_state/mod.rs#L70-L102 Only limited known types can be VoteTransaction and they are all defined in the same crate. So using a trait here only adds overhead. https://github.com/solana-labs/solana/blob/e92a81b74/programs/vote/src/vote_state/mod.rs#L125-L165 https://github.com/solana-labs/solana/blob/e92a81b74/programs/vote/src/vote_state/mod.rs#L221-L264
This commit is contained in:
@ -611,7 +611,7 @@ mod tests {
|
||||
transaction::{self, Transaction},
|
||||
},
|
||||
solana_stake_program::stake_state,
|
||||
solana_vote_program::vote_state::Vote,
|
||||
solana_vote_program::vote_state::{Vote, VoteTransaction},
|
||||
std::{
|
||||
sync::{
|
||||
atomic::{AtomicBool, AtomicU64},
|
||||
@ -1315,7 +1315,7 @@ mod tests {
|
||||
hash: Hash::default(),
|
||||
timestamp: None,
|
||||
};
|
||||
subscriptions.notify_vote(Box::new(vote));
|
||||
subscriptions.notify_vote(VoteTransaction::from(vote));
|
||||
|
||||
let response = receiver.recv();
|
||||
assert_eq!(
|
||||
|
@ -93,7 +93,7 @@ impl From<NotificationEntry> for TimestampedNotificationEntry {
|
||||
pub enum NotificationEntry {
|
||||
Slot(SlotInfo),
|
||||
SlotUpdate(SlotUpdate),
|
||||
Vote(Box<dyn VoteTransaction>),
|
||||
Vote(VoteTransaction),
|
||||
Root(Slot),
|
||||
Bank(CommitmentSlots),
|
||||
Gossip(Slot),
|
||||
@ -677,8 +677,8 @@ impl RpcSubscriptions {
|
||||
self.enqueue_notification(NotificationEntry::SignaturesReceived(slot_signatures));
|
||||
}
|
||||
|
||||
pub fn notify_vote(&self, vote: Box<dyn VoteTransaction>) {
|
||||
self.enqueue_notification(NotificationEntry::Vote(vote.clone()));
|
||||
pub fn notify_vote(&self, vote: VoteTransaction) {
|
||||
self.enqueue_notification(NotificationEntry::Vote(vote));
|
||||
}
|
||||
|
||||
pub fn notify_roots(&self, mut rooted_slots: Vec<Slot>) {
|
||||
|
Reference in New Issue
Block a user