replaces once_cell::sync::OnceCell with std::sync::OnceLock (#33140)
std::sync::OnceLock has become stable since rust 1.70.0 and there is no longer a need for an external crate dependency.
This commit is contained in:
parent
0c896c6076
commit
88ee8f5820
|
@ -5173,7 +5173,6 @@ dependencies = [
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"num_enum 0.6.1",
|
"num_enum 0.6.1",
|
||||||
"once_cell",
|
|
||||||
"ouroboros",
|
"ouroboros",
|
||||||
"percentage",
|
"percentage",
|
||||||
"qualifier_attr",
|
"qualifier_attr",
|
||||||
|
@ -5937,7 +5936,6 @@ dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"log",
|
"log",
|
||||||
"memmap2",
|
"memmap2",
|
||||||
"once_cell",
|
|
||||||
"rustc_version 0.4.0",
|
"rustc_version 0.4.0",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_bytes",
|
"serde_bytes",
|
||||||
|
@ -6854,7 +6852,6 @@ dependencies = [
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"num_enum 0.6.1",
|
"num_enum 0.6.1",
|
||||||
"once_cell",
|
|
||||||
"ouroboros",
|
"ouroboros",
|
||||||
"percentage",
|
"percentage",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
|
|
|
@ -243,7 +243,6 @@ num_cpus = "1.16.0"
|
||||||
num_enum = "0.6.1"
|
num_enum = "0.6.1"
|
||||||
num-derive = "0.3"
|
num-derive = "0.3"
|
||||||
num-traits = "0.2"
|
num-traits = "0.2"
|
||||||
once_cell = "1.18.0"
|
|
||||||
openssl = "0.10"
|
openssl = "0.10"
|
||||||
ouroboros = "0.15.6"
|
ouroboros = "0.15.6"
|
||||||
parking_lot = "0.12"
|
parking_lot = "0.12"
|
||||||
|
|
|
@ -36,7 +36,6 @@ num-derive = { workspace = true }
|
||||||
num-traits = { workspace = true }
|
num-traits = { workspace = true }
|
||||||
num_cpus = { workspace = true }
|
num_cpus = { workspace = true }
|
||||||
num_enum = { workspace = true }
|
num_enum = { workspace = true }
|
||||||
once_cell = { workspace = true }
|
|
||||||
ouroboros = { workspace = true }
|
ouroboros = { workspace = true }
|
||||||
percentage = { workspace = true }
|
percentage = { workspace = true }
|
||||||
qualifier_attr = { workspace = true }
|
qualifier_attr = { workspace = true }
|
||||||
|
|
|
@ -13,7 +13,6 @@ use {
|
||||||
secondary_index::*,
|
secondary_index::*,
|
||||||
},
|
},
|
||||||
log::*,
|
log::*,
|
||||||
once_cell::sync::OnceCell,
|
|
||||||
ouroboros::self_referencing,
|
ouroboros::self_referencing,
|
||||||
rand::{thread_rng, Rng},
|
rand::{thread_rng, Rng},
|
||||||
rayon::{
|
rayon::{
|
||||||
|
@ -37,7 +36,7 @@ use {
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, AtomicU64, AtomicU8, AtomicUsize, Ordering},
|
atomic::{AtomicBool, AtomicU64, AtomicU8, AtomicUsize, Ordering},
|
||||||
Arc, Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard,
|
Arc, Mutex, OnceLock, RwLock, RwLockReadGuard, RwLockWriteGuard,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
thiserror::Error,
|
thiserror::Error,
|
||||||
|
@ -703,7 +702,7 @@ pub struct AccountsIndex<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> {
|
||||||
pub max_distance_to_min_scan_slot: AtomicU64,
|
pub max_distance_to_min_scan_slot: AtomicU64,
|
||||||
|
|
||||||
/// populated at generate_index time - accounts that could possibly be rent paying
|
/// populated at generate_index time - accounts that could possibly be rent paying
|
||||||
pub rent_paying_accounts_by_partition: OnceCell<RentPayingAccountsByPartition>,
|
pub rent_paying_accounts_by_partition: OnceLock<RentPayingAccountsByPartition>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> {
|
impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> {
|
||||||
|
@ -737,7 +736,7 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> {
|
||||||
roots_removed: AtomicUsize::default(),
|
roots_removed: AtomicUsize::default(),
|
||||||
active_scans: AtomicUsize::default(),
|
active_scans: AtomicUsize::default(),
|
||||||
max_distance_to_min_scan_slot: AtomicU64::default(),
|
max_distance_to_min_scan_slot: AtomicU64::default(),
|
||||||
rent_paying_accounts_by_partition: OnceCell::default(),
|
rent_paying_accounts_by_partition: OnceLock::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,13 @@ use {
|
||||||
error::TieredStorageError,
|
error::TieredStorageError,
|
||||||
footer::{AccountBlockFormat, AccountMetaFormat, OwnersBlockFormat},
|
footer::{AccountBlockFormat, AccountMetaFormat, OwnersBlockFormat},
|
||||||
index::AccountIndexFormat,
|
index::AccountIndexFormat,
|
||||||
once_cell::sync::OnceCell,
|
|
||||||
readable::TieredStorageReader,
|
readable::TieredStorageReader,
|
||||||
solana_sdk::{account::ReadableAccount, hash::Hash},
|
solana_sdk::{account::ReadableAccount, hash::Hash},
|
||||||
std::{
|
std::{
|
||||||
borrow::Borrow,
|
borrow::Borrow,
|
||||||
fs::OpenOptions,
|
fs::OpenOptions,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
sync::OnceLock,
|
||||||
},
|
},
|
||||||
writer::TieredStorageWriter,
|
writer::TieredStorageWriter,
|
||||||
};
|
};
|
||||||
|
@ -45,7 +45,7 @@ pub struct TieredStorageFormat {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TieredStorage {
|
pub struct TieredStorage {
|
||||||
reader: OnceCell<TieredStorageReader>,
|
reader: OnceLock<TieredStorageReader>,
|
||||||
format: Option<TieredStorageFormat>,
|
format: Option<TieredStorageFormat>,
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ impl TieredStorage {
|
||||||
/// is called.
|
/// is called.
|
||||||
pub fn new_writable(path: impl Into<PathBuf>, format: TieredStorageFormat) -> Self {
|
pub fn new_writable(path: impl Into<PathBuf>, format: TieredStorageFormat) -> Self {
|
||||||
Self {
|
Self {
|
||||||
reader: OnceCell::<TieredStorageReader>::new(),
|
reader: OnceLock::<TieredStorageReader>::new(),
|
||||||
format: Some(format),
|
format: Some(format),
|
||||||
path: path.into(),
|
path: path.into(),
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ impl TieredStorage {
|
||||||
pub fn new_readonly(path: impl Into<PathBuf>) -> TieredStorageResult<Self> {
|
pub fn new_readonly(path: impl Into<PathBuf>) -> TieredStorageResult<Self> {
|
||||||
let path = path.into();
|
let path = path.into();
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
reader: OnceCell::with_value(TieredStorageReader::new_from_path(&path)?),
|
reader: TieredStorageReader::new_from_path(&path).map(OnceLock::from)?,
|
||||||
format: None,
|
format: None,
|
||||||
path,
|
path,
|
||||||
})
|
})
|
||||||
|
|
|
@ -14,7 +14,6 @@ bs58 = { workspace = true }
|
||||||
bv = { workspace = true, features = ["serde"] }
|
bv = { workspace = true, features = ["serde"] }
|
||||||
lazy_static = { workspace = true }
|
lazy_static = { workspace = true }
|
||||||
log = { workspace = true, features = ["std"] }
|
log = { workspace = true, features = ["std"] }
|
||||||
once_cell = { workspace = true }
|
|
||||||
serde = { workspace = true, features = ["derive", "rc"] }
|
serde = { workspace = true, features = ["derive", "rc"] }
|
||||||
serde_bytes = { workspace = true }
|
serde_bytes = { workspace = true }
|
||||||
serde_derive = { workspace = true }
|
serde_derive = { workspace = true }
|
||||||
|
@ -32,7 +31,6 @@ either = { workspace = true, features = ["use_std"] }
|
||||||
generic-array = { workspace = true, features = ["serde", "more_lengths"] }
|
generic-array = { workspace = true, features = ["serde", "more_lengths"] }
|
||||||
im = { workspace = true, features = ["rayon", "serde"] }
|
im = { workspace = true, features = ["rayon", "serde"] }
|
||||||
memmap2 = { workspace = true }
|
memmap2 = { workspace = true }
|
||||||
once_cell = { workspace = true, features = ["alloc", "race"] }
|
|
||||||
subtle = { workspace = true }
|
subtle = { workspace = true }
|
||||||
|
|
||||||
[target.'cfg(any(unix, windows))'.dependencies]
|
[target.'cfg(any(unix, windows))'.dependencies]
|
||||||
|
|
|
@ -555,9 +555,3 @@ impl<O: AbiEnumVisitor, E: AbiEnumVisitor> AbiEnumVisitor for Result<O, E> {
|
||||||
digester.create_child()
|
digester.create_child()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: AbiExample> AbiExample for once_cell::sync::OnceCell<T> {
|
|
||||||
fn example() -> Self {
|
|
||||||
Self::with_value(T::example())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -4496,7 +4496,6 @@ dependencies = [
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"num_enum 0.6.1",
|
"num_enum 0.6.1",
|
||||||
"once_cell",
|
|
||||||
"ouroboros",
|
"ouroboros",
|
||||||
"percentage",
|
"percentage",
|
||||||
"qualifier_attr",
|
"qualifier_attr",
|
||||||
|
@ -4942,7 +4941,6 @@ dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"log",
|
"log",
|
||||||
"memmap2",
|
"memmap2",
|
||||||
"once_cell",
|
|
||||||
"rustc_version",
|
"rustc_version",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_bytes",
|
"serde_bytes",
|
||||||
|
@ -5548,7 +5546,6 @@ dependencies = [
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"num_enum 0.6.1",
|
"num_enum 0.6.1",
|
||||||
"once_cell",
|
|
||||||
"ouroboros",
|
"ouroboros",
|
||||||
"percentage",
|
"percentage",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
|
|
|
@ -37,7 +37,6 @@ num-derive = { workspace = true }
|
||||||
num-traits = { workspace = true }
|
num-traits = { workspace = true }
|
||||||
num_cpus = { workspace = true }
|
num_cpus = { workspace = true }
|
||||||
num_enum = { workspace = true }
|
num_enum = { workspace = true }
|
||||||
once_cell = { workspace = true }
|
|
||||||
ouroboros = { workspace = true }
|
ouroboros = { workspace = true }
|
||||||
percentage = { workspace = true }
|
percentage = { workspace = true }
|
||||||
rand = { workspace = true }
|
rand = { workspace = true }
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
#[cfg(RUSTC_WITH_SPECIALIZATION)]
|
||||||
|
use solana_frozen_abi::abi_example::AbiExample;
|
||||||
use {
|
use {
|
||||||
itertools::Itertools,
|
itertools::Itertools,
|
||||||
once_cell::sync::OnceCell,
|
|
||||||
serde::ser::{Serialize, Serializer},
|
serde::ser::{Serialize, Serializer},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::{AccountSharedData, ReadableAccount},
|
account::{AccountSharedData, ReadableAccount},
|
||||||
|
@ -12,7 +13,7 @@ use {
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
collections::{hash_map::Entry, HashMap},
|
collections::{hash_map::Entry, HashMap},
|
||||||
iter::FromIterator,
|
iter::FromIterator,
|
||||||
sync::Arc,
|
sync::{Arc, OnceLock},
|
||||||
},
|
},
|
||||||
thiserror::Error,
|
thiserror::Error,
|
||||||
};
|
};
|
||||||
|
@ -29,20 +30,20 @@ pub enum Error {
|
||||||
InvalidOwner(/*owner:*/ Pubkey),
|
InvalidOwner(/*owner:*/ Pubkey),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, AbiExample)]
|
#[derive(Debug)]
|
||||||
struct VoteAccountInner {
|
struct VoteAccountInner {
|
||||||
account: AccountSharedData,
|
account: AccountSharedData,
|
||||||
vote_state: OnceCell<Result<VoteState, Error>>,
|
vote_state: OnceLock<Result<VoteState, Error>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type VoteAccountsHashMap = HashMap<Pubkey, (/*stake:*/ u64, VoteAccount)>;
|
pub type VoteAccountsHashMap = HashMap<Pubkey, (/*stake:*/ u64, VoteAccount)>;
|
||||||
|
|
||||||
#[derive(Clone, Debug, AbiExample, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
#[serde(from = "Arc<VoteAccountsHashMap>")]
|
#[serde(from = "Arc<VoteAccountsHashMap>")]
|
||||||
pub struct VoteAccounts {
|
pub struct VoteAccounts {
|
||||||
vote_accounts: Arc<VoteAccountsHashMap>,
|
vote_accounts: Arc<VoteAccountsHashMap>,
|
||||||
// Inner Arc is meant to implement copy-on-write semantics.
|
// Inner Arc is meant to implement copy-on-write semantics.
|
||||||
staked_nodes: OnceCell<
|
staked_nodes: OnceLock<
|
||||||
Arc<
|
Arc<
|
||||||
HashMap<
|
HashMap<
|
||||||
Pubkey, // VoteAccount.vote_state.node_pubkey.
|
Pubkey, // VoteAccount.vote_state.node_pubkey.
|
||||||
|
@ -243,7 +244,7 @@ impl TryFrom<AccountSharedData> for VoteAccountInner {
|
||||||
}
|
}
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
account,
|
account,
|
||||||
vote_state: OnceCell::new(),
|
vote_state: OnceLock::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,7 +263,7 @@ impl Default for VoteAccounts {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
vote_accounts: Arc::default(),
|
vote_accounts: Arc::default(),
|
||||||
staked_nodes: OnceCell::new(),
|
staked_nodes: OnceLock::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -281,7 +282,7 @@ impl From<Arc<VoteAccountsHashMap>> for VoteAccounts {
|
||||||
fn from(vote_accounts: Arc<VoteAccountsHashMap>) -> Self {
|
fn from(vote_accounts: Arc<VoteAccountsHashMap>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
vote_accounts,
|
vote_accounts,
|
||||||
staked_nodes: OnceCell::new(),
|
staked_nodes: OnceLock::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -316,6 +317,26 @@ impl Serialize for VoteAccounts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(RUSTC_WITH_SPECIALIZATION)]
|
||||||
|
impl AbiExample for VoteAccountInner {
|
||||||
|
fn example() -> Self {
|
||||||
|
Self {
|
||||||
|
account: AccountSharedData::example(),
|
||||||
|
vote_state: OnceLock::from(Result::<VoteState, Error>::example()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(RUSTC_WITH_SPECIALIZATION)]
|
||||||
|
impl AbiExample for VoteAccounts {
|
||||||
|
fn example() -> Self {
|
||||||
|
Self {
|
||||||
|
vote_accounts: Arc::<VoteAccountsHashMap>::example(),
|
||||||
|
staked_nodes: OnceLock::from(Arc::<HashMap<Pubkey, u64>>::example()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use {
|
use {
|
||||||
|
|
Loading…
Reference in New Issue