availability distribution: don't early return on runtime errors (#2606)

* availability distribution: don't early return on runtime errors

* log error

* extract runtime api error from Error

* uh

* oh
This commit is contained in:
Andronik Ordian
2021-03-11 19:47:56 +01:00
committed by GitHub
parent bd2f5b27dd
commit a543b1d6c3
4 changed files with 57 additions and 43 deletions
@@ -39,7 +39,8 @@ use polkadot_subsystem::{
messages::AllMessages, ActiveLeavesUpdate, jaeger, SubsystemContext,
};
use super::{error::recv_runtime, session_cache::SessionCache, Result, LOG_TARGET, Metrics};
use super::{error::recv_runtime, session_cache::SessionCache, LOG_TARGET, Metrics};
use crate::error::NonFatalError;
/// A task fetching a particular chunk.
mod fetch_task;
@@ -96,7 +97,7 @@ impl Requester {
&mut self,
ctx: &mut Context,
update: ActiveLeavesUpdate,
) -> Result<()>
) -> super::Result<Option<NonFatalError>>
where
Context: SubsystemContext,
{
@@ -106,10 +107,9 @@ impl Requester {
} = update;
// Order important! We need to handle activated, prior to deactivated, otherwise we might
// cancel still needed jobs.
self.start_requesting_chunks(ctx, activated.into_iter())
.await?;
let err = self.start_requesting_chunks(ctx, activated.into_iter()).await?;
self.stop_requesting_chunks(deactivated.into_iter());
Ok(())
Ok(err)
}
/// Start requesting chunks for newly imported heads.
@@ -117,15 +117,20 @@ impl Requester {
&mut self,
ctx: &mut Context,
new_heads: impl Iterator<Item = (Hash, Arc<jaeger::Span>)>,
) -> Result<()>
) -> super::Result<Option<NonFatalError>>
where
Context: SubsystemContext,
{
for (leaf, _) in new_heads {
let cores = query_occupied_cores(ctx, leaf).await?;
self.add_cores(ctx, leaf, cores).await?;
let cores = match query_occupied_cores(ctx, leaf).await {
Err(err) => return Ok(Some(err)),
Ok(cores) => cores,
};
if let Some(err) = self.add_cores(ctx, leaf, cores).await? {
return Ok(Some(err));
}
}
Ok(())
Ok(None)
}
/// Stop requesting chunks for obsolete heads.
@@ -150,7 +155,7 @@ impl Requester {
ctx: &mut Context,
leaf: Hash,
cores: impl IntoIterator<Item = OccupiedCore>,
) -> Result<()>
) -> super::Result<Option<NonFatalError>>
where
Context: SubsystemContext,
{
@@ -165,7 +170,7 @@ impl Requester {
let tx = self.tx.clone();
let metrics = self.metrics.clone();
let task_cfg = self
let task_cfg = match self
.session_cache
.with_session_info(
ctx,
@@ -175,7 +180,11 @@ impl Requester {
leaf,
|info| FetchTaskConfig::new(leaf, &core, tx, metrics, info),
)
.await?;
.await
{
Err(err) => return Ok(Some(err)),
Ok(task_cfg) => task_cfg,
};
if let Some(task_cfg) = task_cfg {
e.insert(FetchTask::start(task_cfg, ctx).await?);
@@ -184,7 +193,7 @@ impl Requester {
}
}
}
Ok(())
Ok(None)
}
}
@@ -219,7 +228,7 @@ impl Stream for Requester {
async fn query_occupied_cores<Context>(
ctx: &mut Context,
relay_parent: Hash,
) -> Result<Vec<OccupiedCore>>
) -> Result<Vec<OccupiedCore>, NonFatalError>
where
Context: SubsystemContext,
{