caches vote-state de-serialized from vote accounts (#13795)
Gossip and other places repeatedly de-serialize vote-state stored in vote accounts. Ideally the first de-serialization should cache the result. This commit adds new VoteAccount type which lazily de-serializes VoteState from Account data and caches the result internally. Serialize and Deserialize traits are manually implemented to match existing code. So, despite changes to frozen_abi, this commit should be backward compatible.
This commit is contained in:
@ -537,13 +537,15 @@ impl JsonRpcRequestProcessor {
|
||||
let epoch_vote_accounts = bank
|
||||
.epoch_vote_accounts(bank.get_epoch_and_slot_index(bank.slot()).0)
|
||||
.ok_or_else(Error::invalid_request)?;
|
||||
let default_vote_state = VoteState::default();
|
||||
let (current_vote_accounts, delinquent_vote_accounts): (
|
||||
Vec<RpcVoteAccountInfo>,
|
||||
Vec<RpcVoteAccountInfo>,
|
||||
) = vote_accounts
|
||||
.iter()
|
||||
.map(|(pubkey, (activated_stake, account))| {
|
||||
let vote_state = VoteState::from(&account).unwrap_or_default();
|
||||
let vote_state = account.vote_state();
|
||||
let vote_state = vote_state.as_ref().unwrap_or(&default_vote_state);
|
||||
let last_vote = if let Some(vote) = vote_state.votes.iter().last() {
|
||||
vote.slot
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user