From 331b95355108efef43a946180219e6500fdf93ff Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Wed, 26 Jan 2022 22:03:03 -0800 Subject: [PATCH] Add vote account address to vote subscription --- client/src/rpc_response.rs | 2 ++ core/src/cluster_info_vote_listener.rs | 2 +- rpc/src/rpc_pubsub.rs | 4 ++-- rpc/src/rpc_subscriptions.rs | 9 +++++---- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/client/src/rpc_response.rs b/client/src/rpc_response.rs index 38bea673c3..a625072ebb 100644 --- a/client/src/rpc_response.rs +++ b/client/src/rpc_response.rs @@ -290,6 +290,8 @@ pub struct RpcIdentity { #[derive(Serialize, Deserialize, Clone, Debug)] #[serde(rename_all = "camelCase")] pub struct RpcVote { + /// Vote account address, as base-58 encoded string + pub vote_pubkey: String, pub slots: Vec, pub hash: String, pub timestamp: Option, diff --git a/core/src/cluster_info_vote_listener.rs b/core/src/cluster_info_vote_listener.rs index 28fbdccac7..13795908d6 100644 --- a/core/src/cluster_info_vote_listener.rs +++ b/core/src/cluster_info_vote_listener.rs @@ -688,7 +688,7 @@ impl ClusterInfoVoteListener { } if is_new_vote { - subscriptions.notify_vote(vote); + subscriptions.notify_vote(*vote_pubkey, vote); let _ = verified_vote_sender.send((*vote_pubkey, vote_slots)); } } diff --git a/rpc/src/rpc_pubsub.rs b/rpc/src/rpc_pubsub.rs index afbfaa176e..e0144017ac 100644 --- a/rpc/src/rpc_pubsub.rs +++ b/rpc/src/rpc_pubsub.rs @@ -1316,12 +1316,12 @@ mod tests { hash: Hash::default(), timestamp: None, }; - subscriptions.notify_vote(VoteTransaction::from(vote)); + subscriptions.notify_vote(Pubkey::default(), VoteTransaction::from(vote)); let response = receiver.recv(); assert_eq!( 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}}"# ); } diff --git a/rpc/src/rpc_subscriptions.rs b/rpc/src/rpc_subscriptions.rs index 617047b4ab..ae21692e26 100644 --- a/rpc/src/rpc_subscriptions.rs +++ b/rpc/src/rpc_subscriptions.rs @@ -93,7 +93,7 @@ impl From for TimestampedNotificationEntry { pub enum NotificationEntry { Slot(SlotInfo), SlotUpdate(SlotUpdate), - Vote(VoteTransaction), + Vote((Pubkey, 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: VoteTransaction) { - self.enqueue_notification(NotificationEntry::Vote(vote)); + pub fn notify_vote(&self, vote_pubkey: Pubkey, vote: VoteTransaction) { + self.enqueue_notification(NotificationEntry::Vote((vote_pubkey, vote))); } pub fn notify_roots(&self, mut rooted_slots: Vec) { @@ -760,8 +760,9 @@ impl RpcSubscriptions { // These notifications are only triggered by votes observed on gossip, // unlike `NotificationEntry::Gossip`, which also accounts for slots seen // 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 { + vote_pubkey: vote_pubkey.to_string(), slots: vote_info.slots(), hash: bs58::encode(vote_info.hash()).into_string(), timestamp: vote_info.timestamp(),