26 |
--------------------------------------------------------------------------------
/Containerfile:
--------------------------------------------------------------------------------
1 | FROM quay.io/official-images/debian
2 | RUN bash -c "echo cache buster 22"
3 | RUN bash -c "apt update"
4 | RUN apt --yes upgrade
5 | RUN apt --yes install build-essential curl procps git
6 | RUN gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
7 | RUN \curl -sSL https://get.rvm.io/ | bash -s stable
8 | #RUN /bin/bash -l -c ". /etc/profile.d/rvm.sh && rvm install 2.6.4 && rvm use 2.6.4"
9 | RUN bash -l -c "rvm install 3.2.2"
10 | RUN bash -l -c "rvm use 3.2.2"
11 | WORKDIR /srv/
12 | ENV PATH /usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
13 | RUN bash -l -c "gem install http_parser.rb -v '0.8.0' --source 'https://rubygems.org/'"
14 | RUN bash -l -c "gem install bundler --source 'https://rubygems.org/'"
15 | RUN bash -l -c "gem install bundle --source 'https://rubygems.org/'"
16 | RUN bash -c "echo cache buster 23"
17 | RUN bash -l -c "bundle install"
18 |
19 | RUN bash -l -c "\curl https://nodejs.org/dist/v18.17.1/node-v18.17.1-linux-x64.tar.xz > /usr/local/node.tar.xz"
20 | RUN bash -l -c "cd /usr/local ; tar xJf node.tar.xz --strip-components=1"
21 | RUN bash -l -c "npm install -g @mermaid-js/mermaid-cli"
22 |
23 | ENV LANG C.UTF-8
24 | ENV LC_ALL C.UTF-8
25 | ENTRYPOINT bash -l
26 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ruby:3.2.2-slim-bookworm
2 |
3 | RUN apt update && \
4 | apt --yes upgrade && \
5 | apt --yes install build-essential curl procps git \
6 | fonts-liberation libasound2 \
7 | libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 \
8 | libfontconfig1 libgbm1 libgcc1 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 \
9 | libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 \
10 | libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \
11 | --no-install-recommends && \
12 | rm -rf /var/lib/apt/lists/*
13 |
14 | ARG UID=1000
15 | ARG GID=1000
16 |
17 | WORKDIR /srv/
18 | COPY Gemfile /srv/Gemfile
19 |
20 | RUN groupadd -g ${GID} docs && \
21 | useradd -m -u ${UID} -g docs -s /bin/bash docs
22 | RUN chown -R docs:docs /srv/
23 | USER docs
24 |
25 | RUN bash -l -c "echo 'export GEM_HOME=${HOME}/.gem' >> ${HOME}/.bashrc \
26 | && echo 'export GEM_PATH=${HOME}/.gem' >> ${HOME}/.bashrc \
27 | && source ~/.bashrc \
28 | && bundle config set --local path ${HOME}/.gem \
29 | && bundle install"
30 |
31 | RUN bash -l -c "curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash \
32 | && export NVM_DIR=\"\$([ -z \"${XDG_CONFIG_HOME-}\" ] && printf %s \"${HOME}/.nvm\" || printf %s \"${XDG_CONFIG_HOME}/nvm\")\" \
33 | && [ -s \"\$NVM_DIR/nvm.sh\" ] && \\. \"\$NVM_DIR/nvm.sh\" \
34 | && echo 'export PATH=${PATH}:/srv/node_modules/.bin' >> ${HOME}/.bashrc \
35 | && source ~/.bashrc \
36 | && nvm install node \
37 | && npm install @mermaid-js/mermaid-cli"
38 |
39 | ENV LANG C.UTF-8
40 | ENV LC_ALL C.UTF-8
41 | ENTRYPOINT ["bash", "-l"]
42 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | ## If you update the version here, also update it in .travis.yml, .ruby-version,
4 | ## and README.md. Then push your branch and make sure Travis supports that
5 | ## version.
6 | ruby '3.2.2'
7 |
8 | gem "asciidoctor", "~>2.0.20"
9 | gem "rouge"
10 |
11 | ## If you add a new Gem below, run `bundle install` to install it.
12 | group :development do
13 | gem "jekyll", "~> 4.3.2"
14 | gem "just-the-docs"
15 | gem 'jekyll-redirect-from'
16 | # Lock `http_parser.rb` gem to `v0.6.x` on JRuby builds since newer versions of the gem
17 | # do not have a Java counterpart.
18 | #gem "http_parser.rb", "~> 0.6.0", :platforms => [:jruby]
19 | end
20 |
21 | group :jekyll_plugins do
22 | gem "asciidoctor-diagram"
23 | gem "jekyll-feed", "~> 0.12"
24 | gem "jekyll-asciidoc", "~> 3.0.0"
25 | end
26 |
27 | group :asciidoc_plugins do
28 | gem "asciidoctor-epub3"
29 | gem "asciidoctor-pdf"
30 | end
31 |
32 | group :testing do
33 | gem 'html-proofer'
34 | gem 'mdl'
35 | gem 'json-schema'
36 | gem 'toml'
37 | end
38 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | all: test-before-build build-other-versions build test-after-build
2 | build-other-versions: html pdf epub
3 | publish: test-before-build build-other-versions build
4 | production: clean all production-test
5 |
6 | ## If we call git in our tests without using the --no-pager option
7 | ## or redirecting stdout to another command, fail unconditionally.
8 | ## This addresses an issue where `make` can't be run within an IDE because
9 | ## it tries to paginate the output, see:
10 | ## https://github.com/bitcoinops/bitcoinops.github.io/pull/494#discussion_r546376335
11 | export GIT_PAGER='_contrib/kill0'
12 | JEKYLL_FLAGS = --future --drafts --unpublished --incremental
13 | ## Needed for github actions to work properly
14 | SHELL=/bin/bash
15 |
16 | clean:
17 | bundle exec jekyll clean
18 |
19 | preview:
20 | ## Don't do a full rebuild (to save time), but always rebuild index pages.
21 | rm -f _site/index.html \
22 |
23 | bundle exec jekyll serve --host 0.0.0.0 $(JEKYLL_FLAGS)
24 |
25 | build:
26 | @# Tiny sleep for when running concurrently to ensure output
27 | @# files aren't created before changed input files are marked
28 | @# for schema validation.
29 | @sleep 0.1
30 | bundle exec jekyll build $(JEKYLL_FLAGS) $(ADD_JEKYLL_ARGS)
31 |
32 | test-before-build: $(compatibility_validation) $(topic_validation)
33 | ## Check for Markdown formatting problems
34 | @ ## - MD009: trailing spaces (can lead to extraneous tags
35 | bundle exec mdl -g -r MD009 .
36 |
37 | test-after-build: build
38 | ## Check for broken Markdown reference-style links that are displayed in text unchanged, e.g. [broken][broken link]
39 | ## Check for duplicate anchors
40 | ! find _site/ -name '*.html' | while read file ; do \
41 | cat $$file \
42 | | egrep -o "(id|name)=[\"'][^\"']*[\"']" \
43 | | sed -E "s/^(id|name)=//; s/[\"']//g" \
44 | | sort | uniq -d \
45 | | sed "s|.*|Duplicate anchor in $$file: #&|" ; \
46 | done | grep .
47 |
48 | ## Check for broken links
49 | bundle exec htmlproofer --disable-external --ignore-urls '/^\/bin/.*/' ./_site
50 |
51 | html:
52 | mkdir -p bin
53 | ## Single page HTML
54 | ## Set imagesdir to parent_dir/images to work with jekyll build
55 | bundle exec asciidoctor -r asciidoctor-diagram -o onboarding-to-bitcoin-core.html index.adoc
56 | ## Delete non-deterministic asciidoctor output
57 | sed -i '/^Last updated /d' onboarding-to-bitcoin-core.html
58 | mv onboarding-to-bitcoin-core.html bin/
59 | cp -r images bin/
60 |
61 | pdf:
62 | bundle exec asciidoctor -r asciidoctor-pdf -b pdf -r asciidoctor-diagram -o onboarding-to-bitcoin-core.pdf index_pdf.adoc
63 | mv onboarding-to-bitcoin-core.pdf bin/
64 |
65 | epub:
66 | bundle exec asciidoctor -b epub3 -r asciidoctor-epub3 -r asciidoctor-diagram -o index.epub index_epub.adoc
67 | mv index.epub bin/onboarding-to-bitcoin-core.epub
68 |
--------------------------------------------------------------------------------
/README.adoc:
--------------------------------------------------------------------------------
1 | = Onboarding to Bitcoin Core
2 |
3 | This documentation is currently hosted at https://bitcoincore.academy[bitcoincore.academy] however this location may be subject to change in the future.
4 |
5 | See https://github.com/chaincodelabs/onboarding-to-bitcoin-core/blob/master/asciidoc_workflow.adoc[asciidoc_workflow.adoc]
6 | and https://github.com/chaincodelabs/onboarding-to-bitcoin-core/blob/master/jekyll_workflow.md[jekyll_workflow.md] for tips on contributing and instructions for running locally.
7 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | # Welcome to Jekyll!
2 | #
3 | # This config file is meant for settings that affect your whole blog, values
4 | # which you are expected to set up once and rarely edit after that. If you find
5 | # yourself editing this file very often, consider using Jekyll's data files
6 | # feature for the data you need to update frequently.
7 | #
8 | # For technical reasons, this file is *NOT* reloaded automatically when you use
9 | # 'bundle exec jekyll serve'. If you change this file, please restart the server process.
10 | #
11 | # If you need help with YAML syntax, here are some quick references for you:
12 | # https://learn-the-web.algonquindesign.ca/topics/markdown-yaml-cheat-sheet/#yaml
13 | # https://learnxinyminutes.com/docs/yaml/
14 | #
15 | # Site settings
16 | # These are used to personalize your new site. If you look in the HTML files,
17 | # you will see them accessed via {{ site.title }}, {{ site.email }}, and so on.
18 | # You can create any custom variable you would like, and they will be accessible
19 | # in the templates via {{ site.myvariable }}.
20 |
21 | title: Bitcoin Core Onboarding
22 | email: your-email@example.com
23 | description: >- # this means to ignore newlines until "baseurl:"
24 | Bitcoin Core developer onboarding documentation
25 | baseurl: "" # the subpath of your site, e.g. /blog
26 | url: "https://bitcoincore.academy" # the base hostname & protocol for your site, e.g. http://example.com
27 | twitter_username: chaincodelabs
28 | github_username: chaincodelabs
29 |
30 | # Build settings
31 | theme: just-the-docs
32 | # Color scheme supports "light" and "dark"
33 | color_scheme: dark
34 | plugins:
35 | - asciidoctor-diagram
36 | - jekyll-feed
37 | - jekyll-asciidoc
38 |
39 | asciidoc:
40 | processor: asciidoctor
41 |
42 | asciidoctor:
43 | attributes:
44 | imagesdir: /images
45 | mermaid-config: mermaid-config.json
46 | mermaid-format: svg
47 | mermaid-puppeteer-config: puppeteer-config.json
48 | source-highlighter: rouge
49 | rouge-style: github
50 | icons: font
51 |
52 | keep_files:
53 | - images
54 |
55 | # Footer "Edit this page on GitHub" link text
56 | gh_edit_link: true # show or hide edit this page link
57 | gh_edit_link_text: "Edit this page on GitHub."
58 | gh_edit_repository: "https://github.com/chaincodelabs/onboarding-to-bitcoin-core" # the github URL for your repo
59 | gh_edit_branch: "master" # the branch that your docs is served from
60 | gh_edit_view_mode: "edit" # "tree" or "edit" if you want the user to jump into the editor immediately
61 |
62 | mermaid:
63 | # Version of mermaid library
64 | # Pick an available version from https://cdn.jsdelivr.net/npm/mermaid/
65 | version: "9.1.3"
66 |
67 | # Exclude from processing.
68 | # The following items will not be processed, by default.
69 | # Any item listed under the `exclude:` key here will be automatically added to
70 | # the internal "default list".
71 | #
72 | # Excluded items can be processed by explicitly listing the directories or
73 | # their entries' file path in the `include:` list.
74 | exclude:
75 | - .jekyll-cache/
76 | - all_chapters.adoc
77 | - 01_overview-and-development.adoc
78 | - 02_architecture.adoc
79 | - 03_consensus-and-validation.adoc
80 | - 04_wallet.adoc
81 | - 05_gui.adoc
82 | - 06_p2p.adoc
83 | - 07_mempool.adoc
84 | - 08_script.adoc
85 | - 09_build-system.adoc
86 | - 10_rpc.adoc
87 | - asciidoc_workflow.adoc
88 | - index.adoc
89 | - index_pdf.adoc
90 | - index_epub.adoc
91 | - settings.adoc
92 | - README.adoc
93 | - book.html
94 | - Gemfile
95 | - Gemfile.lock
96 | - jekyll_workflow.md
97 | - Makefile
98 | - mermaid-config.json
99 | - node_modules/
100 | - vendor/bundle/
101 | - vendor/cache/
102 | - vendor/gems/
103 | - vendor/ruby/
104 |
--------------------------------------------------------------------------------
/_includes/best-way.md:
--------------------------------------------------------------------------------
1 | _Ensuring that Bitcoin Core remains highly secure software requires
2 | reviewers and maintainers scrutinize every contribution, no matter how
3 | minor it seems. The best way to avoid wasting the time of reviewers and
4 | risking having them ignore your contribution is to read the entire
5 | onboarding guide, as described on the [main page](/). However, if
6 | you're going to contribute anyway without reading all of the
7 | documentation, this quickstart will guide you to the most relevant parts
8 | of the contributor documentation._
9 |
--------------------------------------------------------------------------------
/_includes/head_custom.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
20 |
--------------------------------------------------------------------------------
/address-relay.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Address relay
2 | :page-nav_order: 70
3 | :page-parent: P2P
4 | [[address_relay]]
5 | === Address relay
6 |
7 | The Bitcoin network uses `addr` messages to communicate (node) network addresses.
8 | See the https://en.bitcoin.it/wiki/Protocol_documentation#addr[Bitcoin wiki p2p documentation^] for more details.
9 | Good address propagation improves network connectivity and increases the difficulty of executing an eclipse attack.
10 |
11 | Bitcoin Core nodes will periodically self-announce (also known as self-advertise) their own network address to peers.
12 | When a Bitcoin Core node receives an `addr` message that contains 10 addresses or fewer, it forwards those addresses with a timestamp within 10 minutes of the current time to 1 or 2 peers, selected at random.
13 | If we assume all nodes do this, then self-announcements should reach a large portion of the nodes on the network. The timestamp condition is there to ensure that the relay of a given address stops after some time.
14 |
15 | Since https://github.com/bitcoin/bitcoin/pull/22387[PR#22387^], there is a rate limit for address relay processing, so that addresses from peers that send too many of them are ignored which can help to prevent CPU/memory exhaustion attacks.
16 |
17 | ==== `Addr` privacy
18 |
19 | For some time, it was possible for a spy node to easily scrape the full contents of any reachable node's `AddrMan`.
20 | The spy just had to connect to a victim node multiple times and execute `GETADDR`.
21 | This scraped data could then be used to infer private information about the victim.
22 |
23 | For example, a spy could monitor the victim's `AddrMan` content in real time and figure out which peers a node is connected to.
24 | A spy could also compare the `AddrMan` content from two different connections (e.g. one identified by Tor address and one identified by IPv4) and figure out that it's actually the same physical node (`fingerprinting`).
25 |
26 | https://github.com/bitcoin/bitcoin/pull/18991[PR#18991^] was a first step towards fixing these privacy issues.
27 | By limiting (caching) the leaked portion of `AddrMan`, these inference activities became much harder.
28 | Caching in this context means that the `ADDR` response (which is only a small subset of a node's `AddrMan` content) remains the same for every `GETADDR` call during (roughly) a day.
29 |
30 | ==== Addr black holes
31 |
32 | We know that some nodes on the network do _not_ relay `addr` messages that they receive.
33 | Two known cases are block-relay-only connections from Bitcoin Core nodes, and connections from certain light clients.
34 | We refer to these connections as `addr` black holes.
35 | `addr` messages go in, but they never escape!
36 |
37 | If a large portion of the connections on the network are `addr` black holes, then `addr` propagation may be negatively impacted: self-announcements might not reach a majority of nodes on the network in a timely fashion.
38 | It'd be better if we could somehow avoid picking black holes as the 1 or 2 peers that we select for relaying `addr` messages to.
39 |
40 | https://github.com/bitcoin/bitcoin/pull/21528[PR#21528^] defers initialization of `m_addr_known` of inbound peers until the peer sends an address related message (`addr`, `addrv2`, `getaddr` or `sendaddrv2`).
41 | The node uses the presence of `m_addr_known` to decide whether the peer is a candidate for relaying `addr` messages received from the network.
42 |
43 | ==== addrv2
44 |
45 | https://github.com/bitcoin/bitcoin/pull/19031[PR#19031^] is a proposed implementation of the https://github.com/bitcoin/bips/blob/9286b5254317d9e73fb25c5f0acd2b2d9937843e/bip-0155.mediawiki[BIP155^] `addrv2` message, a new P2P message format proposed in early 2019 by Wladimir J. van der Laan to gossip longer node addresses.
46 |
47 | The `addrv2` message is required to support https://trac.torproject.org/projects/tor/wiki/doc/NextGenOnions[next-generation Tor v3 Onion addresses^], the https://geti2p.net[Invisible Internet Project (I2P)^], and potentially other networks that have longer endpoint addresses than fit in the 128 bits/16 bytes of the current `addr` message.
48 |
49 |
--------------------------------------------------------------------------------
/all_chapters.adoc:
--------------------------------------------------------------------------------
1 | include::01_overview-and-development.adoc[]
2 |
3 | include::02_architecture.adoc[]
4 |
5 | include::03_consensus-and-validation.adoc[]
6 |
7 | include::04_wallet.adoc[]
8 |
9 | include::05_gui.adoc[]
10 |
11 | include::06_p2p.adoc[]
12 |
13 | include::07_mempool.adoc[]
14 |
15 | include::08_script.adoc[]
16 |
17 | include::09_build-system.adoc[]
18 |
19 | include::10_rpc.adoc[]
20 |
21 | include::appendix.adoc[]
22 |
23 | include::glossary.adoc[]
24 |
--------------------------------------------------------------------------------
/appendix.adoc:
--------------------------------------------------------------------------------
1 | = Appendix
2 | :page-nav_order: 100
3 |
4 | [id=pimpl-technique]
5 | == PIMPL technique
6 |
7 | :pimpl_addrman_review: https://bitcoincore.reviews/22950
8 |
9 | The Bitcoin Core codebase contains many classes of the form `class *Impl`.
10 | These classes are taking advantage of the Pointer to Implementation https://en.cppreference.com/w/cpp/language/pimpl[technique^] which helps to both provide more stable ABIs and also to reduce compile-time dependencies.
11 |
12 | .Some of the current Bitcoin Core PIMPL classes
13 | [source,cpp]
14 | ----
15 | AddrManImpl
16 | ChainImpl
17 | NodeImpl
18 | PeerManagerImpl
19 | WalletImpl
20 |
21 | FieldImpl
22 | DBImpl
23 | ExternalSignerImpl
24 | NotificationsHandlerImpl
25 | RPCHandlerImpl
26 | IpcImpl
27 | ProcessImpl
28 | RPCMethodImpl
29 | SketchImpl
30 | DescriptorImpl
31 | ----
32 |
33 | Amiti Uttarwar {pimpl_addrman_review}[hosted^] a PR review club "Pimpl AddrMan to abstract implementation details" which contains information on the design aims, advantages and disadvantages.
34 | Below are copies of the annotated pictures she created and included to assist learning.
35 |
36 | .PIMPL peerman
37 | [link=https://bitcoincore.reviews/22950]
38 | image::pimpl_peerman_amiti.png[]
39 |
40 | .PIMPL txrequest
41 | [link=https://bitcoincore.reviews/22950]
42 | image::pimpl_txrequest_amiti.png[]
43 |
44 | .Compilation firewall
45 | [link=https://bitcoincore.reviews/22950]
46 | image::compilation_firewall_amiti.jpg[]
47 |
48 |
--------------------------------------------------------------------------------
/architecture.adoc:
--------------------------------------------------------------------------------
1 | = Architecture
2 | :page-nav_order: 10
3 | :page-has_children: true
4 |
5 | TIP: This section has been updated to Bitcoin Core @ https://github.com/bitcoin/bitcoin/tree/v23.0[v23.0^]
6 |
7 | Bitcoin Core v0.1 contained 26 source code and header files (*.h/cpp) with _main.cpp_ containing the majority of the business logic.
8 | As of v23.0 there are more than 800 source files (excluding _bench/_, _test/_ and all subtrees), more than 200 benchmarking and cpp unit tests, and more than 200 python tests and lints.
9 |
--------------------------------------------------------------------------------
/asciidoc_workflow.adoc:
--------------------------------------------------------------------------------
1 | = Use of the asciidoc format
2 |
3 | The https://asciidoctor.org/[asciidoc] format has been used for this documentation.
4 |
5 | To use asciidoc format, ensure that the `asciidoctor` tool is installed (and on your system $PATH).
6 | Also, it can be useful to ensure your editor understands the filetype, e.g. for Vim you can install https://github.com/habamax/vim-asciidoctor[vim-asciidoctor].
7 |
8 | A quick reference for asciidoc formatting can be found https://docs.asciidoctor.org/asciidoc/latest/syntax-quick-reference/[here].
9 |
10 | This documentation follows the asciidoc recommended practice of https://asciidoctor.org/docs/asciidoc-recommended-practices/#one-sentence-per-line[One Sentence Per Line].
11 | If you choose to contribute (thank you!) please try and continue this practice to make future editing more straightforward.
12 |
13 | == Generating _index.html_ for static web hosting
14 |
15 | You can generate an _index.html_ file for static web hosting by installing the <> tool and then running:
16 |
17 | [source,bash]
18 | ----
19 | asciidoctor index.adoc
20 | ----
21 |
22 | Simply host _index.html_ along with the _images/_ directory and its contents at the root of your web server to serve the documentation.
23 |
24 | === Adding mermaid diagrams
25 |
26 | If you add a mermaid diagram to an article, you must add:
27 |
28 | ----
29 | :mermaid-puppeteer-config: ./puppeteer-config.json
30 | ----
31 |
32 | To the header of the file, in order that the Container/Dockerfile can have mermaid-cli pass the puppeteer config to puppeteer.
33 |
34 | === Regenerate mermaid diagrams
35 |
36 | In order to regenerate the mermaid diagrams, you will need https://github.com/mermaid-js/mermaid-cli[mermaid-cli] and https://docs.asciidoctor.org/diagram-extension/latest/[asciidoctor-diagram] installed.
37 |
38 | With both of the above programs on your PATH, you can then run command:
39 |
40 | [source,shell]
41 | ----
42 | asciidoctor -r asciidoctor-diagram index.adoc
43 | ----
44 |
45 | To generate index.html, along with required images in the `/images` sub-directory.
46 |
47 | === Update _index.html_ automatically as a pre-commit hook
48 |
49 | If you prefer you can write a simple pre-commit hook to update _index.html_ file automatically at each commit.
50 | An example of this might be:
51 |
52 | ._$PROJECT_ROOT/.git/hooks/pre-commit_
53 | [source,bash]
54 | ----
55 | #!/usr/bin/bash
56 |
57 | asciidoctor index.adoc
58 | ----
59 |
--------------------------------------------------------------------------------
/backports.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Backports
2 | :page-nav_order: 140
3 | :page-parent: Overview and Development Process
4 | === Backports
5 |
6 | Bitcoin Core often backports fixes for bugs and soft fork activations into previous software releases.
7 |
8 | Generally maintainers will handle backporting for you, unless for some reason the process will be too difficult.
9 | If this point is reached a decision will be made on whether the backport is abandoned, or a specific (new) fix is created for the older software version.
10 |
11 | == Software Life-cycle
12 |
13 | An overview of the software life-cycle for Bitcoin Core can be found at https://bitcoincore.org/en/lifecycle/
14 |
15 |
--------------------------------------------------------------------------------
/bips.adoc:
--------------------------------------------------------------------------------
1 | :page-title: BIPs
2 | :page-nav_order: 180
3 | :page-parent: Overview and Development Process
4 | [[bips]]
5 | == BIPs
6 |
7 | Bitcoin uses Bitcoin Improvement Proposals (BIPs) as a design document for introducing new features or behaviour into bitcoin.
8 | Bitcoin Magazine describes what a BIP is in their article https://bitcoinmagazine.com/guides/what-is-a-bitcoin-improvement-proposal-bip[What Is A Bitcoin Improvement Proposal (BIP)^], specifically highlighting how BIPs are not necessarily binding documents required to achieve consensus.
9 |
10 | The BIPs are currently hosted on GitHub in the bitcoin/bips https://github.com/bitcoin/bips[repo^].
11 |
12 | [TIP]
13 | .BIP process
14 | ====
15 | The BIPs include https://github.com/bitcoin/bips/tree/master/bip-0002.mediawiki[BIP 2^] which self-describes the BIP process in more detail.
16 | Of particular interest might be the sections https://github.com/bitcoin/bips/tree/master/bip-0002.mediawiki#BIP_types[BIP Types^] and https://github.com/bitcoin/bips/tree/master/bip-0002.mediawiki#BIP_workflow[BIP Workflow^].
17 | ====
18 |
19 | === What does having a BIP number assigned to an idea mean
20 |
21 | Bitcoin Core https://github.com/bitcoin/bitcoin/pull/22665[issue #22665^] described how BIP125 was not being strictly adhered to by Bitcoin Core.
22 | This raised discussion amongst developers about whether the code (i.e. "the implementation") or the BIP itself should act as the specification, with most developers expressing that they felt that "the code was the spec" and any BIP generated was merely a design document to aid with re-implementation by others, and should be corrected if necessary.
23 |
24 | NOTE: This view was not completely unanimous in the community.
25 |
26 | For consensus-critical code most Bitcoin Core Developers consider "the code is the spec" to be the ultimate source of truth, which is one of the reasons that recommending running other full node implementations can be so difficult.
27 | A knock-on effect of this was that there were calls for review on BIP2 itself, with respect to how BIPs should be updated/amended.
28 | Newly-appointed BIP maintainer Karl-Johan Alm (a.k.a. kallewoof) posted his thoughts on this to the https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-September/019457.html[bitcoin-dev mailing list^].
29 |
30 | In summary a BIP represents a design document which should assist others in implementing a specific feature in a compatible way.
31 | These features are optional to usage of Bitcoin, and therefore implementation of BIPs are not required to use Bitcoin, only to remain compatible.
32 | Simply being _assigned_ a BIP does *not* mean that an idea is endorsed as being a "good" idea, only that it is fully-specified in a way that others could use to re-implement.
33 | Many ideas are assigned a BIP and then never implemented or used on the wider network.
34 |
--------------------------------------------------------------------------------
/bitcoin-design.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Bitcoin design
2 | :page-nav_order: 30
3 | :page-parent: GUI
4 | == Bitcoin design
5 |
6 | The https://bitcoin.design/guide/[Bitcoin design guide^] provides some guidance on common pitfalls that Bitcoin GUI designers should look out for when designing apps (like `bitcoin-qt`).
7 |
8 |
--------------------------------------------------------------------------------
/bootstrapping.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Bootstrapping
2 | :page-nav_order: 50
3 | :page-parent: P2P
4 | [[bootstrapping]]
5 | == Bootstrapping
6 |
7 | Bootstrapping is probably the most dangerous moment in a node's life.
8 | If the new node cannot make at least one connection to an honest node, from whom it can eventually learn more honest addresses, then it may not ever be able to join the most-work bitcoin chain without manual user intervention.
9 |
10 | NOTE: Manual intervention here would require the user to find the IP address of a known-honest node and connect to it either using `addnode` or `connect`.
11 |
12 | When the node first starts up, and if no node addresses are manually specified, we have no choice but to fetch addresses from one (or more) hardcoded DNS seed(s) the list of which can be found in https://github.com/bitcoin/bitcoin/blob/v23.0/src/chainparams.cpp#L121-L129[_src/chainparams.cpp_^].
13 |
14 | If the node is fed only attacker-controlled addresses by one or more dishonest DNS seed(s) then it has little opportunity to join the rest of the honest network.
15 | However, if one or more of the addresses returned by the DNS query are honest then we want the node to be able to (eventually) find and connect to the honest network.
16 |
17 | Note that if the DNS seed queries are unsuccessful, or the node is being run in a Tor-only mode (and currently the DNS seeds cannot support long Tor V3 addresses) then bitcoind will fall back to connecting to a hard-coded https://github.com/bitcoin/bitcoin/blob/v23.0/src/chainparamsseeds.h[list^] of seed nodes.
18 | This fall back functionality could help to protect against e.g. an attack on the DNS seed infrastructure.
19 |
20 | [[service_flags]]
21 | == Service flags
22 |
23 | Nodes can advertise https://github.com/bitcoin/bitcoin/blob/v24.0.1/src/protocol.h#L266-L296[service flags] (a.k.a. "service bits") indicating which services that node supports.
24 |
25 | == Managing connections
26 |
27 | An enumeration of the different types of connections, along with detailed descriptions on their functions, can be found in https://github.com/bitcoin/bitcoin/blob/v23.0/src/net.h#L117-L184[src/_net.h_].
28 |
29 |
--------------------------------------------------------------------------------
/build.adoc:
--------------------------------------------------------------------------------
1 | = Build system
2 | :page-nav_order: 80
3 |
4 | [source,cpp]
5 | ----
6 | return Error("Build system section not implemented yet!");
7 | ----
8 |
9 |
--------------------------------------------------------------------------------
/building.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Building Bitcoin Core
2 | :page-nav_order: 70
3 | :page-parent: Overview and Development Process
4 | === Building from source
5 |
6 | When building Bitcoin Core from source, there are some platform-dependant instructions to follow.
7 |
8 | To learn how to build for your platform, visit the Bitcoin Core https://github.com/bitcoin/bitcoin/tree/master/doc[bitcoin/doc^] directory, and read the file named "build-\*.md", where "*" is the name of your platform.
9 | For windows this is "build-windows.md", for macOS this is "build-osx.md" and for most linux distributions this is "build-unix.md".
10 |
11 | There is also a guide by Jon Atack on how to https://jonatack.github.io/articles/how-to-compile-bitcoin-core-and-run-the-tests[compile and test Bitcoin Core^].
12 |
13 | Finally, Blockchain Commons also offer a guide to https://github.com/BlockchainCommons/Learning-Bitcoin-from-the-Command-Line/blob/master/A2_0_Compiling_Bitcoin_from_Source.md[building from source^].
14 |
15 | ==== Cleaner builds
16 |
17 | It can be helpful to use a separate build directory e.g. `build/` when compiling from source.
18 | This can help avoid spurious Linker errors without requiring you to run `make clean` often.
19 |
20 | From within your Bitcoin Core source directory you can run:
21 |
22 | [source,bash]
23 | ----
24 | # Clean current source dir in case it was already configured
25 | make distclean
26 |
27 | # Make new build dir
28 | mkdir build && cd build
29 |
30 | # Run normal build sequence with amended path
31 | ../autogen.sh
32 | ../configure --your-normal-options-here
33 | make -j `nproc`
34 | make check
35 | ----
36 |
37 | [TIP]
38 | ====
39 | To run individual functional tests using the bitcoind binary built in an out-of-source build change directory back to the root source and specify the _config.ini_ file from within the build directory:
40 |
41 | [source,bash]
42 | ----
43 | $ pwd
44 | /path/to/source/build
45 | $ cd ..
46 | $ test/functional/p2p_ping.py --configfile build/test/config.ini
47 | ----
48 | ====
49 |
--------------------------------------------------------------------------------
/codedocs.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Codebase documentation
2 | :page-nav_order: 80
3 | :page-parent: Overview and Development Process
4 | === Codebase documentation
5 |
6 | Bitcoin Core uses https://www.doxygen.nl/index.html[Doxygen^] to generate developer documentation automatically from its annotated C++ codebase.
7 | Developers can access documentation of the current release of Bitcoin Core online at https://doxygen.bitcoincore.org/[doxygen.bitcoincore.org^], or alternatively can generate documentation for their current git `HEAD` using `make docs` (see https://github.com/bitcoin/bitcoin/tree/master/doc/developer-notes.md#generating-documentation[Generating Documentation^] for more info).
8 |
--------------------------------------------------------------------------------
/coin-selection.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Coin selection
2 | :page-nav_order: 40
3 | :page-parent: Wallet
4 | include::links-onepage.adoc[]
5 | [id=coin-selection-overview]
6 | === Coin selection
7 |
8 | See https://bitcoinops.org/en/topics/coin-selection/[Bitcoin Optech^] for more information on coin selection.
9 | There is a section digging deeper into the coin selection code found xref:constructing-transactions.adoc#coin-selection[below].
10 | To select inputs to a transaction our primary considerations are privacy and fees.
11 |
12 | The below sections form an overview of creating a transaction via `CreateTransactionInternal()`.
13 |
14 | ==== `AvailableCoins()`
15 |
16 | The gist of how we generate a list of coins available to spend (via `AvailableCoins()`) is that we iterate `mapWallet` and check for coins that:
17 |
18 | * Are not immature coinbase outputs
19 | * Are not conflicted
20 | * Must be at least in our mempool
21 | * Not currently replacing or being replaced by another transaction
22 | * Are not locked
23 | * Are `IsMine`
24 | * Are `spendable`
25 |
26 | ...and return them as a `std::vector`.
27 |
28 | [id=GroupOutputs]
29 | ==== `GroupOutputs()`
30 |
31 | Once we have this vector of coins `GroupOutputs()` will turn them into ``OutputGroup``s.
32 | An `OutputGroup` consists of outputs with the same script, i.e. "coins sent to the same address".
33 |
34 | ////
35 | Effective Value is = Coins value - Fee
36 | ////
37 |
38 | [id=selectCoins]
39 | ==== `selectCoins()`
40 |
41 | If you manually choose inputs, it will add outputs to the transaction automatically.
42 | It tries first to make sure that all outputs selected have 6 confirmations, if unsuccessful it then tries again with 1 confirmation as the lower bound.
43 |
44 | For change outputs it starts with 1 confirmation and then again with 0.
45 | If this is still unsuccessful it increases the number of ancestors and descendants that unconfirmed change can have.
46 |
47 | ==== `AttemptSelection()`
48 |
49 | This function is orchestrating the <> creation, and then the <>.
50 | Currently, this is always based on the xref:constructing-transactions.adoc#coin-selection[waste metric].
51 |
52 | It is using 3 algorithms and then selecting the "best" of the three (based on the waste metric):
53 |
54 | . Branch n bound (bnb)
55 | . Knapsack
56 | . Single Random Draw (SRD)
57 |
58 | There is currently an idea that a limited SRD could replace Knapsack in the future.
59 | Due to this plan for removal, it would not make sense to focus development effort on improving the Knapsack algorithm at this time.
60 |
--------------------------------------------------------------------------------
/comms.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Communication channels
2 | :page-nav_order: 120
3 | :page-parent: Overview and Development Process
4 | === #bitcoin-core-dev IRC channel
5 |
6 | The Bitcoin Core project has an IRC channel `#bitcoin-core-dev` available on the Libera.chat network.
7 | If you are unfamiliar with IRC there is a short guide on how to use it with a client called Matrix https://hackmd.io/ZcCoEDnOSTSqb2RDa7fB8Q[here^].
8 | IRC clients for all platforms and many terminals are available.
9 |
10 | "Lurking" (watching but not talking) in the IRC channel can both be a great way to learn about new developments as well as observe how new technical changes and issues are described and thought about from other developers with an adversarial mindset.
11 | Once you are comfortable with the rules of the room and have questions about development then you can join in too!
12 |
13 | [NOTE]
14 | ====
15 | This channel is reserved for discussion about _development of the Bitcoin Core software only_, so please don't ask general Bitcoin questions or talk about the price or other things which would be off topic in there.
16 |
17 | There are plenty of other channels on IRC where those topics can be discussed.
18 | ====
19 |
20 | There are also regular meetings held on #bitcoin-core-dev which are free and open for anyone to attend.
21 | Details and timings of the various meetings are found https://bitcoincore.org/en/meetings/[here^].
22 |
23 | === Communication
24 |
25 | In reality there are no hard rules on choosing a discussion forum, but in practice there are some common conventions which are generally followed:
26 |
27 | * If you want to discuss the codebase of the Bitcoin Core implementation, then discussion on either the GitHub repo or IRC channel is usually most-appropriate.
28 | * If you want to discuss changes to the core bitcoin protocol, then discussion on the mailing list is usually warranted to solicit feedback from (all) bitcoin developers, including the many of them that do not work on Bitcoin Core directly.
29 | ** If mailing list discussions seem to indicate interest for a proposal, then creation of a BIP usually follows.
30 |
31 | If discussing something Bitcoin Core-related, there can also be a question of whether it's best to open an Issue, to first discuss the problem and brainstorm possible solution approaches, or whether you should implement the changes as you see best first, open a PR, and then discuss changes in the PR.
32 | Again, there are no hard rules here, but general advice would be that for potentially-controversial subjects, it might be worth opening an Issue first, before (potentially) wasting time implementing a PR fix which is unlikely to be accepted.
33 |
34 | Regarding communication timelines it is important to remember that many contributors are unpaid volunteers, and even if they are sponsored or paid directly, nobody owes you their time.
35 | That being said, often during back-and-forth communication you might want to nudge somebody for a response and it's important that you do this in a courteous way.
36 | There are again no hard rules here, but it's often good practice to give somebody on the order of a few days to a week to respond.
37 | Remember that people have personal lives and often jobs outside of Bitcoin development.
38 |
--------------------------------------------------------------------------------
/consensus-and-validation.adoc:
--------------------------------------------------------------------------------
1 | :page-nav_order: 20
2 | :page-has_children: true
3 | include::links-onepage.adoc[]
4 | = Consensus and Validation
5 |
6 | TIP: This section has been updated to Bitcoin Core @ https://github.com/bitcoin/bitcoin/tree/v23.0[v23.0^]
7 |
8 | One of the fundamental concepts underlying bitcoin is that nodes on the network are able to maintain decentralized consensus on the ordering of transactions in the system.
9 |
10 | The primary mechanism at work is that all nodes validate every block, and every transaction contained within that block, against their own copy of the consensus rules.
11 | The secondary mechanism is that in the event of a discrepancy between two competing chain tips nodes should follow the chain with the most cumulative proof-of-work.
12 | The result is that all honest nodes in the network will eventually converge onto a single, canonical, valid chain.
13 |
14 | WARNING: If all nodes do not compute consensus values identically (including edge cases) a chainsplit will result.
15 |
16 | For more information on how the bitcoin networks' decentralized consensus mechanism works see the Mastering Bitcoin section on https://github.com/bitcoinbook/bitcoinbook/tree/develop/ch10.asciidoc#decentralized-consensus[decentralized consensus^].
17 |
18 | TIP: In Bitcoin Core there are an extra level of validation checks applied to incoming transactions in addition to consensus checks called "policy" which have a slightly different purpose, see xref:consensus-v-policy.adoc#consensus_vs_policy[consensus vs policy] for more information on the differences between the two.
19 |
20 | Consensus::
21 | A collection of functions and variables which **must** be computed identically to all https://bitnodes.io/nodes/[other^] nodes on the network in order to remain in consensus and therefore on the main chain.
22 |
23 | Validation::
24 | Validation of blocks, transactions and scripts, with a view to permitting them to be added to either the blockchain (must pass consensus checks) or our local mempool (must pass policy checks).
25 |
--------------------------------------------------------------------------------
/consensus-libraries.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Consensus libraries
2 | :page-nav_order: 70
3 | :page-parent: Consensus and Validation
4 | == libbitcoinkernel
5 |
6 | The https://github.com/bitcoin/bitcoin/issues/24303[libbitcoinkernel^] project seeks to modularise Bitcoin Cores' consensus engine and make it easier for developers to reason about when they are modifying code which could be consensus-critical.
7 |
8 | This project differs from `libbitcoinconsensus` in that it is designed to be a stateful engine, with a view to eventually: being able to spawn its own threads, do caching (e.g. of script and signature verification), do its own I/O, and manage dynamic objects like a mempool.
9 | Another benefit of fully extracting the consensus engine in this way may be that it becomes easier to write and reason about consensus test cases.
10 |
11 | In the future, if a full de-coupling is successfully completed, other Bitcoin applications might be able to use `libbitcoinkernel` as their own consensus engine permitting multiple full node implementations to operate on the network in a somewhat safer manner than many of them operate under today.
12 | The initial objective of this library however is to actually have it used by Bitcoin Core internally, something which is not possible with libbitcoinconsensus due to it's lack of caching and state (making it too slow to use).
13 |
14 | Some examples have surfaced recently where script validation in the BTCD code (used internally by LND) has diverged from the results from Bitcoin Core:
15 |
16 | . https://twitter.com/brqgoo/status/1579216353780957185[Witness size check^]: https://github.com/lightningnetwork/lnd/issues/7002[issue^] and https://github.com/btcsuite/btcd/pull/1896[fix^]
17 | . https://twitter.com/brqgoo/status/1587397646125260802[Max witness items check^]: https://github.com/btcsuite/btcd/issues/1906[issue^] and https://github.com/btcsuite/btcd/pull/1907[fix^].
18 |
19 | The implementation approaches of libbitcoinconsensus and libbitcoinkernel also differ; with lb-consensus parts of consensus were moved into the library piece by piece, with the eventual goal that it would be encapsulated.
20 | lb-kernel takes a different approach -- first cast a super wide net around everything needed to run a consensus engine, and then gradually strip pieces out where they can be.
21 | In theory this should get us something which Bitcoin Core can use much faster (in fact, you can build the optional `bitcoin-chainstate` binary which already has some functionality).
22 |
23 | Part of libbitcoinkernel has been merged in via Carl Dong's https://github.com/bitcoin/bitcoin/pull/24304[`bitcoin-chainstate` PR^].
24 | It also has its own project https://github.com/bitcoin/bitcoin/projects/18[board^] to track progress.
25 |
26 | == libbitcoinconsensus
27 |
28 | The libbitcoinconsensus library has been deprecated since Bitcoin Core v27.0, with the Release Note:
29 |
30 | [quote]
31 | ____
32 | libbitcoinconsensus is deprecated and will be removed for v28. This library has
33 | existed for nearly 10 years with very little known uptake or impact. It has
34 | become a maintenance burden.
35 |
36 | The underlying functionality does not change between versions, so any users of
37 | the library can continue to use the final release indefinitely, with the
38 | understanding that Taproot is its final consensus update.
39 |
40 | In the future, libbitcoinkernel will provide a much more useful API that is
41 | aware of the UTXO set, and therefore be able to fully validate transactions and
42 | blocks. (#29189)
43 | ____
44 |
--------------------------------------------------------------------------------
/consensus-model.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Consensus model
2 | :page-nav_order: 10
3 | :page-parent: Consensus and Validation
4 | === Consensus model
5 |
6 | The consensus model in the codebase can be thought of as a database of the current state of the blockchain.
7 | When a new block is learned about it is processed and the consensus code must determine which block is the current best.
8 | Consensus can be thought of as a function of available information -- it's output is simply a deterministic function of its input.
9 |
10 | There are a simple set of rules for determining the best block:
11 |
12 | . Only consider valid blocks
13 | . Where multiple chains exist choose the one with the most cumulative Proof of Work (PoW)
14 | . If there is a tie-breaker (same height and work), then use first-seen
15 |
16 | The result of these rules is a tree-like structure from genesis to the current day, building on only valid blocks.
17 |
18 | Whilst this is easy-enough to reason about in theory, the implementation doesn't work exactly like that.
19 | It must consider state, do I go forward or backwards for example.
20 |
21 | == Validation in Bitcoin Core
22 |
23 | Originally consensus and validation were much of the same thing, in the same source file.
24 | However splitting of the code into strongly delineated sections was never fully completed, so validation.* files still hold some consensus codepaths.
25 |
26 |
--------------------------------------------------------------------------------
/consensus-specification.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Consensus specification
2 | :page-nav_order: 60
3 | :page-parent: Consensus and Validation
4 | include::links-onepage.adoc[]
5 | == Bitcoin core consensus specification
6 |
7 | A common question is where the bitcoin protocol is documented, i.e. specified.
8 | However bitcoin does not have a formal specification, even though many ideas have some specification (in xref:bips.adoc[BIPS]) to aid re-implementation.
9 |
10 | IMPORTANT: The requirements to be compliant with "the bitcoin spec" are to be bug-for-bug compatible with the Bitcoin Core implementation.
11 |
12 | The reasons for Bitcoin not having a codified specification are historical; Satoshi never released one.
13 | Instead, in true "Cypherpunks write code" style and after releasing a general whitepaper, they simply released the first client.
14 | This client existed on it's own for the best part of two years before others sought to re-implement the rule-set in other clients:
15 |
16 | * https://github.com/libbitcoin/libbitcoin-system/commit/9dea4682bf0e4247f3c4cb8a6c140ade61bf7df7[libbitcoin^]
17 | * https://github.com/bitcoinj/bitcoinj/commit/d1036b101f01b7ab79fc3e10e5199f80f478674d[BitcoinJ^]
18 |
19 | A forum https://bitcointalk.org/index.php?topic=195.msg1611#msg1611[post^] from Satoshi in June 2010 had however previously discouraged alternative implementations with the rationale:
20 |
21 | [quote,Satoshi Nakamoto]
22 | ____
23 | ...
24 |
25 | I don't believe a second, compatible implementation of Bitcoin will ever be a good idea. So much of the design depends on all nodes getting exactly identical results in lockstep that a second implementation would be a menace to the network. The MIT license is compatible with all other licenses and commercial uses, so there is no need to rewrite it from a licensing standpoint.
26 | ____
27 |
28 | It is still a point of contention amongst some developers in the community, however the fact remains that if you wish to remain in consensus with the majority of (Bitcoin Core) nodes on the network, you must be _exactly_ bug-for-bug compatible with Bitcoin Core's consensus code.
29 |
30 | TIP: If Satoshi _had_ launched Bitcoin by providing a specification, could it have ever been specified well-enough to enable us to have multiple node implementations?
31 |
32 | [TIP]
33 | ====
34 | One mechanism often employed by those who want to run custom node software is to position an up-to-date Bitcoin Core node to act as a "gateway" to the network.
35 | Internally your own node can then make a single connection to this Bitcoin Core node.
36 | This means that your custom internal node will now only receive transactions and blocks which have passed Bitcoin Core's consensus (or policy) checks, allowing you to be sure that your custom node is not accepting objects which could cause you to split onto a different chain tip.
37 | ====
38 |
--------------------------------------------------------------------------------
/consensus-v-policy.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Consensus vs Policy
2 | :page-nav_order: 20
3 | :page-parent: Consensus and Validation
4 | [[consensus_vs_policy]]
5 | == Consensus vs Policy
6 |
7 | What is the difference between consensus and policy checks?
8 | Both seem to be related to validating transactions.
9 | We can learn a lot about the answer to this question from sdaftuar's StackExchange https://bitcoin.stackexchange.com/questions/100317/what-is-the-difference-between-policy-and-consensus-when-it-comes-to-a-bitcoin-c/100319#100319[answer^].
10 |
11 | The answer teaches us that policy checks are a superset of validation checks -- that is to say that a transaction that passes policy checks has implicitly passed consensus checks too.
12 | Nodes perform policy-level checks on all transactions they learn about before adding them to their local mempool.
13 | Many of the policy checks contained in `policy` are called from inside `validation`, in the context of adding a new transaction to the mempool.
14 |
15 |
--------------------------------------------------------------------------------
/contributing.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Contributing code
2 | :page-nav_order: 30
3 | :page-parent: Overview and Development Process
4 | === Contributing code
5 |
6 | This section details some of the processes surrounding code contributions to the Bitcoin Core project along with some common pitfalls and tips to try and avoid them.
7 |
8 | ==== Branches
9 |
10 | You should *not* use the built-in GitHub branch https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-and-deleting-branches-within-your-repository[creation^] process, as this interferes with and confuses the Bitcoin Core git process.
11 |
12 | Instead, you should use either the native https://git-scm.com/downloads[`git`^] or the GitHub https://github.com/cli/cli[`gh` cli^] (requires `git`) tools to create your own branches locally, before pushing them to your fork of the repo, and opening a PR against the Bitcoin Core repo from there.
13 |
14 | ==== Creating a PR
15 |
16 | Jon Atack's article https://jonatack.github.io/articles/how-to-contribute-pull-requests-to-bitcoin-core[How To Contribute Pull Requests To Bitcoin Core^] describes some less-obvious requirements that any PR you make might be subjected to during peer review, for example that it needs an accompanying test, or that an intermediate commit on the branch doesn't compile.
17 | It also describes the uncodified expectation that Contributors should not only be writing code, but perhaps more importantly be providing reviews on other Contributors' PRs.
18 | Most developers enjoy writing their own code more than reviewing code from others, but the decentralized review process is arguably the most critical defence Bitcoin development has against malicious actors and therefore important to try and uphold.
19 |
20 | IMPORTANT: Jon's estimates of "5-15 PR reviews|issues solved" per PR submitted is not a hard requirement, just what Jon himself feels would be best for the project. Don't be put off submitting a potentially valuable PR just because "you haven't done enough reviews"!
21 |
22 | For some tips on how to maintain an open PR using git, such as how to redo commit history, as well as edit specific commits, check out this https://github.com/satsie/bitcoin-notez/blob/master/bitcoin-core-development/git-guide.md[guide^].
23 |
24 | ==== Commit messages
25 |
26 | When writing commit messages be sure to have read Chris Beams' "How to Write a Git Commit Message" https://chris.beams.io/posts/git-commit/[blog post^].
27 | As described in CONTRIBUTING.md, PRs should be prefixed with the component or area the PR affects.
28 | Common areas are listed in CONTRIBUTING.md section: https://github.com/bitcoin/bitcoin/tree/master/CONTRIBUTING.md#creating-the-pull-request[Creating the pull request^].
29 | Individual commit messages are also often given similar prefixes in the commit title depending on which area of the codebase the changes primarily affect.
30 |
31 | [TIP]
32 | ====
33 | Unless there is a merge conflict (usually detected by DrahtBot), don't rebase your changes on master branch before pushing.
34 | If you avoid rebases on upstream, Github will show a very useful "Compare" button which reviewers can often use to quickly re-ACK the new changes if they are sufficiently small.
35 | If you _do_ rebase this button becomes useless, as all the rebased changes from master get included and so a full re-review may be needed.
36 | Developer review time is currently our major bottleneck in the project!
37 | ====
38 |
--------------------------------------------------------------------------------
/contributors.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Project roles
2 | :page-nav_order: 160
3 | :page-parent: Overview and Development Process
4 | == Organisation & roles
5 |
6 | The objective of the Bitcoin Core Organisation is to represent an entity that is decentralized as much as practically possible on a centralised platform.
7 | One where no single Contributor, Member, or Maintainer has unilateral control over what is/isn't merged into the project.
8 | Having multiple Maintainers, Members, Contributors, and Reviewers gives this objective the best chance of being realised.
9 |
10 | === Contributors
11 |
12 | Anyone who contributes code to the codebase is labelled a Contributor by GitHub and also by the community.
13 | As of Version 23.0 of Bitcoin Core, there are > 850 individual Contributors credited with changes.
14 |
15 | === Members
16 |
17 | Some Contributors are also labelled as Members of the https://github.com/orgs/bitcoin/people[Bitcoin organisation^].
18 | There are no defined criteria for becoming a Member of the organisation; persons are usually nominated for addition or removal by current Maintainer/Member/Admin on an ad-hoc basis.
19 | Members are typically frequent Contributors/Reviewers and have good technical knowledge of the codebase.
20 |
21 | Some members also have some additional permissions over Contributors, such as adding/removing tags on issues and Pull Requests (PRs); however, being a Member **does not** permit you to merge PRs into the project.
22 | Members can also be assigned sections of the codebase in which they have specific expertise to be more easily requested for review as Suggested Reviewers by PR authors.
23 |
24 | ////
25 | NOTE: It is neither necessary nor desirable to "request reviews" from suggested reviewers in a normal workflow. Doing so without a good reason might be interpreted as being pushy and having the opposite result than intended.
26 | ////
27 |
28 | === Maintainers
29 |
30 | Some organisation Members are also project Maintainers.
31 | The number of maintainers is arbitrary and is subject to change as people join and leave the project, but has historically been less than 10.
32 | PRs can only be merged into the main project by Maintainers.
33 | While this might give the illusion that Maintainers are in control of the project, the Maintainers' role dictates that they *should not* be unilaterally deciding which PRs get merged and which don't.
34 | Instead, they should be determining the mergability of changes based primarily on the reviews and discussions of other Contributors on the GitHub PR.
35 |
36 | Working on that basis, the Maintainers' role becomes largely _janitorial_.
37 | They are simply executing the desires of the community review process, a community which is made up of a decentralized and diverse group of Contributors.
38 |
39 | ////
40 | A list of Maintainers and suggested Reviewers can be found in the https://github.com/bitcoin/bitcoin/tree/master/REVIEWERS[REVIEWERS^] document.
41 | As the document states, these are *not* the only people who should be reviewing PRs.
42 | The project needs as many reviews on each PR as possible, ideally from a diverse range of Reviewers.
43 | ////
44 |
45 | === Organisation fail-safes
46 |
47 | It is possible for a "rogue PR" to be submitted by a Contributor; we rely on systematic and thorough peer review to catch these.
48 | There has been https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-September/019490.html[discussion^] on the mailing list about purposefully submitting malicious PRs to test the robustness of this review process.
49 |
50 | In the event that a Maintainer goes rogue and starts merging controversial code, or conversely, _not_ merging changes that are desired by the community at large, then there are two possible avenues of recourse:
51 |
52 | . Have the Lead Maintainer remove the malicious Maintainer
53 | . In the case that the Lead Maintainer themselves is considered to be the rogue agent: fork the project to a new location and continue development there.
54 |
55 | In the case that GitHub itself becomes the rogue entity, there have been numerous discussions about how to move away from GitHub, which have been summarized on the devwiki https://github.com/bitcoin-core/bitcoin-devwiki/wiki/GitHub-alternatives-for-Bitcoin-Core[here^].
56 | This summary came in part from discussions on https://github.com/bitcoin/bitcoin/issues/20227[this^] GitHub issue.
57 |
--------------------------------------------------------------------------------
/controlling-the-wallet.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Wallet locks
2 | :page-nav_order: 80
3 | :page-parent: Wallet
4 | == Controlling the wallet
5 |
6 | As we can see wallet component startup and shutdown is largely driven from outside the wallet codebase from _src/init.cpp_.
7 |
8 | Once the wallet component is started and any wallets supplied via argument have been verified and loaded, wallet functionality ceases to be called from _init.cpp_ and instead is controlled using external programs in a number of ways.
9 | The wallet can be controlled using `bitcoin-cli` or `bitcoin-qt` GUI, and wallet files can be interacted with using the stand-alone `bitcoin-wallet` tool.
10 |
11 | Both `bitcoind` and `bitcoin-qt` run a (JSON) RPC server which is ready to service, amongst other things, commands to interact with wallets.
12 | The command line tool `bitcoin-cli` will allow interaction of any RPC server started by either `bitcoind` or `bitcoin-qt`.
13 |
14 | TIP: If using `bitcoin-qt` there is also an RPC console built into the GUI or you can run with `-server=1` to allow access via `bitcoin-cli`.
15 |
16 | If using the `bitcoin-qt` GUI itself then communication with the wallet is done directly via qt's https://github.com/bitcoin/bitcoin/blob/v23.0/src/qt/walletmodel.h#L51-L52[`WalletModel` interface^].
17 |
18 | Commands which can be used to control the wallet via RPC are listed in https://github.com/bitcoin/bitcoin/blob/v23.0/src/wallet/rpc/wallet.cpp#L662-L731[_rpcwallet.cpp_^].
19 |
20 | === Wallet via RPC
21 |
22 | If we take a look at the https://github.com/bitcoin/bitcoin/blob/v23.0/src/wallet/rpc/wallet.cpp#L195-L238[`loadwallet` RPC^] we can see similarities to ``WalletClientImpl``'s `LoadWallets()` function.
23 |
24 | However this time the function will check the `WalletContext` to check that we have a wallet context (in this case a reference to a chain interface) loaded.
25 | Next it will call https://github.com/bitcoin/bitcoin/blob/v23.0/src/wallet/wallet.cpp#L260-L271[`wallet.cpp#LoadWallet`^] which starts by grabbing `g_loading_wallet_mutex` and adding the wallet to `g_loading_wallet_set`, before calling https://github.com/bitcoin/bitcoin/blob/v23.0/src/wallet/wallet.cpp#L227-L257[`LoadWalletInternal`^] which adds the wallet to `vpwallets` and sets up various event notifications.
26 |
27 | Further operation of the wallet RPCs are detailed in their man pages, but one thing to take note of is that whilst `loadwallet()` (and `unloadwallet()`) both take a `wallet_name` argument, the other wallet RPCs do not.
28 | Therefore in order to control a specific wallet from an instance of `bitcoin{d|-qt}` that has multiple wallets loaded, bitcoin-cli must be called with the `-rpcwallet` argument, to specify the wallet which the action should be performed against, e.g. `bitcoin-cli --rpcwallet=your_wallet_name getbalance`
29 |
30 | === Via `bitcoin-cli` tool
31 |
32 | ****
33 | Blockchain Commons contains numerous guides and examples of controlling the wallet using `bitcoin-cli`, including:
34 |
35 | * https://github.com/BlockchainCommons/Learning-Bitcoin-from-the-Command-Line/blob/master/04_0_Sending_Bitcoin_Transactions.md[Sending Bitcoin Transactions^] including using raw transactions
36 | * https://github.com/BlockchainCommons/Learning-Bitcoin-from-the-Command-Line/blob/master/05_0_Controlling_Bitcoin_Transactions.md[Controlling Bitcoin Transactions^] using RBF and CPFP
37 | * https://github.com/BlockchainCommons/Learning-Bitcoin-from-the-Command-Line/blob/master/06_0_Expanding_Bitcoin_Transactions_Multisigs.md[Using multisig^] to send and receive
38 | * https://github.com/BlockchainCommons/Learning-Bitcoin-from-the-Command-Line/blob/master/07_0_Expanding_Bitcoin_Transactions_PSBTs.md[Creating and using PSBTs^] and integrating them with hardware wallets
39 | * https://github.com/BlockchainCommons/Learning-Bitcoin-from-the-Command-Line/blob/master/08_0_Expanding_Bitcoin_Transactions_Other.md[Adding locktimes and OP_RETURN data^]
40 | ****
41 |
--------------------------------------------------------------------------------
/css/asciidoc.css:
--------------------------------------------------------------------------------
1 | span.icon > .fa {
2 | cursor: default;
3 | }
4 | .admonitionblock td.icon {
5 | text-align: center;
6 | width: 80px;
7 | }
8 | .admonitionblock td.icon [class^="fa icon-"] {
9 | font-size: 2.5em;
10 | text-shadow: 1px 1px 2px rgba(0,0,0,.5);
11 | cursor: default;
12 | }
13 | .admonitionblock td.icon .icon-note:before {
14 | content: "\f05a";
15 | color: #19407c;
16 | }
17 | .admonitionblock td.icon .icon-tip:before {
18 | content: "\f0eb";
19 | text-shadow: 1px 1px 2px rgba(155,155,0,.8);
20 | color: #111;
21 | }
22 | .admonitionblock td.icon .icon-warning:before {
23 | content: "\f071";
24 | color: #bf6900;
25 | }
26 | .admonitionblock td.icon .icon-caution:before {
27 | content: "\f06d";
28 | color: #bf3400;
29 | }
30 | .admonitionblock td.icon .icon-important:before {
31 | content: "\f06a";
32 | color: #bf0000;
33 | }
34 |
--------------------------------------------------------------------------------
/cwallet.adoc:
--------------------------------------------------------------------------------
1 | :page-title: CWallet
2 | :page-nav_order: 100
3 | :page-parent: Wallet
4 | include::links-onepage.adoc[]
5 | == CWallet
6 |
7 | The `CWallet` object is the fundamental wallet representation inside Bitcoin Core.
8 | `CWallet` stores transactions and balances and has the ability to create new transactions.
9 | `CWallet` also contains references to the chain interface for the wallet along with storing wallet metadata such as `nWalletVersion`, wallet flags, wallet name and address book.
10 |
11 | === CWallet creation
12 |
13 | The `CWallet` constructor takes a pointer to the chain interface for the wallet, a wallet name and a pointer to the underlying `WalletDatabase`:
14 |
15 | The constructor is not called directly, but instead from the public function `CWallet::Create()`, which is itself called from `CreateWallet()`, `LoadWallets()` (or `TestLoadWallet()`).
16 | In addition to the arguments required by the constructor, `CWallet::Create()` also has a `wallet_flags` argument.
17 | Wallet flags are represented as a single `unit64_t` bit field which encode certain wallet properties:
18 |
19 | .src/wallet/walletutil.h
20 | [source,cpp,options=nowrap]
21 | ----
22 | enum WalletFlags : uint64_t {
23 | WALLET_FLAG_AVOID_REUSE = (1ULL << 0),
24 | WALLET_FLAG_KEY_ORIGIN_METADATA = (1ULL << 1),
25 | WALLET_FLAG_DISABLE_PRIVATE_KEYS = (1ULL << 32),
26 | WALLET_FLAG_BLANK_WALLET = (1ULL << 33),
27 | WALLET_FLAG_DESCRIPTORS = (1ULL << 34),
28 | WALLET_FLAG_EXTERNAL_SIGNER = (1ULL << 35),
29 | };
30 | ----
31 |
32 | See https://github.com/bitcoin/bitcoin/blob/v23.0/src/wallet/walletutil.h#L36-L70[_src/wallet/walletutil.h_^] for additional information on the meanings of the wallet flags.
33 |
34 | `CWallet::Create()` will first attempt to create the `CWallet` object and load it, returning if any errors are encountered.
35 |
36 | If `CWallet::Create` is creating a new wallet -- on its 'first run' -- the wallet version and wallet flags will be set, before either `LegacyScriptPubKeyMan` or ``DescriptorScriptPubKeyMan``'s are setup, depending on whether the `WALLET_FLAG_DESCRIPTORS` flag was set on the wallet.
37 |
38 | Following successful creation, various program arguments are checked and applied to the wallet.
39 | These include options such as `-addresstype`, `-changetype`, `-mintxfee` and `-maxtxfee` amongst others.
40 | It is at this stage that warnings for unusual or unsafe values of these arguments are generated to be returned to the user.
41 |
42 | After the wallet is fully initialized and setup, its keypool will be topped up before the wallet is locked and registered with the Validation interface, which will handle callback notifications generated during the (optional) upcoming chain rescan.
43 | The rescan is smart in detecting the wallet "birthday" using metadata stored in the xref:scriptpubkeymanagers.adoc#scriptpubkeymanagers[SPKM] and won't scan blocks produced before this date.
44 |
45 | Finally, the `walletinterface` is setup for the wallet before the `WalletInstance` is returned to the caller.
46 |
--------------------------------------------------------------------------------
/debugging.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Debugging Bitcoin Core
2 | :page-nav_order: 50
3 | :page-parent: Overview and Development Process
4 | ==== Debugging Bitcoin Core
5 |
6 | // Archived @ https://archive.is/hRExH
7 | Fabian Jahr has created a https://github.com/fjahr/debugging_bitcoin[guide^] on "Debugging Bitcoin Core", aimed at detailing the ways in which various Bitcoin Core components can be debugged, including the Bitcoin Core binary itself, unit tests, functional tests along with an introduction to core dumps and the Valgrind memory leak detection suite.
8 |
9 | Of particular note to Developers are the configure flags used to build Bitcoin Core without optimisations to permit more effective debugging of the various resulting binary files.
10 |
11 | Fabian has also presented on this topic a number of times.
12 | A https://btctranscripts.com/scalingbitcoin/tel-aviv-2019/edgedevplusplus/debugging-bitcoin/[transcript^] of his edgedevplusplus talk is available.
13 |
--------------------------------------------------------------------------------
/deep-arch.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Deep technical dive
2 | :page-nav_order: 80
3 | :page-parent: Architecture
4 | == Deep technical dive
5 |
6 | lsilva01 has written a deep technical dive into the architecture of Bitcoin Core as part of the Bitcoin Core Onboarding Documentation in https://github.com/chaincodelabs/bitcoin-core-onboarding/blob/main/1.0_bitcoin_core_architecture.asciidoc[Bitcoin Architecture^].
7 |
8 | Once you've gained some insight into the architecture of the program itself you can learn further details about which code files implement which functionality from the https://github.com/chaincodelabs/bitcoin-core-onboarding/blob/main/1.1_regions.asciidoc[Bitcoin Core regions^] document.
9 |
10 | James O'Beirne has recorded 3 videos which go into detail on how the codebase is laid out, how the build system works, what developer tools there are, as well as what the primary function of many of the files in the codebase are:
11 |
12 | . https://www.youtube.com/watch?v=J1Ru8V36z_Y[Architectural tour of Bitcoin Core (part 1 of 3)^]
13 | . https://www.youtube.com/watch?v=RVWcUnpZX4E[Architectural tour of Bitcoin Core (part 2 of 3)^]
14 | . https://www.youtube.com/watch?v=UiD5DZU9Zp4[Architectural tour of Bitcoin Core (part 3 of 3)^]
15 |
16 | ryanofsky has written a handy https://github.com/ryanofsky/bitcoin/blob/pr/libs/doc/design/libraries.md[guide^] covering the different libraries contained within Bitcoin Core, along with some of their conventions and a dependency graph for them.
17 | Generally speaking, the desire is for the Bitcoin Core project to become more modular and less monolithic over time.
18 |
--------------------------------------------------------------------------------
/design-principles.adoc:
--------------------------------------------------------------------------------
1 | :page-title: General design principles
2 | :page-nav_order: 10
3 | :page-parent: Architecture
4 | == General design principles
5 |
6 | Over the last decade, as the scope, complexity and test coverage of the codebase has increased, there has been a general effort to not only break Bitcoin Core down from its monolithic structure but also to move towards it being a collection of self-contained subsystems.
7 | The rationale for such a goal is that this makes components easier to reason about, easier to test, and less-prone to layer violations, as subsystems can contain a full view of all the information they need to operate.
8 |
9 | Subsystems can be notified of events relevant to them and take appropriate actions on their own.
10 | On the GUI/QT side this is handled with signals and slots, but in the core daemon this is largely still a producer/consumer pattern.
11 |
12 | The various subsystems are often suffixed with `Manager` or `man`, e.g. `CConnman` or `ChainstateManager`.
13 |
14 | TIP: The extra "C" in `CConnman` is a hangover from the https://en.wikipedia.org/wiki/Hungarian_notation[Hungarian notation^] used originally by Satoshi.
15 | This is being phased out as-and-when affected code is touched during other changes.
16 |
17 | You can see some (but not all) of these subsystems being initialized in https://github.com/bitcoin/bitcoin/blob/v23.0/src/init.cpp#L1113[_init.cpp#AppInitMain()_^].
18 |
19 | There is a recent preference to favour python over bash/sh for scripting, e.g. for linters, but many shell scripts remain in place for CI and contrib/ scripts.
20 |
--------------------------------------------------------------------------------
/docinfo-footer.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
34 |
--------------------------------------------------------------------------------
/docinfo.html:
--------------------------------------------------------------------------------
1 |
7 |
8 |
12 |
13 |
28 |
29 |
35 |
36 |
41 |
--------------------------------------------------------------------------------
/entries/bugs.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: "Quickstart: fixing bugs"
4 | nav_exclude: true
5 | ---
6 | # Quickstart: fixing bugs
7 |
8 | {% include best-way.md %}
9 |
10 | In this guide, we assume that you think you've discovered a bug. You
11 | may want to immediately report the bug, or you may want to begin
12 | debugging and fixing it yourself.
13 |
14 | - To report an issue:
15 |
16 | - You may want to quickly [mention](/comms.html) the behavior you
17 | think is a bug in chat to confirm it's unexpected behavior.
18 |
19 | - You should get [set up with GitHub](/github.html) to submit an
20 | issue.
21 |
22 | - To debug an issue:
23 |
24 | - You will need to [build Bitcoin
25 | Core](/building.html) optionally with [debugging
26 | options](/debugging.html).
27 |
28 | - You may want to [write a test](/testing.html) that demonstrates your
29 | bug and will prove it's been fixed.
30 |
31 | - If you need certain network activity to reproduce your bug, you can
32 | test on [test networks](/testnets.html).
33 |
34 | - If you're trying to find a particular file, learn about Bitcoin
35 | Core's [architecture](/architecture.html).
36 |
37 | - If you begin to suspect that your "bug" might be deliberate
38 | behavior, research the [history of particular
39 | code](/past-changes.html).
40 |
41 | - To contribute a change:
42 |
43 | - Follow project [guidelines](/contributing.html) for effective
44 | commits and GitHub PRs.
45 |
46 | - Understand the jargon and process other developers will use in
47 | [evaluating](/pr-maturation.html) your proposed change.
48 |
49 | - Optionally help [review](/reviewing.html) contributions from other
50 | developers to encourage them to review your contribution.
51 |
52 | Many other parts of the contributing guide can help explain how to
53 | successfully debug, report, and fix a bug. If you find yourself stymied
54 | at any point, or just curious about Bitcoin Core, please consider
55 | reading the full documentation starting from the [main page](/).
56 |
--------------------------------------------------------------------------------
/entries/first-contribution.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: "Quickstart: first contribution"
4 | nav_exclude: true
5 | ---
6 | # Quickstart: first contribution
7 |
8 | {% include best-way.md %}
9 |
10 | This guide is for developers who want to quickly begin contributing
11 | to Bitcoin Core but don't know what to work on or how to get started.
12 |
13 | - Find an [entry point](/starting-ideas.html) such as a bug an
14 | established contributor has tagged as a "good first issue".
15 |
16 | - You may want to quickly [mention](/comms.html) your planned approach
17 | in chat to confirm established contributors agree that it's a good
18 | direction.
19 |
20 | - Note on the issue, PR, or other page that you're working on the
21 | problem so others don't duplicate your work.
22 |
23 | - To address an issue:
24 |
25 | - You will need to [build Bitcoin
26 | Core](/building.html) optionally with [debugging
27 | options](/debugging.html).
28 |
29 | - You may want to [write a test](/testing.html) that demonstrates your
30 | bug and will prove it's been fixed.
31 |
32 | - If you need certain network activity to reproduce your bug, you can
33 | test on [test networks](/testnets.html).
34 |
35 | - If you're trying to find a particular file, learn about Bitcoin
36 | Core's [architecture](/architecture.html).
37 |
38 | - If you encounter confusing code, research the [history of that
39 | particular code](/past-changes.html).
40 |
41 | - To contribute a change:
42 |
43 | - Follow project [guidelines](/contributing.html) for effective
44 | commits and GitHub PRs.
45 |
46 | - Understand the jargon and process other developers will use in
47 | [evaluating](/pr-maturation.html) your proposed change.
48 |
49 | - Optionally help [review](/reviewing.html) contributions from other
50 | developers to encourage them to review your contribution.
51 |
52 | Many other parts of the contributing guide can help explain how to
53 | successfully make your first contribution. If you find yourself stymied
54 | at any point, or just curious about Bitcoin Core, please consider
55 | reading the full documentation starting from the [main page](/).
56 |
--------------------------------------------------------------------------------
/exercise-intro.adoc:
--------------------------------------------------------------------------------
1 | include::links-onepage.adoc[]
2 |
3 | ****
4 | Using either `bitcoin-cli` in your terminal, or a xref:contributor-exercises.adoc#test_shell_nodes[Jupyter notebook] in conjunction with the `TestShell` class from the Bitcoin Core Test Framework, try to complete the following exercises.
5 |
6 | Changes to the codebase will require you to re-compile afterwards.
7 |
8 | Don't forget to use the compiled binaries found in your source directory, for example `/home/user/bitcoin/src/bitcoind`, otherwise your system might select a previously-installed (non-modified) version of bitcoind.
9 | ****
10 |
--------------------------------------------------------------------------------
/exercise_base.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 3,
6 | "metadata": {
7 | "pycharm": {
8 | "name": "#%%\n"
9 | }
10 | },
11 | "outputs": [],
12 | "source": [
13 | "import sys, os\n",
14 | "from test_framework.test_shell import TestShell\n",
15 | "\n",
16 | "sys.path.insert(0, os.path.expanduser(\"~/bitcoin/test/functional\"))\n",
17 | "test = TestShell().setup(\n",
18 | " num_nodes=2,\n",
19 | " setup_clean_chain=True,\n",
20 | " extra_args=[[], ['-fallbackfee=0.0002']],\n",
21 | ")"
22 | ]
23 | }
24 | ],
25 | "metadata": {
26 | "kernelspec": {
27 | "display_name": "Python 3 (ipykernel)",
28 | "language": "python",
29 | "name": "python3"
30 | },
31 | "language_info": {
32 | "codemirror_mode": {
33 | "name": "ipython",
34 | "version": 3
35 | },
36 | "file_extension": ".py",
37 | "mimetype": "text/x-python",
38 | "name": "python",
39 | "nbconvert_exporter": "python",
40 | "pygments_lexer": "ipython3",
41 | "version": "3.9.7"
42 | }
43 | },
44 | "nbformat": 4,
45 | "nbformat_minor": 1
46 | }
--------------------------------------------------------------------------------
/fork-wishlist.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Fork wish lists
2 | :page-nav_order: 50
3 | :page-parent: Consensus and Validation
4 | == Fork wish lists
5 |
6 | There are a number of items that developers have had on their wish lists to tidy up in future fork events.
7 |
8 | An https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2019-March/016714.html[email^] from Matt Corallo with the subject "The Great Consensus Cleanup" described a "wish list" of items developers were keen to tidy up in a future soft fork.
9 |
10 | The Hard Fork Wishlist is described on this en.bitcoin.it/wiki https://en.bitcoin.it/wiki/Hardfork_Wishlist[page^].
11 | The rationale for collecting these changes together, is that if backwards-incompatible (hard forking) changes are being made, then we "might as well" try and get a few in at once, as these events are so rare.
12 |
--------------------------------------------------------------------------------
/github.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Development workflow
2 | :page-nav_order: 10
3 | :page-parent: Overview and Development Process
4 | == Development workflow
5 |
6 | Bitcoin Core uses a GitHub-based workflow for development.
7 | The primary function of GitHub in the workflow is to discuss patches and connect them with review comments.
8 |
9 | While some other prominent projects, e.g. the Linux kernel, use email to solicit feedback and review, Bitcoin Core has used GitHub for many years.
10 | Initially, Satoshi distributed the code through private emails and hosting source archives at bitcoin.org, and later by hosting on SourceForge (which used SVN but did not at that time have a pull request system like GitHub).
11 | The earliest reviewers submitted changes using patches either through email exchange with Satoshi, or by posting them on the bitcoin forum.
12 |
13 | In August 2009, the source code was moved to GitHub by Sirius, and development has remained there and used the GitHub workflows ever since.
14 |
15 | === Use of GitHub
16 |
17 | The GitHub side of the Bitcoin Core workflow for Contributors consists primarily of:
18 |
19 | * Issues
20 | * PRs
21 | * Reviews
22 | * Comments
23 |
24 | Generally, issues are used for two purposes:
25 |
26 | . Posting known issues with the software, e.g., bug reports, crash logs
27 | . Soliciting feedback on potential changes without providing associated code, as would be required in a PR.
28 |
29 | GitHub provides their own https://guides.github.com/features/issues/[guide^] on mastering Issues which is worth reading to understand the feature-set available when working with an issue.
30 |
31 | PRs are where Contributors can submit their code against the main codebase and solicit feedback on the concept, the approach taken for the implementation, and the actual implementation itself.
32 |
33 | PRs and Issues are often linked to/from one another:
34 |
35 | [example]
36 | ====
37 | One common workflow is when an Issue is opened to report a bug.
38 | After replicating the issue, a Contributor creates a patch and then opens a PR with their proposed changes.
39 |
40 | In this case, the Contributor should, in addition to comments about the patch, reference that the patch fixes the issue.
41 | For a patch which fixes issue 22889 this would be done by writing "fixes #22889" in the PR description or in a commit message.
42 | In this case, the syntax "fixes #issue-number" is caught by GitHub's https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue[pull request linker^], which handles the cross-link automatically.
43 | ====
44 |
45 | Another use-case of Issues is soliciting feedback on ideas that might require _significant_ changes.
46 | This helps free the project from having too many PRs open which aren't ready for review and might waste reviewers' time.
47 | In addition, this workflow can also save Contributors their _own_ valuable time, as an idea might be identified as unlikely to be accepted _before_ the contributor spends their time writing the code for it.
48 |
49 | Most code changes to bitcoin are proposed directly as PRs -- there's no need to open an Issue for every idea before implementing it unless it may require significant changes.
50 | Additionally, other Contributors (and would-be Reviewers) will often agree with the approach of a change, but want to "see the implementation" before they can really pass judgement on it.
51 |
52 | GitHub is therefore used to help store and track reviews to PRs in a public way.
53 |
54 | Comments (inside Issues, PRs, Projects etc.) are where all (GitHub) users can discuss relevant aspects of the item and have history of those discussions preserved for future reference.
55 | Often Contributors having "informal" discussions about changes on e.g. IRC will be advised that they should echo the gist of their conversation as a comment on GitHub, so that the rationale behind changes can be more easily determined in the future.
56 |
--------------------------------------------------------------------------------
/gui-building.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Building the GUI
2 | :page-nav_order: 10
3 | :page-parent: GUI
4 | include::links-onepage.adoc[]
5 | == Building the GUI
6 |
7 | `bitcoin-qt`, which includes the QT GUI with the node, is built automatically when the build dependencies are met.
8 | Required packages to meet dependencies can be found in the build instructions in _src/doc/build-*.md_ as appropriate for your platform.
9 | If you have the required packages installed but do not wish to build the `bitcoin-qt` then you must run `./configure` with the option `--with-gui=no`.
10 |
11 | [NOTE]
12 | ====
13 | If the build is configured with `--enable-multiprocess` then additional binaries will be built:
14 |
15 | . `bitcoin-node`
16 | . `bitcoin-wallet`
17 | . `bitcoin-gui`
18 | ====
19 |
20 | == Qt
21 |
22 | QT is currently very intertwined with the rest of the codebase.
23 | See the library xref:library-structure.adoc#library-dependency-graph[depencency graph] for more context.
24 |
25 | Developers would ideally like to reduce these dependencies in the future.
26 |
27 | == Qt documentation
28 |
29 | There is useful documentation for developers looking to contribute to the Qt side of the codebase found at https://github.com/bitcoin-core/bitcoin-devwiki/wiki//Developer-Notes-for-Qt-Code[Developer Notes for Qt Code^].
30 |
31 |
--------------------------------------------------------------------------------
/gui-initialization.adoc:
--------------------------------------------------------------------------------
1 | :page-title: GUI initialization
2 | :page-nav_order: 20
3 | :page-parent: GUI
4 | include::links-onepage.adoc[]
5 | == Main GUI program
6 |
7 | The loading point for the GUI is _src/qt/main.cpp_.
8 | `main()` calls `GuiMain()` from _src/qt/bitcoin.cpp_, passing along any program arguments with it.
9 | `GuiMain` starts by calling `SetupEnvironment()` which amongst other things, configures the runtime locale and charset.
10 |
11 | Next an empty `NodeContext` is set up, which is then populated into a fully-fledged node interface via being passed to `interfaces::MakeNode()`, which returns an `interfaces::Node`.
12 | Recall that in xref:wallet-init.adoc#wallet_component_initialisation[wallet component initialization] we also saw the wallet utilizing a `NodeContext` as part of its `WalletInitInterface`.
13 | In both cases the `NodeContext` is being used to pass chain and network references around without needing to create globals.
14 |
15 | After some QT setup, command-line and application arguments are parsed.
16 | What follows can be outlined from the code comments:
17 |
18 | [start=3]
19 | . Application identification
20 | . Initialization of translations, so that intro dialogue is in user's language
21 | . Now that settings and translations are available, ask user for data directory
22 | . Determine availability of data directory and parse bitcoin.conf
23 | . Determine network (and switch to network specific options)
24 | . URI IPC sending
25 | . Main GUI initialization
26 |
27 | == GUI initialisation
28 |
29 | After configuration the GUI is initialized.
30 | Here the `Node` object created earlier is passed to `app.SetNode()` before a window is created and the application executed.
31 |
32 | The bulk of the Qt GUI classes are defined in _src/qt/bitcoingui.{h|cpp}_.
33 |
34 |
--------------------------------------------------------------------------------
/gui-motivation.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Motivation for a GUI
2 | :page-nav_order: 0
3 | :page-parent: GUI
4 | == Motivation for a GUI
5 |
6 | Bitcoin Core has shipped with a GUI since the first version.
7 | Originally this was a wxWidgets GUI, but in 2011 a move to QT was https://github.com/bitcoin/bitcoin/pull/521[completed].
8 | Satoshi originally had plans to have a decentralized market place and even poker game inside Bitcoin, so including a GUI, which also had wallet and address book functionality, made sense from the get-go.
9 |
10 | The motivation to _continue_ to include a GUI with Bitcoin Core today is for accessibility.
11 | New users can access a best-in-class Bitcoin experience via a single software package.
12 | It's not safe or realistic to expect users to download multiple programs and connect them securely into a software suite, just to use bitcoin.
13 |
14 | It does not have to be the prettiest UI, but needs to provide the functionality to use bitcoin.
15 | It is possible to connect other frontends to Bitcoin Core, but they are connected via RPCs, and do not have the first-class interface (to the node component) that the bundled GUI has.
16 |
--------------------------------------------------------------------------------
/gui.adoc:
--------------------------------------------------------------------------------
1 | = GUI
2 | :page-nav_order: 40
3 | :page-has_children: true
4 |
5 | TIP: This section has been updated to Bitcoin Core @ https://github.com/bitcoin/bitcoin/tree/v23.0[v23.0^]
6 |
7 | The GUI has its own separate repo at https://github.com/bitcoin-core/gui[bitcoin-core/gui^].
8 | PRs which primarily target the GUI should be made here, and then they will get merged into the primary repo.
9 | Developer Marco Falke created https://github.com/MarcoFalke/bitcoin-core/issues/26[an issue^] in his fork which detailed some of the rationale for the split, but essentially it came down to:
10 |
11 | . Separate issue and patch management
12 | . More focused review and interests
13 | . Maintain high quality assurance
14 |
15 | He also stated that:
16 |
17 | [quote, Marco Falke]
18 | ____
19 | Splitting up the GUI (and splitting out modules in general) has been brought up often in recent years. Now that the GUI is primarily connected through interfaces with a bitcoin node, it seems an appropriate time to revive this discussion.
20 | ____
21 |
22 | https://github.com/bitcoin/bitcoin/pull/19071[PR#19071^] contained the documentation change now contained in the Bitcoin Core primary repository, along with details of the monotree approach that was ultimately taken.
23 | The documentation change provides guidance on what a "GUI change" is:
24 |
25 | [quote, src/CONTRIBUTING.md]
26 | ____
27 | As a rule of thumb, everything that only modifies `src/qt` is a GUI-only pull
28 | request. However:
29 |
30 | * For global refactoring or other transversal changes the node repository
31 | should be used.
32 | * For GUI-related build system changes, the node repository should be used
33 | because the change needs review by the build systems reviewers.
34 | * Changes in `src/interfaces` need to go to the node repository because they
35 | might affect other components like the wallet.
36 |
37 | For large GUI changes that include build system and interface changes, it is
38 | recommended to first open a PR against the GUI repository. When there
39 | is agreement to proceed with the changes, a PR with the build system
40 | and interfaces changes can be submitted to the node repository.
41 | ____
42 |
43 | On a related note, another https://github.com/bitcoin/bitcoin/issues/24045[issue^] was recently opened by Falke, to discuss the possibility of instituting the same monotree changes for wallet code.
44 |
45 |
--------------------------------------------------------------------------------
/hardcoded-consensus-values.adoc:
--------------------------------------------------------------------------------
1 | :page-title: Hardcoded consensus values
2 | :page-nav_order: 80
3 | :page-parent: Consensus and Validation
4 | == Hardcoded consensus values
5 |
6 | _consensus/consensus.h_ contains a number of `static const` values relating to consensus rules.
7 | These are globally shared between files such as _validation.cpp_, _rpc_mining.cpp_ and _rpc/mining.cpp_.
8 | These consensus-critical values are marked as `const` so that there is no possibility that they can be changed at any point during program execution.
9 |
10 | One example of this would be the maximum block weight which should not ever be exceeded:
11 |
12 | [source,cpp]
13 | ----
14 | static const unsigned int MAX_BLOCK_WEIGHT = 4000000;
15 | ----
16 |
17 | _consensus/amount.h_ contains the conversion rate between satoshis and one "bitcoin", as well as a `MAX_MONEY` constant.
18 | These are marked as `constexpr` to indicate that they should be evaluated at compile time and then remain as `const` during execution.
19 |
20 | [source,cpp]
21 | ----
22 | /** The amount of satoshis in one BTC. */
23 | static constexpr CAmount COIN = 100000000;
24 |
25 | /** No amount larger than this (in satoshi) is valid.
26 | *
27 | * Note that this constant is *not* the total money supply, which in Bitcoin
28 | * currently happens to be less than 21,000,000 BTC for various reasons, but
29 | * rather a sanity check. As this sanity check is used by consensus-critical
30 | * validation code, the exact value of the MAX_MONEY constant is consensus
31 | * critical; in unusual circumstances like a(nother) overflow bug that allowed
32 | * for the creation of coins out of thin air modification could lead to a fork.
33 | * */
34 | static constexpr CAmount MAX_MONEY = 21000000 * COIN;
35 | ----
36 |
37 | [TIP]
38 | ====
39 | Do you think that the `COIN` constant is necessary at a consensus level, or is it a Bitcoin Core-specific abstraction?
40 | ====
41 |
--------------------------------------------------------------------------------
/images/compilation_firewall_amiti.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chaincodelabs/onboarding-to-bitcoin-core/63309556fb4fd8b64bed5e2e5ffd6173dedda826/images/compilation_firewall_amiti.jpg
--------------------------------------------------------------------------------
/images/jupyter_duplicate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chaincodelabs/onboarding-to-bitcoin-core/63309556fb4fd8b64bed5e2e5ffd6173dedda826/images/jupyter_duplicate.png
--------------------------------------------------------------------------------
/images/pimpl_peerman_amiti.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chaincodelabs/onboarding-to-bitcoin-core/63309556fb4fd8b64bed5e2e5ffd6173dedda826/images/pimpl_peerman_amiti.png
--------------------------------------------------------------------------------
/images/pimpl_txrequest_amiti.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chaincodelabs/onboarding-to-bitcoin-core/63309556fb4fd8b64bed5e2e5ffd6173dedda826/images/pimpl_txrequest_amiti.png
--------------------------------------------------------------------------------
/index.adoc:
--------------------------------------------------------------------------------
1 | = Onboarding to Bitcoin Core
2 | include::settings.adoc[]
3 | :leveloffset: +1
4 |
5 | include::all_chapters.adoc[]
6 |
7 | :leveloffset: -1
8 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 | ---
2 | # Feel free to add content and custom Front Matter to this file.
3 | # To modify the layout, see https://jekyllrb.com/docs/themes/#overriding-theme-defaults
4 |
5 | layout: home
6 | ---
7 |
31 |
32 |