{"action":"created","issue":{"url":"https://api.github.com/repos/btcsuite/btcd/issues/491","labels_url":"https://api.github.com/repos/btcsuite/btcd/issues/491/labels{/name}","comments_url":"https://api.github.com/repos/btcsuite/btcd/issues/491/comments","events_url":"https://api.github.com/repos/btcsuite/btcd/issues/491/events","html_url":"https://github.com/btcsuite/btcd/pull/491","id":103175568,"number":491,"title":"WIP: blockchain: Rework to use new db interface.","user":{"login":"davecgh","id":2115102,"avatar_url":"https://avatars.githubusercontent.com/u/2115102?v=3","gravatar_id":"","url":"https://api.github.com/users/davecgh","html_url":"https://github.com/davecgh","followers_url":"https://api.github.com/users/davecgh/followers","following_url":"https://api.github.com/users/davecgh/following{/other_user}","gists_url":"https://api.github.com/users/davecgh/gists{/gist_id}","starred_url":"https://api.github.com/users/davecgh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davecgh/subscriptions","organizations_url":"https://api.github.com/users/davecgh/orgs","repos_url":"https://api.github.com/users/davecgh/repos","events_url":"https://api.github.com/users/davecgh/events{/privacy}","received_events_url":"https://api.github.com/users/davecgh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-08-26T05:09:23Z","updated_at":"2015-12-20T18:48:28Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/btcsuite/btcd/pulls/491","html_url":"https://github.com/btcsuite/btcd/pull/491","diff_url":"https://github.com/btcsuite/btcd/pull/491.diff","patch_url":"https://github.com/btcsuite/btcd/pull/491.patch"},"body":"**This pull request requires #380**\r\n\r\n<!-- Reviewable:start -->\r\n[<img src=\"https://reviewable.io/review_button.png\" height=40 alt=\"Review on Reviewable\"/>](https://reviewable.io/reviews/btcsuite/btcd/491)\r\n<!-- Reviewable:end -->\r\n\r\nThis pull request is the first stage of several that are planned to convert the `blockchain` package into a concurrent safe package that will ultimately allow support for multi-peer download and concurrent chain processing.  The goal is to update `btcd` proper after each step so it can take advantage of the enhancements as they are developed.\r\n\r\nIn addition to the aforementioned benefit, this staged approach has been chosen since it is absolutely critical to maintain consensus.  Separating the changes into several stages makes it easier for reviewers to logically follow what is happening and therefore helps prevent consensus bugs.  Naturally there are significant automated tests to help prevent consensus issues as well.\r\n\r\nThe main focus of this stage is to convert the `blockchain` package to use the new database interface and implement the chain-related functionality which it no longer handles while aiming to improve efficiency along the way in various areas by making use of the new database and chain capabilities.\r\n\r\nThe following is an overview of the chain changes:\r\n\r\n- Update to use the new database interface\r\n- Add chain-related functionality that the old database used to handle\r\n  - Main chain structure and state\r\n  - Transaction spend tracking\r\n  - Transaction indexing\r\n- Implement a new pruned unspent transaction output (utxo) set\r\n  - Provides efficient direct access to the unspent transaction outputs\r\n  - Uses a domain specific compression algorithm that understands the standard transaction scripts in order to significantly compress them\r\n  - Removes reliance on the transaction index and paves the way toward eventually enabling block pruning\r\n- Replace the old TxStore type with a new UtxoView type that makes use of the new pruned utxo set\r\n- Convert code to treat the new UtxoView as a rolling view that is used between connects and disconnects to improve efficiency\r\n- Make all exported functions concurrent safe\r\n  - Currently using a single chain state lock as it provides a straight forward and easy to review path forward however this can be improved with more fine grained locking\r\n- Optimize various cases where full blocks were being loaded when only\r\n  the header is needed to help reduce the I/O load\r\n- Add the ability for callers to get a snapshot of the current best chain stats in a concurrent safe fashion\r\n  - Does not block callers while new blocks are being processed\r\n- Make error messages that reference transaction outputs consistently use `<transaction hash>:<output index>`\r\n- Update tests and examples to reflect the changes\r\n\r\nThe following is an overview of the btcd changes:\r\n\r\n- Update to use the new database and chain interfaces\r\n- Temporarily remove all code related to the address index\r\n- Convert all code that uses transaction stores to use the new utxo store\r\n- Rework several calls that required the block manager for safe concurrency to use the chain package directly now that it is concurrent safe\r\n- Change all calls to obtain the best hash to use the new best state snapshot capability from the chain package\r\n- Remove workaround for limits on fetching height ranges since the new database interface no longer imposes them\r\n- Correct the `gettxout` RPC handler to return the best chain hash as opposed the hash the txout was found in\r\n- Optimize various RPC handlers:\r\n  - Change several of the RPC handlers to use the new chain snapshot capability to avoid needlessly loading data\r\n  - Update several handlers to use new functionality to avoid accessing the block manager so they are able to return the data without blocking when the server is busy processing blocks\r\n  - Update non-verbose `getblock` to avoid deserialization and serialization overhead\r\n  - Update `getblockheader` to request the block height directly from chain and only load the header\r\n  - Update `getdifficulty` to use the new cached data from chain\r\n  - Update `getmininginfo` to use the new cached data from chain\r\n  - Update non-verbose `getrawtransaction` to avoid deserialization and serialization overhead\r\n  - Update `gettxout` to use the new utxo view versus loading full transactions using the transaction index\r\n\r\nThe following is an overview of the utility changes:\r\n- Update `addblock` to use the new database and chain interfaces\r\n- Update `findcheckpoint` to use the new database and chain interfaces\r\n- Remove the `dropafter` utility which is no longer supported\r\n\r\n**NOTE:** In order to get testing started on this code this commit is being pushed via a pull request before everything in done although it should be stable.  Before it can be merged to master, the following additional\r\nthings are needed:\r\n\r\n- [x] Implement a proper pruned utxo set and reorg journal\r\n- [ ] Implement utxo cache for efficiency\r\n- [ ] Reimplement the address index using the new database interface including implementing the functionality that used to live in the old database, but will now be needed in btcd proper (#573)\r\n- [ ] Increase test coverage"},"comment":{"url":"https://api.github.com/repos/btcsuite/btcd/issues/comments/166146719","html_url":"https://github.com/btcsuite/btcd/pull/491#issuecomment-166146719","issue_url":"https://api.github.com/repos/btcsuite/btcd/issues/491","id":166146719,"user":{"login":"Dirbaio","id":1247578,"avatar_url":"https://avatars.githubusercontent.com/u/1247578?v=3","gravatar_id":"","url":"https://api.github.com/users/Dirbaio","html_url":"https://github.com/Dirbaio","followers_url":"https://api.github.com/users/Dirbaio/followers","following_url":"https://api.github.com/users/Dirbaio/following{/other_user}","gists_url":"https://api.github.com/users/Dirbaio/gists{/gist_id}","starred_url":"https://api.github.com/users/Dirbaio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Dirbaio/subscriptions","organizations_url":"https://api.github.com/users/Dirbaio/orgs","repos_url":"https://api.github.com/users/Dirbaio/repos","events_url":"https://api.github.com/users/Dirbaio/events{/privacy}","received_events_url":"https://api.github.com/users/Dirbaio/received_events","type":"User","site_admin":false},"created_at":"2015-12-20T18:48:28Z","updated_at":"2015-12-20T18:48:28Z","body":"\n\n\n\nReview status: 0 of 84 files reviewed at latest revision, 4 unresolved discussions.\n\n---\n\n*[blockchain/utxoviewpoint.go, line 237 \\[r7\\]](https://reviewable.io:443/reviews/btcsuite/btcd/491#-K6-gp-WJl7VjNb0tapV:-K6-gp-WJl7VjNb0tapW:941988020) ([raw file](https://github.com/btcsuite/btcd/blob/315459419ad86a5d3891d1ec6dfb981862027752/blockchain/utxoviewpoint.go#L237)):*\nShouldn't this set output.compressed = false?\n\n---\n\n*[blockchain/validate.go, line 873 \\[r7\\]](https://reviewable.io:443/reviews/btcsuite/btcd/491#-K6-hUzKI4pcJG1WpK0e:-K6-hUzKI4pcJG1WpK0f:2000373971) ([raw file](https://github.com/btcsuite/btcd/blob/315459419ad86a5d3891d1ec6dfb981862027752/blockchain/validate.go#L873)):*\nThis error message could be confusing if the cause is actually an out-of-bounds index. How about something like \"Transaction X tried to spend output Y, which is either already spent or out of bounds.\"\n\n---\n\n\n*Comments from the [review on Reviewable.io](https://reviewable.io:443/reviews/btcsuite/btcd/491)*\n<!-- Sent from Reviewable.io -->\n"}}