Go to file
Dave Collins fc91d2ccbf
blockchain: Convert to full block index in mem.
This reworks the block index code such that it loads all of the headers
in the main chain at startup and constructs the full block index
accordingly.

Since the full index from the current best tip all the way back to the
genesis block is now guaranteed to be in memory, this also removes all
code related to dynamically loading the nodes and updates some of the
logic to take advantage of the fact traversing the block index can no
longer potentially fail.  There are also many more optimizations and
simplifications that can be made in the future as a result of this.

Due to removing all of the extra overhead of tracking the dynamic state,
and ensuring the block node structs are aligned to eliminate extra
padding, the end result of a fully populated block index now takes quite
a bit less memory than the previous dynamically loaded version.

It also speeds up the initial startup process by roughly 2x since it is
faster to bulk load the nodes in order as opposed to dynamically loading
only the nodes near the tip in backwards order.

For example, here is some startup timing information before and after
this commit on a node that contains roughly 238,000 blocks:

7200 RPM HDD:
-------------
Startup time before this commit: ~7.71s
Startup time after this commit: ~3.47s

SSD:
----
Startup time before this commit: ~6.34s
Startup time after this commit: ~3.51s

Some additional benefits are:

- Since every block node is in memory, the code which reconstructs
  headers from block nodes means that all headers can always be served
  from memory which will be important since the network will be moving
  to header-based semantics
- Several of the error paths can be removed since they are no longer
  necessary
- It is no longer expensive to calculate CSV sequence locks or median
  times of blocks way in the past
- It is much less expensive to calculate the initial states for the
  various intervals such as the stake and voter version
- It will be possible to create much more efficient iteration and
  simplified views of the overall index

An overview of the logic changes are as follows:

- Move AncestorNode from blockIndex to blockNode and greatly simplify
  since it no longer has to deal with the possibility of dynamically
  loading nodes and related failures
- Replace nodeAtHeightFromTopNode from BlockChain with RelativeAncestor
  on blockNode and define it in terms of AncestorNode
- Move CalcPastMedianTime from blockIndex to blockNode and remove no
  longer necessary test for nil
- Remove findNode and replace all of its uses with direct queries of the
  block index
- Remove blockExists and replace all of its uses with direct queries of
  the block index
- Remove all functions and fields related to dynamically loading nodes
  - children and parentHash fields from blockNode
  - depNodes from blockIndex
  - loadBlockNode from blockIndex
  - PrevNodeFromBlock from blockIndex
  - {p,P}revNodeFromNode from blockIndex
  - RemoveNode
- Replace all instances of iterating backwards through nodes to directly
  access the parent now that nodes don't potentially need to be
  dynamically loaded
- Introduce a lookupNode function on blockIndex which allows the
  initialization code to locklessly query the index
- No longer take the chain lock when only access to the block index,
  which has its own lock, is needed
- Removed the error paths from several functions that can no longer fail
  - getReorganizeNodes
  - findPrevTestNetDifficulty
  - sumPurchasedTickets
  - findStakeVersionPriorNode
- Removed all error paths related to node iteration that can no longer
  fail
