-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Merge IterableStorageMap into StorageMap and IterableStorageDoubleMap into StorageDoubleMap #5335
Conversation
I really don't like this PR. The point of having an |
I reimplemented without making use of StorageHasherInfo. I'm still unsure why such traits is agains't rust principle: the trait basically implement what kind of information the encoding of a key using the hasher has. /// Trait to retrieve some info from hash of type `Key` encoded.
pub trait StorageHasherInfo<Key> {
/// Some info contained in the hash of type `Key` encoded.
type Info;
/// Decode the hash and then decode the info from the decoded hash.
///
/// # WARNING
///
/// Even if info is (), input must be modified to have read the entire encoded hash.
fn decode_hash_and_then_info<I: codec::Input>(input: &mut I)
-> Result<Self::Info, codec::Error>;
} But I removed it and introduced Note that we could generalize
to be able to call it is still in progress I want to verify this design but this is the direction. |
Also the traits StorageMap and StorageDoubleMap didn't expose StorageHasherInfo::Info in their API, they just make use of it in the where clause in order to make sure that the So the iter_key1_key2_value function was only available when both hasher were reversibe. Same as before. |
} else { | ||
Err(errors) | ||
} | ||
} |
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.
this function has the old signature and implementation of PrefixedStorage::translate_values.
Change is planned in a following PR
I removed the superfluous iter functions, now the only new function introduced is Additionnally I updated the top message for clarification about the reorganization and consistency. This is ready for review |
closing because of inactivity. |
@shawntabrizi I guess we can do this reorganization later for me it allow more discoverability. |
FIRST NOTE
to make this PR easiy to review, I'll split it into multiple small ones:
1 - make iteration consistent and translate consistent #5470
2 - refactor all iterators to make use of a single PrefixIterator
3 - refactor all traits to only StorageMap and StorageDoubleMap
4 - add iter to StorageDoubleMap which decodes key when both hasher are reversible #5504 (merge)
(considering the current iter will be renamed to iter_prefix or iter_sub). This point can be made after or before reorganization.
Context
for now DoubleMap allows to iterate with the keys only when iterating over a prefix (i.e over a first key).
This PR adds iter on all key1, key2, value for DoubleMap.
This PR also reorganize storage traits to include everything in one Traits, this allow to see all available functionality easily.
It also remove the duplicate of IterableDoubleMap::translate and PrefixedStorage::translate which were both available for a double_map but with a slightly different behavior.
DONE
StoragePrefixedMap is removed and merged into StorageDoubleMap and StorageMap.
so
fn iter_values
fn translate_values
fn remove_all
are now available in both traits.(for doublemap translate_values is actually removed in favor of IterableDoubleMap::translate which has been renamed to translate_values, see consistency section)
IterableStorageMap is removed and merged into StorageMap: so
iter
drain
andtranslate
are now in StorageMap under some condition on the hasher.IterableStorageDoubleMap is removed and merged into StorageDoubleMap:
iter
is renamediter_prefix
to be consistent with other function name (though we can discuss changing it to iter_sub and rename remove_prefix to remove_sub etc..)drain
is renameddrain_prefix
for same reasontranslate
is renamed totranslate_values
see consistency sectionbehavior of
iter_values
has changed as it no longer stop on the first value that failed to decode, instead if continues until the last value inside the given prefix.TODO
Note
I think the biggest advantages are:
Traits consistency
now StorageDoubleMap has:
now StorageMap has: