• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..13-May-2020-

fullblocktests/H13-May-2020-2,3231,208

indexers/H13-May-2020-3,0501,772

testdata/H03-May-2022-181151

README.mdH A D13-May-20204.6 KiB10482

accept.goH A D13-May-20203.4 KiB9345

bench_test.goH A D13-May-2020700 3219

blockindex.goH A D13-May-202011.3 KiB349176

chain.goH A D13-May-202063.9 KiB1,804921

chain_test.goH A D13-May-202030.7 KiB967701

chainio.goH A D13-May-202048.6 KiB1,417726

chainio_test.goH A D13-May-202022.5 KiB722608

chainview.goH A D13-May-202013.7 KiB424189

chainview_test.goH A D13-May-202015.6 KiB488345

checkpoints.goH A D13-May-20208.8 KiB262133

common_test.goH A D13-May-202010.1 KiB385261

compress.goH A D13-May-202021.3 KiB587258

compress_test.goH A D13-May-202014.8 KiB448371

difficulty.goH A D13-May-202011.6 KiB313148

difficulty_test.goH A D13-May-20201.5 KiB7657

doc.goH A D13-May-20204.1 KiB821

error.goH A D13-May-202011 KiB299119

error_test.goH A D13-May-20203.7 KiB135118

example_test.goH A D13-May-20203.8 KiB10856

fullblocks_test.goH A D13-May-20209.6 KiB311229

log.goH A D13-May-2020758 3114

mediantime.goH A D13-May-20207.3 KiB219103

mediantime_test.goH A D13-May-20203.8 KiB10565

merkle.goH A D13-May-20209.4 KiB266135

merkle_test.goH A D13-May-2020675 2415

notifications.goH A D13-May-20202.7 KiB8239

notifications_test.goH A D13-May-20201.3 KiB5235

process.goH A D13-May-20208.5 KiB245130

scriptval.goH A D13-May-20209.4 KiB320216

scriptval_test.goH A D13-May-20201.2 KiB5037

thresholdstate.goH A D13-May-202011.9 KiB357180

thresholdstate_test.goH A D13-May-20203.6 KiB135105

timesorter.goH A D13-May-2020825 2811

timesorter_test.goH A D13-May-20201.3 KiB4839

upgrade.goH A D13-May-202019.5 KiB605315

upgrade_test.goH A D13-May-20203.6 KiB11793

utxoviewpoint.goH A D13-May-202022.5 KiB643328

validate.goH A D13-May-202046.9 KiB1,280712

validate_test.goH A D13-May-202015.8 KiB488412

versionbits.goH A D13-May-202010.3 KiB302138

weight.goH A D13-May-20204.3 KiB11856

README.md

1blockchain
2==========
3
4[![Build Status](http://img.shields.io/travis/btcsuite/btcd.svg)](https://travis-ci.org/btcsuite/btcd)
5[![ISC License](http://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)
6[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](http://godoc.org/github.com/btcsuite/btcd/blockchain)
7
8Package blockchain implements bitcoin block handling and chain selection rules.
9The test coverage is currently only around 60%, but will be increasing over
10time. See `test_coverage.txt` for the gocov coverage report.  Alternatively, if
11you are running a POSIX OS, you can run the `cov_report.sh` script for a
12real-time report.  Package blockchain is licensed under the liberal ISC license.
13
14There is an associated blog post about the release of this package
15[here](https://blog.conformal.com/btcchain-the-bitcoin-chain-package-from-bctd/).
16
17This package has intentionally been designed so it can be used as a standalone
18package for any projects needing to handle processing of blocks into the bitcoin
19block chain.
20
21## Installation and Updating
22
23```bash
24$ go get -u github.com/btcsuite/btcd/blockchain
25```
26
27## Bitcoin Chain Processing Overview
28
29Before a block is allowed into the block chain, it must go through an intensive
30series of validation rules.  The following list serves as a general outline of
31those rules to provide some intuition into what is going on under the hood, but
32is by no means exhaustive:
33
34 - Reject duplicate blocks
35 - Perform a series of sanity checks on the block and its transactions such as
36   verifying proof of work, timestamps, number and character of transactions,
37   transaction amounts, script complexity, and merkle root calculations
38 - Compare the block against predetermined checkpoints for expected timestamps
39   and difficulty based on elapsed time since the checkpoint
40 - Save the most recent orphan blocks for a limited time in case their parent
41   blocks become available
42 - Stop processing if the block is an orphan as the rest of the processing
43   depends on the block's position within the block chain
44 - Perform a series of more thorough checks that depend on the block's position
45   within the block chain such as verifying block difficulties adhere to
46   difficulty retarget rules, timestamps are after the median of the last
47   several blocks, all transactions are finalized, checkpoint blocks match, and
48   block versions are in line with the previous blocks
49 - Determine how the block fits into the chain and perform different actions
50   accordingly in order to ensure any side chains which have higher difficulty
51   than the main chain become the new main chain
52 - When a block is being connected to the main chain (either through
53   reorganization of a side chain to the main chain or just extending the
54   main chain), perform further checks on the block's transactions such as
55   verifying transaction duplicates, script complexity for the combination of
56   connected scripts, coinbase maturity, double spends, and connected
57   transaction values
58 - Run the transaction scripts to verify the spender is allowed to spend the
59   coins
60 - Insert the block into the block database
61
62## Examples
63
64* [ProcessBlock Example](http://godoc.org/github.com/btcsuite/btcd/blockchain#example-BlockChain-ProcessBlock)
65  Demonstrates how to create a new chain instance and use ProcessBlock to
66  attempt to add a block to the chain.  This example intentionally
67  attempts to insert a duplicate genesis block to illustrate how an invalid
68  block is handled.
69
70* [CompactToBig Example](http://godoc.org/github.com/btcsuite/btcd/blockchain#example-CompactToBig)
71  Demonstrates how to convert the compact "bits" in a block header which
72  represent the target difficulty to a big integer and display it using the
73  typical hex notation.
74
75* [BigToCompact Example](http://godoc.org/github.com/btcsuite/btcd/blockchain#example-BigToCompact)
76  Demonstrates how to convert a target difficulty into the
77  compact "bits" in a block header which represent that target difficulty.
78
79## GPG Verification Key
80
81All official release tags are signed by Conformal so users can ensure the code
82has not been tampered with and is coming from the btcsuite developers.  To
83verify the signature perform the following:
84
85- Download the public key from the Conformal website at
86  https://opensource.conformal.com/GIT-GPG-KEY-conformal.txt
87
88- Import the public key into your GPG keyring:
89  ```bash
90  gpg --import GIT-GPG-KEY-conformal.txt
91  ```
92
93- Verify the release tag with the following command where `TAG_NAME` is a
94  placeholder for the specific tag:
95  ```bash
96  git tag -v TAG_NAME
97  ```
98
99## License
100
101
102Package blockchain is licensed under the [copyfree](http://copyfree.org) ISC
103License.
104