xmtp / libxmtp

MIT License
33 stars 13 forks source link

Better handling for new groups where the creator has multiple installations #761

Open neekolas opened 1 month ago

neekolas commented 1 month ago

I found an oversight in our original design.

Imagine the following situation:

What should the sequence_id be on the initial GroupMembership?

If we set it to 3, we will never be able to add the first two installations since they are happened before sequence_id 3 and we only allow for updates that increment the sequence_id for the group and for installations to be added that match a diff between the old and new sequence_id.

We could set it initially to 0, and then have the add_missing_members function create a commit that adds all the missing installations. But that poses a problem: moving from 0 -> 3 will also add the group creator installation, who is already a member of the group. This is not allowed.

I've instituted a hack for this problem where we set the initial sequence_id to 0 and then allowing members to be missing from the installation diff so long as they are already members of the group. This is confusing and not ideal. Even if we can't come up with a better solution we'll want to document this clearly.