Repository: paritytech/substrate
File: client/finality-grandpa/src/import.rs (Rust)

Code before:
				|insert| {
					block
						.auxiliary
						.extend(insert.iter().map(|(k, v)| (k.to_vec(), Some(v.to_vec()))))
				},
			);
		}

		let just_in_case = just_in_case.map(|(o, i)| (o, i.release_mutex()));

		Ok(PendingSetChanges { just_in_case, applied_changes, do_pause })
	}

	/// Read current set id form a given state.
	fn current_set_id(&self, id: &BlockId<Block>) -> Result<SetId, ConsensusError> {
		let runtime_version = self.inner.runtime_api().version(id).map_err(|e| {
			ConsensusError::ClientImport(format!(
				"Unable to retrieve current runtime version. {}",
				e
			))
		})?;

		let hash = self
			.inner
			.expect_block_hash_from_id(id)
			.map_err(|e| ConsensusError::Other(e.into()))?;

		if runtime_version
			.api_version(&<dyn GrandpaApi<Block>>::ID)
			.map_or(false, |v| v < 3)
		{
			// The new API is not supported in this runtime. Try reading directly from storage.
			// This code may be removed once warp sync to an old runtime is no longer needed.
			for prefix in ["GrandpaFinality", "Grandpa"] {
				let k = [twox_128(prefix.as_bytes()), twox_128(b"CurrentSetId")].concat();
				if let Ok(Some(id)) =
					self.inner.storage(&hash, &sc_client_api::StorageKey(k.to_vec()))
				{
					if let Ok(id) = SetId::decode(&mut id.0.as_ref()) {
						return Ok(id)
					}
				}
			}
			Err(ConsensusError::ClientImport("Unable to retrieve current set id.".into()))
		} else {
			self.inner
				.runtime_api()
				.current_set_id(id)
				.map_err(|e| ConsensusError::ClientImport(e.to_string()))
		}
	}

Review comment (suggestion):
```suggestion
```

Please make this function take `Block::Hash` directly.

Code after:
				|insert| {
					block
						.auxiliary
						.extend(insert.iter().map(|(k, v)| (k.to_vec(), Some(v.to_vec()))))
				},
			);
		}

		let just_in_case = just_in_case.map(|(o, i)| (o, i.release_mutex()));

		Ok(PendingSetChanges { just_in_case, applied_changes, do_pause })
	}

	/// Read current set id form a given state.
	fn current_set_id(&self, hash: &Block::Hash) -> Result<SetId, ConsensusError> {
		let id = &BlockId::hash(*hash);
		let runtime_version = self.inner.runtime_api().version(id).map_err(|e| {
			ConsensusError::ClientImport(format!(
				"Unable to retrieve current runtime version. {}",
				e
			))
		})?;

		if runtime_version
			.api_version(&<dyn GrandpaApi<Block>>::ID)
			.map_or(false, |v| v < 3)
		{
			// The new API is not supported in this runtime. Try reading directly from storage.
			// This code may be removed once warp sync to an old runtime is no longer needed.
			for prefix in ["GrandpaFinality", "Grandpa"] {
				let k = [twox_128(prefix.as_bytes()), twox_128(b"CurrentSetId")].concat();
				if let Ok(Some(id)) =
					self.inner.storage(hash, &sc_client_api::StorageKey(k.to_vec()))
				{
					if let Ok(id) = SetId::decode(&mut id.0.as_ref()) {
						return Ok(id)
					}
				}
			}
			Err(ConsensusError::ClientImport("Unable to retrieve current set id.".into()))
		} else {
			self.inner
				.runtime_api()
				.current_set_id(id)
				.map_err(|e| ConsensusError::ClientImport(e.to_string()))
		}
	}

	/// Import whole new state and reset authority set.
	async fn import_state(
		&mut self,