Optimize decode_len (#5975)

* Optimize `decode_len`

Instead of reading the full storage value into the runtime, we only read
at maximum `5bytes` from the storage into the runtime. Furthermore this
drops any handling with regards to set default values in
`decl_storage!`. If the value does not exists or the decoding of the
length fails, it will return `None`. To prevent people from messing
stuff up, this feature relies on the `StorageDecodeLength` trait that is
sealed by `frame-support` (aka only implementable inside this crate).

* Some clean ups

* Update frame/support/src/storage/mod.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
This commit is contained in:
Bastian Köcher
2020-05-12 12:13:28 +02:00
committed by GitHub
parent 0690bb51a8
commit 22db788c08
7 changed files with 91 additions and 87 deletions
+1 -1
View File
@@ -2337,7 +2337,7 @@ impl<T: Trait> Module<T> {
// that we need. Then it should be Self::validator_count(). Else it should be all the
// candidates.
let snapshot_length = <SnapshotValidators<T>>::decode_len()
.map_err(|_| Error::<T>::SnapshotUnavailable)?;
.ok_or_else(|| Error::<T>::SnapshotUnavailable)?;
// check the winner length only here and when we know the length of the snapshot validators
// length.