Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

BEEFY: Simplify hashing for pallet-beefy-mmr #12387

Closed
serban300 opened this issue Sep 29, 2022 · 2 comments
Closed

BEEFY: Simplify hashing for pallet-beefy-mmr #12387

serban300 opened this issue Sep 29, 2022 · 2 comments
Assignees
Labels
I7-refactor Code needs refactoring. U3-nice_to_have Issue is worth doing eventually.

Comments

@serban300
Copy link
Contributor

Right now pallet-beefy-mmr Declares a new Hasher trait and a new Keccak256 struct which implements it. I was wondering if this is needed.

I was thinking of 2 possible simplifications:

  1. Instead of defining a new struct we could reuse the Keccak256 struct that's already present in sp_runtime, doing something like:
#[cfg(feature = "keccak")]
mod keccak256 {
	pub use sp_runtime::traits::Keccak256;

	/// Keccak256 hasher implementation.
	impl super::Hasher for Keccak256 {
		fn hash(data: &[u8]) -> super::Hash {
			Self::hash(data).into()
		}
	}
}

Or we could do even something more generic:

	impl<T> super::Hasher for T
		where T: sp_runtime::traits::Hash,
		<T as sp_runtime::traits::Hash>::Output: Into<super::Hash> {
		fn hash(data: &[u8]) -> super::Hash {
			Self::hash(data).into()
		}
	}
  1. Could we go one step further and remove the Hasher trait completely and use sp_runtime::traits::Hash instead ? And maybe in the end we could also remove this.

@acatangiu WDYT ? If this issue makes sense I would be happy to implement it.

@serban300 serban300 self-assigned this Sep 29, 2022
@serban300 serban300 added this to BEEFY Sep 29, 2022
@acatangiu acatangiu moved this to Some Day Maybe in BEEFY Sep 30, 2022
@acatangiu acatangiu added I7-refactor Code needs refactoring. U3-nice_to_have Issue is worth doing eventually. labels Sep 30, 2022
@acatangiu
Copy link
Contributor

No 1 sounds good to me, for no.2 it'd be better to see an RFC/PR 👍

@serban300
Copy link
Contributor Author

Implemented in #12393

Repository owner moved this from Some Day Maybe to Done ✅ in BEEFY Oct 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
I7-refactor Code needs refactoring. U3-nice_to_have Issue is worth doing eventually.
Projects
No open projects
Status: Done
Development

No branches or pull requests

2 participants