Skip to content

Commit

Permalink
remote-externalities: rpc_child_get_keys to use paged scraping (p…
Browse files Browse the repository at this point in the history
…aritytech#4512)

Replace usage of deprecated
`substrate_rpc_client::ChildStateApi::storage_keys` with
`substrate_rpc_client::ChildStateApi::storage_keys_paged`.

Required for successful scraping of Aleph Zero state.
  • Loading branch information
liamaharon authored and TarekkMA committed Aug 2, 2024
1 parent 1ce3f9a commit 8c6c3f3
Showing 1 changed file with 37 additions and 16 deletions.
53 changes: 37 additions & 16 deletions substrate/utils/frame/remote-externalities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,30 +834,51 @@ where
) -> Result<Vec<StorageKey>, &'static str> {
let retry_strategy =
FixedInterval::new(Self::KEYS_PAGE_RETRY_INTERVAL).take(Self::MAX_RETRIES);
let get_child_keys_closure = || {
#[allow(deprecated)]
substrate_rpc_client::ChildStateApi::storage_keys(
client,
PrefixedStorageKey::new(prefixed_top_key.as_ref().to_vec()),
child_prefix.clone(),
Some(at),
)
};
let child_keys =
Retry::spawn(retry_strategy, get_child_keys_closure).await.map_err(|e| {
error!(target: LOG_TARGET, "Error = {:?}", e);
"rpc child_get_keys failed."
})?;
let mut all_child_keys = Vec::new();
let mut start_key = None;

loop {
let get_child_keys_closure = || {
let top_key = PrefixedStorageKey::new(prefixed_top_key.0.clone());
substrate_rpc_client::ChildStateApi::storage_keys_paged(
client,
top_key,
Some(child_prefix.clone()),
Self::DEFAULT_KEY_DOWNLOAD_PAGE,
start_key.clone(),
Some(at),
)
};

let child_keys = Retry::spawn(retry_strategy.clone(), get_child_keys_closure)
.await
.map_err(|e| {
error!(target: LOG_TARGET, "Error = {:?}", e);
"rpc child_get_keys failed."
})?;

let keys_count = child_keys.len();
if keys_count == 0 {
break;
}

start_key = child_keys.last().cloned();
all_child_keys.extend(child_keys);

if keys_count < Self::DEFAULT_KEY_DOWNLOAD_PAGE as usize {
break;
}
}

debug!(
target: LOG_TARGET,
"[thread = {:?}] scraped {} child-keys of the child-bearing top key: {}",
std::thread::current().id(),
child_keys.len(),
all_child_keys.len(),
HexDisplay::from(prefixed_top_key)
);

Ok(child_keys)
Ok(all_child_keys)
}
}

Expand Down

0 comments on commit 8c6c3f3

Please sign in to comment.