比特币源码研读之一:目录

如何下载?

我们首先可以进入GitHub官网(https://github.com),在搜索栏搜索bitcoin。就可以找到比特币的源码地址,或通过搜索引擎进入比特币官网(https://bitcoin.org/en/)找到相关链接,或直接通过以下地址进入:https://github.com/bitcoin/bitcoin。进入后点击clone or download就可下载。


讲源码下载到本地之后,我们就可以开始阅读了。

首先来看目录

所有的文件都包含在bitcoin-master目录下,说明你下载的是bitcoin的master分支。

在bitcoin-master目录下有9个目录,分别为:


.github,是和GitHub有关的文件夹,其中只包含一个名为ISSUE_TEMPLATE.md的文件,写了提交问题的规则。


.tx,其中只包含一个名为config的文件,有关翻译管理,翻译管理即为翻译流程自动化,可以减少重复费力的人工任务,同时实现控制、增加协作并提高效率。


Build-aux,里面只有后面看源码才知道。


contrib,里面有个README,写了这个目录下有存储库工具、构建工具和密钥、测试和验证工具,这三类工具:

/ contrib / devtools是针对此存储库的开发人员的特定工具。包含脚本`github-merge.py`,用于安全地合并GitHub拉取请求并使用GPG签名。

/ contrib / verify-commits使用上述`github-merge.py`脚本验证开发人员是否签署了每个合并提交的工具。

/ contrib / linearize用于构建区块链的线性,无叉,最佳版本。

/ contrib / qos 是一个Linux bash脚本,它将设置流量控制(tc)以限制连接到比特币网络的传出带宽。这意味着可以运行一个始终在线的bitcoind实例,以及另一个连接到该节点并从中接收块的本地bitcoind / bitcoin-qt实例。

/ contrib / seeds用于生成编译到客户端的pnSeed []数组的实用程序。

/ contrib / debian包含用于打包bitcoind / bitcoin-qt的文件,用于基于Debian的Linux系统。如果你自己编译bitcoind / bitcoin-qt,这里有一些有用的文件。

/ contrib / gitian-descriptors,gitian构建过程中使用的文件。有关gitian的更多信息,请参阅[比特币核心文档存储库](https://github.com/bitcoin-core/docs)。

/ contrib / gitian-keys用于签署比特币核心

[Gitian发布](/ doc / release-process.md)结果的PGP密钥。

/ contrib / macdeploy适用于Mac的脚本和笔记。

/ contrib / rpm是RPM spec文件,用于在基于RPM的发行版上构建比特币核心。

/ contrib / gitian-build.sh:运行完整Gitian构建的脚本。

/ contrib / testgen 实用程序为数据驱动的比特币测试生成测试向量。

/ contrib / verifybinaries此脚本尝试从bitcoin.org下载并验证签名文件SHA256SUMS.asc


depends,里面有个README,讲对不同系统构建依赖项,和交叉编译。


doc,里面有个README,写了比特币核心的建立和运行即有关如何在本机平台上运行比特币的一些有用说明。


share,里面有pixmaps/qt/rpcauth三个目录,前两个没看源码暂时不知道,rpcauth里有个README,/ share / rpcauth)为JSON-RPC用户创建登录凭据的用法。


Src,最主要,最重要的代码都在这里面,下次单独讲。


test,测试目录,里面有个README,讲了该目录包含测试bitcoind及其的集成测试,完整的公用事业。它不包含单元测试,可以在[/ src / test](/ src / test),[/ src / wallet / test](/ src / wallet / test)等等中找到,目录中目前有两组测试:- [功能](/ test / functional)测试功能,bitcoind和bitcoin-qt通过RPC和P2P与它们交互,接口。- [util](/ test / util),它目前只测试比特币实用程序,比特币-TX。util测试作为`make check`目标的一部分运行。每当启动时,由travis连续构建过程运行测试两组测试也可以在本地运行。


以及11个文件,分别为:

.gitattributes,

.gitignore,

.travis.yml,

autogen.sh,

configure.ac,

CONTRIBUTING.md,

COPYING,

INSTALL.md

libbitcoinconsensus.pc.in,

Makefile.am,

READEME.md,

分目录详解:


第一个目录为.github,其中只包含一个名为ISSUE_TEMPLATE.md的文件,写了提交问题的规则。

原文如下:

<!-- This issue tracker is only for technical issues related to Bitcoin Core.

General bitcoin questions and/or support requests are best directed to the Bitcoin StackExchange at https://bitcoin.stackexchange.com.

For reporting security issues, please read instructions at https://bitcoincore.org/en/contact/.

If the node is "stuck" during sync or giving "block checksum mismatch" errors, please ensure your hardware is stable by running memtest and observe CPU temperature with a load-test tool such as linpack before creating an issue! -->

<!-- Describe the issue -->

<!--- What behavior did you expect? -->

<!--- What was the actual behavior (provide screenshots if the issue is GUI-related)? -->

<!--- How reliably can you reproduce the issue, what are the steps to do so? -->

<!-- What version of Bitcoin Core are you using, where did you get it (website, self-compiled, etc)? -->

<!-- What type of machine are you observing the error on (OS/CPU and disk type)? -->

<!-- Any extra information that might be useful in the debugging process. -->

<!--- This is normally the contents of a `debug.log` or `config.log` file. Raw text or a link to a pastebin type site are preferred. —>

翻译如下

<!— 这是一个仅用来记录关于比特币核心的技术问题跟踪器。

常规的比特币问题以及支持请求最好直接去Bitcoin StackExchange 在 https://bitcoin.stackexchange.com.

因为报告安全性的问题,请在 https://bitcoincore.org/en/contact/阅读指导.

如果节点在同步过程中“堵塞”或报了 "block checksum mismatch(区块检查汇总配对有误)" 的错误,请你在提交问题之前确保的硬件在跑 如linpack的 memtest 和 用负载测试工具检测CPU温度的时候是稳定的! -->

<!-- 描述问题 -->

<!— 你期待什么反馈? -->

<!--- 事实上的反馈是什么样的(如果问题是关于GUI的请提供截图)? -->

<!--- 你有多大把握可以重现这个问题,你操作的步骤是什么? -->

<!--你使用的是那个版本的比特币,你是在哪里得到的这个版本(网站,自行编译,等等)? -->

<!--你是用哪种类型的机器观察到的错误(系统/CPU和硬盘种类)? -->

<!-- 任何其他的在试图定位错误的过程中可能有用的信息. -->

<!--- 这通常是`debug.log`或`config.log`文件的内容。原始文本或指向pastebin类型站点的链接是首选. —>


.tx,其中只包含一个名为config的文件,有关翻译管理

原文如下:

[main]

host = https://www.transifex.com

bitcoin.qt-translation-016x]

