{"action":"created","issue":{"url":"https://api.github.com/repos/bitcoin/bitcoin/issues/7514","repository_url":"https://api.github.com/repos/bitcoin/bitcoin","labels_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/7514/labels{/name}","comments_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/7514/comments","events_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/7514/events","html_url":"https://github.com/bitcoin/bitcoin/pull/7514","id":132921890,"number":7514,"title":"Fix IsInitialBlockDownload for testnet","user":{"login":"jmacwhyte","id":5316685,"avatar_url":"https://avatars.githubusercontent.com/u/5316685?v=3","gravatar_id":"","url":"https://api.github.com/users/jmacwhyte","html_url":"https://github.com/jmacwhyte","followers_url":"https://api.github.com/users/jmacwhyte/followers","following_url":"https://api.github.com/users/jmacwhyte/following{/other_user}","gists_url":"https://api.github.com/users/jmacwhyte/gists{/gist_id}","starred_url":"https://api.github.com/users/jmacwhyte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmacwhyte/subscriptions","organizations_url":"https://api.github.com/users/jmacwhyte/orgs","repos_url":"https://api.github.com/users/jmacwhyte/repos","events_url":"https://api.github.com/users/jmacwhyte/events{/privacy}","received_events_url":"https://api.github.com/users/jmacwhyte/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/bitcoin/bitcoin/labels/P2P","name":"P2P","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2016-02-11T09:07:23Z","updated_at":"2016-02-13T07:07:08Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/bitcoin/bitcoin/pulls/7514","html_url":"https://github.com/bitcoin/bitcoin/pull/7514","diff_url":"https://github.com/bitcoin/bitcoin/pull/7514.diff","patch_url":"https://github.com/bitcoin/bitcoin/pull/7514.patch"},"body":"**Problem:** When running in testnet, a node can get stuck in IsInitialBlockDownload mode which will prevent it from responding to any GETHEADERS requests. This can make testing difficult! This problem does not happen on mainnet.\r\n\r\n**Theory:** Testnet is a little wonky with the 20-minute difficulty reset condition. The nChainWork calculation can cause pindexBestHeader to be set with an old block that has more work than chainActive.Tip(). If that block is more than nMaxTipAge old, IsInitialBlockDownload will always return true.\r\n\r\n**Suggested solution:** The current code works fine for mainnet, so I added a check to see if we are using testnet, and if so use chainActive.Tip() instead of pindexBestHeader when checking to see how far along we are with the block download. It's my thought that if the current tip is less than one day old (the nMaxTipAge default), it's probably safe to release IsInitialBlockDownload regardless of the age of pindexBestHeader.\r\n\r\n_[Edit: As per the comments below, I removed the check for testnet and instead used the greater of chainActive or BestHeader.]_"},"comment":{"url":"https://api.github.com/repos/bitcoin/bitcoin/issues/comments/183613664","html_url":"https://github.com/bitcoin/bitcoin/pull/7514#issuecomment-183613664","issue_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/7514","id":183613664,"user":{"login":"jmacwhyte","id":5316685,"avatar_url":"https://avatars.githubusercontent.com/u/5316685?v=3","gravatar_id":"","url":"https://api.github.com/users/jmacwhyte","html_url":"https://github.com/jmacwhyte","followers_url":"https://api.github.com/users/jmacwhyte/followers","following_url":"https://api.github.com/users/jmacwhyte/following{/other_user}","gists_url":"https://api.github.com/users/jmacwhyte/gists{/gist_id}","starred_url":"https://api.github.com/users/jmacwhyte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmacwhyte/subscriptions","organizations_url":"https://api.github.com/users/jmacwhyte/orgs","repos_url":"https://api.github.com/users/jmacwhyte/repos","events_url":"https://api.github.com/users/jmacwhyte/events{/privacy}","received_events_url":"https://api.github.com/users/jmacwhyte/received_events","type":"User","site_admin":false},"created_at":"2016-02-13T07:07:08Z","updated_at":"2016-02-13T07:07:08Z","body":"It should be, but for some reason my node's BestHeader wasn't even in the\nactive chain. Where is the 20-minute difficulty reset rule defined? Is it\npossible something in there is facilitating high-POW orphans?\n\n\nOn Fri, Feb 12, 2016 at 6:49 PM Luke-Jr <notifications@github.com> wrote:\n\n> The nChainWork calculation can cause pindexBestHeader to be set with an\n> old block that has more work than chainActive.Tip().\n>\n> If it's an old block (ie, presumably one we have), shouldn't it be the\n> active tip???\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/bitcoin/bitcoin/pull/7514#issuecomment-183570013>.\n>\n"}}