[BREAKGLASS] Append-only mirror of github.com/seedhammer/dcrd
Go to file
Dave Collins cfce89ffab
blockchain: Use short keys for block index.
This modifies the block index hash -> node mapping to use shortened keys
with fallback to the full 32-byte key in the event of a collision in the
shortened key.  This saves a significant amount of memory because there
are hundreds of thousands of nodes in the index and Go maps duplicate
keys.  As an added bonus, due to the implementation choices, it also
results in slightly faster overall lookups on average.  This is because
even though lookups of colliding keys are slightly slower, lookups of
non-colliding keys are slightly faster and non-colliding keys are by far
the most common case (typically > 99.5%).

It accomplishes this by taking advantage of the fact the full hash is
part of the node itself and therefore can be used to disambiguate any
collisions in the shortened key and splitting the non-colliding entries
from the colliding entries across two maps where one is keyed by the
shorter key and the other by the full key.

The shortened key is chosen to be the big-endian uint32 formed by the
first 4 bytes of the full hash.  The primary reasons for this choice
are:

- The hash function used to produce the block hashes is a
  uniformly-random distribution, so the number of collisions will
  coincide with the expected value of a uniform distribution
- The bits zeroed by the mining process start at the end of the array,
  so there would need to be effectively impossible to achieve hash rates
  exceeding ~2^215.77 hashes/sec (aka ~89.8 peta yotta yotta hashes/sec)
  in order to start zeroing out the chosen bits
- Using 4 bytes per node results in a savings of 28 bytes per node minus
  a small amount of amortized overhead for the collision handling
- 4-byte keys produce a relatively small expected number of collisions
  - The cutoff point where the overhead of the collisions is expected to
    reach just 10% of the savings gained is around 5800 years given the
    average mainnet block production rate
- Conversion of the bytes to a uint32 is basically free in terms of
  processing overhead