file_filter = src/qt/locale/bitcoin_<lang>.ts

source_file = src/qt/locale/bitcoin_en.ts

source_lang = en


contrib里面有15个目录,9个文件,里面有个README,写了这个目录下有存储库工具、构建工具和密钥、测试和验证工具,这三类工具:

原文如下:

Repository Tools

---------------------

### [Developer tools](/contrib/devtools) ###

Specific tools for developers working on this repository.

Contains the script `github-merge.py` for merging GitHub pull requests securely and signing them using GPG.

### [Verify-Commits](/contrib/verify-commits) ###

Tool to verify that every merge commit was signed by a developer using the above `github-merge.py` script.

### [Linearize](/contrib/linearize) ###

Construct a linear, no-fork, best version of the blockchain.

### [Qos](/contrib/qos) ###

A Linux bash script that will set up traffic control (tc) to limit the outgoing bandwidth for connections to the Bitcoin network. This means one can have an always-on bitcoind instance running, and another local bitcoind/bitcoin-qt instance which connects to this node and receives blocks from it.

### [Seeds](/contrib/seeds) ###

Utility to generate the pnSeed[] array that is compiled into the client.

Build Tools and Keys

---------------------

### [Debian](/contrib/debian) ###

Contains files used to package bitcoind/bitcoin-qt

for Debian-based Linux systems. If you compile bitcoind/bitcoin-qt yourself, there are some useful files here.

### [Gitian-descriptors](/contrib/gitian-descriptors) ###

