Skip to main content

solana_core/
admin_rpc_post_init.rs

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