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)]
#[serde(rename_all = "camelCase")]
pub struct RpcVote {
/// Vote account address, as base-58 encoded string
pub vote_pubkey: String,
pub slots: Vec<Slot>,
pub hash: String,
pub timestamp: Option<UnixTimestamp>,

View File

@ -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));
}
}

View File

@ -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}}"#
);
}

View File

@ -93,7 +93,7 @@ impl From<NotificationEntry> 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<Slot>) {
@ -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(),