Repository: paritytech/substrate
File: client/beefy/src/communication/request_response/incoming_requests_handler.rs (Rust)

Code before:
		let justif_protocol_name = config.name.clone();

		(Self { request_receiver, justif_protocol_name, client, _block: PhantomData }, config)
	}

	/// Network request-response protocol name used by this handler.
	pub fn protocol_name(&self) -> ProtocolName {
		self.justif_protocol_name.clone()
	}

	// Sends back justification response if justification found in client backend.
	fn handle_request(&self, request: IncomingRequest<B>) -> Result<(), Error> {
		// TODO (issue #12293): validate `request` and change peer reputation for invalid requests.

		let maybe_encoded_proof =
			match self.client.block_hash(request.payload.begin).map_err(Error::Client)? {
				Some(hash) => {
					self.client
						.justifications(&hash)
						.map_err(Error::Client)?
						.and_then(|justifs| justifs.get(BEEFY_ENGINE_ID).cloned())
						// No BEEFY justification present.
						.ok_or(())
				},
				None => Err(()),
			};

		request
			.pending_response
			.send(netconfig::OutgoingResponse {
				result: maybe_encoded_proof,
				reputation_changes: Vec::new(),
				sent_feedback: None,
			})
			.map_err(|_| Error::SendResponse)
	}

	/// Run [`BeefyJustifsRequestHandler`].
	pub async fn run(mut self) {
		trace!(target: "beefy::sync", "🥩 Running BeefyJustifsRequestHandler");

		while let Ok(request) = self.request_receiver.recv(|| vec![]).await {
			let peer = request.peer;
			match self.handle_request(request) {
				Ok(()) => {
					debug!(
						target: "beefy::sync",
						"🥩 Handled BEEFY justification request from {:?}.", peer
					)
				},
				Err(e) => {

Review comment (suggestion):
nit:
```suggestion
		let maybe_encoded_proof = if let Some(hash) =
			self.client.block_hash(request.payload.begin).map_err(Error::Client)?
		{
			self.client
				.justifications(&hash)
				.map_err(Error::Client)?
				.and_then(|justifs| justifs.get(BEEFY_ENGINE_ID).cloned())
				// No BEEFY justification present.
				.ok_or(())
		} else {
			Err(())
		};
```

Code after:
		let justif_protocol_name = config.name.clone();

		(Self { request_receiver, justif_protocol_name, client, _block: PhantomData }, config)
	}

	/// Network request-response protocol name used by this handler.
	pub fn protocol_name(&self) -> ProtocolName {
		self.justif_protocol_name.clone()
	}

	// Sends back justification response if justification found in client backend.
	fn handle_request(&self, request: IncomingRequest<B>) -> Result<(), Error> {
		// TODO (issue #12293): validate `request` and change peer reputation for invalid requests.

		let maybe_encoded_proof = if let Some(hash) =
			self.client.block_hash(request.payload.begin).map_err(Error::Client)?
		{
			self.client
				.justifications(&hash)
				.map_err(Error::Client)?
				.and_then(|justifs| justifs.get(BEEFY_ENGINE_ID).cloned())
				// No BEEFY justification present.
				.ok_or(())
		} else {
			Err(())
		};

		request
			.pending_response
			.send(netconfig::OutgoingResponse {
				result: maybe_encoded_proof,
				reputation_changes: Vec::new(),
				sent_feedback: None,
			})
			.map_err(|_| Error::SendResponse)
	}

	/// Run [`BeefyJustifsRequestHandler`].
	pub async fn run(mut self) {
		trace!(target: "beefy::sync", "🥩 Running BeefyJustifsRequestHandler");

		while let Ok(request) = self.request_receiver.recv(|| vec![]).await {
			let peer = request.peer;
			match self.handle_request(request) {
				Ok(()) => {
					debug!(
						target: "beefy::sync",
						"🥩 Handled BEEFY justification request from {:?}.", peer
					)
				},
				Err(e) => {