message: Extract terminal block data computation.
diff: @@ -11,7 +11,7 @@ use crate::{
  consensus_protocol::{FinalizedBlock, TerminalBlockData},
  highway_core::{
  highway::Highway,
  - state::{Observation, State, Weight},
  + state::{Observation, State, Unit, Weight},
  validators::ValidatorIndex,
  },
  traits::Context,
  @@ -65,18 +65,9 @@ impl<C: Context> FinalityDetector<C> {
  let to_id = |vidx: ValidatorIndex| highway.validators().id(vidx).unwrap().clone();
  let block = state.block(bhash);
  let unit = state.unit(bhash);
  - let terminal_block_data = if state.is_terminal_block(bhash) {
  - let rewards = rewards::compute_rewards(state, bhash);
  - let rewards_iter = rewards.enumerate();
  - let rewards = rewards_iter.map(|(vidx, r)| (to_id(vidx), *r)).collect();
  - let inactive_validators = unit.panorama.iter_none().map(to_id).collect();
  - Some(TerminalBlockData {
  - rewards,
  - inactive_validators,
  - })
  - } else {
  - None
  - };
  + let terminal_block_data = state
  + .is_terminal_block(bhash)
  + .then(|| Self::create_terminal_block_data(bhash, unit, highway));
  let finalized_block = FinalizedBlock {
  value: block.value.clone(),
  timestamp: unit.timestamp,
  @@ -171,6 +162,26 @@ impl<C: Context> FinalityDetector<C> {
  pub(crate) fn fault_tolerance_threshold(&self) -> Weight {
  self.ftt
  }
  +
  + /// Creates the information for the terminal block: which validators were inactive, and how
  + /// rewards should be distributed.
  + fn create_terminal_block_data(
  + bhash: &C::Hash,
  + unit: &Unit<C>,
  + highway: &Highway<C>,
  + ) -> TerminalBlockData<C> {
  + let state = highway.state();
  + // Index exists, since we have units from them.
  + let to_id = |vidx: ValidatorIndex| highway.validators().id(vidx).unwrap().clone();
  + let rewards = rewards::compute_rewards(state, bhash);
  + let rewards_iter = rewards.enumerate();
  + let rewards = rewards_iter.map(|(vidx, r)| (to_id(vidx), *r)).collect();
  + let inactive_validators = unit.panorama.iter_none().map(to_id).collect();
  + TerminalBlockData {
  + rewards,
  + inactive_validators,
  + }
  + }
  }
  #[allow(unused_qualifications)] // This is to suppress warnings originating in the test macros.
  