remove compression from getProgramAccounts
This commit is contained in:
parent
95f4374f52
commit
ca7bf93787
|
@ -7,7 +7,8 @@ use base64::Engine;
|
|||
use jsonrpc_core_client::transports::http;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use solana_account_decoder::{UiAccount, UiAccountEncoding};
|
||||
use solana_account_decoder::{UiAccount, UiAccountData, UiAccountEncoding};
|
||||
use solana_client::rpc_response::RpcKeyedAccount;
|
||||
use solana_client::{
|
||||
nonblocking::rpc_client::RpcClient,
|
||||
rpc_config::{RpcAccountInfoConfig, RpcProgramAccountsConfig},
|
||||
|
@ -123,6 +124,9 @@ pub async fn get_compressed_program_account(
|
|||
let config = RpcProgramAccountsConfig {
|
||||
filters: None,
|
||||
with_context: Some(true),
|
||||
account_config: RpcAccountInfoConfig {
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
@ -130,7 +134,6 @@ pub async fn get_compressed_program_account(
|
|||
}
|
||||
|
||||
// called on startup to get the required accounts, few calls with some 100 thousand accounts
|
||||
#[tracing::instrument(skip_all, level = "trace")]
|
||||
pub async fn get_compressed_program_account_rpc(
|
||||
rpc_client: &RpcClient,
|
||||
filters: &HashSet<Pubkey>,
|
||||
|
@ -138,6 +141,10 @@ pub async fn get_compressed_program_account_rpc(
|
|||
) -> anyhow::Result<(u64, Vec<AccountWrite>)> {
|
||||
let config = RpcProgramAccountsConfig {
|
||||
with_context: Some(true),
|
||||
account_config: RpcAccountInfoConfig{
|
||||
encoding: Some(UiAccountEncoding::Base64),
|
||||
..Default::default()
|
||||
},
|
||||
..config
|
||||
};
|
||||
|
||||
|
@ -149,14 +156,11 @@ pub async fn get_compressed_program_account_rpc(
|
|||
info!("gPA for {}", program_id);
|
||||
|
||||
let result = rpc_client
|
||||
.send::<OptionalContext<Vec<RpcKeyedCompressedAccount>>>(
|
||||
solana_client::rpc_request::RpcRequest::Custom {
|
||||
method: "getProgramAccountsCompressed",
|
||||
},
|
||||
.send::<OptionalContext<Vec<RpcKeyedAccount>>>(
|
||||
solana_client::rpc_request::RpcRequest::GetProgramAccounts ,
|
||||
json!([program_id.to_string(), config]),
|
||||
)
|
||||
.await;
|
||||
|
||||
// failed to get over compressed program accounts
|
||||
match result {
|
||||
Ok(OptionalContext::Context(response)) => {
|
||||
|
@ -165,13 +169,19 @@ pub async fn get_compressed_program_account_rpc(
|
|||
min_slot = updated_slot.min(min_slot);
|
||||
|
||||
for key_account in response.value {
|
||||
let base64_decoded =
|
||||
base64::engine::general_purpose::STANDARD.decode(&key_account.a)?;
|
||||
let account_data = if let UiAccountData::Binary(data, encoding) = &key_account.account.data {
|
||||
if let UiAccountEncoding::Base64 = encoding {
|
||||
data
|
||||
} else {
|
||||
panic!("wrong encoding")
|
||||
}
|
||||
} else {
|
||||
panic!("wrong data type")
|
||||
};
|
||||
base64::engine::general_purpose::STANDARD.decode(&account_data)?;
|
||||
// decompress all the account information
|
||||
let uncompressed = lz4::block::decompress(&base64_decoded, None)?;
|
||||
let shared_data = bincode::deserialize::<AccountSharedData>(&uncompressed)?;
|
||||
let pubkey = Pubkey::from_str(&key_account.p).unwrap();
|
||||
let account: Account = shared_data.into();
|
||||
let pubkey = Pubkey::from_str(&key_account.pubkey).unwrap();
|
||||
let account: Account = key_account.account.decode().unwrap();
|
||||
snap_result.push(account_write_from(
|
||||
pubkey,
|
||||
updated_slot,
|
||||
|
@ -180,7 +190,7 @@ pub async fn get_compressed_program_account_rpc(
|
|||
));
|
||||
}
|
||||
|
||||
info!(
|
||||
println!(
|
||||
"Decompressed snapshot for {} with {} accounts",
|
||||
program_id,
|
||||
snap_result.len()
|
||||
|
|
Loading…
Reference in New Issue