Files used during the gitian build process. For more information about gitian, see the [the Bitcoin Core documentation repository](https://github.com/bitcoin-core/docs).

### [Gitian-keys](/contrib/gitian-keys)

PGP keys used for signing Bitcoin Core [Gitian release](/doc/release-process.md) results.

### [MacDeploy](/contrib/macdeploy) ###

Scripts and notes for Mac builds.

### [RPM](/contrib/rpm) ###

RPM spec file for building bitcoin-core on RPM based distributions.

### [Gitian-build](/contrib/gitian-build.sh) ###

Script for running full Gitian builds.

Test and Verify Tools 

---------------------

### [TestGen](/contrib/testgen) ###

Utilities to generate test vectors for the data-driven Bitcoin tests.

### [Verify Binaries](/contrib/verifybinaries) ###

This script attempts to download and verify the signature file SHA256SUMS.asc from bitcoin.org.

翻译如下:

存储库工具

---------------------

### [开发人员工具](/ contrib / devtools)###

针对此存储库的开发人员的特定工具。

包含脚本`github-merge.py`,用于安全地合并GitHub拉取请求并使用GPG签名。

### [Verify-Commits](/ contrib / verify-commits)###

使用上述`github-merge.py`脚本验证开发人员是否签署了每个合并提交的工具。

### [Linearize](/ contrib / linearize)###

构建区块链的线性,无叉,最佳版本。

### [Qos](/ contrib / qos)###

一个Linux bash脚本,它将设置流量控制(tc)以限制连接到比特币网络的传出带宽。这意味着可以运行一个始终在线的bitcoind实例,以及另一个连接到该节点并从中接收块的本地bitcoind / bitcoin-qt实例。

### [种子](/ contrib / seeds)###

用于生成编译到客户端的pnSeed []数组的实用程序。

构建工具和密钥

---------------------

### [Debian](/ contrib / debian)###

包含用于打包bitcoind / bitcoin-qt的文件

用于基于Debian的Linux系统。如果你自己编译bitcoind / bitcoin-qt,这里有一些有用的文件。

### [Gitian-descriptors](/ contrib / gitian-descriptors)###

gitian构建过程中使用的文件。有关gitian的更多信息,请参阅[比特币核心文档存储库](https://github.com/bitcoin-core/docs)。

### [Gitian-keys](/ contrib / gitian-keys)

用于签署比特币核心[Gitian发布](/ doc / release-process.md)结果的PGP密钥。

### [MacDeploy](/ contrib / macdeploy)###

适用于Mac的脚本和笔记。

### [RPM](/ contrib / rpm)###

RPM spec文件,用于在基于RPM的发行版上构建比特币核心。

### [Gitian-build](/ contrib / gitian-build.sh)###

运行完整Gitian构建的脚本。

测试和验证工具

---------------------

### [TestGen](/ contrib / testgen)###

实用程序为数据驱动的比特币测试生成测试向量。

### [验证二进制文件](/ contrib / verifybinaries)###

此脚本尝试从bitcoin.org下载并验证签名文件SHA256SUMS.asc


depends,里面有个README,讲对不同系统构建依赖项,和交叉编译。

原文如下:

### Usage

To build dependencies for the current arch+OS:

    make

To build for another arch/OS:

    make HOST=host-platform-triplet

For example:

    make HOST=x86_64-w64-mingw32 -j4

A prefix will be generated that's suitable for plugging into Bitcoin's

configure. In the above example, a dir named x86_64-w64-mingw32 will be

created. To use it for Bitcoin:

    ./configure --prefix=`pwd`/depends/x86_64-w64-mingw32

Common `host-platform-triplets` for cross compilation are:

- `i686-w64-mingw32` for Win32

- `x86_64-w64-mingw32` for Win64

- `x86_64-apple-darwin11` for macOS

- `arm-linux-gnueabihf` for Linux ARM 32 bit

- `aarch64-linux-gnu` for Linux ARM 64 bit

No other options are needed, the paths are automatically configured.

Install the required dependencies: Ubuntu & Debian

--------------------------------------------------

For macOS cross compilation:

    sudo apt-get install curl librsvg2-bin libtiff-tools bsdmainutils cmake imagemagick libcap-dev libz-dev libbz2-dev python-setuptools

For Win32/Win64 cross compilation:

- see [build-windows.md](../doc/build-windows.md#cross-compilation-for-ubuntu-and-windows-subsystem-for-linux)

For linux (including i386, ARM) cross compilation:

    sudo apt-get install curl g++-aarch64-linux-gnu g++-4.8-aarch64-linux-gnu gcc-4.8-aarch64-linux-gnu binutils-aarch64-linux-gnu g++-arm-linux-gnueabihf g++-4.8-arm-linux-gnueabihf gcc-4.8-arm-linux-gnueabihf binutils-arm-linux-gnueabihf g++-4.8-multilib gcc-4.8-multilib binutils-gold bsdmainutils

Dependency Options:

The following can be set when running make: make FOO=bar

    SOURCES_PATH: downloaded sources will be placed here

    BASE_CACHE: built packages will be placed here

    SDK_PATH: Path where sdk's can be found (used by macOS)

    FALLBACK_DOWNLOAD_PATH: If a source file can't be fetched, try here before giving up

    NO_QT: Don't download/build/cache qt and its dependencies

    NO_WALLET: Don't download/build/cache libs needed to enable the wallet

    NO_UPNP: Don't download/build/cache packages needed for enabling upnp

    DEBUG: disable some optimizations and enable more runtime checking

    HOST_ID_SALT: Optional salt to use when generating host package ids

    BUILD_ID_SALT: Optional salt to use when generating build package ids

If some packages are not built, for example `make NO_WALLET=1`, the appropriate

options will be passed to bitcoin's configure. In this case, `--disable-wallet`.

Additional targets:

    download: run 'make download' to fetch all sources without building them

    download-osx: run 'make download-osx' to fetch all sources needed for macOS builds

    download-win: run 'make download-win' to fetch all sources needed for win builds

    download-linux: run 'make download-linux' to fetch all sources needed for linux builds

### Other documentation

- [description.md](description.md): General description of the depends system

- [packages.md](packages.md): Steps for adding packages

翻译如下:

###用法

要为当前的arch + OS构建依赖项:

    使

为另一个arch / OS构建:

    使HOST = host-platform-triplet

例如:

    制作HOST = x86_64-w64-mingw32 -j4

将生成适合插入比特币的前缀

配置。在上面的例子中,名为x86_64-w64-mingw32的目录将是

创建。将它用于比特币:

    ./configure --prefix =`pwd` / depends / x86_64-w64-mingw32

用于交叉编译的通用`host-platform-triplets`是:

- 用于Win32的`i686-w64-mingw32`

- 用于Win64的`x86_64-w64-mingw32`

- 用于macOS的`x86_64-apple-darwin11`

- 用于Linux ARM 32位的`arm-linux-gnueabihf`

- 用于Linux ARM 64位的`aarch64-linux-gnu`

不需要其他选项,路径会自动配置。

安装所需的依赖项:Ubuntu和Debian

--------------------------------------------------

对于macOS交叉编译:

    sudo apt-get install curl librsvg2-bin libtiff-tools bsdmainutils cmake imagemagick libcap-dev libz-dev libbz2-dev python-setuptools

对于Win32 / Win64交叉编译:

- 参见[build-windows.md](../ doc / build-windows.md#cross-compilation-for-ubuntu-and-windows-subsystem-for-linux)

对于linux(包括i386,ARM)交叉编译:

    sudo apt-get install curl g ++ - aarch64-linux-gnu g ++ - 4.8-aarch64-linux-gnu gcc-4.8-aarch64-linux-gnu binutils-aarch64-linux-gnu g ++ - arm-linux-gnueabihf g ++ - 4.8-arm -linux-gnueabihf gcc-4.8-arm-linux-gnueabihf binutils-arm-linux-gnueabihf g ++ - 4.8-multilib gcc-4.8-multilib binutils-gold bsdmainutils

依赖选项:

运行make时可以设置以下内容:make FOO = bar

    SOURCES_PATH:下载的资源将放在这里

    BASE_CACHE:构建的包将放在这里

    SDK_PATH:可以找到sdk的路径(由macOS使用)

    FALLBACK_DOWNLOAD_PATH:如果无法获取源文件,请在放弃前尝试此处

    NO_QT:不要下载/构建/缓存qt及其依赖项

    NO_WALLET:不要下载/构建/缓存启用钱包所需的库

    NO_UPNP:不要下载/构建/缓存启用upnp所需的包

    DEBUG:禁用一些优化并启用更多运行时检查

    HOST_ID_SALT:生成主机包ID时使用的可选盐

    BUILD_ID_SALT:生成构建包ID时使用的可选盐

如果没有构建某些包,例如`make NO_WALLET = 1`,则相应

选项将传递给比特币的配置。在这种情况下,`--disable-wallet`。

其他目标:

    下载:运行'make download'来获取所有源代码而不构建它们

    download-osx:运行'make download-osx'来获取macOS构建所需的所有源代码

    download-win:运行'make download-win'来获取win build所需的所有资源

    download-linux:运行'make download-linux'来获取linux版本所需的所有资源

###其他文档

- [description.md](description.md):依赖系统的一般描述

- [packages.md](packages.md):添加包的步骤


doc里面的READEME

原文如下:

Bitcoin Core

=============

Setup

---------------------

Bitcoin Core is the original Bitcoin client and it builds the backbone of the network. It downloads and, by default, stores the entire history of Bitcoin transactions (which is currently more than 100 GBs); depending on the speed of your computer and network connection, the synchronization process can take anywhere from a few hours to a day or more.

To download Bitcoin Core, visit [bitcoincore.org](https://bitcoincore.org/en/releases/).

Running

---------------------

The following are some helpful notes on how to run Bitcoin on your native platform.

### Unix

Unpack the files into a directory and run:

- `bin/bitcoin-qt` (GUI) or

- `bin/bitcoind` (headless)

### Windows

Unpack the files into a directory, and then run bitcoin-qt.exe.

### macOS

Drag Bitcoin-Core to your applications folder, and then run Bitcoin-Core.

### Need Help?

* See the documentation at the [Bitcoin Wiki](https://en.bitcoin.it/wiki/Main_Page)

for help and more information.

* Ask for help on [#bitcoin](http://webchat.freenode.net?channels=bitcoin) on Freenode. If you don't have an IRC client use [webchat here](http://webchat.freenode.net?channels=bitcoin).

* Ask for help on the [BitcoinTalk](https://bitcointalk.org/) forums, in the [Technical Support board](https://bitcointalk.org/index.php?board=4.0).

Building

---------------------

The following are developer notes on how to build Bitcoin on your native platform. They are not complete guides, but include notes on the necessary libraries, compile flags, etc.

- [Dependencies](dependencies.md)

- [macOS Build Notes](build-osx.md)

- [Unix Build Notes](build-unix.md)

- [Windows Build Notes](build-windows.md)

- [OpenBSD Build Notes](build-openbsd.md)

- [NetBSD Build Notes](build-netbsd.md)

- [Gitian Building Guide](gitian-building.md)

Development

---------------------

The Bitcoin repo's [root README](/README.md) contains relevant information on the development process and automated testing.

- [Developer Notes](developer-notes.md)

- [Release Notes](release-notes.md)

- [Release Process](release-process.md)

- [Source Code Documentation (External Link)](https://dev.visucore.com/bitcoin/doxygen/)

- [Translation Process](translation_process.md)

- [Translation Strings Policy](translation_strings_policy.md)

- [Travis CI](travis-ci.md)

- [Unauthenticated REST Interface](REST-interface.md)

- [Shared Libraries](shared-libraries.md)

- [BIPS](bips.md)

- [Dnsseed Policy](dnsseed-policy.md)

- [Benchmarking](benchmarking.md)

### Resources

* Discuss on the [BitcoinTalk](https://bitcointalk.org/) forums, in the [Development & Technical Discussion board](https://bitcointalk.org/index.php?board=6.0).

* Discuss project-specific development on #bitcoin-core-dev on Freenode. If you don't have an IRC client use [webchat here](http://webchat.freenode.net/?channels=bitcoin-core-dev).

* Discuss general Bitcoin development on #bitcoin-dev on Freenode. If you don't have an IRC client use [webchat here](http://webchat.freenode.net/?channels=bitcoin-dev).

### Miscellaneous

- [Assets Attribution](assets-attribution.md)

- [Files](files.md)

- [Fuzz-testing](fuzzing.md)

- [Reduce Traffic](reduce-traffic.md)

- [Tor Support](tor.md)

- [Init Scripts (systemd/upstart/openrc)](init.md)

- [ZMQ](zmq.md)

License

---------------------

Distributed under the [MIT software license](/COPYING).

This product includes software developed by the OpenSSL Project for use in the [OpenSSL Toolkit](https://www.openssl.org/). This product includes

cryptographic software written by Eric Young ([[email protected]](mailto:[email protected])), and UPnP software written by Thomas Bernard.

翻译如下:

比特币核心

=============

建立

---------------------

比特币核心是最初的比特币客户端,它构建了网络的主干。它下载并默认存储比特币交易的整个历史记录(目前超过100 GB);根据计算机和网络连接的速度,同步过程可能需要几个小时到一天或更长时间。

要下载比特币核心,请访问[bitcoincore.org](https://bitcoincore.org/en/releases/)。

运行

---------------------

以下是有关如何在本机平台上运行比特币的一些有用说明。

### Unix

将文件解压缩到一个目录中并运行:

- `bin / bitcoin-qt`(GUI)或

- `bin / bitcoind`(无头)

### Windows

将文件解压缩到一个目录中,然后运行bitcoin-qt.exe。

### 苹果系统

将Bitcoin-Core拖到您的应用程序文件夹中,然后运行Bitcoin-Core。

### 需要帮忙?

*请参阅[比特币维基](https://en.bitcoin.it/wiki/Main_Page)上的文档

寻求帮助和更多信息。

*在Freenode上[#bitcoin](http://webchat.freenode.net?channels=bitcoin)寻求帮助。如果您没有IRC客户端,请使用[网络聊天](http://webchat.freenode.net?channels=bitcoin)。

*在[技术支持委员会](https://bitcointalk.org/index.php?board=4.0)的[BitcoinTalk](https://bitcointalk.org/)论坛上寻求帮助。

建造

---------------------

以下是有关如何在本机平台上构建比特币的开发人员说明。它们不是完整的指南,但包括必要的库,编译标志等的注释。

- [依赖项](dependencies.md)

- [macOS Build Notes](build-osx.md)

- [Unix Build Notes](build-unix.md)

- [Windows Build Notes](build-windows.md)

- [OpenBSD Build Notes](build-openbsd.md)

- [NetBSD Build Notes](build-netbsd.md)

- [Gitian Building Guide](gitian-building.md)

发展

---------------------

比特币回购的[root README](/ README.md)包含有关开发过程和自动化测试的相关信息。

- [开发者笔记](developer-notes.md)

- [发行说明](release-notes.md)

- [发布流程](release-process.md)

- [源代码文档(外部链接)](https://dev.visucore.com/bitcoin/doxygen/

- [翻译流程](translation_process.md)

- [翻译字符串政策](translation_strings_policy.md)

- [Travis CI](travis-ci.md)

- [未经身份验证的REST接口](REST-interface.md)

- [共享库](shared-libraries.md)

- [BIPS](bips.md)

- [Dnsseed Policy](dnsseed-policy.md)

- [基准测试](benchmarking.md)

###资源

*在[开发与技术讨论区](https://bitcointalk.org/index.php?board=6.0)中讨论[BitcoinTalk](https://bitcointalk.org/)论坛。

*讨论Freenode上#bitcoin-core-dev的项目特定开发。如果您没有IRC客户端,请使用[网络聊天](http://webchat.freenode.net/?channels=bitcoin-core-dev)。

*讨论Freenode上#bitcoin-dev的一般比特币开发。如果您没有IRC客户端,请使用[网络聊天](http://webchat.freenode.net/?channels=bitcoin-dev)。

###杂项

- [资产归属](assets-attribution.md)

- [文件](files.md)

- [模糊测试](fuzzing.md)

- [减少流量](reduce-traffic.md)

- [Tor支持](tor.md)

- [Init Scripts(systemd / upstart / openrc)](init.md)

- [ZMQ](zmq.md)

执照

---------------------

根据[MIT软件许可证](/ COPYING)分发。

本产品包含由OpenSSL Project开发的软件,用于[OpenSSL Toolkit](https://www.openssl.org/)。该产品包括

由Eric Young编写的加密软件([[email protected]](mailto:[email protected]))和由Thomas Bernard编写的UPnP软件。

share/rpcauth


rpcauth里有个README,rpcauth里有个README,/ share / rpcauth)为JSON-RPC用户创建登录凭据的用法。

原文如下:

RPC Tools

---------------------

### [RPCAuth](/share/rpcauth) ###

Create login credentials for a JSON-RPC user.

Usage:

    ./rpcauth.py <username>

in which case the script will generate a password. To specify a custom password do:

    ./rpcauth.py <username> <password>

翻译如下:

RPC工具

---------------------

### [RPCAuth](/ share / rpcauth)###

为JSON-RPC用户创建登录凭据。

用法:

     ./rpcauth.py <用户名>

在这种情况下,脚本将生成密码。 要指定自定义密码,请执行:

     ./rpcauth.py <用户名> <密码>


test,测试目录,里面有个README,该目录包含测试bitcoind及其的集成测试,完整的公用事业。它不包含单元测试,可以在[/ src / test](/ src / test),[/ src / wallet / test](/ src / wallet / test)等等中找到,目录中目前有两组测试:- [功能](/ test / functional)测试功能,bitcoind和bitcoin-qt通过RPC和P2P与它们交互,接口。- [util](/ test / util),它目前只测试比特币实用程序,比特币-TX。util测试作为`make check`目标的一部分运行。每当启动时,由travis连续构建过程运行测试两组测试也可以在本地运行。

原文如下:

This directory contains integration tests that test bitcoind and its

utilities in their entirety. It does not contain unit tests, which

can be found in [/src/test](/src/test), [/src/wallet/test](/src/wallet/test),

etc.

There are currently two sets of tests in this directory:

- [functional](/test/functional) which test the functionality of 

bitcoind and bitcoin-qt by interacting with them through the RPC and P2P

interfaces.

- [util](/test/util) which tests the bitcoin utilities, currently only

bitcoin-tx.

The util tests are run as part of `make check` target. The functional

tests are run by the travis continuous build process whenever a pull

request is opened. Both sets of tests can also be run locally.

# Running tests locally

Build for your system first. Be sure to enable wallet, utils and daemon when you configure. Tests will not run otherwise.

### Functional tests

#### Dependencies

The ZMQ functional test requires a python ZMQ library. To install it:

- on Unix, run `sudo apt-get install python3-zmq`

- on mac OS, run `pip3 install pyzmq`

#### Running the tests

Individual tests can be run by directly calling the test script, eg:

```

test/functional/feature_rbf.py

```

or can be run through the test_runner harness, eg:

```

test/functional/test_runner.py feature_rbf.py

```

You can run any combination (incl. duplicates) of tests by calling:

```

test/functional/test_runner.py <testname1> <testname2> <testname3> ...

```

Run the regression test suite with:

```

test/functional/test_runner.py

```

Run all possible tests with

```

test/functional/test_runner.py --extended

```

By default, up to 4 tests will be run in parallel by test_runner. To specify

how many jobs to run, append `--jobs=n`

The individual tests and the test_runner harness have many command-line

options. Run `test_runner.py -h` to see them all.

#### Troubleshooting and debugging test failures

##### Resource contention

The P2P and RPC ports used by the bitcoind nodes-under-test are chosen to make

conflicts with other processes unlikely. However, if there is another bitcoind

process running on the system (perhaps from a previous test which hasn't successfully

killed all its bitcoind nodes), then there may be a port conflict which will

cause the test to fail. It is recommended that you run the tests on a system

where no other bitcoind processes are running.

On linux, the test_framework will warn if there is another

bitcoind process running when the tests are started.

If there are zombie bitcoind processes after test failure, you can kill them

by running the following commands. **Note that these commands will kill all

bitcoind processes running on the system, so should not be used if any non-test

bitcoind processes are being run.**

```bash

killall bitcoind

```

or

```bash

pkill -9 bitcoind

```

##### Data directory cache

A pre-mined blockchain with 200 blocks is generated the first time a

functional test is run and is stored in test/cache. This speeds up

test startup times since new blockchains don't need to be generated for

each test. However, the cache may get into a bad state, in which case

tests will fail. If this happens, remove the cache directory (and make

sure bitcoind processes are stopped as above):

```bash

rm -rf cache

killall bitcoind

```

##### Test logging

The tests contain logging at different levels (debug, info, warning, etc). By

default:

- when run through the test_runner harness, *all* logs are written to

  `test_framework.log` and no logs are output to the console.

- when run directly, *all* logs are written to `test_framework.log` and INFO

  level and above are output to the console.

- when run on Travis, no logs are output to the console. However, if a test

  fails, the `test_framework.log` and bitcoind `debug.log`s will all be dumped

  to the console to help troubleshooting.

To change the level of logs output to the console, use the `-l` command line

argument.

`test_framework.log` and bitcoind `debug.log`s can be combined into a single

aggregate log by running the `combine_logs.py` script. The output can be plain

text, colorized text or html. For example:

```

combine_logs.py-c <test data directory> | less -r

```

will pipe the colorized logs from the test into less.

Use `--tracerpc` to trace out all the RPC calls and responses to the console. For

some tests (eg any that use `submitblock` to submit a full block over RPC),

this can result in a lot of screen output.

By default, the test data directory will be deleted after a successful run.

Use `--nocleanup` to leave the test data directory intact. The test data

directory is never deleted after a failed test.

##### Attaching a debugger

A python debugger can be attached to tests at any point. Just add the line:

```py

import pdb; pdb.set_trace()

```

anywhere in the test. You will then be able to inspect variables, as well as

call methods that interact with the bitcoind nodes-under-test.

If further introspection of the bitcoind instances themselves becomes

necessary, this can be accomplished by first setting a pdb breakpoint

at an appropriate location, running the test to that point, then using

`gdb` to attach to the process and debug.

For instance, to attach to `self.node[1]` during a run:

```bash

2017-06-27 14:13:56.686000 TestFramework (INFO): Initializing test directory /tmp/user/1000/testo9vsdjo3

```

use the directory path to get the pid from the pid file:

```bash

cat /tmp/user/1000/testo9vsdjo3/node1/regtest/bitcoind.pid

gdb /home/example/bitcoind <pid>

```

Note: gdb attach step may require `sudo`

### Util tests

Util tests can be run locally by running `test/util/bitcoin-util-test.py`. 

Use the `-v` option for verbose output.

# Writing functional tests

You are encouraged to write functional tests for new or existing features.

Further information about the functional test framework and individual

tests is found in [test/functional](/test/functional).

翻译如下:

该目录包含测试bitcoind及其的集成测试

完整的公用事业。它不包含单元测试

可以在[/ src / test](/ src / test),[/ src / wallet / test](/ src / wallet / test)中找到,

等等

目录中目前有两组测试:

- [功能](/ test / functional)测试功能

bitcoind和bitcoin-qt通过RPC和P2P与它们交互

接口。

- [util](/ test / util),它目前只测试比特币实用程序

比特币-TX。

util测试作为`make check`目标的一部分运行。功能性

每当拉动时,由travis连续构建过程运行测试

请求已打开。两组测试也可以在本地运行。

#在本地运行测试

首先为您的系统构建。配置时一定要启用wallet,utils和daemon。否则测试不会运行。

###功能测试

####依赖关系

ZMQ功能测试需要一个python ZMQ库。要安装它:

- 在Unix上,运行`sudo apt-get install python3-zmq`

- 在Mac OS上运行`pip3 install pyzmq`

####运行测试

可以通过直接调用测试脚本来运行单个测试,例如:

```

测试/功能/ feature_rbf.py

```

或者可以通过test_runner工具运行,例如:

```

test / functional / test_runner.py feature_rbf.py

```

您可以通过调用以下命令运行任何组合(包括重复)测试:

```

test / functional / test_runner.py <testname1> <testname2> <testname3> ...

```

运行回归测试套件:

```

测试/功能/ test_runner.py

```

运行所有可能的测试

```

test / functional / test_runner.py --extended

```

默认情况下,test_runner最多可并行运行4个测试。要指定

运行多少个工作,追加`--jobs = n`

各个测试和test_runner线束有许多命令行

选项。运行`test_runner.py -h`查看全部内容。

####排除故障并调试测试失败

#####资源争用

选择bitcoind被测节点使用的P2P和RPC端口

与其他进程的冲突不太可能但是,如果还有另一个比特币

在系统上运行的进程(可能来自之前没有成功的测试)

杀死所有的bitcoind节点),然后可能会有端口冲突

导致测试失败。建议您在系统上运行测试

没有其他bitcoind进程正在运行。

在linux上,如果有另一个,test_framework将发出警告

bitcoind进程在测试开始时运行。

如果在测试失败后有僵尸比特币进程,你可以杀死它们

通过运行以下命令。 **请注意,这些命令将全部杀死

bitcoind进程在系统上运行,所以不应该使用任何非测试

bitcoind进程正在运行。**

```庆典

killall bitcoind

```

要么

```庆典

pkill -9 bitcoind

```

#####数据目录缓存

第一次生成具有200个块的预挖掘区块链

功能测试运行并存储在测试/缓存中。这加速了

测试启动时间,因为不需要为其生成新的区块链

每次测试。但是,在这种情况下,缓存可能会进入不良状态

测试将失败。如果发生这种情况,请删除缓存目录(并生成

确保bitcoind进程如上所述停止):

```庆典

rm -rf缓存

killall bitcoind

```

#####测试记录

测试包含不同级别的日志记录(调试,信息,警告等)。通过

默认:

- 当通过test_runner线束运行时,*所有*日志都被写入

  `test_framework.log`并且没有日志输出到控制台。

- 直接运行时,* all * logs将写入`test_framework.log`和INFO

  level和above输出到控制台。

- 在Travis上运行时,没有日志输出到控制台。但是,如果进行测试

  失败,`test_framework.log`和bitcoind`debug.log`都将被转储

  到控制台帮助排除故障。

要更改输出到控制台的日志级别,请使用`-l`命令行

论据。

`test_framework.log`和bitcoind`debug.log`可以合并为一个

通过运行`combine_logs.py`脚本来聚合日志。输出可以是简单的

文字,彩色文字或HTML。例如:

```

combine_logs.py -c <测试数据目录> |少 - 

```

将测试中的彩色日志管道输入更少。

使用`--tracerpc`来跟踪所有RPC调用和对控制台的响应。对于

一些测试(例如任何使用`submitblock`来提交RPC的完整块),

这可能会导致大量的屏幕输出。

默认情况下,成功运行后将删除测试数据目录。

使用`--nocleanup`保持测试数据目录不变。测试数据

测试失败后,目录永远不会被删除。

#####附加调试器

python调试器可以随时附加到测试中。只需添加以下行:

```PY

import pdb; pdb.set_trace()

```

在测试的任何地方。然后,您将能够检查变量,以及

调用与bitcoind被测节点交互的方法。

如果进一步反省bitcoind实例themselv

猜你喜欢

转载自blog.csdn.net/qq_27467365/article/details/81610215
今日推荐