Why
The content-topic field in Waku-Message is an identifier to be used for content-based filtering. What filtering means in this case is the way a light-client would subscribe to a specific filter that they are interested in for receiving messages. To elaborate it further, content-based filtering should consider use-cases where messages are queried based on certain criteria or subscribed to be received based on this criteria.
The current content-topic usage in status communities is based on Wakuv1
and hence not following this principle leading to a bloat in content topics (e.g: currently a user who is part of status community almost subscribes to 200 content-topics while registering with Filter protocol).
Problems observed
- content topic count will scale based on number of rooms in community causing a bloat
- limited efficiency of pgsql queries when content topic number is large and variable, limited efficiency of filter and memory usage on server side when subscription have a large number of content topics, need to do several store/filter queries to fetch all content topics. Test results for the store protocol indicate that query response time is almost halved when queried for 1 content-topic instead of 100. Detailed results can be viewed here
By reviewing and optimizing the content-topic
usage in communities, we should be able to reduce a significant amount of the bloat observed in status.
Current usage of content-topics by communities
- As of now for each
room/channel
that is created in a community, a newcontent-topic
is assigned based on hash ofchannelID
. - All control messages are sent on few pre-defined
content-topics
or userâs own content-topic (if private) based on the type of message. Further details of current content-topic usage can be seen seen in this sheet.
Proposed content-topic usage for communities
This is the simplest approach where content-topics are assigned/used based on permissions of channels in community i.e all public channels and community control messages (that are not destined to specific user) can use a single content-topic and channels/rooms that require permissions to access can use a content-topic based on permissions created within community.
- All public chats/channels in communities can start using the default community content-topic derived from i.e
keccak256(communityID)[0..4]
. Note that this content-topic is already used in community and hence it is planned to be reused now for the whole community. - Existing control messages related to communities (which are private in nature) that use userâs own
content-topic
orcontrol nodeâs content-topic
need not be changed an continue to use the same. - Permissions created within a community must be using some sort of
permission/role ID
assigned to specific users. Each such permission set can use a differentcontent-topic
based onpermission-ID
. I am not clear as to how this is implemented and would appreciate some comments on this.
With this proposal content-topics are aligned with filter/store use-cases i.e messages needs to be subscribed to /fetched based on permissions a user has within a community.
e.g: a user with permission1 would always subscribe to/fetch only msgs for public topic and permissions1 topic.
How to migrate existing communities
Following are the points to consider for migration of existing communities to this new proposed usage. Would appreciate some feedback or alternative approaches for migration
- how can an existing community migrate to this new model since users all users will not upgrade to a version released with this new proposal?
- one simple approach is to broadcast a message in the community asking users to update to a new version in order to be able to send/receive new msgs in community without issues
- all new msgs/subscriptions shall follow the new model i.e new send/receive will not work unless version upgrade
- an alternative approach as suggested by @haelius where upgraded/new users send msgs to single content-topic and old users still receive all messages. new users still use all content-topics to receive and fetch messages via Store/Filter. after a certain time(maybe subsequent release) when most users migrate to new version, we can update the code to only use single content-topic for store/Filter as well to complete the upgrade.
- how to handle fetching old data post migration?
- until a certain date (maybe
30 days
since community is migrated), allow fetching data using old content-topic model only via store/Filter.
- until a certain date (maybe
Implementation notes
Needs further review if there is any app specific logic tied to existing content-topics
that can break due to these proposed changes. At first look, i donât think anything should break, since content-topic for community channels are derived based on channelID
and no new info is required to be stored in communityDescription
.
Next step is to do a POC of this approach by changing status-go and then using a version of status-desktop in relay and lightClient mode to dogfood these changes internally. This would also validate that nothing else would be broken by this change apart from migration items mentioned above.