Some overdue cleanup (#2989)

* Cleanup obsolete code.

* Move session cache to requester.
This commit is contained in:
Robert Klotzner
2021-05-06 16:15:23 +02:00
committed by GitHub
parent 6663081bbd
commit 1508024a47
5 changed files with 47 additions and 148 deletions
@@ -30,15 +30,17 @@ use futures::{
Stream,
};
use sp_keystore::SyncCryptoStorePtr;
use polkadot_node_subsystem_util::runtime::get_occupied_cores;
use polkadot_node_subsystem_util::runtime::{RuntimeInfo, get_occupied_cores};
use polkadot_primitives::v1::{CandidateHash, Hash, OccupiedCore};
use polkadot_subsystem::{
messages::AllMessages, ActiveLeavesUpdate, SubsystemContext, ActivatedLeaf,
};
use super::{session_cache::SessionCache, LOG_TARGET, Metrics};
use super::{LOG_TARGET, Metrics};
/// Cache for session information.
mod session_cache;
use session_cache::SessionCache;
/// A task fetching a particular chunk.
@@ -76,12 +78,12 @@ impl Requester {
///
/// You must feed it with `ActiveLeavesUpdate` via `update_fetching_heads` and make it progress
/// by advancing the stream.
#[tracing::instrument(level = "trace", skip(keystore, metrics), fields(subsystem = LOG_TARGET))]
pub fn new(keystore: SyncCryptoStorePtr, metrics: Metrics) -> Self {
#[tracing::instrument(level = "trace", skip(metrics), fields(subsystem = LOG_TARGET))]
pub fn new(metrics: Metrics) -> Self {
let (tx, rx) = mpsc::channel(1);
Requester {
fetches: HashMap::new(),
session_cache: SessionCache::new(keystore),
session_cache: SessionCache::new(),
tx,
rx,
metrics,
@@ -90,10 +92,11 @@ impl Requester {
/// Update heads that need availability distribution.
///
/// For all active heads we will be fetching our chunks for availabilty distribution.
#[tracing::instrument(level = "trace", skip(self, ctx, update), fields(subsystem = LOG_TARGET))]
#[tracing::instrument(level = "trace", skip(self, ctx, runtime, update), fields(subsystem = LOG_TARGET))]
pub async fn update_fetching_heads<Context>(
&mut self,
ctx: &mut Context,
runtime: &mut RuntimeInfo,
update: ActiveLeavesUpdate,
) -> super::Result<()>
where
@@ -110,7 +113,7 @@ 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?;
self.start_requesting_chunks(ctx, runtime, activated.into_iter()).await?;
self.stop_requesting_chunks(deactivated.into_iter());
Ok(())
}
@@ -119,6 +122,7 @@ impl Requester {
async fn start_requesting_chunks<Context>(
&mut self,
ctx: &mut Context,
runtime: &mut RuntimeInfo,
new_heads: impl Iterator<Item = ActivatedLeaf>,
) -> super::Result<()>
where
@@ -131,7 +135,7 @@ impl Requester {
occupied_cores = ?cores,
"Query occupied core"
);
self.add_cores(ctx, leaf, cores).await?;
self.add_cores(ctx, runtime, leaf, cores).await?;
}
Ok(())
}
@@ -156,6 +160,7 @@ impl Requester {
async fn add_cores<Context>(
&mut self,
ctx: &mut Context,
runtime: &mut RuntimeInfo,
leaf: Hash,
cores: impl IntoIterator<Item = OccupiedCore>,
) -> super::Result<()>
@@ -177,6 +182,7 @@ impl Requester {
.session_cache
.with_session_info(
ctx,
runtime,
// We use leaf here, as relay_parent must be in the same session as the
// leaf. (Cores are dropped at session boundaries.) At the same time,
// only leaves are guaranteed to be fetchable by the state trie.