Add vote account address to vote subscription

This commit is contained in:
Michael Vines 2022-01-26 22:03:03 -08:00
parent 9d477d45c7
commit 331b953551
4 changed files with 10 additions and 7 deletions

View File

@ -290,6 +290,8 @@ pub struct RpcIdentity {
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct RpcVote { pub struct RpcVote {
/// Vote account address, as base-58 encoded string
pub vote_pubkey: String,
pub slots: Vec<Slot>, pub slots: Vec<Slot>,
pub hash: String, pub hash: String,
pub timestamp: Option<UnixTimestamp>, pub timestamp: Option<UnixTimestamp>,

View File

@ -688,7 +688,7 @@ impl ClusterInfoVoteListener {
} }
if is_new_vote { if is_new_vote {
subscriptions.notify_vote(vote); subscriptions.notify_vote(*vote_pubkey, vote);
let _ = verified_vote_sender.send((*vote_pubkey, vote_slots)); let _ = verified_vote_sender.send((*vote_pubkey, vote_slots));
} }
} }

View File

@ -1316,12 +1316,12 @@ mod tests {
hash: Hash::default(), hash: Hash::default(),
timestamp: None, timestamp: None,
}; };
subscriptions.notify_vote(VoteTransaction::from(vote)); subscriptions.notify_vote(Pubkey::default(), VoteTransaction::from(vote));
let response = receiver.recv(); let response = receiver.recv();
assert_eq!( assert_eq!(
response, response,
r#"{"jsonrpc":"2.0","method":"voteNotification","params":{"result":{"slots":[1,2],"hash":"11111111111111111111111111111111","timestamp":null},"subscription":0}}"# r#"{"jsonrpc":"2.0","method":"voteNotification","params":{"result":{"votePubkey":"11111111111111111111111111111111","slots":[1,2],"hash":"11111111111111111111111111111111","timestamp":null},"subscription":0}}"#
); );
} }

View File

@ -93,7 +93,7 @@ impl From<NotificationEntry> for TimestampedNotificationEntry {
pub enum NotificationEntry { pub enum NotificationEntry {
Slot(SlotInfo), Slot(SlotInfo),
SlotUpdate(SlotUpdate), SlotUpdate(SlotUpdate),
Vote(VoteTransaction), Vote((Pubkey, VoteTransaction)),
Root(Slot), Root(Slot),
Bank(CommitmentSlots), Bank(CommitmentSlots),
Gossip(Slot), Gossip(Slot),
@ -677,8 +677,8 @@ impl RpcSubscriptions {
self.enqueue_notification(NotificationEntry::SignaturesReceived(slot_signatures)); self.enqueue_notification(NotificationEntry::SignaturesReceived(slot_signatures));
} }
pub fn notify_vote(&self, vote: VoteTransaction) { pub fn notify_vote(&self, vote_pubkey: Pubkey, vote: VoteTransaction) {
self.enqueue_notification(NotificationEntry::Vote(vote)); self.enqueue_notification(NotificationEntry::Vote((vote_pubkey, vote)));
} }
pub fn notify_roots(&self, mut rooted_slots: Vec<Slot>) { pub fn notify_roots(&self, mut rooted_slots: Vec<Slot>) {
@ -760,8 +760,9 @@ impl RpcSubscriptions {
// These notifications are only triggered by votes observed on gossip, // These notifications are only triggered by votes observed on gossip,
// unlike `NotificationEntry::Gossip`, which also accounts for slots seen // unlike `NotificationEntry::Gossip`, which also accounts for slots seen
// in VoteState's from bank states built in ReplayStage. // in VoteState's from bank states built in ReplayStage.
NotificationEntry::Vote(ref vote_info) => { NotificationEntry::Vote((vote_pubkey, ref vote_info)) => {
let rpc_vote = RpcVote { let rpc_vote = RpcVote {
vote_pubkey: vote_pubkey.to_string(),
slots: vote_info.slots(), slots: vote_info.slots(),
hash: bs58::encode(vote_info.hash()).into_string(), hash: bs58::encode(vote_info.hash()).into_string(),
timestamp: vote_info.timestamp(), timestamp: vote_info.timestamp(),