- Modify FetchUtxoView to return an empty view for the genesis block
2018-06-01 11:54:03 -05:00
addrmgr addrmrg: Refine vgo deps. 2018-05-25 17:34:07 -05:00
blockchain blockchain: Convert to full block index in mem. 2018-06-01 11:54:03 -05:00
certgen multi: Define vgo modules. 2018-05-25 15:38:16 -05:00
chaincfg chaincfg: Refine vgo deps. 2018-05-25 18:00:05 -05:00
cmd multi: Return fork len from ProcessBlock. 2018-05-27 20:20:43 -05:00
connmgr multi: Define vgo modules. 2018-05-25 15:38:16 -05:00
database multi: Define vgo modules. 2018-05-25 15:38:16 -05:00
dcrec dcrec: add Pubkey func to secp256k1 and edwards elliptic curves. 2018-05-18 13:45:02 +00:00
dcrjson multi: modify PurchaseTicketCmd. 2018-05-31 11:10:59 -05:00
dcrutil multi: Define vgo modules. 2018-05-25 15:38:16 -05:00
docs docs: Update txaccepted method in json_rpc_api.md. 2018-05-31 11:09:23 -05:00
gcs multi: Define vgo modules. 2018-05-25 15:38:16 -05:00
hdkeychain multi: Define vgo modules. 2018-05-25 15:38:16 -05:00
limits docs: document packages and fix typo 2018-01-08 16:04:45 -06:00
mempool policy: Lower default relay fee to 0.0001/kB. 2018-05-26 09:45:38 -05:00
mining multi: Define vgo modules. 2018-05-25 15:38:16 -05:00
peer multi: Define vgo modules. 2018-05-25 15:38:16 -05:00
release Add example service files. 2017-03-23 02:07:08 -05:00
rpcclient multi: modify PurchaseTicketCmd. 2018-05-31 11:10:59 -05:00
rpctest multi: use secp256k1 types and fields directly. 2018-05-17 00:46:57 +00:00
sampleconfig policy: Lower default relay fee to 0.0001/kB. 2018-05-26 09:45:38 -05:00
txscript txscript: Cleanup code for the substr opcode. 2018-05-25 20:28:57 -05:00
wire wire: Refine vgo deps. 2018-05-25 17:06:49 -05:00
.dockerignore Run testing and linting in a Dockerfile. 2017-05-30 11:39:19 -04:00
.gitignore Improve gitignore. 2017-10-11 14:52:00 -05:00
.travis.yml travis: test in docker container 2018-02-18 10:27:18 -06:00
blocklogger.go multi: Replace btclog with slog. 2018-05-23 14:22:10 -05:00
blockmanager.go multi: No winning ticket ntfns for big reorg depth. 2018-05-29 11:16:09 -05:00
CHANGES multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
config.go multi: Replace btclog with slog. 2018-05-23 14:22:10 -05:00
cpuminer.go cpuminer: Use header for extra nonce. 2018-03-05 12:59:32 -06:00
dcrd.go main: Correct mem profile error message. 2018-05-03 08:17:12 +08:00
doc.go multi: Remove everything to do about bloom filters. 2018-05-01 11:43:32 -05:00
Dockerfile-1.9 travis: test in docker container 2018-02-18 10:27:18 -06:00
Dockerfile-1.10 travis: test in docker container 2018-02-18 10:27:18 -06:00
go.mod build: Update some vgo dependencies to use tags. 2018-05-24 11:18:33 -05:00
go.modverify build: Update some vgo dependencies to use tags. 2018-05-24 11:18:33 -05:00
Gopkg.lock build: Update some vgo dependencies to use tags. 2018-05-24 11:18:33 -05:00
Gopkg.toml build: Update some vgo dependencies to use tags. 2018-05-24 11:18:33 -05:00
ipc.go travis: add ineffassign linter 2017-12-01 09:14:04 -05:00
LICENSE multi: Add initial committed filter (CF) support 2018-03-30 13:52:12 -04:00
log.go multi: Replace btclog with slog. 2018-05-23 14:22:10 -05:00
mining_test.go mining_test: add edge conditions from btcd. 2017-08-31 00:28:36 -05:00
mining.go blockchain: CheckConnectBlockTemplate with tests. 2018-05-03 13:53:24 -05:00
miningerror.go blockchain: Rework to use new db interface. 2016-08-18 15:42:18 -04:00
params.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
README.md Adjust README.md for new Go version 2018-03-01 20:15:08 -06:00
rpcserver_test.go rpctest: Gate rpctest-based behind a build tag. 2017-07-26 12:43:26 -05:00
rpcserver.go rpcserver: Correct rebroadcastwinners handler. 2018-05-28 12:47:40 -05:00
rpcserverhelp_test.go blockchain: Rework to use new db interface. 2016-08-18 15:42:18 -04:00
rpcserverhelp.go dcrjson: Add Expiry field to CreateRawTransactionCmd 2018-05-02 20:49:03 -05:00
rpcwebsocket.go rpc: Use upstream gorilla/websocket. 2018-05-23 19:35:36 -05:00
run_tests.sh travis: test in docker container 2018-02-18 10:27:18 -06:00
server.go multi: Remove everything to do about bloom filters. 2018-05-01 11:43:32 -05:00
service_windows.go multi: Properly capitalize Decred. 2018-03-01 17:41:35 -06:00
signal.go dcrd: Simplify shutdown signal handling logic sync. 2016-11-18 12:06:55 -06:00
signalsigterm.go Add pipes for parent process IPC. (#311) 2016-08-31 10:45:16 -04:00
upnp.go multi: Error descriptions are in lower case. 2017-09-08 18:03:59 +02:00
version.go release: Bump for v1.2.0. 2018-03-07 13:19:37 -06:00

dcrd

Build Status ISC License GoDoc

dcrd is a Decred full node implementation written in Go (golang).

This acts as a chain daemon for the Decred cryptocurrency. dcrd maintains the entire past transactional ledger of Decred and allows relaying of transactions to other Decred nodes across the world. To read more about Decred please see the project documentation.

Note: To send or receive funds and join Proof-of-Stake mining, you will also need dcrwallet.

This project is currently under active development and is in a Beta state. It is extremely stable and has been in production use since February 2016.

It is forked from btcd which is a bitcoin full node implementation written in Go. btcd is a ongoing project under active development. Because dcrd is constantly synced with btcd codebase, it will get the benefit of btcd's ongoing upgrades to peer and connection handling, database optimization and other blockchain related technology improvements.

Requirements

Go 1.9 or newer.

Getting Started

  • dcrd (and utilities) will now be installed in either $GOROOT/bin or $GOPATH/bin depending on your configuration. If you did not already add the bin directory to your system path during Go installation, we recommend you do so now.

Updating

Windows

Install a newer MSI

Linux/BSD/MacOSX/POSIX - Build from Source

  • Dep

    Dep is used to manage project dependencies and provide reproducible builds. To install:

    go get -u github.com/golang/dep/cmd/dep

Unfortunately, the use of dep prevents a handy tool such as go get from automatically downloading, building, and installing the source in a single command. Instead, the latest project and dependency sources must be first obtained manually with git and dep, and then go is used to build and install the project.

Getting the source:

For a first time installation, the project and dependency sources can be obtained manually with git and dep (create directories as needed):

git clone https://github.com/decred/dcrd $GOPATH/src/github.com/decred/dcrd
cd $GOPATH/src/github.com/decred/dcrd
dep ensure
go install . ./cmd/...

To update an existing source tree, pull the latest changes and install the matching dependencies:

cd $GOPATH/src/github.com/decred/dcrd
git pull
dep ensure
go install . ./cmd/...

For more information about Decred and how to set up your software please go to our docs page at docs.decred.org.

Docker

All tests and linters may be run in a docker container using the script run_tests.sh. This script defaults to using the current supported version of go. You can run it with the major version of Go you would like to use as the only arguement to test a previous on a previous version of Go (generally Decred supports the current version of Go and the previous one).

./run_tests.sh 1.9

To run the tests locally without docker:

./run_tests.sh local

Contact

If you have any further questions you can find us at:

  • irc.freenode.net (channel #decred)
  • webchat
  • forum.decred.org
  • decred.slack.com

Issue Tracker

The integrated github issue tracker is used for this project.

Documentation

The documentation is a work-in-progress. It is located in the docs folder.

License

dcrd is licensed under the copyfree ISC License.