solana_core/
admin_rpc_post_init.rs

1use {
2    crate::{
3        cluster_slots_service::cluster_slots::ClusterSlots,
4        repair::{outstanding_requests::OutstandingRequests, serve_repair::ShredRepairType},
5    },
6    solana_gossip::cluster_info::ClusterInfo,
7    solana_pubkey::Pubkey,
8    solana_quic_definitions::NotifyKeyUpdate,
9    solana_runtime::bank_forks::BankForks,
10    std::{
11        collections::{HashMap, HashSet},
12        net::UdpSocket,
13        sync::{Arc, RwLock},
14    },
15};
16
17/// Key updaters:
18#[derive(PartialEq, Eq, Hash, Clone, Debug)]
19pub enum KeyUpdaterType {
20    /// TPU key updater
21    Tpu,
22    /// TPU forwards key updater
23    TpuForwards,
24    /// TPU vote key updater
25    TpuVote,
26    /// Forward key updater
27    Forward,
28    /// For the RPC service
29    RpcService,
30}
31
32/// Responsible for managing the updaters for identity key change
33#[derive(Default)]
34pub struct KeyUpdaters {
35    updaters: HashMap<KeyUpdaterType, Arc<dyn NotifyKeyUpdate + Sync + Send>>,
36}
37
38impl KeyUpdaters {
39    /// Add a new key updater to the list
40    pub fn add(
41        &mut self,
42        updater_type: KeyUpdaterType,
43        updater: Arc<dyn NotifyKeyUpdate + Sync + Send>,
44    ) {
45        self.updaters.insert(updater_type, updater);
46    }
47
48    /// Remove a key updater by its key
49    pub fn remove(&mut self, updater_type: &KeyUpdaterType) {
50        self.updaters.remove(updater_type);
51    }
52}
53
54/// Implement the Iterator trait for KeyUpdaters
55impl<'a> IntoIterator for &'a KeyUpdaters {
56    type Item = (
57        &'a KeyUpdaterType,
58        &'a Arc<dyn NotifyKeyUpdate + Sync + Send>,
59    );
60    type IntoIter = std::collections::hash_map::Iter<
61        'a,
62        KeyUpdaterType,
63        Arc<dyn NotifyKeyUpdate + Sync + Send>,
64    >;
65
66    fn into_iter(self) -> Self::IntoIter {
67        self.updaters.iter()
68    }
69}
70
71#[derive(Clone)]
72pub struct AdminRpcRequestMetadataPostInit {
73    pub cluster_info: Arc<ClusterInfo>,
74    pub bank_forks: Arc<RwLock<BankForks>>,
75    pub vote_account: Pubkey,
76    pub repair_whitelist: Arc<RwLock<HashSet<Pubkey>>>,
77    pub notifies: Arc<RwLock<KeyUpdaters>>,
78    pub repair_socket: Arc<UdpSocket>,
79    pub outstanding_repair_requests: Arc<RwLock<OutstandingRequests<ShredRepairType>>>,
80    pub cluster_slots: Arc<ClusterSlots>,
81}