|
| 1 | +//! The `bank` module tracks client accounts and the progress of on-chain |
| 2 | +//! programs. It offers a high-level API that signs transactions |
| 3 | +//! on behalf of the caller, and a low-level API for when they have |
| 4 | +//! already been signed and verified. |
| 5 | +use crate::{ |
| 6 | + bank::{Bank, BankRc, EnteredEpochCallback, StatusCacheRc}, |
| 7 | + blockhash_queue::BlockhashQueue, |
| 8 | + epoch_stakes::EpochStakes, |
| 9 | + message_processor::MessageProcessor, |
| 10 | + rent_collector::RentCollector, |
| 11 | + serde_utils::{ |
| 12 | + deserialize_atomicbool, deserialize_atomicu64, serialize_atomicbool, serialize_atomicu64, |
| 13 | + }, |
| 14 | + stakes::Stakes, |
| 15 | + storage_utils::StorageAccounts, |
| 16 | +}; |
| 17 | +use serde::{Deserialize, Serialize}; |
| 18 | +use solana_sdk::{ |
| 19 | + clock::{Epoch, Slot, UnixTimestamp}, |
| 20 | + epoch_schedule::EpochSchedule, |
| 21 | + fee_calculator::{FeeCalculator, FeeRateGovernor}, |
| 22 | + hard_forks::HardForks, |
| 23 | + hash::Hash, |
| 24 | + inflation::Inflation, |
| 25 | + pubkey::Pubkey, |
| 26 | +}; |
| 27 | +use std::{ |
| 28 | + collections::HashMap, |
| 29 | + sync::atomic::{AtomicBool, AtomicU64}, |
| 30 | + sync::{Arc, RwLock}, |
| 31 | +}; |
| 32 | + |
| 33 | +/// Manager for the state of all accounts and programs after processing its entries. |
| 34 | +#[derive(Deserialize, Serialize)] |
| 35 | +pub struct Bank1_0 { |
| 36 | + /// References to accounts, parent and signature status |
| 37 | + #[serde(skip)] |
| 38 | + pub rc: BankRc, |
| 39 | + |
| 40 | + #[serde(skip)] |
| 41 | + pub src: StatusCacheRc, |
| 42 | + |
| 43 | + /// FIFO queue of `recent_blockhash` items |
| 44 | + pub blockhash_queue: RwLock<BlockhashQueue>, |
| 45 | + |
| 46 | + /// The set of parents including this bank |
| 47 | + pub ancestors: HashMap<Slot, usize>, |
| 48 | + |
| 49 | + /// Hash of this Bank's state. Only meaningful after freezing. |
| 50 | + pub hash: RwLock<Hash>, |
| 51 | + |
| 52 | + /// Hash of this Bank's parent's state |
| 53 | + pub parent_hash: Hash, |
| 54 | + |
| 55 | + /// parent's slot |
| 56 | + pub parent_slot: Slot, |
| 57 | + |
| 58 | + /// slots to hard fork at |
| 59 | + pub hard_forks: Arc<RwLock<HardForks>>, |
| 60 | + |
| 61 | + /// The number of transactions processed without error |
| 62 | + #[serde(serialize_with = "serialize_atomicu64")] |
| 63 | + #[serde(deserialize_with = "deserialize_atomicu64")] |
| 64 | + pub transaction_count: AtomicU64, |
| 65 | + |
| 66 | + /// Bank tick height |
| 67 | + #[serde(serialize_with = "serialize_atomicu64")] |
| 68 | + #[serde(deserialize_with = "deserialize_atomicu64")] |
| 69 | + pub tick_height: AtomicU64, |
| 70 | + |
| 71 | + /// The number of signatures from valid transactions in this slot |
| 72 | + #[serde(serialize_with = "serialize_atomicu64")] |
| 73 | + #[serde(deserialize_with = "deserialize_atomicu64")] |
| 74 | + pub signature_count: AtomicU64, |
| 75 | + |
| 76 | + /// Total capitalization, used to calculate inflation |
| 77 | + #[serde(serialize_with = "serialize_atomicu64")] |
| 78 | + #[serde(deserialize_with = "deserialize_atomicu64")] |
| 79 | + pub capitalization: AtomicU64, |
| 80 | + |
| 81 | + // Bank max_tick_height |
| 82 | + pub max_tick_height: u64, |
| 83 | + |
| 84 | + /// The number of hashes in each tick. None value means hashing is disabled. |
| 85 | + pub hashes_per_tick: Option<u64>, |
| 86 | + |
| 87 | + /// The number of ticks in each slot. |
| 88 | + pub ticks_per_slot: u64, |
| 89 | + |
| 90 | + /// length of a slot in ns |
| 91 | + pub ns_per_slot: u128, |
| 92 | + |
| 93 | + /// genesis time, used for computed clock |
| 94 | + pub genesis_creation_time: UnixTimestamp, |
| 95 | + |
| 96 | + /// The number of slots per year, used for inflation |
| 97 | + pub slots_per_year: f64, |
| 98 | + |
| 99 | + /// The number of slots per Storage segment |
| 100 | + pub slots_per_segment: u64, |
| 101 | + |
| 102 | + /// Bank slot (i.e. block) |
| 103 | + pub slot: Slot, |
| 104 | + |
| 105 | + /// Bank epoch |
| 106 | + pub epoch: Epoch, |
| 107 | + |
| 108 | + /// Bank block_height |
| 109 | + pub block_height: u64, |
| 110 | + |
| 111 | + /// The pubkey to send transactions fees to. |
| 112 | + pub collector_id: Pubkey, |
| 113 | + |
| 114 | + /// Fees that have been collected |
| 115 | + #[serde(serialize_with = "serialize_atomicu64")] |
| 116 | + #[serde(deserialize_with = "deserialize_atomicu64")] |
| 117 | + pub collector_fees: AtomicU64, |
| 118 | + |
| 119 | + /// Latest transaction fees for transactions processed by this bank |
| 120 | + pub fee_calculator: FeeCalculator, |
| 121 | + |
| 122 | + /// Track cluster signature throughput and adjust fee rate |
| 123 | + pub fee_rate_governor: FeeRateGovernor, |
| 124 | + |
| 125 | + /// Rent that have been collected |
| 126 | + #[serde(serialize_with = "serialize_atomicu64")] |
| 127 | + #[serde(deserialize_with = "deserialize_atomicu64")] |
| 128 | + pub collected_rent: AtomicU64, |
| 129 | + |
| 130 | + /// latest rent collector, knows the epoch |
| 131 | + pub rent_collector: RentCollector, |
| 132 | + |
| 133 | + /// initialized from genesis |
| 134 | + pub epoch_schedule: EpochSchedule, |
| 135 | + |
| 136 | + /// inflation specs |
| 137 | + pub inflation: Arc<RwLock<Inflation>>, |
| 138 | + |
| 139 | + /// cache of vote_account and stake_account state for this fork |
| 140 | + pub stakes: RwLock<Stakes>, |
| 141 | + |
| 142 | + /// cache of validator and archiver storage accounts for this fork |
| 143 | + pub storage_accounts: RwLock<StorageAccounts>, |
| 144 | + |
| 145 | + /// staked nodes on epoch boundaries, saved off when a bank.slot() is at |
| 146 | + /// a leader schedule calculation boundary |
| 147 | + pub epoch_stakes: HashMap<Epoch, Stakes>, |
| 148 | + |
| 149 | + /// A boolean reflecting whether any entries were recorded into the PoH |
| 150 | + /// stream for the slot == self.slot |
| 151 | + #[serde(serialize_with = "serialize_atomicbool")] |
| 152 | + #[serde(deserialize_with = "deserialize_atomicbool")] |
| 153 | + pub is_delta: AtomicBool, |
| 154 | + |
| 155 | + /// The Message processor |
| 156 | + pub message_processor: MessageProcessor, |
| 157 | + |
| 158 | + /// Callback to be notified when a bank enters a new Epoch |
| 159 | + /// (used to adjust cluster features over time) |
| 160 | + #[serde(skip)] |
| 161 | + pub entered_epoch_callback: Arc<RwLock<Option<EnteredEpochCallback>>>, |
| 162 | + |
| 163 | + /// Last time when the cluster info vote listener has synced with this bank |
| 164 | + #[serde(skip)] |
| 165 | + pub last_vote_sync: AtomicU64, |
| 166 | + |
| 167 | + /// Rewards that were paid out immediately after this bank was created |
| 168 | + #[serde(skip)] |
| 169 | + pub rewards: Option<Vec<(Pubkey, i64)>>, |
| 170 | +} |
| 171 | + |
| 172 | +impl Bank1_0 { |
| 173 | + pub fn convert_to_current(self) -> Bank { |
| 174 | + let old_epoch_stakes = self.epoch_stakes; |
| 175 | + let epoch_stakes = old_epoch_stakes |
| 176 | + .iter() |
| 177 | + .map(|(epoch, stakes)| (*epoch, EpochStakes::new(&stakes, *epoch))) |
| 178 | + .collect(); |
| 179 | + Bank { |
| 180 | + rc: self.rc, |
| 181 | + src: self.src, |
| 182 | + blockhash_queue: self.blockhash_queue, |
| 183 | + ancestors: self.ancestors, |
| 184 | + hash: self.hash, |
| 185 | + parent_hash: self.parent_hash, |
| 186 | + parent_slot: self.parent_slot, |
| 187 | + hard_forks: self.hard_forks, |
| 188 | + transaction_count: self.transaction_count, |
| 189 | + tick_height: self.tick_height, |
| 190 | + signature_count: self.signature_count, |
| 191 | + capitalization: self.capitalization, |
| 192 | + max_tick_height: self.max_tick_height, |
| 193 | + hashes_per_tick: self.hashes_per_tick, |
| 194 | + ticks_per_slot: self.ticks_per_slot, |
| 195 | + ns_per_slot: self.ns_per_slot, |
| 196 | + genesis_creation_time: self.genesis_creation_time, |
| 197 | + slots_per_year: self.slots_per_year, |
| 198 | + slots_per_segment: self.slots_per_segment, |
| 199 | + slot: self.slot, |
| 200 | + epoch: self.epoch, |
| 201 | + block_height: self.block_height, |
| 202 | + collector_id: self.collector_id, |
| 203 | + collector_fees: self.collector_fees, |
| 204 | + fee_calculator: self.fee_calculator, |
| 205 | + fee_rate_governor: self.fee_rate_governor, |
| 206 | + collected_rent: self.collected_rent, |
| 207 | + rent_collector: self.rent_collector, |
| 208 | + epoch_schedule: self.epoch_schedule, |
| 209 | + inflation: self.inflation, |
| 210 | + stakes: self.stakes, |
| 211 | + storage_accounts: self.storage_accounts, |
| 212 | + epoch_stakes, |
| 213 | + is_delta: self.is_delta, |
| 214 | + message_processor: self.message_processor, |
| 215 | + entered_epoch_callback: self.entered_epoch_callback, |
| 216 | + last_vote_sync: self.last_vote_sync, |
| 217 | + rewards: self.rewards, |
| 218 | + } |
| 219 | + } |
| 220 | +} |
0 commit comments