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

Use single map and remove_all for EventTopics #4566

Merged

Conversation

shawntabrizi
Copy link
Member

@shawntabrizi shawntabrizi commented Jan 8, 2020

#2491 introduced light client friendly events.

It used a trick with the double_map api where it was able to clear a single map by removing a single prefix of the double_map.

See: paritytech/polkadot-sdk#371

Now that all storage items use StoragePrefixedMap, we can now access the remove_all API directly from a single map.

This updates the implementation of EventTopics to use a single map and the remove_all api rather than the double_map hack.

@shawntabrizi shawntabrizi added A0-please_review Pull request needs code review. A2-insubstantial Pull request requires no code review (e.g., a sub-repository hash update). labels Jan 8, 2020
/// All topic vectors have deterministic storage locations depending on the topic. This
/// allows light-clients to leverage the changes trie storage tracking mechanism and
/// in case of changes fetch the list of events of interest.
///
/// The value has the type `(T::BlockNumber, EventIndex)` because if we used only just
/// the `EventIndex` then in case if the topic has the same contents on the next block
/// no notification will be triggered thus the event might be lost.
EventTopics get(fn event_topics): double_map hasher(blake2_256) (), blake2_256(T::Hash)
=> Vec<(T::BlockNumber, EventIndex)>;
EventTopics get(fn event_topics): map T::Hash => Vec<(T::BlockNumber, EventIndex)>;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could reduce the complexity of the hasher used on the key here.

I don't quite understand if this is something worth changing.

@bkchr
Copy link
Member

bkchr commented Jan 8, 2020

CC @jacogr

@bkchr bkchr merged commit ae46db6 into paritytech:master Jan 8, 2020
@shawntabrizi shawntabrizi deleted the shawntabrizi-event-topics-map branch January 8, 2020 09:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. A2-insubstantial Pull request requires no code review (e.g., a sub-repository hash update).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants