Skip to content

Commit e7b6d7d

Browse files
authored
remote-externalities: rpc_child_get_keys to use paged scraping (#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.
1 parent 247358a commit e7b6d7d

File tree

1 file changed

+37
-16
lines changed
  • substrate/utils/frame/remote-externalities/src

1 file changed

+37
-16
lines changed

substrate/utils/frame/remote-externalities/src/lib.rs

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -834,30 +834,51 @@ where
834834
) -> Result<Vec<StorageKey>, &'static str> {
835835
let retry_strategy =
836836
FixedInterval::new(Self::KEYS_PAGE_RETRY_INTERVAL).take(Self::MAX_RETRIES);
837-
let get_child_keys_closure = || {
838-
#[allow(deprecated)]
839-
substrate_rpc_client::ChildStateApi::storage_keys(
840-
client,
841-
PrefixedStorageKey::new(prefixed_top_key.as_ref().to_vec()),
842-
child_prefix.clone(),
843-
Some(at),
844-
)
845-
};
846-
let child_keys =
847-
Retry::spawn(retry_strategy, get_child_keys_closure).await.map_err(|e| {
848-
error!(target: LOG_TARGET, "Error = {:?}", e);
849-
"rpc child_get_keys failed."
850-
})?;
837+
let mut all_child_keys = Vec::new();
838+
let mut start_key = None;
839+
840+
loop {
841+
let get_child_keys_closure = || {
842+
let top_key = PrefixedStorageKey::new(prefixed_top_key.0.clone());
843+
substrate_rpc_client::ChildStateApi::storage_keys_paged(
844+
client,
845+
top_key,
846+
Some(child_prefix.clone()),
847+
Self::DEFAULT_KEY_DOWNLOAD_PAGE,
848+
start_key.clone(),
849+
Some(at),
850+
)
851+
};
852+
853+
let child_keys = Retry::spawn(retry_strategy.clone(), get_child_keys_closure)
854+
.await
855+
.map_err(|e| {
856+
error!(target: LOG_TARGET, "Error = {:?}", e);
857+
"rpc child_get_keys failed."
858+
})?;
859+
860+
let keys_count = child_keys.len();
861+
if keys_count == 0 {
862+
break;
863+
}
864+
865+
start_key = child_keys.last().cloned();
866+
all_child_keys.extend(child_keys);
867+
868+
if keys_count < Self::DEFAULT_KEY_DOWNLOAD_PAGE as usize {
869+
break;
870+
}
871+
}
851872

852873
debug!(
853874
target: LOG_TARGET,
854875
"[thread = {:?}] scraped {} child-keys of the child-bearing top key: {}",
855876
std::thread::current().id(),
856-
child_keys.len(),
877+
all_child_keys.len(),
857878
HexDisplay::from(prefixed_top_key)
858879
);
859880

860-
Ok(child_keys)
881+
Ok(all_child_keys)
861882
}
862883
}
863884

0 commit comments

Comments
 (0)