ssbc / ssb-meta-feeds

10 stars 0 forks source link

fix branchStream to restart after box2 decryption #110

Closed staltz closed 1 year ago

staltz commented 1 year ago

Context

I'm working on putting 2b funky recps in ssb-tribes2, and noticed a race condition in the tests.

Problem

There's a race condition between:

  1. Replicate the shard feed that announces (encrypted!) a group feed
  2. Replicate the group/add-member message (on the invitations feed) that allows us to decrypt (1)

Ideally, (2) happens first and then (1), but if (1) happens first we have a problem. Even though ssb-tribes2 will run reindexEncrypted() when it bumps into a group/add-member msg, the branchStream() in ssb-meta-feeds won't know that it has to "restart". It just stays stuck in live mode, and of course there are no "new" messages. We only have old messages that were decrypted.

Solution

This is not an ideal solution, but it works. I have an idea for the ideal case, which would be a new API in ssb-db2 that streams all the messages that were freshly decrypted. We need that not only for this branchStream problem, but in other cases too, like in the ssb-box2 "monitor" that matches DM triangles.

The current solution is to just track indexingActive (because reindexEncrypted() bumps that) and restart the branchStream query when indexingActive goes to zero. The live stream was also converted to old-and-live because that's the only way how we can get the old-but-freshly-decrypted messages, AND still get the live messages.

1st :x: 2nd :heavy_check_mark:

arj03 commented 1 year ago

Had a minor comment. Would be better with a solution in db2 so other modules doesn't need to be aware of this as you say. I think this solution is fine for now, lets get this in and improve this along the way. Just create an issue for it in db2 :)