Skip to content

Commit

Permalink
refactor(backing): change error and caching function names
Browse files Browse the repository at this point in the history
  • Loading branch information
sw10pa committed Nov 12, 2024
1 parent 74fc6d6 commit f7898b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
4 changes: 2 additions & 2 deletions polkadot/node/core/backing/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ pub enum Error {
#[error("Availability store error")]
StoreAvailableData(#[source] StoreAvailableDataError),

#[error("Data is not available")]
DataNotAvailable,
#[error("Runtime API returned None for executor params")]
MissingExecutorParams,
}

/// Utility for eating top level errors and log them.
Expand Down
32 changes: 13 additions & 19 deletions polkadot/node/core/backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl PerSessionCache {
}

/// Gets validators from the cache or fetches them from the runtime if not present.
async fn get_or_fetch_validators(
async fn validators(
&mut self,
session_index: SessionIndex,
parent: Hash,
Expand All @@ -358,7 +358,7 @@ impl PerSessionCache {
}

/// Gets the node features from the cache or fetches it from the runtime if not present.
async fn get_or_fetch_node_features(
async fn node_features(
&mut self,
session_index: SessionIndex,
parent: Hash,
Expand All @@ -381,7 +381,7 @@ impl PerSessionCache {

/// Gets the executor parameters from the cache or
/// fetches them from the runtime if not present.
async fn get_or_fetch_executor_params(
async fn executor_params(
&mut self,
session_index: SessionIndex,
parent: Hash,
Expand All @@ -402,7 +402,7 @@ impl PerSessionCache {
})??
.ok_or_else(|| RuntimeApiError::Execution {
runtime_api_name: "SessionExecutorParams",
source: Arc::new(Error::DataNotAvailable),
source: Arc::new(Error::MissingExecutorParams),
})?;

// Wrap the executor parameters in an Arc to avoid a deep copy when storing it in the cache.
Expand All @@ -416,7 +416,7 @@ impl PerSessionCache {

/// Gets the minimum backing votes threshold from the
/// cache or fetches it from the runtime if not present.
async fn get_or_fetch_minimum_backing_votes(
async fn minimum_backing_votes(
&mut self,
session_index: SessionIndex,
parent: Hash,
Expand All @@ -442,7 +442,7 @@ impl PerSessionCache {
}

/// Gets or computes the validator-to-group mapping for a session.
fn get_or_compute_validator_to_group(
fn validator_to_group(
&mut self,
session_index: SessionIndex,
validators: &[ValidatorId],
Expand Down Expand Up @@ -1270,13 +1270,11 @@ async fn construct_per_relay_parent_state<Context>(

let session_index = try_runtime_api!(session_index);

let validators = per_session_cache
.get_or_fetch_validators(session_index, parent, ctx.sender())
.await;
let validators = per_session_cache.validators(session_index, parent, ctx.sender()).await;
let validators = try_runtime_api!(validators);

let node_features = per_session_cache
.get_or_fetch_node_features(session_index, parent, ctx.sender())
.node_features(session_index, parent, ctx.sender())
.await?
.unwrap_or(NodeFeatures::EMPTY);

Expand All @@ -1285,9 +1283,8 @@ async fn construct_per_relay_parent_state<Context>(
.map(|b| *b)
.unwrap_or(false);

let executor_params = per_session_cache
.get_or_fetch_executor_params(session_index, parent, ctx.sender())
.await;
let executor_params =
per_session_cache.executor_params(session_index, parent, ctx.sender()).await;
let executor_params = try_runtime_api!(executor_params);

gum::debug!(target: LOG_TARGET, inject_core_index, ?parent, "New state");
Expand All @@ -1296,7 +1293,7 @@ async fn construct_per_relay_parent_state<Context>(
let cores = try_runtime_api!(cores);

let minimum_backing_votes = per_session_cache
.get_or_fetch_minimum_backing_votes(session_index, parent, ctx.sender())
.minimum_backing_votes(session_index, parent, ctx.sender())
.await;
let minimum_backing_votes = try_runtime_api!(minimum_backing_votes);

Expand Down Expand Up @@ -1371,11 +1368,8 @@ async fn construct_per_relay_parent_state<Context>(
}
gum::debug!(target: LOG_TARGET, ?groups, "TableContext");

let validator_to_group = per_session_cache.get_or_compute_validator_to_group(
session_index,
&validators,
&validator_groups,
);
let validator_to_group =
per_session_cache.validator_to_group(session_index, &validators, &validator_groups);

let table_context =
TableContext { validator, groups, validators: validators.to_vec(), disabled_validators };
Expand Down

0 comments on commit f7898b7

Please sign in to comment.