okTurtles / group-income

A decentralized and private (end-to-end encrypted) financial safety net for you and your friends.
https://groupincome.org
GNU Affero General Public License v3.0
331 stars 44 forks source link

Fix confused and outdated 'chelonia/contract/sync' situation #2298

Closed taoeffect closed 1 month ago

taoeffect commented 3 months ago

Problem

Our Information-Flow.md documentation is outdated for how to sync a contract.

It currently says that developers should use 'chelonia/contract/sync', but that's wrong, as they're supposed to use 'cheloina/contract/retain' along with 'chelonia/contract/release'.

A separate problem is this code inside of 'chelonia/contract/sync':

      if (!forcedSync && this.subscriptionSet.has(contractID)) {
        const rootState = sbp(this.config.stateSelector)
        if (!rootState[contractID]?._volatile?.dirty) {
          return sbp('chelonia/private/queueEvent', contractID, ['chelonia/private/noop'])
        }
      }

It's unclear to me what this code is doing, and it should be clearly commented.

Solution

  1. Search the Group Income side of the app and replace all calls to 'chelonia/contract/sync' with 'chelonia/contract/retain' (and release).
  2. Then anywhere the concept of resyncing a currently sync'd and retained contract is needed, either call a new selector (e.g. 'chelonia/contract/forceSync'), or change the behavior of 'chelonia/contract/sync' so that it does force syncing. Be careful if you pick the "change behavior" route, since if any old versions of contracts that call that expecting the old behavior to be there, then the behavior shouldn't be changed (since those are deployed for life now). My preference would be to change the behavior for 'chelonia/contract/sync', so that forceSync is true by default, and tell developers to call this on contracts upon logging in (or coming back online). Go through the app and search for places where we need to explicitly set forceSync: false.
  3. Update the Information Flow section with the latest correct guidance (use retain most of the time, and sync upon login).