{"action":"opened","number":5864,"pull_request":{"url":"https://api.github.com/repos/bitcoin/bitcoin/pulls/5864","id":30694614,"html_url":"https://github.com/bitcoin/bitcoin/pull/5864","diff_url":"https://github.com/bitcoin/bitcoin/pull/5864.diff","patch_url":"https://github.com/bitcoin/bitcoin/pull/5864.patch","issue_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/5864","number":5864,"state":"open","locked":false,"title":"fix possible block db breakage during re-index","user":{"login":"theuni","id":417043,"avatar_url":"https://avatars.githubusercontent.com/u/417043?v=3","gravatar_id":"","url":"https://api.github.com/users/theuni","html_url":"https://github.com/theuni","followers_url":"https://api.github.com/users/theuni/followers","following_url":"https://api.github.com/users/theuni/following{/other_user}","gists_url":"https://api.github.com/users/theuni/gists{/gist_id}","starred_url":"https://api.github.com/users/theuni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theuni/subscriptions","organizations_url":"https://api.github.com/users/theuni/orgs","repos_url":"https://api.github.com/users/theuni/repos","events_url":"https://api.github.com/users/theuni/events{/privacy}","received_events_url":"https://api.github.com/users/theuni/received_events","type":"User","site_admin":false},"body":"I could really use some more eyes on this. I discussed it briefly with @sipa on IRC a few days ago.\r\n\r\nI noticed this while looking into https://github.com/bitcoin/bitcoin/issues/5668 . This is one possible explanation I can come up with for overlapping block data. Whether it has anything to do with that issue or not, I think this still needs to be addressed.\r\n\r\nWhen re-indexing, there are a few cases where garbage data may be skipped in the block files. In these cases, the indices are correctly written to the index db, however the pointer to the next position for writing in the current block file is calculated by adding the sizes of the valid blocks found.\r\n\r\nAs a result, when the re-index is finished, the index db is correct for all existing blocks, but the next block will be written to an incorrect offset, likely overwriting existing blocks.\r\n\r\nRather than using the sum of all valid blocks to determine the next write position, use the end of the last block written to the file. Don't assume that the current block is the last one in the file, since they may be read out-of-order.\r\n\r\nI was able to trigger this problem by inserting some garbage data between two valid blocks on disk in the last .dat file, then reindexing. After that, run normally for a few min in order to write a few new blocks to disk, then run with -checkblocks=0.\r\n\r\nBefore this change, I would get different errors (de-serialization, eof, etc) depending on what garbage i add and where. After the change, it appears to survive the re-index without issue regardless of the garbage.","created_at":"2015-03-07T01:48:08Z","updated_at":"2015-03-07T01:48:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bitcoin/bitcoin/pulls/5864/commits","review_comments_url":"https://api.github.com/repos/bitcoin/bitcoin/pulls/5864/comments","review_comment_url":"https://api.github.com/repos/bitcoin/bitcoin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/5864/comments","statuses_url":"https://api.github.com/repos/bitcoin/bitcoin/statuses/9add379b92f961d372803522239574cf3481b5e5","head":{"label":"theuni:fix-reindex-corruption","ref":"fix-reindex-corruption","sha":"9add379b92f961d372803522239574cf3481b5e5","user":{"login":"theuni","id":417043,"avatar_url":"https://avatars.githubusercontent.com/u/417043?v=3","gravatar_id":"","url":"https://api.github.com/users/theuni","html_url":"https://github.com/theuni","followers_url":"https://api.github.com/users/theuni/followers","following_url":"https://api.github.com/users/theuni/following{/other_user}","gists_url":"https://api.github.com/users/theuni/gists{/gist_id}","starred_url":"https://api.github.com/users/theuni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theuni/subscriptions","organizations_url":"https://api.github.com/users/theuni/orgs","repos_url":"https://api.github.com/users/theuni/repos","events_url":"https://api.github.com/users/theuni/events{/privacy}","received_events_url":"https://api.github.com/users/theuni/received_events","type":"User","site_admin":false},"repo":{"id":10302141,"name":"bitcoin","full_name":"theuni/bitcoin","owner":{"login":"theuni","id":417043,"avatar_url":"https://avatars.githubusercontent.com/u/417043?v=3","gravatar_id":"","url":"https://api.github.com/users/theuni","html_url":"https://github.com/theuni","followers_url":"https://api.github.com/users/theuni/followers","following_url":"https://api.github.com/users/theuni/following{/other_user}","gists_url":"https://api.github.com/users/theuni/gists{/gist_id}","starred_url":"https://api.github.com/users/theuni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theuni/subscriptions","organizations_url":"https://api.github.com/users/theuni/orgs","repos_url":"https://api.github.com/users/theuni/repos","events_url":"https://api.github.com/users/theuni/events{/privacy}","received_events_url":"https://api.github.com/users/theuni/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/theuni/bitcoin","description":"Bitcoin integration/staging tree","fork":true,"url":"https://api.github.com/repos/theuni/bitcoin","forks_url":"https://api.github.com/repos/theuni/bitcoin/forks","keys_url":"https://api.github.com/repos/theuni/bitcoin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/theuni/bitcoin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/theuni/bitcoin/teams","hooks_url":"https://api.github.com/repos/theuni/bitcoin/hooks","issue_events_url":"https://api.github.com/repos/theuni/bitcoin/issues/events{/number}","events_url":"https://api.github.com/repos/theuni/bitcoin/events","assignees_url":"https://api.github.com/repos/theuni/bitcoin/assignees{/user}","branches_url":"https://api.github.com/repos/theuni/bitcoin/branches{/branch}","tags_url":"https://api.github.com/repos/theuni/bitcoin/tags","blobs_url":"https://api.github.com/repos/theuni/bitcoin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/theuni/bitcoin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/theuni/bitcoin/git/refs{/sha}","trees_url":"https://api.github.com/repos/theuni/bitcoin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/theuni/bitcoin/statuses/{sha}","languages_url":"https://api.github.com/repos/theuni/bitcoin/languages","stargazers_url":"https://api.github.com/repos/theuni/bitcoin/stargazers","contributors_url":"https://api.github.com/repos/theuni/bitcoin/contributors","subscribers_url":"https://api.github.com/repos/theuni/bitcoin/subscribers","subscription_url":"https://api.github.com/repos/theuni/bitcoin/subscription","commits_url":"https://api.github.com/repos/theuni/bitcoin/commits{/sha}","git_commits_url":"https://api.github.com/repos/theuni/bitcoin/git/commits{/sha}","comments_url":"https://api.github.com/repos/theuni/bitcoin/comments{/number}","issue_comment_url":"https://api.github.com/repos/theuni/bitcoin/issues/comments{/number}","contents_url":"https://api.github.com/repos/theuni/bitcoin/contents/{+path}","compare_url":"https://api.github.com/repos/theuni/bitcoin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/theuni/bitcoin/merges","archive_url":"https://api.github.com/repos/theuni/bitcoin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/theuni/bitcoin/downloads","issues_url":"https://api.github.com/repos/theuni/bitcoin/issues{/number}","pulls_url":"https://api.github.com/repos/theuni/bitcoin/pulls{/number}","milestones_url":"https://api.github.com/repos/theuni/bitcoin/milestones{/number}","notifications_url":"https://api.github.com/repos/theuni/bitcoin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/theuni/bitcoin/labels{/name}","releases_url":"https://api.github.com/repos/theuni/bitcoin/releases{/id}","created_at":"2013-05-26T18:55:06Z","updated_at":"2015-02-26T05:06:17Z","pushed_at":"2015-03-07T01:38:19Z","git_url":"git://github.com/theuni/bitcoin.git","ssh_url":"git@github.com:theuni/bitcoin.git","clone_url":"https://github.com/theuni/bitcoin.git","svn_url":"https://github.com/theuni/bitcoin","homepage":"http://www.bitcoin.org","size":54956,"stargazers_count":1,"watchers_count":1,"language":"C++","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"trivial-next"}},"base":{"label":"bitcoin:master","ref":"master","sha":"7c3fbc34aed578398b3f180a621c671ff3837cec","user":{"login":"bitcoin","id":528860,"avatar_url":"https://avatars.githubusercontent.com/u/528860?v=3","gravatar_id":"","url":"https://api.github.com/users/bitcoin","html_url":"https://github.com/bitcoin","followers_url":"https://api.github.com/users/bitcoin/followers","following_url":"https://api.github.com/users/bitcoin/following{/other_user}","gists_url":"https://api.github.com/users/bitcoin/gists{/gist_id}","starred_url":"https://api.github.com/users/bitcoin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitcoin/subscriptions","organizations_url":"https://api.github.com/users/bitcoin/orgs","repos_url":"https://api.github.com/users/bitcoin/repos","events_url":"https://api.github.com/users/bitcoin/events{/privacy}","received_events_url":"https://api.github.com/users/bitcoin/received_events","type":"Organization","site_admin":false},"repo":{"id":1181927,"name":"bitcoin","full_name":"bitcoin/bitcoin","owner":{"login":"bitcoin","id":528860,"avatar_url":"https://avatars.githubusercontent.com/u/528860?v=3","gravatar_id":"","url":"https://api.github.com/users/bitcoin","html_url":"https://github.com/bitcoin","followers_url":"https://api.github.com/users/bitcoin/followers","following_url":"https://api.github.com/users/bitcoin/following{/other_user}","gists_url":"https://api.github.com/users/bitcoin/gists{/gist_id}","starred_url":"https://api.github.com/users/bitcoin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitcoin/subscriptions","organizations_url":"https://api.github.com/users/bitcoin/orgs","repos_url":"https://api.github.com/users/bitcoin/repos","events_url":"https://api.github.com/users/bitcoin/events{/privacy}","received_events_url":"https://api.github.com/users/bitcoin/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bitcoin/bitcoin","description":"Bitcoin Core integration/staging tree","fork":false,"url":"https://api.github.com/repos/bitcoin/bitcoin","forks_url":"https://api.github.com/repos/bitcoin/bitcoin/forks","keys_url":"https://api.github.com/repos/bitcoin/bitcoin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bitcoin/bitcoin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bitcoin/bitcoin/teams","hooks_url":"https://api.github.com/repos/bitcoin/bitcoin/hooks","issue_events_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/events{/number}","events_url":"https://api.github.com/repos/bitcoin/bitcoin/events","assignees_url":"https://api.github.com/repos/bitcoin/bitcoin/assignees{/user}","branches_url":"https://api.github.com/repos/bitcoin/bitcoin/branches{/branch}","tags_url":"https://api.github.com/repos/bitcoin/bitcoin/tags","blobs_url":"https://api.github.com/repos/bitcoin/bitcoin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bitcoin/bitcoin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bitcoin/bitcoin/git/refs{/sha}","trees_url":"https://api.github.com/repos/bitcoin/bitcoin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bitcoin/bitcoin/statuses/{sha}","languages_url":"https://api.github.com/repos/bitcoin/bitcoin/languages","stargazers_url":"https://api.github.com/repos/bitcoin/bitcoin/stargazers","contributors_url":"https://api.github.com/repos/bitcoin/bitcoin/contributors","subscribers_url":"https://api.github.com/repos/bitcoin/bitcoin/subscribers","subscription_url":"https://api.github.com/repos/bitcoin/bitcoin/subscription","commits_url":"https://api.github.com/repos/bitcoin/bitcoin/commits{/sha}","git_commits_url":"https://api.github.com/repos/bitcoin/bitcoin/git/commits{/sha}","comments_url":"https://api.github.com/repos/bitcoin/bitcoin/comments{/number}","issue_comment_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/comments{/number}","contents_url":"https://api.github.com/repos/bitcoin/bitcoin/contents/{+path}","compare_url":"https://api.github.com/repos/bitcoin/bitcoin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bitcoin/bitcoin/merges","archive_url":"https://api.github.com/repos/bitcoin/bitcoin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bitcoin/bitcoin/downloads","issues_url":"https://api.github.com/repos/bitcoin/bitcoin/issues{/number}","pulls_url":"https://api.github.com/repos/bitcoin/bitcoin/pulls{/number}","milestones_url":"https://api.github.com/repos/bitcoin/bitcoin/milestones{/number}","notifications_url":"https://api.github.com/repos/bitcoin/bitcoin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bitcoin/bitcoin/labels{/name}","releases_url":"https://api.github.com/repos/bitcoin/bitcoin/releases{/id}","created_at":"2010-12-19T15:16:43Z","updated_at":"2015-03-06T23:17:16Z","pushed_at":"2015-03-06T17:35:43Z","git_url":"git://github.com/bitcoin/bitcoin.git","ssh_url":"git@github.com:bitcoin/bitcoin.git","clone_url":"https://github.com/bitcoin/bitcoin.git","svn_url":"https://github.com/bitcoin/bitcoin","homepage":"https://bitcoin.org/en/download","size":110801,"stargazers_count":6570,"watchers_count":6570,"language":"C++","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":4605,"mirror_url":null,"open_issues_count":450,"forks":4605,"open_issues":450,"watchers":6570,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bitcoin/bitcoin/pulls/5864"},"html":{"href":"https://github.com/bitcoin/bitcoin/pull/5864"},"issue":{"href":"https://api.github.com/repos/bitcoin/bitcoin/issues/5864"},"comments":{"href":"https://api.github.com/repos/bitcoin/bitcoin/issues/5864/comments"},"review_comments":{"href":"https://api.github.com/repos/bitcoin/bitcoin/pulls/5864/comments"},"review_comment":{"href":"https://api.github.com/repos/bitcoin/bitcoin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bitcoin/bitcoin/pulls/5864/commits"},"statuses":{"href":"https://api.github.com/repos/bitcoin/bitcoin/statuses/9add379b92f961d372803522239574cf3481b5e5"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":4,"deletions":1,"changed_files":1}}