Returning only program id, when there are no filters and dataslice lenghth is 0
This commit is contained in:
parent
b1d8e4181f
commit
de5362d4bb
|
@ -1065,6 +1065,7 @@ impl Accounts {
|
||||||
filter: F,
|
filter: F,
|
||||||
config: &ScanConfig,
|
config: &ScanConfig,
|
||||||
byte_limit_for_scan: Option<usize>,
|
byte_limit_for_scan: Option<usize>,
|
||||||
|
just_get_program_ids: bool,
|
||||||
) -> ScanResult<Vec<TransactionAccount>> {
|
) -> ScanResult<Vec<TransactionAccount>> {
|
||||||
let sum = AtomicUsize::default();
|
let sum = AtomicUsize::default();
|
||||||
let config = config.recreate_with_abort();
|
let config = config.recreate_with_abort();
|
||||||
|
@ -1077,21 +1078,30 @@ impl Accounts {
|
||||||
*index_key,
|
*index_key,
|
||||||
|some_account_tuple| {
|
|some_account_tuple| {
|
||||||
Self::load_while_filtering(&mut collector, some_account_tuple, |account| {
|
Self::load_while_filtering(&mut collector, some_account_tuple, |account| {
|
||||||
let use_account = filter(account);
|
if just_get_program_ids {
|
||||||
if use_account
|
Self::accumulate_and_check_scan_result_size(
|
||||||
&& Self::accumulate_and_check_scan_result_size(
|
|
||||||
&sum,
|
&sum,
|
||||||
account,
|
account,
|
||||||
&byte_limit_for_scan,
|
&byte_limit_for_scan,
|
||||||
)
|
)
|
||||||
{
|
} else {
|
||||||
// total size of results exceeds size limit, so abort scan
|
let use_account = filter(account);
|
||||||
config.abort();
|
if use_account
|
||||||
|
&& Self::accumulate_and_check_scan_result_size(
|
||||||
|
&sum,
|
||||||
|
account,
|
||||||
|
&byte_limit_for_scan,
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// total size of results exceeds size limit, so abort scan
|
||||||
|
config.abort();
|
||||||
|
}
|
||||||
|
use_account
|
||||||
}
|
}
|
||||||
use_account
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
&config,
|
&config,
|
||||||
|
just_get_program_ids,
|
||||||
)
|
)
|
||||||
.map(|_| collector);
|
.map(|_| collector);
|
||||||
Self::maybe_abort_scan(result, &config)
|
Self::maybe_abort_scan(result, &config)
|
||||||
|
|
|
@ -4947,6 +4947,7 @@ impl AccountsDb {
|
||||||
index_key: IndexKey,
|
index_key: IndexKey,
|
||||||
mut scan_func: F,
|
mut scan_func: F,
|
||||||
config: &ScanConfig,
|
config: &ScanConfig,
|
||||||
|
just_get_program_ids: bool,
|
||||||
) -> ScanResult<bool>
|
) -> ScanResult<bool>
|
||||||
where
|
where
|
||||||
F: FnMut(Option<(&Pubkey, AccountSharedData, Slot)>),
|
F: FnMut(Option<(&Pubkey, AccountSharedData, Slot)>),
|
||||||
|
@ -4968,11 +4969,16 @@ impl AccountsDb {
|
||||||
bank_id,
|
bank_id,
|
||||||
index_key,
|
index_key,
|
||||||
|pubkey, (account_info, slot)| {
|
|pubkey, (account_info, slot)| {
|
||||||
let account_slot = self
|
if just_get_program_ids {
|
||||||
.get_account_accessor(slot, pubkey, &account_info.storage_location())
|
let dummy_shared_data = AccountSharedData::new(0, 0, key);
|
||||||
.get_loaded_account()
|
scan_func(Some((pubkey, dummy_shared_data, slot)))
|
||||||
.map(|loaded_account| (pubkey, loaded_account.take_account(), slot));
|
} else {
|
||||||
scan_func(account_slot)
|
let account_slot = self
|
||||||
|
.get_account_accessor(slot, pubkey, &account_info.storage_location())
|
||||||
|
.get_loaded_account()
|
||||||
|
.map(|loaded_account| (pubkey, loaded_account.take_account(), slot));
|
||||||
|
scan_func(account_slot)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
config,
|
config,
|
||||||
)?;
|
)?;
|
||||||
|
|
|
@ -105,7 +105,7 @@ impl Default for ScanConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
collect_all_unsorted: true,
|
collect_all_unsorted: true,
|
||||||
abort: None
|
abort: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -486,6 +486,12 @@ impl JsonRpcRequestProcessor {
|
||||||
min_context_slot,
|
min_context_slot,
|
||||||
})?;
|
})?;
|
||||||
let encoding = encoding.unwrap_or(UiAccountEncoding::Binary);
|
let encoding = encoding.unwrap_or(UiAccountEncoding::Binary);
|
||||||
|
let just_get_program_ids = data_slice_config
|
||||||
|
.clone()
|
||||||
|
.map(|x| x.length == 0)
|
||||||
|
.unwrap_or_default()
|
||||||
|
&& filters.len() == 0;
|
||||||
|
|
||||||
optimize_filters(&mut filters);
|
optimize_filters(&mut filters);
|
||||||
let keyed_accounts = {
|
let keyed_accounts = {
|
||||||
if let Some(owner) = get_spl_token_owner_filter(program_id, &filters) {
|
if let Some(owner) = get_spl_token_owner_filter(program_id, &filters) {
|
||||||
|
@ -493,7 +499,12 @@ impl JsonRpcRequestProcessor {
|
||||||
} else if let Some(mint) = get_spl_token_mint_filter(program_id, &filters) {
|
} else if let Some(mint) = get_spl_token_mint_filter(program_id, &filters) {
|
||||||
self.get_filtered_spl_token_accounts_by_mint(&bank, program_id, &mint, filters)?
|
self.get_filtered_spl_token_accounts_by_mint(&bank, program_id, &mint, filters)?
|
||||||
} else {
|
} else {
|
||||||
self.get_filtered_program_accounts(&bank, program_id, filters)?
|
self.get_filtered_program_accounts(
|
||||||
|
&bank,
|
||||||
|
program_id,
|
||||||
|
filters,
|
||||||
|
just_get_program_ids,
|
||||||
|
)?
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let accounts = if is_known_spl_token_id(program_id)
|
let accounts = if is_known_spl_token_id(program_id)
|
||||||
|
@ -1969,7 +1980,7 @@ impl JsonRpcRequestProcessor {
|
||||||
} else {
|
} else {
|
||||||
// Filter on Token Account state
|
// Filter on Token Account state
|
||||||
filters.push(RpcFilterType::TokenAccountState);
|
filters.push(RpcFilterType::TokenAccountState);
|
||||||
self.get_filtered_program_accounts(&bank, &token_program_id, filters)?
|
self.get_filtered_program_accounts(&bank, &token_program_id, filters, false)?
|
||||||
};
|
};
|
||||||
let accounts = if encoding == UiAccountEncoding::JsonParsed {
|
let accounts = if encoding == UiAccountEncoding::JsonParsed {
|
||||||
get_parsed_token_accounts(bank.clone(), keyed_accounts.into_iter()).collect()
|
get_parsed_token_accounts(bank.clone(), keyed_accounts.into_iter()).collect()
|
||||||
|
@ -1993,6 +2004,7 @@ impl JsonRpcRequestProcessor {
|
||||||
bank: &Bank,
|
bank: &Bank,
|
||||||
program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
mut filters: Vec<RpcFilterType>,
|
mut filters: Vec<RpcFilterType>,
|
||||||
|
just_get_program_ids: bool,
|
||||||
) -> RpcCustomResult<Vec<(Pubkey, AccountSharedData)>> {
|
) -> RpcCustomResult<Vec<(Pubkey, AccountSharedData)>> {
|
||||||
optimize_filters(&mut filters);
|
optimize_filters(&mut filters);
|
||||||
let filter_closure = |account: &AccountSharedData| {
|
let filter_closure = |account: &AccountSharedData| {
|
||||||
|
@ -2023,6 +2035,7 @@ impl JsonRpcRequestProcessor {
|
||||||
},
|
},
|
||||||
&ScanConfig::default(),
|
&ScanConfig::default(),
|
||||||
bank.byte_limit_for_scans(),
|
bank.byte_limit_for_scans(),
|
||||||
|
just_get_program_ids,
|
||||||
)
|
)
|
||||||
.map_err(|e| RpcCustomError::ScanError {
|
.map_err(|e| RpcCustomError::ScanError {
|
||||||
message: e.to_string(),
|
message: e.to_string(),
|
||||||
|
@ -2079,12 +2092,13 @@ impl JsonRpcRequestProcessor {
|
||||||
},
|
},
|
||||||
&ScanConfig::default(),
|
&ScanConfig::default(),
|
||||||
bank.byte_limit_for_scans(),
|
bank.byte_limit_for_scans(),
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.map_err(|e| RpcCustomError::ScanError {
|
.map_err(|e| RpcCustomError::ScanError {
|
||||||
message: e.to_string(),
|
message: e.to_string(),
|
||||||
})?)
|
})?)
|
||||||
} else {
|
} else {
|
||||||
self.get_filtered_program_accounts(bank, program_id, filters)
|
self.get_filtered_program_accounts(bank, program_id, filters, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2129,12 +2143,13 @@ impl JsonRpcRequestProcessor {
|
||||||
},
|
},
|
||||||
&ScanConfig::default(),
|
&ScanConfig::default(),
|
||||||
bank.byte_limit_for_scans(),
|
bank.byte_limit_for_scans(),
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.map_err(|e| RpcCustomError::ScanError {
|
.map_err(|e| RpcCustomError::ScanError {
|
||||||
message: e.to_string(),
|
message: e.to_string(),
|
||||||
})?)
|
})?)
|
||||||
} else {
|
} else {
|
||||||
self.get_filtered_program_accounts(bank, program_id, filters)
|
self.get_filtered_program_accounts(bank, program_id, filters, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6818,6 +6818,7 @@ impl Bank {
|
||||||
filter: F,
|
filter: F,
|
||||||
config: &ScanConfig,
|
config: &ScanConfig,
|
||||||
byte_limit_for_scan: Option<usize>,
|
byte_limit_for_scan: Option<usize>,
|
||||||
|
just_get_program_ids: bool,
|
||||||
) -> ScanResult<Vec<TransactionAccount>> {
|
) -> ScanResult<Vec<TransactionAccount>> {
|
||||||
self.rc.accounts.load_by_index_key_with_filter(
|
self.rc.accounts.load_by_index_key_with_filter(
|
||||||
&self.ancestors,
|
&self.ancestors,
|
||||||
|
@ -6826,6 +6827,7 @@ impl Bank {
|
||||||
filter,
|
filter,
|
||||||
config,
|
config,
|
||||||
byte_limit_for_scan,
|
byte_limit_for_scan,
|
||||||
|
just_get_program_ids,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4329,6 +4329,7 @@ fn test_get_filtered_indexed_accounts_limit_exceeded() {
|
||||||
|_| true,
|
|_| true,
|
||||||
&ScanConfig::default(),
|
&ScanConfig::default(),
|
||||||
Some(limit), // limit here will be exceeded, resulting in aborted scan
|
Some(limit), // limit here will be exceeded, resulting in aborted scan
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.is_err());
|
.is_err());
|
||||||
}
|
}
|
||||||
|
@ -4355,6 +4356,7 @@ fn test_get_filtered_indexed_accounts() {
|
||||||
|_| true,
|
|_| true,
|
||||||
&ScanConfig::default(),
|
&ScanConfig::default(),
|
||||||
None,
|
None,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(indexed_accounts.len(), 1);
|
assert_eq!(indexed_accounts.len(), 1);
|
||||||
|
@ -4373,6 +4375,7 @@ fn test_get_filtered_indexed_accounts() {
|
||||||
|_| true,
|
|_| true,
|
||||||
&ScanConfig::default(),
|
&ScanConfig::default(),
|
||||||
None,
|
None,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(indexed_accounts.len(), 1);
|
assert_eq!(indexed_accounts.len(), 1);
|
||||||
|
@ -4383,6 +4386,7 @@ fn test_get_filtered_indexed_accounts() {
|
||||||
|_| true,
|
|_| true,
|
||||||
&ScanConfig::default(),
|
&ScanConfig::default(),
|
||||||
None,
|
None,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(indexed_accounts.len(), 1);
|
assert_eq!(indexed_accounts.len(), 1);
|
||||||
|
@ -4395,6 +4399,7 @@ fn test_get_filtered_indexed_accounts() {
|
||||||
|account| account.owner() == &program_id,
|
|account| account.owner() == &program_id,
|
||||||
&ScanConfig::default(),
|
&ScanConfig::default(),
|
||||||
None,
|
None,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(indexed_accounts.is_empty());
|
assert!(indexed_accounts.is_empty());
|
||||||
|
@ -4404,6 +4409,7 @@ fn test_get_filtered_indexed_accounts() {
|
||||||
|account| account.owner() == &another_program_id,
|
|account| account.owner() == &another_program_id,
|
||||||
&ScanConfig::default(),
|
&ScanConfig::default(),
|
||||||
None,
|
None,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(indexed_accounts.len(), 1);
|
assert_eq!(indexed_accounts.len(), 1);
|
||||||
|
|
|
@ -43,6 +43,7 @@ pub fn calculate_non_circulating_supply(bank: &Bank) -> ScanResult<NonCirculatin
|
||||||
|account| account.owner() == &stake::program::id(),
|
|account| account.owner() == &stake::program::id(),
|
||||||
config,
|
config,
|
||||||
None,
|
None,
|
||||||
|
false,
|
||||||
)?
|
)?
|
||||||
} else {
|
} else {
|
||||||
bank.get_program_accounts(&stake::program::id(), config)?
|
bank.get_program_accounts(&stake::program::id(), config)?
|
||||||
|
|
|
@ -88,8 +88,7 @@ impl FromStr for Hash {
|
||||||
if s.len() > MAX_BASE58_LEN {
|
if s.len() > MAX_BASE58_LEN {
|
||||||
return Err(ParseHashError::WrongSize);
|
return Err(ParseHashError::WrongSize);
|
||||||
}
|
}
|
||||||
let bytes = fd_bs58::decode_32(s)
|
let bytes = fd_bs58::decode_32(s).map_err(|_| ParseHashError::Invalid)?;
|
||||||
.map_err(|_| ParseHashError::Invalid)?;
|
|
||||||
if bytes.len() != mem::size_of::<Hash>() {
|
if bytes.len() != mem::size_of::<Hash>() {
|
||||||
Err(ParseHashError::WrongSize)
|
Err(ParseHashError::WrongSize)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -109,8 +109,7 @@ impl FromStr for Hash {
|
||||||
if s.len() > MAX_BASE58_LEN {
|
if s.len() > MAX_BASE58_LEN {
|
||||||
return Err(ParseHashError::WrongSize);
|
return Err(ParseHashError::WrongSize);
|
||||||
}
|
}
|
||||||
let bytes = fd_bs58::decode_32(s)
|
let bytes = fd_bs58::decode_32(s).map_err(|_| ParseHashError::Invalid)?;
|
||||||
.map_err(|_| ParseHashError::Invalid)?;
|
|
||||||
if bytes.len() != mem::size_of::<Hash>() {
|
if bytes.len() != mem::size_of::<Hash>() {
|
||||||
Err(ParseHashError::WrongSize)
|
Err(ParseHashError::WrongSize)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -88,8 +88,7 @@ impl FromStr for Hash {
|
||||||
if s.len() > MAX_BASE58_LEN {
|
if s.len() > MAX_BASE58_LEN {
|
||||||
return Err(ParseHashError::WrongSize);
|
return Err(ParseHashError::WrongSize);
|
||||||
}
|
}
|
||||||
let bytes = fd_bs58::decode_32(s)
|
let bytes = fd_bs58::decode_32(s).map_err(|_| ParseHashError::Invalid)?;
|
||||||
.map_err(|_| ParseHashError::Invalid)?;
|
|
||||||
if bytes.len() != mem::size_of::<Hash>() {
|
if bytes.len() != mem::size_of::<Hash>() {
|
||||||
Err(ParseHashError::WrongSize)
|
Err(ParseHashError::WrongSize)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -115,8 +115,7 @@ impl FromStr for Pubkey {
|
||||||
if s.len() > MAX_BASE58_LEN {
|
if s.len() > MAX_BASE58_LEN {
|
||||||
return Err(ParsePubkeyError::WrongSize);
|
return Err(ParsePubkeyError::WrongSize);
|
||||||
}
|
}
|
||||||
let pubkey_vec = fd_bs58::decode_32(s)
|
let pubkey_vec = fd_bs58::decode_32(s).map_err(|_| ParsePubkeyError::Invalid)?;
|
||||||
.map_err(|_| ParsePubkeyError::Invalid)?;
|
|
||||||
if pubkey_vec.len() != mem::size_of::<Pubkey>() {
|
if pubkey_vec.len() != mem::size_of::<Pubkey>() {
|
||||||
Err(ParsePubkeyError::WrongSize)
|
Err(ParsePubkeyError::WrongSize)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue