{"action":"created","comment":{"url":"https://api.github.com/repos/bitpay/bitcoind.js/pulls/comments/35478781","id":35478781,"diff_hunk":"@@ -81,36 +75,181 @@ Node.prototype._loadBitcoind = function(config) {\n \n };\n \n+/**\n+ * This function will find the common ancestor between the current chain and a forked block,\n+ * by moving backwards from the forked block until it meets the current chain.\n+ * @param {Block} block - The new tip that forks the current chain.\n+ * @param {Function} done - A callback function that is called when complete.\n+ */\n+Node.prototype._syncBitcoindAncestor = function(block, done) {\n+\n+  var self = this;\n+\n+  // The current chain of hashes will likely already be available in a cache.\n+  self.chain.getHashes(self.chain.tip.hash, function(err, currentHashes) {\n+    if (err) {\n+      done(err);\n+    }\n+\n+    // Create a hash map for faster lookups\n+    var currentHashesMap = {};\n+    var length = currentHashes.length;\n+    for (var i = 0; i < length; i++) {\n+      currentHashesMap[currentHashes[i]] = true;\n+    }","path":"lib/node.js","position":88,"original_position":88,"commit_id":"9890a4f0daefd4dce7526893e351753b26413fb0","original_commit_id":"9890a4f0daefd4dce7526893e351753b26413fb0","user":{"login":"braydonf","id":544777,"avatar_url":"https://avatars.githubusercontent.com/u/544777?v=3","gravatar_id":"","url":"https://api.github.com/users/braydonf","html_url":"https://github.com/braydonf","followers_url":"https://api.github.com/users/braydonf/followers","following_url":"https://api.github.com/users/braydonf/following{/other_user}","gists_url":"https://api.github.com/users/braydonf/gists{/gist_id}","starred_url":"https://api.github.com/users/braydonf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/braydonf/subscriptions","organizations_url":"https://api.github.com/users/braydonf/orgs","repos_url":"https://api.github.com/users/braydonf/repos","events_url":"https://api.github.com/users/braydonf/events{/privacy}","received_events_url":"https://api.github.com/users/braydonf/received_events","type":"User","site_admin":false},"body":"`_syncBitcoindAncestor()` with 500,000 hashes finding a fork six deep into the chain takes less than ~230ms, and should increase linearly the deeper the fork.","created_at":"2015-07-25T02:43:46Z","updated_at":"2015-07-25T02:43:46Z","html_url":"https://github.com/bitpay/bitcoind.js/pull/51#discussion_r35478781","pull_request_url":"https://api.github.com/repos/bitpay/bitcoind.js/pulls/51","_links":{"self":{"href":"https://api.github.com/repos/bitpay/bitcoind.js/pulls/comments/35478781"},"html":{"href":"https://github.com/bitpay/bitcoind.js/pull/51#discussion_r35478781"},"pull_request":{"href":"https://api.github.com/repos/bitpay/bitcoind.js/pulls/51"}}},"pull_request":{"url":"https://api.github.com/repos/bitpay/bitcoind.js/pulls/51","id":40614482,"html_url":"https://github.com/bitpay/bitcoind.js/pull/51","diff_url":"https://github.com/bitpay/bitcoind.js/pull/51.diff","patch_url":"https://github.com/bitpay/bitcoind.js/pull/51.patch","issue_url":"https://api.github.com/repos/bitpay/bitcoind.js/issues/51","number":51,"state":"open","locked":false,"title":"Initial daemon sync and setup","user":{"login":"braydonf","id":544777,"avatar_url":"https://avatars.githubusercontent.com/u/544777?v=3","gravatar_id":"","url":"https://api.github.com/users/braydonf","html_url":"https://github.com/braydonf","followers_url":"https://api.github.com/users/braydonf/followers","following_url":"https://api.github.com/users/braydonf/following{/other_user}","gists_url":"https://api.github.com/users/braydonf/gists{/gist_id}","starred_url":"https://api.github.com/users/braydonf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/braydonf/subscriptions","organizations_url":"https://api.github.com/users/braydonf/orgs","repos_url":"https://api.github.com/users/braydonf/repos","events_url":"https://api.github.com/users/braydonf/events{/privacy}","received_events_url":"https://api.github.com/users/braydonf/received_events","type":"User","site_admin":false},"body":"- Creates directories on initial startup\r\n- Simultaneous syncing of bitcoind.js daemon and additional modules","created_at":"2015-07-22T21:35:01Z","updated_at":"2015-07-25T02:43:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b327bf329b1f4145922659a4b9243787d017186b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bitpay/bitcoind.js/pulls/51/commits","review_comments_url":"https://api.github.com/repos/bitpay/bitcoind.js/pulls/51/comments","review_comment_url":"https://api.github.com/repos/bitpay/bitcoind.js/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bitpay/bitcoind.js/issues/51/comments","statuses_url":"https://api.github.com/repos/bitpay/bitcoind.js/statuses/9890a4f0daefd4dce7526893e351753b26413fb0","head":{"label":"braydonf:freshstart","ref":"freshstart","sha":"9890a4f0daefd4dce7526893e351753b26413fb0","user":{"login":"braydonf","id":544777,"avatar_url":"https://avatars.githubusercontent.com/u/544777?v=3","gravatar_id":"","url":"https://api.github.com/users/braydonf","html_url":"https://github.com/braydonf","followers_url":"https://api.github.com/users/braydonf/followers","following_url":"https://api.github.com/users/braydonf/following{/other_user}","gists_url":"https://api.github.com/users/braydonf/gists{/gist_id}","starred_url":"https://api.github.com/users/braydonf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/braydonf/subscriptions","organizations_url":"https://api.github.com/users/braydonf/orgs","repos_url":"https://api.github.com/users/braydonf/repos","events_url":"https://api.github.com/users/braydonf/events{/privacy}","received_events_url":"https://api.github.com/users/braydonf/received_events","type":"User","site_admin":false},"repo":{"id":38714741,"name":"bitcoind.js","full_name":"braydonf/bitcoind.js","owner":{"login":"braydonf","id":544777,"avatar_url":"https://avatars.githubusercontent.com/u/544777?v=3","gravatar_id":"","url":"https://api.github.com/users/braydonf","html_url":"https://github.com/braydonf","followers_url":"https://api.github.com/users/braydonf/followers","following_url":"https://api.github.com/users/braydonf/following{/other_user}","gists_url":"https://api.github.com/users/braydonf/gists{/gist_id}","starred_url":"https://api.github.com/users/braydonf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/braydonf/subscriptions","organizations_url":"https://api.github.com/users/braydonf/orgs","repos_url":"https://api.github.com/users/braydonf/repos","events_url":"https://api.github.com/users/braydonf/events{/privacy}","received_events_url":"https://api.github.com/users/braydonf/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/braydonf/bitcoind.js","description":"bitcoind linked to node.js","fork":true,"url":"https://api.github.com/repos/braydonf/bitcoind.js","forks_url":"https://api.github.com/repos/braydonf/bitcoind.js/forks","keys_url":"https://api.github.com/repos/braydonf/bitcoind.js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/braydonf/bitcoind.js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/braydonf/bitcoind.js/teams","hooks_url":"https://api.github.com/repos/braydonf/bitcoind.js/hooks","issue_events_url":"https://api.github.com/repos/braydonf/bitcoind.js/issues/events{/number}","events_url":"https://api.github.com/repos/braydonf/bitcoind.js/events","assignees_url":"https://api.github.com/repos/braydonf/bitcoind.js/assignees{/user}","branches_url":"https://api.github.com/repos/braydonf/bitcoind.js/branches{/branch}","tags_url":"https://api.github.com/repos/braydonf/bitcoind.js/tags","blobs_url":"https://api.github.com/repos/braydonf/bitcoind.js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/braydonf/bitcoind.js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/braydonf/bitcoind.js/git/refs{/sha}","trees_url":"https://api.github.com/repos/braydonf/bitcoind.js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/braydonf/bitcoind.js/statuses/{sha}","languages_url":"https://api.github.com/repos/braydonf/bitcoind.js/languages","stargazers_url":"https://api.github.com/repos/braydonf/bitcoind.js/stargazers","contributors_url":"https://api.github.com/repos/braydonf/bitcoind.js/contributors","subscribers_url":"https://api.github.com/repos/braydonf/bitcoind.js/subscribers","subscription_url":"https://api.github.com/repos/braydonf/bitcoind.js/subscription","commits_url":"https://api.github.com/repos/braydonf/bitcoind.js/commits{/sha}","git_commits_url":"https://api.github.com/repos/braydonf/bitcoind.js/git/commits{/sha}","comments_url":"https://api.github.com/repos/braydonf/bitcoind.js/comments{/number}","issue_comment_url":"https://api.github.com/repos/braydonf/bitcoind.js/issues/comments{/number}","contents_url":"https://api.github.com/repos/braydonf/bitcoind.js/contents/{+path}","compare_url":"https://api.github.com/repos/braydonf/bitcoind.js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/braydonf/bitcoind.js/merges","archive_url":"https://api.github.com/repos/braydonf/bitcoind.js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/braydonf/bitcoind.js/downloads","issues_url":"https://api.github.com/repos/braydonf/bitcoind.js/issues{/number}","pulls_url":"https://api.github.com/repos/braydonf/bitcoind.js/pulls{/number}","milestones_url":"https://api.github.com/repos/braydonf/bitcoind.js/milestones{/number}","notifications_url":"https://api.github.com/repos/braydonf/bitcoind.js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/braydonf/bitcoind.js/labels{/name}","releases_url":"https://api.github.com/repos/braydonf/bitcoind.js/releases{/id}","created_at":"2015-07-07T21:04:07Z","updated_at":"2015-07-23T19:15:56Z","pushed_at":"2015-07-24T17:45:43Z","git_url":"git://github.com/braydonf/bitcoind.js.git","ssh_url":"git@github.com:braydonf/bitcoind.js.git","clone_url":"https://github.com/braydonf/bitcoind.js.git","svn_url":"https://github.com/braydonf/bitcoind.js","homepage":"","size":17240,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"bitpay:master","ref":"master","sha":"ac09e767fb2dda527ae04a7fd4097158c2637de9","user":{"login":"bitpay","id":2554930,"avatar_url":"https://avatars.githubusercontent.com/u/2554930?v=3","gravatar_id":"","url":"https://api.github.com/users/bitpay","html_url":"https://github.com/bitpay","followers_url":"https://api.github.com/users/bitpay/followers","following_url":"https://api.github.com/users/bitpay/following{/other_user}","gists_url":"https://api.github.com/users/bitpay/gists{/gist_id}","starred_url":"https://api.github.com/users/bitpay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitpay/subscriptions","organizations_url":"https://api.github.com/users/bitpay/orgs","repos_url":"https://api.github.com/users/bitpay/repos","events_url":"https://api.github.com/users/bitpay/events{/privacy}","received_events_url":"https://api.github.com/users/bitpay/received_events","type":"Organization","site_admin":false},"repo":{"id":22961238,"name":"bitcoind.js","full_name":"bitpay/bitcoind.js","owner":{"login":"bitpay","id":2554930,"avatar_url":"https://avatars.githubusercontent.com/u/2554930?v=3","gravatar_id":"","url":"https://api.github.com/users/bitpay","html_url":"https://github.com/bitpay","followers_url":"https://api.github.com/users/bitpay/followers","following_url":"https://api.github.com/users/bitpay/following{/other_user}","gists_url":"https://api.github.com/users/bitpay/gists{/gist_id}","starred_url":"https://api.github.com/users/bitpay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitpay/subscriptions","organizations_url":"https://api.github.com/users/bitpay/orgs","repos_url":"https://api.github.com/users/bitpay/repos","events_url":"https://api.github.com/users/bitpay/events{/privacy}","received_events_url":"https://api.github.com/users/bitpay/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bitpay/bitcoind.js","description":"bitcoind linked to node.js","fork":false,"url":"https://api.github.com/repos/bitpay/bitcoind.js","forks_url":"https://api.github.com/repos/bitpay/bitcoind.js/forks","keys_url":"https://api.github.com/repos/bitpay/bitcoind.js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bitpay/bitcoind.js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bitpay/bitcoind.js/teams","hooks_url":"https://api.github.com/repos/bitpay/bitcoind.js/hooks","issue_events_url":"https://api.github.com/repos/bitpay/bitcoind.js/issues/events{/number}","events_url":"https://api.github.com/repos/bitpay/bitcoind.js/events","assignees_url":"https://api.github.com/repos/bitpay/bitcoind.js/assignees{/user}","branches_url":"https://api.github.com/repos/bitpay/bitcoind.js/branches{/branch}","tags_url":"https://api.github.com/repos/bitpay/bitcoind.js/tags","blobs_url":"https://api.github.com/repos/bitpay/bitcoind.js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bitpay/bitcoind.js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bitpay/bitcoind.js/git/refs{/sha}","trees_url":"https://api.github.com/repos/bitpay/bitcoind.js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bitpay/bitcoind.js/statuses/{sha}","languages_url":"https://api.github.com/repos/bitpay/bitcoind.js/languages","stargazers_url":"https://api.github.com/repos/bitpay/bitcoind.js/stargazers","contributors_url":"https://api.github.com/repos/bitpay/bitcoind.js/contributors","subscribers_url":"https://api.github.com/repos/bitpay/bitcoind.js/subscribers","subscription_url":"https://api.github.com/repos/bitpay/bitcoind.js/subscription","commits_url":"https://api.github.com/repos/bitpay/bitcoind.js/commits{/sha}","git_commits_url":"https://api.github.com/repos/bitpay/bitcoind.js/git/commits{/sha}","comments_url":"https://api.github.com/repos/bitpay/bitcoind.js/comments{/number}","issue_comment_url":"https://api.github.com/repos/bitpay/bitcoind.js/issues/comments{/number}","contents_url":"https://api.github.com/repos/bitpay/bitcoind.js/contents/{+path}","compare_url":"https://api.github.com/repos/bitpay/bitcoind.js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bitpay/bitcoind.js/merges","archive_url":"https://api.github.com/repos/bitpay/bitcoind.js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bitpay/bitcoind.js/downloads","issues_url":"https://api.github.com/repos/bitpay/bitcoind.js/issues{/number}","pulls_url":"https://api.github.com/repos/bitpay/bitcoind.js/pulls{/number}","milestones_url":"https://api.github.com/repos/bitpay/bitcoind.js/milestones{/number}","notifications_url":"https://api.github.com/repos/bitpay/bitcoind.js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bitpay/bitcoind.js/labels{/name}","releases_url":"https://api.github.com/repos/bitpay/bitcoind.js/releases{/id}","created_at":"2014-08-14T16:45:31Z","updated_at":"2015-07-14T21:07:04Z","pushed_at":"2015-07-24T20:20:37Z","git_url":"git://github.com/bitpay/bitcoind.js.git","ssh_url":"git@github.com:bitpay/bitcoind.js.git","clone_url":"https://github.com/bitpay/bitcoind.js.git","svn_url":"https://github.com/bitpay/bitcoind.js","homepage":"","size":17996,"stargazers_count":35,"watchers_count":35,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":17,"mirror_url":null,"open_issues_count":11,"forks":17,"open_issues":11,"watchers":35,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bitpay/bitcoind.js/pulls/51"},"html":{"href":"https://github.com/bitpay/bitcoind.js/pull/51"},"issue":{"href":"https://api.github.com/repos/bitpay/bitcoind.js/issues/51"},"comments":{"href":"https://api.github.com/repos/bitpay/bitcoind.js/issues/51/comments"},"review_comments":{"href":"https://api.github.com/repos/bitpay/bitcoind.js/pulls/51/comments"},"review_comment":{"href":"https://api.github.com/repos/bitpay/bitcoind.js/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bitpay/bitcoind.js/pulls/51/commits"},"statuses":{"href":"https://api.github.com/repos/bitpay/bitcoind.js/statuses/9890a4f0daefd4dce7526893e351753b26413fb0"}}}}