{"action":"created","comment":{"url":"https://api.github.com/repos/counterfactual/monorepo/pulls/comments/310134654","pull_request_review_id":270181994,"id":310134654,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDMxMDEzNDY1NA==","diff_hunk":"@@ -36,138 +37,213 @@ export async function handleReceivedProtocolMessage(\n     router\n   } = requestHandler;\n \n-  const deserializedMsg = bigNumberifyJson(msg);\n-\n-  const { data } = deserializedMsg;\n+  const { data } = bigNumberifyJson(msg) as NodeMessageWrappedProtocolMessage;\n \n   const { protocol, seq, params } = data;\n \n-  if (seq === -1) return;\n+  if (seq === UNASSIGNED_SEQ_NO) return;\n \n-  let stateChannelsMap;\n-  let uninstallMsg;\n+  const preProtocolStateChannelsMap = new Map<string, StateChannel>(\n+    Object.entries(await store.getAllChannels())\n+  );\n \n-  if (protocol === Protocol.UninstallVirtualApp) {\n-    const {\n-      initiatorXpub,\n-      intermediaryXpub,\n-      responderXpub,\n-      targetAppIdentityHash\n-    } = params as UninstallVirtualAppParams;\n-\n-    let channelWithIntermediary = await store.getMultisigAddressFromOwnersHash(\n-      hashOfOrderedPublicIdentifiers([initiatorXpub, intermediaryXpub])\n-    );\n+  const queueNames = await getQueueNamesListByProtocolName(\n+    protocol,\n+    params,\n+    store,\n+    requestHandler\n+  );\n \n-    if (channelWithIntermediary === null) {\n-      channelWithIntermediary = await store.getMultisigAddressFromOwnersHash(\n-        hashOfOrderedPublicIdentifiers([responderXpub, intermediaryXpub])\n+  const postProtocolStateChannelsMap = await executeFunctionWithinQueues(\n+    queueNames.map(requestHandler.getShardedQueue.bind(requestHandler)),\n+    async () => {\n+      const ret = await instructionExecutor.runProtocolWithMessage(\n+        data,\n+        preProtocolStateChannelsMap\n       );\n+\n+      ret.forEach(store.saveStateChannel.bind(store));\n+\n+      return ret;\n     }\n+  );\n \n-    await requestHandler\n-      .getShardedQueue(channelWithIntermediary)\n-      .add(async () => {\n-        stateChannelsMap = await instructionExecutor.runProtocolWithMessage(\n-          data,\n-          new Map<string, StateChannel>(\n-            Object.entries(await store.getAllChannels())\n-          )\n-        );\n-\n-        stateChannelsMap.forEach(\n-          async stateChannel => await store.saveStateChannel(stateChannel)\n-        );\n-      });\n-\n-    uninstallMsg = {\n-      from: publicIdentifier,\n-      type: NODE_EVENTS.UNINSTALL_VIRTUAL,\n-      data: {\n-        appInstanceId: targetAppIdentityHash,\n-        intermediaryIdentifier: intermediaryXpub\n-      }\n-    } as UninstallVirtualMessage;\n-\n-    await router.emit(uninstallMsg.type, uninstallMsg, \"outgoing\");\n-  } else {\n-    const { multisigAddress } = params as\n-      | UninstallParams\n-      | WithdrawParams\n-      | SetupParams\n-      | TakeActionParams\n-      | UpdateParams;\n-\n-    await requestHandler.getShardedQueue(multisigAddress).add(async () => {\n-      stateChannelsMap = await instructionExecutor.runProtocolWithMessage(\n-        data,\n-        new Map<string, StateChannel>(\n-          Object.entries(await store.getAllChannels())\n+  const outgoingEventData = getOutgoingEventDataFromProtocol(\n+    protocol,\n+    params,\n+    publicIdentifier,\n+    postProtocolStateChannelsMap\n+  );\n+\n+  if (outgoingEventData) {\n+    await emitOutgoingNodeMessage(router, outgoingEventData);\n+  }\n+}\n+\n+function emitOutgoingNodeMessage(router: RpcRouter, msg: object) {\n+  return router.emit(msg[\"type\"], msg, \"outgoing\");\n+}\n+\n+function getOutgoingEventDataFromProtocol(\n+  protocol: string,\n+  params: ProtocolParameters,\n+  publicIdentifier: string,\n+  stateChannelsMap: Map<string, StateChannel>\n+) {\n+  const baseEvent = { from: publicIdentifier };\n+\n+  switch (protocol) {\n+    case Protocol.Install:\n+      // TODO: Have to take an InstallParams object and somehow compute the","path":"packages/node/src/message-handling/handle-protocol-message.ts","position":152,"original_position":152,"commit_id":"e0c8eae5808d3aa937560864d13f751dc12fd4f9","original_commit_id":"e0c8eae5808d3aa937560864d13f751dc12fd4f9","user":{"login":"snario","id":1933029,"node_id":"MDQ6VXNlcjE5MzMwMjk=","avatar_url":"https://avatars1.githubusercontent.com/u/1933029?v=4","gravatar_id":"","url":"https://api.github.com/users/snario","html_url":"https://github.com/snario","followers_url":"https://api.github.com/users/snario/followers","following_url":"https://api.github.com/users/snario/following{/other_user}","gists_url":"https://api.github.com/users/snario/gists{/gist_id}","starred_url":"https://api.github.com/users/snario/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snario/subscriptions","organizations_url":"https://api.github.com/users/snario/orgs","repos_url":"https://api.github.com/users/snario/repos","events_url":"https://api.github.com/users/snario/events{/privacy}","received_events_url":"https://api.github.com/users/snario/received_events","type":"User","site_admin":false},"body":"No","created_at":"2019-08-02T13:37:11Z","updated_at":"2019-08-02T13:37:11Z","html_url":"https://github.com/counterfactual/monorepo/pull/2092#discussion_r310134654","pull_request_url":"https://api.github.com/repos/counterfactual/monorepo/pulls/2092","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/counterfactual/monorepo/pulls/comments/310134654"},"html":{"href":"https://github.com/counterfactual/monorepo/pull/2092#discussion_r310134654"},"pull_request":{"href":"https://api.github.com/repos/counterfactual/monorepo/pulls/2092"}},"in_reply_to_id":309913409},"pull_request":{"url":"https://api.github.com/repos/counterfactual/monorepo/pulls/2092","id":303491077,"node_id":"MDExOlB1bGxSZXF1ZXN0MzAzNDkxMDc3","html_url":"https://github.com/counterfactual/monorepo/pull/2092","diff_url":"https://github.com/counterfactual/monorepo/pull/2092.diff","patch_url":"https://github.com/counterfactual/monorepo/pull/2092.patch","issue_url":"https://api.github.com/repos/counterfactual/monorepo/issues/2092","number":2092,"state":"open","locked":false,"title":"Handle asymmetric event emission + better concurrency handling","user":{"login":"snario","id":1933029,"node_id":"MDQ6VXNlcjE5MzMwMjk=","avatar_url":"https://avatars1.githubusercontent.com/u/1933029?v=4","gravatar_id":"","url":"https://api.github.com/users/snario","html_url":"https://github.com/snario","followers_url":"https://api.github.com/users/snario/followers","following_url":"https://api.github.com/users/snario/following{/other_user}","gists_url":"https://api.github.com/users/snario/gists{/gist_id}","starred_url":"https://api.github.com/users/snario/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snario/subscriptions","organizations_url":"https://api.github.com/users/snario/orgs","repos_url":"https://api.github.com/users/snario/repos","events_url":"https://api.github.com/users/snario/events{/privacy}","received_events_url":"https://api.github.com/users/snario/received_events","type":"User","site_admin":false},"body":"Concurrency fixes:\r\n\r\n1. Install virtual app now has queuing. It did not before.\r\n2. Uninstall virtual app now queues on both channels with counterparties, not just one.\r\n3. Update and take action now queues on app instance identity hash, not multisig address","created_at":"2019-08-01T17:53:47Z","updated_at":"2019-08-02T13:37:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5fbf32958e77105e6fa48a3affac0acd257b5ff2","assignee":null,"assignees":[],"requested_reviewers":[{"login":"joelalejandro","id":118913,"node_id":"MDQ6VXNlcjExODkxMw==","avatar_url":"https://avatars1.githubusercontent.com/u/118913?v=4","gravatar_id":"","url":"https://api.github.com/users/joelalejandro","html_url":"https://github.com/joelalejandro","followers_url":"https://api.github.com/users/joelalejandro/followers","following_url":"https://api.github.com/users/joelalejandro/following{/other_user}","gists_url":"https://api.github.com/users/joelalejandro/gists{/gist_id}","starred_url":"https://api.github.com/users/joelalejandro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joelalejandro/subscriptions","organizations_url":"https://api.github.com/users/joelalejandro/orgs","repos_url":"https://api.github.com/users/joelalejandro/repos","events_url":"https://api.github.com/users/joelalejandro/events{/privacy}","received_events_url":"https://api.github.com/users/joelalejandro/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/counterfactual/monorepo/pulls/2092/commits","review_comments_url":"https://api.github.com/repos/counterfactual/monorepo/pulls/2092/comments","review_comment_url":"https://api.github.com/repos/counterfactual/monorepo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/counterfactual/monorepo/issues/2092/comments","statuses_url":"https://api.github.com/repos/counterfactual/monorepo/statuses/e0c8eae5808d3aa937560864d13f751dc12fd4f9","head":{"label":"counterfactual:liam/symmetric","ref":"liam/symmetric","sha":"e0c8eae5808d3aa937560864d13f751dc12fd4f9","user":{"login":"counterfactual","id":33231299,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMzMjMxMjk5","avatar_url":"https://avatars3.githubusercontent.com/u/33231299?v=4","gravatar_id":"","url":"https://api.github.com/users/counterfactual","html_url":"https://github.com/counterfactual","followers_url":"https://api.github.com/users/counterfactual/followers","following_url":"https://api.github.com/users/counterfactual/following{/other_user}","gists_url":"https://api.github.com/users/counterfactual/gists{/gist_id}","starred_url":"https://api.github.com/users/counterfactual/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/counterfactual/subscriptions","organizations_url":"https://api.github.com/users/counterfactual/orgs","repos_url":"https://api.github.com/users/counterfactual/repos","events_url":"https://api.github.com/users/counterfactual/events{/privacy}","received_events_url":"https://api.github.com/users/counterfactual/received_events","type":"Organization","site_admin":false},"repo":{"id":143227440,"node_id":"MDEwOlJlcG9zaXRvcnkxNDMyMjc0NDA=","name":"monorepo","full_name":"counterfactual/monorepo","private":false,"owner":{"login":"counterfactual","id":33231299,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMzMjMxMjk5","avatar_url":"https://avatars3.githubusercontent.com/u/33231299?v=4","gravatar_id":"","url":"https://api.github.com/users/counterfactual","html_url":"https://github.com/counterfactual","followers_url":"https://api.github.com/users/counterfactual/followers","following_url":"https://api.github.com/users/counterfactual/following{/other_user}","gists_url":"https://api.github.com/users/counterfactual/gists{/gist_id}","starred_url":"https://api.github.com/users/counterfactual/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/counterfactual/subscriptions","organizations_url":"https://api.github.com/users/counterfactual/orgs","repos_url":"https://api.github.com/users/counterfactual/repos","events_url":"https://api.github.com/users/counterfactual/events{/privacy}","received_events_url":"https://api.github.com/users/counterfactual/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/counterfactual/monorepo","description":"Home for all packages related to the Counterfactual project","fork":false,"url":"https://api.github.com/repos/counterfactual/monorepo","forks_url":"https://api.github.com/repos/counterfactual/monorepo/forks","keys_url":"https://api.github.com/repos/counterfactual/monorepo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/counterfactual/monorepo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/counterfactual/monorepo/teams","hooks_url":"https://api.github.com/repos/counterfactual/monorepo/hooks","issue_events_url":"https://api.github.com/repos/counterfactual/monorepo/issues/events{/number}","events_url":"https://api.github.com/repos/counterfactual/monorepo/events","assignees_url":"https://api.github.com/repos/counterfactual/monorepo/assignees{/user}","branches_url":"https://api.github.com/repos/counterfactual/monorepo/branches{/branch}","tags_url":"https://api.github.com/repos/counterfactual/monorepo/tags","blobs_url":"https://api.github.com/repos/counterfactual/monorepo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/counterfactual/monorepo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/counterfactual/monorepo/git/refs{/sha}","trees_url":"https://api.github.com/repos/counterfactual/monorepo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/counterfactual/monorepo/statuses/{sha}","languages_url":"https://api.github.com/repos/counterfactual/monorepo/languages","stargazers_url":"https://api.github.com/repos/counterfactual/monorepo/stargazers","contributors_url":"https://api.github.com/repos/counterfactual/monorepo/contributors","subscribers_url":"https://api.github.com/repos/counterfactual/monorepo/subscribers","subscription_url":"https://api.github.com/repos/counterfactual/monorepo/subscription","commits_url":"https://api.github.com/repos/counterfactual/monorepo/commits{/sha}","git_commits_url":"https://api.github.com/repos/counterfactual/monorepo/git/commits{/sha}","comments_url":"https://api.github.com/repos/counterfactual/monorepo/comments{/number}","issue_comment_url":"https://api.github.com/repos/counterfactual/monorepo/issues/comments{/number}","contents_url":"https://api.github.com/repos/counterfactual/monorepo/contents/{+path}","compare_url":"https://api.github.com/repos/counterfactual/monorepo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/counterfactual/monorepo/merges","archive_url":"https://api.github.com/repos/counterfactual/monorepo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/counterfactual/monorepo/downloads","issues_url":"https://api.github.com/repos/counterfactual/monorepo/issues{/number}","pulls_url":"https://api.github.com/repos/counterfactual/monorepo/pulls{/number}","milestones_url":"https://api.github.com/repos/counterfactual/monorepo/milestones{/number}","notifications_url":"https://api.github.com/repos/counterfactual/monorepo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/counterfactual/monorepo/labels{/name}","releases_url":"https://api.github.com/repos/counterfactual/monorepo/releases{/id}","deployments_url":"https://api.github.com/repos/counterfactual/monorepo/deployments","created_at":"2018-08-02T01:43:08Z","updated_at":"2019-08-02T07:42:55Z","pushed_at":"2019-08-02T07:34:15Z","git_url":"git://github.com/counterfactual/monorepo.git","ssh_url":"git@github.com:counterfactual/monorepo.git","clone_url":"https://github.com/counterfactual/monorepo.git","svn_url":"https://github.com/counterfactual/monorepo","homepage":"https://counterfactual.com","size":21527,"stargazers_count":176,"watchers_count":176,"language":"TypeScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":40,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":154,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":40,"open_issues":154,"watchers":176,"default_branch":"master"}},"base":{"label":"counterfactual:master","ref":"master","sha":"405b14d52b0dbe75df8283bfc71fd9dd04ccb419","user":{"login":"counterfactual","id":33231299,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMzMjMxMjk5","avatar_url":"https://avatars3.githubusercontent.com/u/33231299?v=4","gravatar_id":"","url":"https://api.github.com/users/counterfactual","html_url":"https://github.com/counterfactual","followers_url":"https://api.github.com/users/counterfactual/followers","following_url":"https://api.github.com/users/counterfactual/following{/other_user}","gists_url":"https://api.github.com/users/counterfactual/gists{/gist_id}","starred_url":"https://api.github.com/users/counterfactual/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/counterfactual/subscriptions","organizations_url":"https://api.github.com/users/counterfactual/orgs","repos_url":"https://api.github.com/users/counterfactual/repos","events_url":"https://api.github.com/users/counterfactual/events{/privacy}","received_events_url":"https://api.github.com/users/counterfactual/received_events","type":"Organization","site_admin":false},"repo":{"id":143227440,"node_id":"MDEwOlJlcG9zaXRvcnkxNDMyMjc0NDA=","name":"monorepo","full_name":"counterfactual/monorepo","private":false,"owner":{"login":"counterfactual","id":33231299,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMzMjMxMjk5","avatar_url":"https://avatars3.githubusercontent.com/u/33231299?v=4","gravatar_id":"","url":"https://api.github.com/users/counterfactual","html_url":"https://github.com/counterfactual","followers_url":"https://api.github.com/users/counterfactual/followers","following_url":"https://api.github.com/users/counterfactual/following{/other_user}","gists_url":"https://api.github.com/users/counterfactual/gists{/gist_id}","starred_url":"https://api.github.com/users/counterfactual/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/counterfactual/subscriptions","organizations_url":"https://api.github.com/users/counterfactual/orgs","repos_url":"https://api.github.com/users/counterfactual/repos","events_url":"https://api.github.com/users/counterfactual/events{/privacy}","received_events_url":"https://api.github.com/users/counterfactual/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/counterfactual/monorepo","description":"Home for all packages related to the Counterfactual project","fork":false,"url":"https://api.github.com/repos/counterfactual/monorepo","forks_url":"https://api.github.com/repos/counterfactual/monorepo/forks","keys_url":"https://api.github.com/repos/counterfactual/monorepo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/counterfactual/monorepo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/counterfactual/monorepo/teams","hooks_url":"https://api.github.com/repos/counterfactual/monorepo/hooks","issue_events_url":"https://api.github.com/repos/counterfactual/monorepo/issues/events{/number}","events_url":"https://api.github.com/repos/counterfactual/monorepo/events","assignees_url":"https://api.github.com/repos/counterfactual/monorepo/assignees{/user}","branches_url":"https://api.github.com/repos/counterfactual/monorepo/branches{/branch}","tags_url":"https://api.github.com/repos/counterfactual/monorepo/tags","blobs_url":"https://api.github.com/repos/counterfactual/monorepo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/counterfactual/monorepo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/counterfactual/monorepo/git/refs{/sha}","trees_url":"https://api.github.com/repos/counterfactual/monorepo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/counterfactual/monorepo/statuses/{sha}","languages_url":"https://api.github.com/repos/counterfactual/monorepo/languages","stargazers_url":"https://api.github.com/repos/counterfactual/monorepo/stargazers","contributors_url":"https://api.github.com/repos/counterfactual/monorepo/contributors","subscribers_url":"https://api.github.com/repos/counterfactual/monorepo/subscribers","subscription_url":"https://api.github.com/repos/counterfactual/monorepo/subscription","commits_url":"https://api.github.com/repos/counterfactual/monorepo/commits{/sha}","git_commits_url":"https://api.github.com/repos/counterfactual/monorepo/git/commits{/sha}","comments_url":"https://api.github.com/repos/counterfactual/monorepo/comments{/number}","issue_comment_url":"https://api.github.com/repos/counterfactual/monorepo/issues/comments{/number}","contents_url":"https://api.github.com/repos/counterfactual/monorepo/contents/{+path}","compare_url":"https://api.github.com/repos/counterfactual/monorepo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/counterfactual/monorepo/merges","archive_url":"https://api.github.com/repos/counterfactual/monorepo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/counterfactual/monorepo/downloads","issues_url":"https://api.github.com/repos/counterfactual/monorepo/issues{/number}","pulls_url":"https://api.github.com/repos/counterfactual/monorepo/pulls{/number}","milestones_url":"https://api.github.com/repos/counterfactual/monorepo/milestones{/number}","notifications_url":"https://api.github.com/repos/counterfactual/monorepo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/counterfactual/monorepo/labels{/name}","releases_url":"https://api.github.com/repos/counterfactual/monorepo/releases{/id}","deployments_url":"https://api.github.com/repos/counterfactual/monorepo/deployments","created_at":"2018-08-02T01:43:08Z","updated_at":"2019-08-02T07:42:55Z","pushed_at":"2019-08-02T07:34:15Z","git_url":"git://github.com/counterfactual/monorepo.git","ssh_url":"git@github.com:counterfactual/monorepo.git","clone_url":"https://github.com/counterfactual/monorepo.git","svn_url":"https://github.com/counterfactual/monorepo","homepage":"https://counterfactual.com","size":21527,"stargazers_count":176,"watchers_count":176,"language":"TypeScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":40,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":154,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":40,"open_issues":154,"watchers":176,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/counterfactual/monorepo/pulls/2092"},"html":{"href":"https://github.com/counterfactual/monorepo/pull/2092"},"issue":{"href":"https://api.github.com/repos/counterfactual/monorepo/issues/2092"},"comments":{"href":"https://api.github.com/repos/counterfactual/monorepo/issues/2092/comments"},"review_comments":{"href":"https://api.github.com/repos/counterfactual/monorepo/pulls/2092/comments"},"review_comment":{"href":"https://api.github.com/repos/counterfactual/monorepo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/counterfactual/monorepo/pulls/2092/commits"},"statuses":{"href":"https://api.github.com/repos/counterfactual/monorepo/statuses/e0c8eae5808d3aa937560864d13f751dc12fd4f9"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"snario"}}