{"action":"created","comment":{"url":"https://api.github.com/repos/bitcoinj/bitcoinj/pulls/comments/26438950","id":26438950,"diff_hunk":"@@ -1691,24 +1692,46 @@ private boolean checkForDoubleSpendAgainstPending(Transaction tx, boolean takeAc\n             outpoints.add(input.getOutpoint());\n         }\n         // Now for each pending transaction, see if it shares any outpoints with this tx.\n-        LinkedList<Transaction> doubleSpentTxns = Lists.newLinkedList();\n-        for (Transaction p : pending.values()) {\n+        Set<Transaction> doubleSpendTxns = Sets.newHashSet();\n+        for (Transaction p : candidates.values()) {\n             for (TransactionInput input : p.getInputs()) {\n                 // This relies on the fact that TransactionOutPoint equality is defined at the protocol not object\n                 // level - outpoints from two different inputs that point to the same output compare the same.\n                 TransactionOutPoint outpoint = input.getOutpoint();\n                 if (outpoints.contains(outpoint)) {\n-                    // It does, it's a double spend against the pending pool, which makes it relevant.\n-                    if (!doubleSpentTxns.isEmpty() && doubleSpentTxns.getLast() == p) continue;\n-                    doubleSpentTxns.add(p);\n+                    // It does, it's a double spend against the candidates, which makes it relevant.\n+                    doubleSpendTxns.add(p);\n                 }\n             }\n         }\n-        if (takeAction && !doubleSpentTxns.isEmpty()) {\n-            killTx(tx, doubleSpentTxns);\n+        return doubleSpendTxns;\n+    }\n+\n+    /**\n+     * Adds to txSet all the txns in txPool spending outputs of txns in txSet, \n+     * and all txns spending the outputs of those txns, recursively.\n+     * @param txSet The set of txns whose dependencies should be added. This method updates txSet.\n+     * @param txPool The set of txns to evaluate adding to txSet\n+     */\n+    void addTransactionsDependingOn(Set<Transaction> txSet, Set<Transaction> txPool) {\n+        Deque<Transaction> txDeque = new LinkedList<Transaction>();\n+        txDeque.addAll(txSet);\n+        while(!txDeque.isEmpty()) {\n+            Transaction tx = txDeque.poll();\n+            for (Transaction anotherTx : txPool) {\n+                if (anotherTx.equals(tx)) continue;\n+                for (TransactionInput input : anotherTx.getInputs()) {\n+                    if (input.getOutpoint().getHash().equals(tx.getHash())) {\n+                        if (!txDeque.contains(anotherTx)) {","path":"core/src/main/java/org/bitcoinj/core/Wallet.java","position":null,"original_position":76,"commit_id":"a9d0813bbaefb5a745a472ac3cdbd0ba14b51ec8","original_commit_id":"22d5013f481a6d43e4cffc50b965ba3f701ce195","user":{"login":"oscarguindzberg","id":1145132,"avatar_url":"https://avatars.githubusercontent.com/u/1145132?v=3","gravatar_id":"","url":"https://api.github.com/users/oscarguindzberg","html_url":"https://github.com/oscarguindzberg","followers_url":"https://api.github.com/users/oscarguindzberg/followers","following_url":"https://api.github.com/users/oscarguindzberg/following{/other_user}","gists_url":"https://api.github.com/users/oscarguindzberg/gists{/gist_id}","starred_url":"https://api.github.com/users/oscarguindzberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oscarguindzberg/subscriptions","organizations_url":"https://api.github.com/users/oscarguindzberg/orgs","repos_url":"https://api.github.com/users/oscarguindzberg/repos","events_url":"https://api.github.com/users/oscarguindzberg/events{/privacy}","received_events_url":"https://api.github.com/users/oscarguindzberg/received_events","type":"User","site_admin":false},"body":"done","created_at":"2015-03-14T15:53:23Z","updated_at":"2015-03-14T15:53:23Z","html_url":"https://github.com/bitcoinj/bitcoinj/pull/331#discussion_r26438950","pull_request_url":"https://api.github.com/repos/bitcoinj/bitcoinj/pulls/331","_links":{"self":{"href":"https://api.github.com/repos/bitcoinj/bitcoinj/pulls/comments/26438950"},"html":{"href":"https://github.com/bitcoinj/bitcoinj/pull/331#discussion_r26438950"},"pull_request":{"href":"https://api.github.com/repos/bitcoinj/bitcoinj/pulls/331"}}},"pull_request":{"url":"https://api.github.com/repos/bitcoinj/bitcoinj/pulls/331","id":30995304,"html_url":"https://github.com/bitcoinj/bitcoinj/pull/331","diff_url":"https://github.com/bitcoinj/bitcoinj/pull/331.diff","patch_url":"https://github.com/bitcoinj/bitcoinj/pull/331.patch","issue_url":"https://api.github.com/repos/bitcoinj/bitcoinj/issues/331","number":331,"state":"open","locked":false,"title":"Support double spend forwarding","user":{"login":"oscarguindzberg","id":1145132,"avatar_url":"https://avatars.githubusercontent.com/u/1145132?v=3","gravatar_id":"","url":"https://api.github.com/users/oscarguindzberg","html_url":"https://github.com/oscarguindzberg","followers_url":"https://api.github.com/users/oscarguindzberg/followers","following_url":"https://api.github.com/users/oscarguindzberg/following{/other_user}","gists_url":"https://api.github.com/users/oscarguindzberg/gists{/gist_id}","starred_url":"https://api.github.com/users/oscarguindzberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oscarguindzberg/subscriptions","organizations_url":"https://api.github.com/users/oscarguindzberg/orgs","repos_url":"https://api.github.com/users/oscarguindzberg/repos","events_url":"https://api.github.com/users/oscarguindzberg/events{/privacy}","received_events_url":"https://api.github.com/users/oscarguindzberg/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-03-11T23:22:41Z","updated_at":"2015-03-14T15:53:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f3786642155be9505f6e0b65e390845eaa5f4009","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bitcoinj/bitcoinj/pulls/331/commits","review_comments_url":"https://api.github.com/repos/bitcoinj/bitcoinj/pulls/331/comments","review_comment_url":"https://api.github.com/repos/bitcoinj/bitcoinj/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bitcoinj/bitcoinj/issues/331/comments","statuses_url":"https://api.github.com/repos/bitcoinj/bitcoinj/statuses/a9d0813bbaefb5a745a472ac3cdbd0ba14b51ec8","head":{"label":"oscarguindzberg:forward-double-spends2","ref":"forward-double-spends2","sha":"a9d0813bbaefb5a745a472ac3cdbd0ba14b51ec8","user":{"login":"oscarguindzberg","id":1145132,"avatar_url":"https://avatars.githubusercontent.com/u/1145132?v=3","gravatar_id":"","url":"https://api.github.com/users/oscarguindzberg","html_url":"https://github.com/oscarguindzberg","followers_url":"https://api.github.com/users/oscarguindzberg/followers","following_url":"https://api.github.com/users/oscarguindzberg/following{/other_user}","gists_url":"https://api.github.com/users/oscarguindzberg/gists{/gist_id}","starred_url":"https://api.github.com/users/oscarguindzberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oscarguindzberg/subscriptions","organizations_url":"https://api.github.com/users/oscarguindzberg/orgs","repos_url":"https://api.github.com/users/oscarguindzberg/repos","events_url":"https://api.github.com/users/oscarguindzberg/events{/privacy}","received_events_url":"https://api.github.com/users/oscarguindzberg/received_events","type":"User","site_admin":false},"repo":{"id":19839304,"name":"bitcoinj","full_name":"oscarguindzberg/bitcoinj","owner":{"login":"oscarguindzberg","id":1145132,"avatar_url":"https://avatars.githubusercontent.com/u/1145132?v=3","gravatar_id":"","url":"https://api.github.com/users/oscarguindzberg","html_url":"https://github.com/oscarguindzberg","followers_url":"https://api.github.com/users/oscarguindzberg/followers","following_url":"https://api.github.com/users/oscarguindzberg/following{/other_user}","gists_url":"https://api.github.com/users/oscarguindzberg/gists{/gist_id}","starred_url":"https://api.github.com/users/oscarguindzberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oscarguindzberg/subscriptions","organizations_url":"https://api.github.com/users/oscarguindzberg/orgs","repos_url":"https://api.github.com/users/oscarguindzberg/repos","events_url":"https://api.github.com/users/oscarguindzberg/events{/privacy}","received_events_url":"https://api.github.com/users/oscarguindzberg/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/oscarguindzberg/bitcoinj","description":"A library for working with Bitcoin","fork":true,"url":"https://api.github.com/repos/oscarguindzberg/bitcoinj","forks_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/forks","keys_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/keys{/key_id}","collaborators_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/teams","hooks_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/hooks","issue_events_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/issues/events{/number}","events_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/events","assignees_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/assignees{/user}","branches_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/branches{/branch}","tags_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/tags","blobs_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/git/refs{/sha}","trees_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/git/trees{/sha}","statuses_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/statuses/{sha}","languages_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/languages","stargazers_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/stargazers","contributors_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/contributors","subscribers_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/subscribers","subscription_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/subscription","commits_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/commits{/sha}","git_commits_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/git/commits{/sha}","comments_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/comments{/number}","issue_comment_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/issues/comments{/number}","contents_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/contents/{+path}","compare_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/compare/{base}...{head}","merges_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/merges","archive_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/downloads","issues_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/issues{/number}","pulls_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/pulls{/number}","milestones_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/milestones{/number}","notifications_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/labels{/name}","releases_url":"https://api.github.com/repos/oscarguindzberg/bitcoinj/releases{/id}","created_at":"2014-05-16T00:09:32Z","updated_at":"2015-03-11T23:00:52Z","pushed_at":"2015-03-14T15:52:27Z","git_url":"git://github.com/oscarguindzberg/bitcoinj.git","ssh_url":"git@github.com:oscarguindzberg/bitcoinj.git","clone_url":"https://github.com/oscarguindzberg/bitcoinj.git","svn_url":"https://github.com/oscarguindzberg/bitcoinj","homepage":"http://www.bitcoinj.org","size":16382,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"bitcoinj:master","ref":"master","sha":"c4a49eeb85ab4df9967b13b96b0b891efd261778","user":{"login":"bitcoinj","id":5951625,"avatar_url":"https://avatars.githubusercontent.com/u/5951625?v=3","gravatar_id":"","url":"https://api.github.com/users/bitcoinj","html_url":"https://github.com/bitcoinj","followers_url":"https://api.github.com/users/bitcoinj/followers","following_url":"https://api.github.com/users/bitcoinj/following{/other_user}","gists_url":"https://api.github.com/users/bitcoinj/gists{/gist_id}","starred_url":"https://api.github.com/users/bitcoinj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitcoinj/subscriptions","organizations_url":"https://api.github.com/users/bitcoinj/orgs","repos_url":"https://api.github.com/users/bitcoinj/repos","events_url":"https://api.github.com/users/bitcoinj/events{/privacy}","received_events_url":"https://api.github.com/users/bitcoinj/received_events","type":"Organization","site_admin":false},"repo":{"id":14514251,"name":"bitcoinj","full_name":"bitcoinj/bitcoinj","owner":{"login":"bitcoinj","id":5951625,"avatar_url":"https://avatars.githubusercontent.com/u/5951625?v=3","gravatar_id":"","url":"https://api.github.com/users/bitcoinj","html_url":"https://github.com/bitcoinj","followers_url":"https://api.github.com/users/bitcoinj/followers","following_url":"https://api.github.com/users/bitcoinj/following{/other_user}","gists_url":"https://api.github.com/users/bitcoinj/gists{/gist_id}","starred_url":"https://api.github.com/users/bitcoinj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitcoinj/subscriptions","organizations_url":"https://api.github.com/users/bitcoinj/orgs","repos_url":"https://api.github.com/users/bitcoinj/repos","events_url":"https://api.github.com/users/bitcoinj/events{/privacy}","received_events_url":"https://api.github.com/users/bitcoinj/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bitcoinj/bitcoinj","description":"A library for working with Bitcoin","fork":false,"url":"https://api.github.com/repos/bitcoinj/bitcoinj","forks_url":"https://api.github.com/repos/bitcoinj/bitcoinj/forks","keys_url":"https://api.github.com/repos/bitcoinj/bitcoinj/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bitcoinj/bitcoinj/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bitcoinj/bitcoinj/teams","hooks_url":"https://api.github.com/repos/bitcoinj/bitcoinj/hooks","issue_events_url":"https://api.github.com/repos/bitcoinj/bitcoinj/issues/events{/number}","events_url":"https://api.github.com/repos/bitcoinj/bitcoinj/events","assignees_url":"https://api.github.com/repos/bitcoinj/bitcoinj/assignees{/user}","branches_url":"https://api.github.com/repos/bitcoinj/bitcoinj/branches{/branch}","tags_url":"https://api.github.com/repos/bitcoinj/bitcoinj/tags","blobs_url":"https://api.github.com/repos/bitcoinj/bitcoinj/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bitcoinj/bitcoinj/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bitcoinj/bitcoinj/git/refs{/sha}","trees_url":"https://api.github.com/repos/bitcoinj/bitcoinj/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bitcoinj/bitcoinj/statuses/{sha}","languages_url":"https://api.github.com/repos/bitcoinj/bitcoinj/languages","stargazers_url":"https://api.github.com/repos/bitcoinj/bitcoinj/stargazers","contributors_url":"https://api.github.com/repos/bitcoinj/bitcoinj/contributors","subscribers_url":"https://api.github.com/repos/bitcoinj/bitcoinj/subscribers","subscription_url":"https://api.github.com/repos/bitcoinj/bitcoinj/subscription","commits_url":"https://api.github.com/repos/bitcoinj/bitcoinj/commits{/sha}","git_commits_url":"https://api.github.com/repos/bitcoinj/bitcoinj/git/commits{/sha}","comments_url":"https://api.github.com/repos/bitcoinj/bitcoinj/comments{/number}","issue_comment_url":"https://api.github.com/repos/bitcoinj/bitcoinj/issues/comments{/number}","contents_url":"https://api.github.com/repos/bitcoinj/bitcoinj/contents/{+path}","compare_url":"https://api.github.com/repos/bitcoinj/bitcoinj/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bitcoinj/bitcoinj/merges","archive_url":"https://api.github.com/repos/bitcoinj/bitcoinj/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bitcoinj/bitcoinj/downloads","issues_url":"https://api.github.com/repos/bitcoinj/bitcoinj/issues{/number}","pulls_url":"https://api.github.com/repos/bitcoinj/bitcoinj/pulls{/number}","milestones_url":"https://api.github.com/repos/bitcoinj/bitcoinj/milestones{/number}","notifications_url":"https://api.github.com/repos/bitcoinj/bitcoinj/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bitcoinj/bitcoinj/labels{/name}","releases_url":"https://api.github.com/repos/bitcoinj/bitcoinj/releases{/id}","created_at":"2013-11-19T04:33:23Z","updated_at":"2015-03-14T10:31:15Z","pushed_at":"2015-03-14T01:00:17Z","git_url":"git://github.com/bitcoinj/bitcoinj.git","ssh_url":"git@github.com:bitcoinj/bitcoinj.git","clone_url":"https://github.com/bitcoinj/bitcoinj.git","svn_url":"https://github.com/bitcoinj/bitcoinj","homepage":"http://www.bitcoinj.org","size":28019,"stargazers_count":349,"watchers_count":349,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":365,"mirror_url":null,"open_issues_count":13,"forks":365,"open_issues":13,"watchers":349,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bitcoinj/bitcoinj/pulls/331"},"html":{"href":"https://github.com/bitcoinj/bitcoinj/pull/331"},"issue":{"href":"https://api.github.com/repos/bitcoinj/bitcoinj/issues/331"},"comments":{"href":"https://api.github.com/repos/bitcoinj/bitcoinj/issues/331/comments"},"review_comments":{"href":"https://api.github.com/repos/bitcoinj/bitcoinj/pulls/331/comments"},"review_comment":{"href":"https://api.github.com/repos/bitcoinj/bitcoinj/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bitcoinj/bitcoinj/pulls/331/commits"},"statuses":{"href":"https://api.github.com/repos/bitcoinj/bitcoinj/statuses/a9d0813bbaefb5a745a472ac3cdbd0ba14b51ec8"}}}}