From 1403eaeefcf7a99754e990111129d4c493a72a00 Mon Sep 17 00:00:00 2001 From: behzad nouri Date: Thu, 5 Aug 2021 16:44:07 -0400 Subject: [PATCH] makes solana_runtime::vote_account::VoteAccount private VoteAccount is an implementation detail, and should not be public. Only ArcVoteAccount is the public type. --- runtime/src/vote_account.rs | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/runtime/src/vote_account.rs b/runtime/src/vote_account.rs index deebc99d2a..6037eb36b6 100644 --- a/runtime/src/vote_account.rs +++ b/runtime/src/vote_account.rs @@ -11,7 +11,6 @@ use { cmp::Ordering, collections::{hash_map::Entry, HashMap}, iter::FromIterator, - ops::Deref, sync::{Arc, Once, RwLock, RwLockReadGuard}, }, }; @@ -25,7 +24,7 @@ const INVALID_VOTE_STATE: Result = pub struct ArcVoteAccount(Arc); #[derive(Debug, AbiExample)] -pub struct VoteAccount { +struct VoteAccount { account: Account, vote_state: RwLock>, vote_state_once: Once, @@ -47,16 +46,18 @@ pub struct VoteAccounts { staked_nodes_once: Once, } -impl VoteAccount { +impl ArcVoteAccount { pub fn lamports(&self) -> u64 { - self.account.lamports + self.0.account.lamports } pub fn vote_state(&self) -> RwLockReadGuard> { - self.vote_state_once.call_once(|| { - *self.vote_state.write().unwrap() = VoteState::deserialize(&self.account.data); + let inner = &self.0; + inner.vote_state_once.call_once(|| { + let vote_state = VoteState::deserialize(&inner.account.data); + *inner.vote_state.write().unwrap() = vote_state; }); - self.vote_state.read().unwrap() + inner.vote_state.read().unwrap() } /// VoteState.node_pubkey of this vote-account. @@ -155,20 +156,12 @@ impl VoteAccounts { } } -impl Deref for ArcVoteAccount { - type Target = VoteAccount; - - fn deref(&self) -> &Self::Target { - self.0.deref() - } -} - impl Serialize for ArcVoteAccount { fn serialize(&self, serializer: S) -> Result where S: Serializer, { - self.account.serialize(serializer) + self.0.account.serialize(serializer) } } @@ -187,6 +180,7 @@ impl From for ArcVoteAccount { Self(Arc::new(VoteAccount::from(account))) } } + impl From for ArcVoteAccount { fn from(account: Account) -> Self { Self(Arc::new(VoteAccount::from(account))) @@ -195,11 +189,7 @@ impl From for ArcVoteAccount { impl From for VoteAccount { fn from(account: AccountSharedData) -> Self { - Self { - account: Account::from(account), - vote_state: RwLock::new(INVALID_VOTE_STATE), - vote_state_once: Once::new(), - } + Self::from(Account::from(account)) } }