Profiling of the implemented code as well as simulations show that both
the actual number of observed collisions and observed memory savings
match the expected theoretical values.  Specifically, as of block height
575166 on mainnet, there are 35 collisions in the shortened keys and the
memory savings is around 30 MiB.
2021-07-30 16:20:19 -05:00
.github build: Test against go 1.16. 2021-02-18 12:55:12 -06:00
addrmgr addrmgr: Start v2 module dev cycle. 2021-02-12 12:15:54 -06:00
bech32 multi: Update README.md files for go modules. 2021-01-22 14:39:23 -06:00
blockchain blockchain: Use short keys for block index. 2021-07-30 16:20:19 -05:00
certgen multi: Update README.md files for go modules. 2021-01-22 14:39:23 -06:00
chaincfg multi: Update README.md files for go modules. 2021-01-22 14:39:23 -06:00
cmd multi: Address some linter complaints. 2021-07-26 20:51:03 -05:00
connmgr multi: Fix various typos. 2021-03-01 10:57:51 -06:00
container/apbf apbf: Switch to fast reduce method. 2021-02-03 23:17:58 -06:00
contrib contrib: Update OpenBSD rc script for 6.9 features. 2021-05-05 12:43:55 -05:00
crypto multi: Address a bunch of lint issues. 2019-12-30 13:54:41 -06:00
database database: Add comment on os.MkdirAll behavior. 2021-07-30 16:20:26 -05:00
dcrec secp256k1: Allow code generation to compile again. 2021-07-28 20:53:43 -05:00
dcrjson dcrjson: Minor jsonerr.go update. 2021-06-21 03:43:05 -05:00
dcrutil dcrutil: Remove all code related to Address. 2021-04-15 16:58:35 -05:00
docs docs: Update JSON-RPC API for max request limits. 2021-06-30 12:39:02 -05:00
gcs gcs: No standardness code in consensus. 2021-06-14 11:58:11 -05:00
hdkeychain txscript: Break dcrutil dependency. 2021-04-12 11:21:01 -05:00
internal multi: Update UtxoBackend to use leveldb directly. 2021-07-30 16:20:26 -05:00
lru multi: Update README.md files for go modules. 2021-01-22 14:39:23 -06:00
peer peer: Remove unneeded PushRejectMsg. 2021-02-08 16:11:15 -06:00
rpc/jsonrpc/types jsonrpc/types: Add missing Method type to vars. 2021-07-29 17:00:33 -05:00
rpcclient multi: Address some linter complaints. 2021-07-26 20:51:03 -05:00
rpctest txscript: Split signing code to sign subpackage. 2021-05-07 13:19:00 -05:00
sampleconfig config: Add utxocachemaxsize. 2021-02-22 12:16:31 -06:00
txscript txscript: Explicit consensus any kind p2sh tests. 2021-06-15 13:01:26 -05:00
wire multi: Address some linter complaints. 2021-07-26 20:51:03 -05:00
.dockerignore docker: Add dockerfiles for running dcrd nodes. 2018-07-07 05:33:53 -05:00
.gitignore multi: Address some linter complaints. 2020-10-06 12:29:14 -05:00
blockdb.go multi: Introduce UTXO database. 2021-04-28 10:27:55 -05:00
cert_test.go server: Add tlscurve config parameter 2019-10-31 16:01:49 -05:00
CHANGES multi: Use https links where available. 2019-06-18 14:20:06 -05:00
config_test.go config: Consolidate error reporting. 2020-09-25 12:44:37 -05:00
config.go config: Correct dir create failure error message. 2021-07-24 23:04:08 -05:00
dcrd.go multi: Move UTXO database. 2021-07-30 16:20:26 -05:00
doc.go config: Add utxocachemaxsize. 2021-02-22 12:16:31 -06:00
Dockerfile docker: Update image to golang:1.15 2020-08-20 01:54:29 -05:00
Dockerfile.alpine contrib: Bump Dockerfile.alpine to alpine:3.14.0. 2021-07-20 03:39:25 -05:00
go.mod blockchain: Bump database module minor version. 2021-05-21 07:59:41 -05:00
go.sum rpctest: Make tests work properly with latest code. 2021-03-13 16:33:15 -06:00
ipc.go ipc: Fix lifetimeEvent comments. 2021-04-28 10:27:55 -05:00
LICENSE LICENSE: update year 2020-02-18 19:37:06 -06:00
log.go addrmgr: Start v2 module dev cycle. 2021-02-12 12:15:54 -06:00
networkparams_test.go standalone: Start v2 module dev cycle 2020-06-11 15:48:38 -05:00
params.go chaincfg: Start v3 module dev cycle. 2020-01-29 13:24:14 -06:00
README.md docs: Update min recommended specs in README.md. 2021-02-22 12:16:31 -06:00
require.go multi: Start dcrec/secp256k1 v4 module dev cycle. 2020-12-16 16:30:24 -06:00
rpcadaptors.go peer: Start v3 module dev cycle. 2021-02-06 20:40:03 -06:00
run_tests.sh rpctest: Don't use installed node. 2021-01-21 23:42:15 -06:00
server.go multi: Update UtxoBackend to use leveldb directly. 2021-07-30 16:20:26 -05:00
service_windows.go multi: Fix various typos. 2021-03-01 10:57:51 -06:00
signal_unix.go main: Handle SIGHUP with clean shutdown. 2021-05-05 12:29:05 -05:00
signal.go main: Convert signal handling to use context. 2019-04-01 14:09:07 -05:00
upnp.go upnp: More accurate getOurIP. 2021-03-13 21:57:05 -06:00

dcrd

Build Status ISC License Doc Go Report Card

Decred Overview

Decred is a blockchain-based cryptocurrency with a strong focus on community input, open governance, and sustainable funding for development. It utilizes a hybrid proof-of-work and proof-of-stake mining system to ensure that a small group cannot dominate the flow of transactions or make changes to Decred without the input of the community. A unit of the currency is called a decred (DCR).

https://decred.org

Latest Downloads

https://decred.org/downloads/

Core software:

  • dcrd: a Decred full node daemon (this)
  • dcrwallet: a CLI Decred wallet daemon
  • dcrctl: a CLI client for dcrd and dcrwallet

Bundles:

What is dcrd?

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

It acts as a fully-validating chain daemon for the Decred cryptocurrency. dcrd maintains the entire past transactional ledger of Decred and allows relaying of transactions to other Decred nodes around the world.

This software is currently under active development. It is extremely stable and has been in production use since February 2016.

It important to note that dcrd does NOT include wallet functionality. Users who desire a wallet will need to use dcrwallet(CLI) or Decrediton(GUI).

What is a full node?

The term 'full node' is short for 'fully-validating node' and refers to software that fully validates all transactions and blocks, as opposed to trusting a 3rd party. In addition to validating transactions and blocks, nearly all full nodes also participate in relaying transactions and blocks to other full nodes around the world, thus forming the peer-to-peer network that is the backbone of the Decred cryptocurrency.

The full node distinction is important, since full nodes are not the only type of software participating in the Decred peer network. For instance, there are 'lightweight nodes' which rely on full nodes to serve the transactions, blocks, and cryptographic proofs they require to function, as well as relay their transactions to the rest of the global network.

Why run dcrd?

As described in the previous section, the Decred cryptocurrency relies on having a peer-to-peer network of nodes that fully validate all transactions and blocks and then relay them to other full nodes.

