{"action":"created","comment":{"url":"https://api.github.com/repos/golemfactory/golem/pulls/comments/193978775","pull_request_review_id":127062592,"id":193978775,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5Mzk3ODc3NQ==","diff_hunk":"@@ -69,18 +67,64 @@ def get_gas_cost_per_payment(self) -> int:\n \n     def load_from_db(self):\n         with db.atomic():\n+            sent = {}\n             for sent_payment in Payment \\\n                     .select() \\\n                     .where(Payment.status == PaymentStatus.sent):\n-                transaction_hash = '0x' + sent_payment.details.tx\n-                if transaction_hash not in self._inprogress:\n-                    self._inprogress[transaction_hash] = []\n-                self._inprogress[transaction_hash].append(sent_payment)\n+                tx_hash = '0x' + sent_payment.details.tx\n+                if tx_hash not in sent:\n+                    sent[tx_hash] = []\n+                sent[tx_hash].append(sent_payment)\n+                self._gntb_reserved += sent_payment.value\n+            for tx_hash, payments in sent.items():\n+                self._sci.on_transaction_confirmed(\n+                    tx_hash,\n+                    lambda r: threads.deferToThread(\n+                        self._on_batch_confirmed, payments.copy(), r),\n+                )\n+\n             for awaiting_payment in Payment \\\n                     .select() \\\n                     .where(Payment.status == PaymentStatus.awaiting):\n                 self.add(awaiting_payment)\n \n+    def _on_batch_confirmed(self, payments: List[Payment], receipt) -> None:\n+        if not receipt.status:\n+            log.critical(\"Failed batch transfer: %s\", receipt)\n+            for p in payments:\n+                p.status = PaymentStatus.awaiting  # type: ignore\n+                p.save()\n+                self._gntb_reserved -= p.value\n+                self.add(p)\n+            return\n+\n+        # TODO: Use the actual gas price of the transaction\n+        total_fee = receipt.gas_used * self._sci.GAS_PRICE\n+        fee = total_fee // len(payments)\n+        log.info(\n+            \"Batch transfer confirmed %s average gas fee per subtask %f\",\n+            receipt,\n+            fee / denoms.ether,\n+        )\n+        for p in payments:\n+            p.status = PaymentStatus.confirmed  # type: ignore\n+            p.details.block_number = receipt.block_number\n+            p.details.block_hash = receipt.block_hash[2:]\n+            p.details.fee = fee\n+            p.save()\n+            self._gntb_reserved -= p.value","path":"golem/ethereum/paymentprocessor.py","position":93,"original_position":93,"commit_id":"b3d83e6fa5370906b26eef9c68bb8274dddbfb3a","original_commit_id":"b3d83e6fa5370906b26eef9c68bb8274dddbfb3a","user":{"login":"Krigpl","id":3904252,"node_id":"MDQ6VXNlcjM5MDQyNTI=","avatar_url":"https://avatars0.githubusercontent.com/u/3904252?v=4","gravatar_id":"","url":"https://api.github.com/users/Krigpl","html_url":"https://github.com/Krigpl","followers_url":"https://api.github.com/users/Krigpl/followers","following_url":"https://api.github.com/users/Krigpl/following{/other_user}","gists_url":"https://api.github.com/users/Krigpl/gists{/gist_id}","starred_url":"https://api.github.com/users/Krigpl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Krigpl/subscriptions","organizations_url":"https://api.github.com/users/Krigpl/orgs","repos_url":"https://api.github.com/users/Krigpl/repos","events_url":"https://api.github.com/users/Krigpl/events{/privacy}","received_events_url":"https://api.github.com/users/Krigpl/received_events","type":"User","site_admin":false},"body":"Not sure what you meant but if we ever change the threading model in Golem not to run everything from Twisted when many more places in Golem will have the same problem.","created_at":"2018-06-08T07:52:38Z","updated_at":"2018-06-08T07:52:41Z","html_url":"https://github.com/golemfactory/golem/pull/2856#discussion_r193978775","pull_request_url":"https://api.github.com/repos/golemfactory/golem/pulls/2856","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/golemfactory/golem/pulls/comments/193978775"},"html":{"href":"https://github.com/golemfactory/golem/pull/2856#discussion_r193978775"},"pull_request":{"href":"https://api.github.com/repos/golemfactory/golem/pulls/2856"}},"in_reply_to_id":193823866},"pull_request":{"url":"https://api.github.com/repos/golemfactory/golem/pulls/2856","id":193296210,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkzMjk2MjEw","html_url":"https://github.com/golemfactory/golem/pull/2856","diff_url":"https://github.com/golemfactory/golem/pull/2856.diff","patch_url":"https://github.com/golemfactory/golem/pull/2856.patch","issue_url":"https://api.github.com/repos/golemfactory/golem/issues/2856","number":2856,"state":"open","locked":false,"title":"Upgrade to better SCI","user":{"login":"Krigpl","id":3904252,"node_id":"MDQ6VXNlcjM5MDQyNTI=","avatar_url":"https://avatars0.githubusercontent.com/u/3904252?v=4","gravatar_id":"","url":"https://api.github.com/users/Krigpl","html_url":"https://github.com/Krigpl","followers_url":"https://api.github.com/users/Krigpl/followers","following_url":"https://api.github.com/users/Krigpl/following{/other_user}","gists_url":"https://api.github.com/users/Krigpl/gists{/gist_id}","starred_url":"https://api.github.com/users/Krigpl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Krigpl/subscriptions","organizations_url":"https://api.github.com/users/Krigpl/orgs","repos_url":"https://api.github.com/users/Krigpl/repos","events_url":"https://api.github.com/users/Krigpl/events{/privacy}","received_events_url":"https://api.github.com/users/Krigpl/received_events","type":"User","site_admin":false},"body":"See https://github.com/golemfactory/golem-smart-contracts-interface/pull/30","created_at":"2018-06-07T11:57:31Z","updated_at":"2018-06-08T07:52:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d97c91b481744994ad59bde0e630f837d5db3835","assignee":null,"assignees":[],"requested_reviewers":[{"login":"maaktweluit","id":10008353,"node_id":"MDQ6VXNlcjEwMDA4MzUz","avatar_url":"https://avatars0.githubusercontent.com/u/10008353?v=4","gravatar_id":"","url":"https://api.github.com/users/maaktweluit","html_url":"https://github.com/maaktweluit","followers_url":"https://api.github.com/users/maaktweluit/followers","following_url":"https://api.github.com/users/maaktweluit/following{/other_user}","gists_url":"https://api.github.com/users/maaktweluit/gists{/gist_id}","starred_url":"https://api.github.com/users/maaktweluit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maaktweluit/subscriptions","organizations_url":"https://api.github.com/users/maaktweluit/orgs","repos_url":"https://api.github.com/users/maaktweluit/repos","events_url":"https://api.github.com/users/maaktweluit/events{/privacy}","received_events_url":"https://api.github.com/users/maaktweluit/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/golemfactory/golem/pulls/2856/commits","review_comments_url":"https://api.github.com/repos/golemfactory/golem/pulls/2856/comments","review_comment_url":"https://api.github.com/repos/golemfactory/golem/pulls/comments{/number}","comments_url":"https://api.github.com/repos/golemfactory/golem/issues/2856/comments","statuses_url":"https://api.github.com/repos/golemfactory/golem/statuses/b3d83e6fa5370906b26eef9c68bb8274dddbfb3a","head":{"label":"golemfactory:better_sci","ref":"better_sci","sha":"b3d83e6fa5370906b26eef9c68bb8274dddbfb3a","user":{"login":"golemfactory","id":23193179,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIzMTkzMTc5","avatar_url":"https://avatars1.githubusercontent.com/u/23193179?v=4","gravatar_id":"","url":"https://api.github.com/users/golemfactory","html_url":"https://github.com/golemfactory","followers_url":"https://api.github.com/users/golemfactory/followers","following_url":"https://api.github.com/users/golemfactory/following{/other_user}","gists_url":"https://api.github.com/users/golemfactory/gists{/gist_id}","starred_url":"https://api.github.com/users/golemfactory/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/golemfactory/subscriptions","organizations_url":"https://api.github.com/users/golemfactory/orgs","repos_url":"https://api.github.com/users/golemfactory/repos","events_url":"https://api.github.com/users/golemfactory/events{/privacy}","received_events_url":"https://api.github.com/users/golemfactory/received_events","type":"Organization","site_admin":false},"repo":{"id":46433937,"node_id":"MDEwOlJlcG9zaXRvcnk0NjQzMzkzNw==","name":"golem","full_name":"golemfactory/golem","owner":{"login":"golemfactory","id":23193179,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIzMTkzMTc5","avatar_url":"https://avatars1.githubusercontent.com/u/23193179?v=4","gravatar_id":"","url":"https://api.github.com/users/golemfactory","html_url":"https://github.com/golemfactory","followers_url":"https://api.github.com/users/golemfactory/followers","following_url":"https://api.github.com/users/golemfactory/following{/other_user}","gists_url":"https://api.github.com/users/golemfactory/gists{/gist_id}","starred_url":"https://api.github.com/users/golemfactory/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/golemfactory/subscriptions","organizations_url":"https://api.github.com/users/golemfactory/orgs","repos_url":"https://api.github.com/users/golemfactory/repos","events_url":"https://api.github.com/users/golemfactory/events{/privacy}","received_events_url":"https://api.github.com/users/golemfactory/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/golemfactory/golem","description":"Golem is creating a global market for computing power.","fork":false,"url":"https://api.github.com/repos/golemfactory/golem","forks_url":"https://api.github.com/repos/golemfactory/golem/forks","keys_url":"https://api.github.com/repos/golemfactory/golem/keys{/key_id}","collaborators_url":"https://api.github.com/repos/golemfactory/golem/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/golemfactory/golem/teams","hooks_url":"https://api.github.com/repos/golemfactory/golem/hooks","issue_events_url":"https://api.github.com/repos/golemfactory/golem/issues/events{/number}","events_url":"https://api.github.com/repos/golemfactory/golem/events","assignees_url":"https://api.github.com/repos/golemfactory/golem/assignees{/user}","branches_url":"https://api.github.com/repos/golemfactory/golem/branches{/branch}","tags_url":"https://api.github.com/repos/golemfactory/golem/tags","blobs_url":"https://api.github.com/repos/golemfactory/golem/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/golemfactory/golem/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/golemfactory/golem/git/refs{/sha}","trees_url":"https://api.github.com/repos/golemfactory/golem/git/trees{/sha}","statuses_url":"https://api.github.com/repos/golemfactory/golem/statuses/{sha}","languages_url":"https://api.github.com/repos/golemfactory/golem/languages","stargazers_url":"https://api.github.com/repos/golemfactory/golem/stargazers","contributors_url":"https://api.github.com/repos/golemfactory/golem/contributors","subscribers_url":"https://api.github.com/repos/golemfactory/golem/subscribers","subscription_url":"https://api.github.com/repos/golemfactory/golem/subscription","commits_url":"https://api.github.com/repos/golemfactory/golem/commits{/sha}","git_commits_url":"https://api.github.com/repos/golemfactory/golem/git/commits{/sha}","comments_url":"https://api.github.com/repos/golemfactory/golem/comments{/number}","issue_comment_url":"https://api.github.com/repos/golemfactory/golem/issues/comments{/number}","contents_url":"https://api.github.com/repos/golemfactory/golem/contents/{+path}","compare_url":"https://api.github.com/repos/golemfactory/golem/compare/{base}...{head}","merges_url":"https://api.github.com/repos/golemfactory/golem/merges","archive_url":"https://api.github.com/repos/golemfactory/golem/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/golemfactory/golem/downloads","issues_url":"https://api.github.com/repos/golemfactory/golem/issues{/number}","pulls_url":"https://api.github.com/repos/golemfactory/golem/pulls{/number}","milestones_url":"https://api.github.com/repos/golemfactory/golem/milestones{/number}","notifications_url":"https://api.github.com/repos/golemfactory/golem/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/golemfactory/golem/labels{/name}","releases_url":"https://api.github.com/repos/golemfactory/golem/releases{/id}","deployments_url":"https://api.github.com/repos/golemfactory/golem/deployments","created_at":"2015-11-18T17:02:35Z","updated_at":"2018-06-07T14:07:22Z","pushed_at":"2018-06-08T07:47:36Z","git_url":"git://github.com/golemfactory/golem.git","ssh_url":"git@github.com:golemfactory/golem.git","clone_url":"https://github.com/golemfactory/golem.git","svn_url":"https://github.com/golemfactory/golem","homepage":"https://golem.network","size":91160,"stargazers_count":2503,"watchers_count":2503,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":259,"mirror_url":null,"archived":false,"open_issues_count":287,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":259,"open_issues":287,"watchers":2503,"default_branch":"develop"}},"base":{"label":"golemfactory:develop","ref":"develop","sha":"c5c2cb49f762b4f6cbd85810e449731819d95888","user":{"login":"golemfactory","id":23193179,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIzMTkzMTc5","avatar_url":"https://avatars1.githubusercontent.com/u/23193179?v=4","gravatar_id":"","url":"https://api.github.com/users/golemfactory","html_url":"https://github.com/golemfactory","followers_url":"https://api.github.com/users/golemfactory/followers","following_url":"https://api.github.com/users/golemfactory/following{/other_user}","gists_url":"https://api.github.com/users/golemfactory/gists{/gist_id}","starred_url":"https://api.github.com/users/golemfactory/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/golemfactory/subscriptions","organizations_url":"https://api.github.com/users/golemfactory/orgs","repos_url":"https://api.github.com/users/golemfactory/repos","events_url":"https://api.github.com/users/golemfactory/events{/privacy}","received_events_url":"https://api.github.com/users/golemfactory/received_events","type":"Organization","site_admin":false},"repo":{"id":46433937,"node_id":"MDEwOlJlcG9zaXRvcnk0NjQzMzkzNw==","name":"golem","full_name":"golemfactory/golem","owner":{"login":"golemfactory","id":23193179,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIzMTkzMTc5","avatar_url":"https://avatars1.githubusercontent.com/u/23193179?v=4","gravatar_id":"","url":"https://api.github.com/users/golemfactory","html_url":"https://github.com/golemfactory","followers_url":"https://api.github.com/users/golemfactory/followers","following_url":"https://api.github.com/users/golemfactory/following{/other_user}","gists_url":"https://api.github.com/users/golemfactory/gists{/gist_id}","starred_url":"https://api.github.com/users/golemfactory/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/golemfactory/subscriptions","organizations_url":"https://api.github.com/users/golemfactory/orgs","repos_url":"https://api.github.com/users/golemfactory/repos","events_url":"https://api.github.com/users/golemfactory/events{/privacy}","received_events_url":"https://api.github.com/users/golemfactory/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/golemfactory/golem","description":"Golem is creating a global market for computing power.","fork":false,"url":"https://api.github.com/repos/golemfactory/golem","forks_url":"https://api.github.com/repos/golemfactory/golem/forks","keys_url":"https://api.github.com/repos/golemfactory/golem/keys{/key_id}","collaborators_url":"https://api.github.com/repos/golemfactory/golem/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/golemfactory/golem/teams","hooks_url":"https://api.github.com/repos/golemfactory/golem/hooks","issue_events_url":"https://api.github.com/repos/golemfactory/golem/issues/events{/number}","events_url":"https://api.github.com/repos/golemfactory/golem/events","assignees_url":"https://api.github.com/repos/golemfactory/golem/assignees{/user}","branches_url":"https://api.github.com/repos/golemfactory/golem/branches{/branch}","tags_url":"https://api.github.com/repos/golemfactory/golem/tags","blobs_url":"https://api.github.com/repos/golemfactory/golem/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/golemfactory/golem/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/golemfactory/golem/git/refs{/sha}","trees_url":"https://api.github.com/repos/golemfactory/golem/git/trees{/sha}","statuses_url":"https://api.github.com/repos/golemfactory/golem/statuses/{sha}","languages_url":"https://api.github.com/repos/golemfactory/golem/languages","stargazers_url":"https://api.github.com/repos/golemfactory/golem/stargazers","contributors_url":"https://api.github.com/repos/golemfactory/golem/contributors","subscribers_url":"https://api.github.com/repos/golemfactory/golem/subscribers","subscription_url":"https://api.github.com/repos/golemfactory/golem/subscription","commits_url":"https://api.github.com/repos/golemfactory/golem/commits{/sha}","git_commits_url":"https://api.github.com/repos/golemfactory/golem/git/commits{/sha}","comments_url":"https://api.github.com/repos/golemfactory/golem/comments{/number}","issue_comment_url":"https://api.github.com/repos/golemfactory/golem/issues/comments{/number}","contents_url":"https://api.github.com/repos/golemfactory/golem/contents/{+path}","compare_url":"https://api.github.com/repos/golemfactory/golem/compare/{base}...{head}","merges_url":"https://api.github.com/repos/golemfactory/golem/merges","archive_url":"https://api.github.com/repos/golemfactory/golem/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/golemfactory/golem/downloads","issues_url":"https://api.github.com/repos/golemfactory/golem/issues{/number}","pulls_url":"https://api.github.com/repos/golemfactory/golem/pulls{/number}","milestones_url":"https://api.github.com/repos/golemfactory/golem/milestones{/number}","notifications_url":"https://api.github.com/repos/golemfactory/golem/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/golemfactory/golem/labels{/name}","releases_url":"https://api.github.com/repos/golemfactory/golem/releases{/id}","deployments_url":"https://api.github.com/repos/golemfactory/golem/deployments","created_at":"2015-11-18T17:02:35Z","updated_at":"2018-06-07T14:07:22Z","pushed_at":"2018-06-08T07:47:36Z","git_url":"git://github.com/golemfactory/golem.git","ssh_url":"git@github.com:golemfactory/golem.git","clone_url":"https://github.com/golemfactory/golem.git","svn_url":"https://github.com/golemfactory/golem","homepage":"https://golem.network","size":91160,"stargazers_count":2503,"watchers_count":2503,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":259,"mirror_url":null,"archived":false,"open_issues_count":287,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":259,"open_issues":287,"watchers":2503,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/golemfactory/golem/pulls/2856"},"html":{"href":"https://github.com/golemfactory/golem/pull/2856"},"issue":{"href":"https://api.github.com/repos/golemfactory/golem/issues/2856"},"comments":{"href":"https://api.github.com/repos/golemfactory/golem/issues/2856/comments"},"review_comments":{"href":"https://api.github.com/repos/golemfactory/golem/pulls/2856/comments"},"review_comment":{"href":"https://api.github.com/repos/golemfactory/golem/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/golemfactory/golem/pulls/2856/commits"},"statuses":{"href":"https://api.github.com/repos/golemfactory/golem/statuses/b3d83e6fa5370906b26eef9c68bb8274dddbfb3a"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"Krigpl"}}