fix branchStream to restart after box2 decryption #110
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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, thebranchStream()
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 ❌ 2nd ✔️