Running a full node with dcrd contributes to the overall security of the network, increases the available paths for transactions and blocks to relay, and helps ensure there are an adequate number of nodes available to serve lightweight clients, such as Simplified Payment Verification (SPV) wallets.

Without enough full nodes, the network could be unable to expediently serve users of lightweight clients which could force them to have to rely on centralized services that significantly reduce privacy and are vulnerable to censorship.

In terms of individual benefits, since dcrd fully validates every block and transaction, it provides the highest security and privacy possible when used in conjunction with a wallet that also supports directly connecting to it in full validation mode, such as dcrwallet (CLI) and Decrediton (GUI).

  • 12 GB disk space (as of April 2020, increases over time)
  • 2GB memory (RAM)
  • ~150MB/day download, ~1.5GB/day upload
    • Plus one-time initial download of the entire block chain
  • Windows 10 (server preferred), macOS, Linux
  • High uptime

Getting Started

So, you've decided to help the network by running a full node. Great! Running dcrd is simple. All you need to do is install dcrd on a machine that is connected to the internet and meets the minimum recommended specifications, and launch it.

Also, make sure your firewall is configured to allow inbound connections to port 9108.

Installing and updating

Binaries (Windows/Linux/macOS)

Binary releases are provided for common operating systems and architectures. The easiest method is to download Decrediton from the link below, which will include dcrd. Advanced users may prefer the Command-line app suite, which includes dcrd and dcrwallet.

https://decred.org/downloads/

  • How to verify binaries before installing: https://docs.decred.org/advanced/verifying-binaries/
  • How to install the CLI Suite: https://docs.decred.org/wallets/cli/cli-installation/
  • How to install Decrediton: https://docs.decred.org/wallets/decrediton/decrediton-setup/

Build from source (all platforms)

Install Dependencies
  • Go 1.14 or 1.15

    Installation instructions can be found here: https://golang.org/doc/install. Ensure Go was installed properly and is a supported version:

    $ go version
    $ go env GOROOT GOPATH
    

    NOTE: GOROOT and GOPATH must not be on the same path. Since Go 1.8 (2016), GOROOT and GOPATH are set automatically, and you do not need to change them. However, you still need to add $GOPATH/bin to your PATH in order to run binaries installed by go get and go install (On Windows, this happens automatically).

    Unix example -- add these lines to .profile:

    PATH="$PATH:/usr/local/go/bin"  # main Go binaries ($GOROOT/bin)
    PATH="$PATH:$HOME/go/bin"       # installed Go projects ($GOPATH/bin)
    
  • Git

    Installation instructions can be found at https://git-scm.com or https://gitforwindows.org.

    $ git version
    
Windows Example
PS> git clone https://github.com/decred/dcrd $env:USERPROFILE\src\dcrd
PS> cd $env:USERPROFILE\src\dcrd
PS> go install . .\cmd\...
PS> dcrd -V

Run the dcrd executable now installed in "$(go env GOPATH)\bin".

Unix Example

This assumes you have already added $GOPATH/bin to your $PATH as described in dependencies.

$ git clone https://github.com/decred/dcrd $HOME/src/dcrd
$ git clone https://github.com/decred/dcrctl $HOME/src/dcrctl
$ (cd $HOME/src/dcrd && go install . ./...)
$ (cd $HOME/src/dcrctl && go install)
$ dcrd -V

Run the dcrd executable now installed in $GOPATH/bin.

Docker

Running dcrd

You can run a decred node from inside a docker container. To build the image yourself, use the following command:

docker build -t decred/dcrd .

Or you can create an alpine based image (requires Docker 17.05 or higher):

docker build -t decred/dcrd:alpine -f Dockerfile.alpine .

You can then run the image using:

docker run decred/dcrd

You may wish to use an external volume to customize your config and persist the data in an external volume:

docker run --rm -v /home/user/dcrdata:/root/.dcrd/data decred/dcrd

For a minimal image, you can use the decred/dcrd:alpine tag. This is typically a more secure option while also being a much smaller image.

You can run dcrctl from inside the image. For example, run an image (mounting your data from externally) with:

docker run --rm -ti --name=dcrd-1 -v /home/user/.dcrd:/root/.dcrd \
  decred/dcrd:alpine

And then run dcrctl commands against it. For example:

docker exec -ti dcrd-1 dcrctl getbestblock

Running Tests

All tests and linters may be run using the script run_tests.sh. Generally, Decred only supports the current and previous major versions of Go.

./run_tests.sh

Contact

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

https://decred.org/community/

Issue Tracker

The integrated github issue tracker is used for this project.

Documentation

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

License

dcrd is licensed under the copyfree ISC License.