Skip to content

Commit

Permalink
Remove await for actions in identity contract
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed Jan 23, 2024
1 parent c7de2e8 commit 13dbaaa
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
7 changes: 5 additions & 2 deletions frontend/controller/actions/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ export default (sbp('sbp/selectors/register', {
// JOINING_GROUP, so that we process leave actions and don't interfere
// with the leaving process (otherwise, the side-effects will prevent
// us from fully leaving).
await sbp('chelonia/contract/wait', params.contractID)
await Promise.all([
sbp('chelonia/contract/wait', params.originatingContractID),
sbp('chelonia/contract/wait', params.contractID)
])

This comment has been minimized.

Copy link
@taoeffect

taoeffect Jan 24, 2024

Member

Can you change this to:

await sbp('chelonia/contract/wait', [params.originatingContractID, params.contractID])
sbp('okTurtles.data/set', 'JOINING_GROUP-' + params.contractID, true)
try {
const { loggedIn } = sbp('state/vuex/state')
Expand Down Expand Up @@ -369,7 +372,7 @@ export default (sbp('sbp/selectors/register', {
postpublish: null
}
}).catch((e) => {
console.error(`[gi.actions/group/join] Error while sending key request for ${params.contractID}:`, e)
console.error(`[gi.actions/group/join] Error while sending key request for ${params.contractID}:`, e?.message || e, e)
throw e
})

Expand Down
21 changes: 19 additions & 2 deletions frontend/controller/actions/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,26 @@ export default (sbp('sbp/selectors/register', {
try {
const state = sbp('state/vuex/state')
console.info('logging out, waiting for any events to finish...')
// wait for any pending operations to finish before calling state/vuex/save
// This includes, in order:
// 1. Actions to be sent (in the `encrypted-action` queue)
// 2. (In reset) Actions that haven't been published yet (the
// `publish:${contractID}` queues)
// 3. (In reset) Processing of any action (waiting on all the contract
// queues), including their side-effects (the `${contractID}` queues)
// 4. (In reset handler) Outgoing actions from side-effects (again, in
// the `encrypted-action` queue)
await sbp('okTurtles.eventQueue/queueEvent', 'encrypted-action', () => {})
// reset will wait until we have processed any remaining actions
await sbp('chelonia/reset', async () => {
// wait for any pending sync operations to finish before saving,
// including those that side-effects might have sent
// some of the actions that reset waited for might have side-effects
// that send actions
// we wait for those as well (the duplication in this case is
// intended) -- see 4. above
// The intent of this is to wait for all the current actions to be
// sent and then wait until any actions that are a side-effect are sent
// TODO: We might not need this second await and 1-3 could be fine (i.e.,
// we could avoid waiting on these 2nd layer of actions)
await sbp('okTurtles.eventQueue/queueEvent', 'encrypted-action', () => {})
// See comment below for 'gi.db/settings/delete'
await sbp('state/vuex/save')
Expand Down
6 changes: 4 additions & 2 deletions frontend/model/contracts/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ sbp('chelonia/defineContract', {
// a deadlock.
if (!inviteSecretId) return

return sbp('gi.actions/group/join', {
sbp('gi.actions/group/join', {
originatingContractID: contractID,
originatingContractName: 'gi.contracts/identity',
contractID: data.groupContractID,
Expand All @@ -202,6 +202,8 @@ sbp('chelonia/defineContract', {
signingKeyId: inviteSecretId,
innerSigningKeyId: sbp('chelonia/contract/currentKeyIdByName', state, 'csk'),
encryptionKeyId: sbp('chelonia/contract/currentKeyIdByName', state, 'cek')
}).catch(e => {
console.error(`[gi.contracts/identity/joinGroup/sideEffect] Error sending gi.actions/group/join action for group ${data.groupContractID}`, e)
})
}).catch(e => {
console.error(`[gi.contracts/identity/joinGroup/sideEffect] Error at queueInvocation group ${data.groupContractID}`, e)
Expand Down Expand Up @@ -243,7 +245,7 @@ sbp('chelonia/defineContract', {
contractID: groupContractID,
data: {}
}).catch(e => {
console.error(`[gi.contracts/identity/leaveGroup/sideEffect] Error sending /removeOurselvs action to group ${data.groupContractID}`, e)
console.error(`[gi.contracts/identity/leaveGroup/sideEffect] Error sending /removeOurselves action to group ${data.groupContractID}`, e)
})
}

Expand Down
4 changes: 2 additions & 2 deletions frontend/model/contracts/manifests.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifests": {
"gi.contracts/chatroom": "21XWnNMgR144Bw53R99pzoqhdg7n6VdEE1o4PWdoN5mdrGQSTT",
"gi.contracts/group": "21XWnNRJJiwLyc5Ldgo5eTaDaJ8zSp74pYFB9JV2yCDjGa3gvA",
"gi.contracts/identity": "21XWnNWbBF1cz7VSRKffrmppQuPNncZdbmbN2Zf7bdmRSMgGCx"
"gi.contracts/group": "21XWnNUSm3U7wAEnPxnNDhocjPa235sAzMtLare3cfFkasN1ks",
"gi.contracts/identity": "21XWnNLTgLyFrGkbGbXCMtbCtB2apx88qXLDBhPiew2PzWtDCP"
}
}
3 changes: 1 addition & 2 deletions shared/domains/chelonia/chelonia.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,8 @@ export default (sbp('sbp/selectors/register', {
'chelonia/contract/sync': function (contractIDs: string | string[], params?: { force?: boolean, deferredRemove?: boolean }): Promise<*> {
const listOfIds = typeof contractIDs === 'string' ? [contractIDs] : contractIDs
const forcedSync = !!params?.force
const rootState = sbp(this.config.stateSelector)
return Promise.all(listOfIds.map(contractID => {
if (!forcedSync && has(rootState.contracts, contractID)) {
if (!forcedSync && this.subscriptionSet.has(contractID)) {
if (params?.deferredRemove) {
this.removeCount[contractID] = (this.removeCount[contractID] || 0) + 1
}
Expand Down
2 changes: 1 addition & 1 deletion shared/domains/chelonia/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const validateKeyPermissions = (state: Object, signingKeyId: string, opT:
)
)
) {
console.error(`Signing key ${signingKey.id} is missing permissions for operation ${opT}`)
console.error(`Signing key ${signingKeyId} is missing permissions for operation ${opT}`)
return false
}

Expand Down

0 comments on commit 13dbaaa

Please sign in to comment.