-
Notifications
You must be signed in to change notification settings - Fork 2.6k
BEEFY: Simplify hashing for pallet-beefy-mmr #12393
BEEFY: Simplify hashing for pallet-beefy-mmr #12393
Conversation
0b9959d
to
af8c43c
Compare
af8c43c
to
52348da
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
PR needs a Polkadot companion |
Sorry, I missed this. Done. Also reduced the number of generic parameters for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure there has been some reason to have this custom trait - e.g. to explicitly voice that it'll only work with H256
(to make it compatible with other H256
chains) and do not confuse this hash with the "base" hash, used on the chain. But I agree that it is harder to develop with two similar traits. If we'll ever need some restrictions on the hash type, we may use constraints for that.
{ | ||
let upper = Vec::with_capacity(leaves.size_hint().0); | ||
let upper = Vec::with_capacity(leaves.size_hint().1.unwrap()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you, please, change .unwrap()
to .expect("<why-you-think-noone-will-ever-see-this-text; qed>")
(see https://github.com/paritytech/substrate/blob/master/docs/STYLE_GUIDE.md#style for details).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I would just change it to
let upper = Vec::with_capacity(leaves.size_hint().1.unwrap()); | |
let upper = Vec::with_capacity(leaves.size_hint().1.unwrap_or(0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this was just an experiment that I forgot about. Normally for Vec
size_hint().1
will always return Some(len)
, but probably it doesn't make sense for other type of iterators. I rolled it back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm unwrap_or(0)
also sounds good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Changed it to leaves.size_hint().1.unwrap_or(0).saturating_add(1)) / 2
bot merge |
* beefy-mmr: reuse sp_runtime::traits::Keccak256 * beefy-mmr: use sp_runtime::traits:Hash for generating merkle proofs * beefy-mmr: use sp_runtime::traits:Hash for validating merkle proofs * beefy-mmr: remove primitives::Hasher and primitives::Hash * fixes * beefy-mmr: reduce the number of generic parameters for merkle_root() * fix * compute upper Vec capacity more accurately
* master: (42 commits) Adapt `pallet-contracts` to WeightV2 (#12421) Improved election pallet testing (#12327) Bump prost to 0.11+ (#12419) Use saturating add for alliance::disband witness data (#12418) [Fix] Rename VoterBagsList -> VoterList to match pdot (#12416) client/beefy: small code improvements (#12414) BEEFY: Simplify hashing for pallet-beefy-mmr (#12393) Add @koute to `docs/CODEOWNERS` and update stale paths (#12408) docs/CODEOWNERS: add @acatangiu as MMR owner (#12406) Remove unnecessary Clone trait bounds on CountedStorageMap (#12402) Fix `Weight::is_zero` (#12396) Beefy on-demand justifications as a custom RequestResponse protocol (#12124) Remove contracts RPCs (#12358) pallet-mmr: generate historical proofs (#12324) unsafe_pruning flag removed (#12385) Carry over where clauses defined in Config to Call and Hook (#12388) Properly set the max proof size weight on defaults and tests (#12383) BEEFY: impl TypeInfo for SignedCommitment (#12382) bounding staking: `BoundedElectionProvider` trait (#12362) New Pallet: Root offences (#11943) ...
* beefy-mmr: reuse sp_runtime::traits::Keccak256 * beefy-mmr: use sp_runtime::traits:Hash for generating merkle proofs * beefy-mmr: use sp_runtime::traits:Hash for validating merkle proofs * beefy-mmr: remove primitives::Hasher and primitives::Hash * fixes * beefy-mmr: reduce the number of generic parameters for merkle_root() * fix * compute upper Vec capacity more accurately
* beefy-mmr: reuse sp_runtime::traits::Keccak256 * beefy-mmr: use sp_runtime::traits:Hash for generating merkle proofs * beefy-mmr: use sp_runtime::traits:Hash for validating merkle proofs * beefy-mmr: remove primitives::Hasher and primitives::Hash * fixes * beefy-mmr: reduce the number of generic parameters for merkle_root() * fix * compute upper Vec capacity more accurately
Reuse
sp_runtime::traits::Hash
instead of defining a newHasher
trait for beefy.Addresses both items in issue #12387
polkadot companion: paritytech/polkadot#6098