Skip to content

Commit

Permalink
Merge pull request #549 from paritytech/AndreiEres/fix-claim-queue
Browse files Browse the repository at this point in the history
Fix crashing on empty claim queue
  • Loading branch information
AndreiEres authored Sep 22, 2023
2 parents a566ada + 85a8018 commit 745eb7d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
22 changes: 8 additions & 14 deletions essentials/src/api/subxt_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ impl RequestExecutor {
let need_to_retry = matches!(
e,
SubxtWrapperError::SubxtError(subxt::Error::Io(_)) |
SubxtWrapperError::SubxtError(subxt::Error::Rpc(_)) |
SubxtWrapperError::NoResponseFromDynamicApi(_)
SubxtWrapperError::SubxtError(subxt::Error::Rpc(_))
);
if !need_to_retry {
return Err(e)
Expand Down Expand Up @@ -527,7 +526,7 @@ async fn fetch_dynamic_storage(
.at(block_hash)
.fetch(&subxt::dynamic::storage_root(pallet_name, entry_name))
.await?
.map_or(Err(SubxtWrapperError::NoResponseFromDynamicApi(format!("{pallet_name}.{entry_name}"))), |v| {
.map_or(Err(SubxtWrapperError::EmptyResponseFromDynamicStorage(format!("{pallet_name}.{entry_name}"))), |v| {
v.to_value().map_err(|e| e.into())
})
}
Expand Down Expand Up @@ -673,15 +672,10 @@ async fn subxt_get_host_configuration(api: &OnlineClient<PolkadotConfig>) -> Res
let pallet_name = "Configuration";
let entry_name = "ActiveConfig";
let addr = subxt::dynamic::storage_root(pallet_name, entry_name);
let value = api
.storage()
.at_latest()
.await?
.fetch(&addr)
.await?
.map_or(Err(SubxtWrapperError::NoResponseFromDynamicApi(format!("{pallet_name}.{entry_name}"))), |v| {
v.to_value().map_err(|e| e.into())
})?;
let value = api.storage().at_latest().await?.fetch(&addr).await?.map_or(
Err(SubxtWrapperError::EmptyResponseFromDynamicStorage(format!("{pallet_name}.{entry_name}"))),
|v| v.to_value().map_err(|e| e.into()),
)?;

Ok(Response::HostConfiguration(DynamicHostConfiguration::new(value)))
}
Expand Down Expand Up @@ -726,8 +720,8 @@ pub enum SubxtWrapperError {
ConnectionError,
#[error("decode extinisc error")]
DecodeExtrinsicError,
#[error("no response from dynamic api: {0}")]
NoResponseFromDynamicApi(String),
#[error("{0} not found in dynamic storage")]
EmptyResponseFromDynamicStorage(String),
#[error("decode dynamic value error: expected `{0}`, got {1}")]
DecodeDynamicError(String, ValueDef<u32>),
}
Expand Down
19 changes: 12 additions & 7 deletions parachain-tracer/src/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,18 @@ impl SubxtTracker {

async fn set_core_assignment(&mut self, block_hash: H256, rpc: &mut impl TrackerRpc) -> color_eyre::Result<()> {
// After adding On-demand Parachains, `ParaScheduler.Scheduled` API call will be removed
let assignments = match rpc.core_assignments_via_scheduled_paras(block_hash).await {
// `ParaScheduler,Scheduled` not found, try to fetch `ParaScheduler.ClaimQueue`
Err(SubxtWrapperError::SubxtError(Error::Metadata(MetadataError::StorageEntryNotFound(_)))) =>
rpc.core_assignments_via_claim_queue(block_hash).await,
v => v,
}?;
if let Some((&core, scheduled_ids)) = assignments.iter().find(|(_, ids)| ids.contains(&self.para_id)) {
let mut assignments = rpc.core_assignments_via_scheduled_paras(block_hash).await;
// `ParaScheduler,Scheduled` not found, try to fetch `ParaScheduler.ClaimQueue`
if let Err(SubxtWrapperError::SubxtError(Error::Metadata(MetadataError::StorageEntryNotFound(_)))) = assignments
{
assignments = rpc.core_assignments_via_claim_queue(block_hash).await;
}
if let Err(SubxtWrapperError::EmptyResponseFromDynamicStorage(reason)) = assignments {
info!("{}. Nothing to process", reason);
return Ok(())
}

if let Some((&core, scheduled_ids)) = assignments?.iter().find(|(_, ids)| ids.contains(&self.para_id)) {
self.current_candidate.assigned_core = Some(core);
self.current_candidate.core_occupied =
matches!(rpc.occupied_cores(block_hash).await?[core as usize], CoreOccupied::Paras);
Expand Down

0 comments on commit 745eb7d

Please sign in to comment.