Skip to content

Commit

Permalink
Revert "rpc: performance fix for getProgramAccounts (solana-labs#19941)"
Browse files Browse the repository at this point in the history
This reverts commit 05415ce.
  • Loading branch information
frits-metalogix authored Nov 24, 2021
1 parent ce3d125 commit fc84c50
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,18 @@ impl JsonRpcRequestProcessor {
pubkeys: Vec<Pubkey>,
config: Option<RpcAccountInfoConfig>,
) -> Result<RpcResponse<Vec<Option<UiAccount>>>> {
let mut accounts: Vec<Option<UiAccount>> = vec![];

let config = config.unwrap_or_default();
let bank = self.bank(config.commitment);
let encoding = config.encoding.unwrap_or(UiAccountEncoding::Base64);
check_slice_and_encoding(&encoding, config.data_slice.is_some())?;

let accounts = pubkeys
.into_iter()
.map(|pubkey| get_encoded_account(&bank, &pubkey, encoding, config.data_slice))
.collect::<Result<Vec<_>>>()?;
for pubkey in pubkeys {
let response_account =
get_encoded_account(&bank, &pubkey, encoding, config.data_slice)?;
accounts.push(response_account)
}
Ok(new_response(&bank, accounts))
}

Expand Down Expand Up @@ -392,21 +395,19 @@ impl JsonRpcRequestProcessor {
self.get_filtered_program_accounts(&bank, program_id, filters)?
}
};
let result = if program_id == &spl_token_id_v2_0()
&& encoding == UiAccountEncoding::JsonParsed
{
get_parsed_token_accounts(bank.clone(), keyed_accounts.into_iter()).collect()
} else {
keyed_accounts
.into_iter()
.map(|(pubkey, account)| {
Ok(RpcKeyedAccount {
let result =
if program_id == &spl_token_id_v2_0() && encoding == UiAccountEncoding::JsonParsed {
get_parsed_token_accounts(bank.clone(), keyed_accounts.into_iter()).collect()
} else {
let mut encoded_accounts = vec![];
for (pubkey, account) in keyed_accounts {
encoded_accounts.push(RpcKeyedAccount {
pubkey: pubkey.to_string(),
account: encode_account(&account, &pubkey, encoding, data_slice_config)?,
})
})
.collect::<Result<Vec<_>>>()?
};
});
}
encoded_accounts
};
Ok(result).map(|result| match with_context {
true => OptionalContext::Context(new_response(&bank, result)),
false => OptionalContext::NoContext(result),
Expand Down Expand Up @@ -2825,10 +2826,10 @@ pub mod rpc_accounts {
max_multiple_accounts
)));
}
let pubkeys = pubkey_strs
.into_iter()
.map(|pubkey_str| verify_pubkey(&pubkey_str))
.collect::<Result<Vec<_>>>()?;
let mut pubkeys: Vec<Pubkey> = vec![];
for pubkey_str in pubkey_strs {
pubkeys.push(verify_pubkey(&pubkey_str)?);
}
meta.get_multiple_accounts(pubkeys, config)
}

Expand Down

0 comments on commit fc84c50

Please sign in to comment.