Repository: paritytech/substrate
File: client/beefy/src/worker.rs (Rust)

Code before:
		if Some(block_num) > self.best_beefy_block {
			// Set new best BEEFY block number.
			self.best_beefy_block = Some(block_num);
			metric_set!(self, beefy_best_block, block_num);

			self.on_demand_justifications.cancel_requests_older_than(block_num);

			let maybe_block_hash =
				self.backend.blockchain().expect_block_hash_from_id(&BlockId::Number(block_num));

			match maybe_block_hash {
				Ok(hash) => {
					if let Err(err) = self
						.backend
						.append_justification(&hash, (BEEFY_ENGINE_ID, finality_proof.encode()))
					{
						error!(target: "beefy", "🥩 Error {:?} on appending justification: {:?}", err, finality_proof);
					};

					self.links
						.to_rpc_best_block_sender
						.notify(|| Ok::<_, ()>(hash))
						.expect("forwards closure result; the closure always returns Ok; qed.");
				},
				Err(err) => {
					error!(target: "beefy", "🥩 Error {:?} hash not know for given block_num: {:?}", err, finality_proof);
				},
			};

			self.links
				.to_rpc_justif_sender
				.notify(|| Ok::<_, ()>(finality_proof))
				.expect("forwards closure result; the closure always returns Ok; qed.");
		} else {
			debug!(target: "beefy", "🥩 Can't set best beefy to older: {}", block_num);
		}
		Ok(())
	}

	/// Handle previously buffered justifications and votes that now land in the voting interval.
	fn try_pending_justif_and_votes(&mut self) -> Result<(), Error> {
		let best_grandpa = *self.best_grandpa_block_header.number();
		let _ph = PhantomData::<B>::default();

		fn to_process_for<B: Block, T>(
			pending: &mut BTreeMap<NumberFor<B>, T>,
			(start, end): (NumberFor<B>, NumberFor<B>),
			_: PhantomData<B>,
		) -> BTreeMap<NumberFor<B>, T> {
			// These are still pending.
			let still_pending = pending.split_off(&end.saturating_add(1u32.into()));

Review comment (suggestion):
```suggestion
					error!(target: "beefy", "🥩 Error {:?} hash not known for given proof: {:?}", err, finality_proof);
```

Code after:
		if Some(block_num) > self.best_beefy_block {
			// Set new best BEEFY block number.
			self.best_beefy_block = Some(block_num);
			metric_set!(self, beefy_best_block, block_num);

			self.on_demand_justifications.cancel_requests_older_than(block_num);

			if let Err(e) = self
				.backend
				.blockchain()
				.expect_block_hash_from_id(&BlockId::Number(block_num))
				.and_then(|hash| {
					self.links
						.to_rpc_best_block_sender
						.notify(|| Ok::<_, ()>(hash))
						.expect("forwards closure result; the closure always returns Ok; qed.");

					self.backend
						.append_justification(&hash, (BEEFY_ENGINE_ID, finality_proof.encode()))
				}) {
				error!(target: "beefy", "🥩 Error {:?} on appending justification: {:?}", e, finality_proof);
			}

			self.links
				.to_rpc_justif_sender
				.notify(|| Ok::<_, ()>(finality_proof))
				.expect("forwards closure result; the closure always returns Ok; qed.");
		} else {
			debug!(target: "beefy", "🥩 Can't set best beefy to older: {}", block_num);
		}
		Ok(())
	}

	/// Handle previously buffered justifications and votes that now land in the voting interval.
	fn try_pending_justif_and_votes(&mut self) -> Result<(), Error> {
		let best_grandpa = *self.best_grandpa_block_header.number();
		let _ph = PhantomData::<B>::default();

		fn to_process_for<B: Block, T>(
			pending: &mut BTreeMap<NumberFor<B>, T>,
			(start, end): (NumberFor<B>, NumberFor<B>),
			_: PhantomData<B>,
		) -> BTreeMap<NumberFor<B>, T> {
			// These are still pending.
			let still_pending = pending.split_off(&end.saturating_add(1u32.into()));
			// These can be processed.
			let to_handle = pending.split_off(&start);
			// The rest can be dropped.
			*pending = still_pending;
			// Return ones to process.
			to_handle