solana_core/
admin_rpc_post_init.rs

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