区块链节点运维相关

区块链节点,钱包运维相关

2019/09/18 Chenxin

参考
https://bitcoinsv.io/services/wallets-and-exchanges/ 钱包推荐列表
https://aaron67.cc/2019/02/18/bitcoin-wallet-best-practice/ 钱包使用实践

本文档对应版本
0.18.1

分类

钱包
节点
btc类,eth类等

btc类

部署

https://bitcoincore.org/en/download/ 安装软件下载地址.
https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes.md 版本说明
https://github.com/bitcoin/bitcoin/blob/master/doc/bitcoin-conf.md 启动配置参数
https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list API参考(老旧,很多用不了.可以直接使用命令后 -h 或 help 查看)
https://lhalcyon.com/blockchain-bitcoin-node/ 本章节参考

安装
资源占用说明
测试网会占用500MB左右内存,35GB的左右的磁盘空间(2019/09/23)

linux(命令行)
linux直接到官网下载tar.gz包.解压,放置到磁盘空间足够大的地方(250GB以上),便于全节点.

Mac(GUI界面,命令行)
下载,安装dmg文件.可以将linux上的已经同步完的节点数据和钱包一并拷贝到mac上(之后钱包可以在两边一起用),mac上安装节点.然后测试钱包.

目录结构

[root@localhost bitcoin]# tree
.
├── bin
│   ├── bitcoin-cli
│   ├── bitcoind
│   ├── bitcoin-qt
│   ├── bitcoin-tx
│   ├── bitcoin-wallet
│   └── test_bitcoin
├── include
│   └── bitcoinconsensus.h
├── lib
│   ├── libbitcoinconsensus.so -> libbitcoinconsensus.so.0.0.0
│   ├── libbitcoinconsensus.so.0 -> libbitcoinconsensus.so.0.0.0
│   └── libbitcoinconsensus.so.0.0.0
├── README.md
└── share
    └── man
        └── man1
            ├── bitcoin-cli.1
            ├── bitcoind.1
            ├── bitcoin-qt.1
            ├── bitcoin-tx.1
            └── bitcoin-wallet.1

直接执行 /data/coin_test/bitcoin/bitcoin/bin/bitcoind 二进制,会自动到/root目录下创建 ".bitcoin"文件夹.
可以将 bin 目录,加入系统变量PATH里.

常用指令请参考本文日常"运维"部分

bitcoind指令参数(此为命令行方式,与配置文件一一对应)
bitcoind -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf
一般选项

-conf=<file>                #指定配置文件,默认~/.bitcoin/bitcoin.conf
-port=<port>                #监听端口,默认8332或测试网络的testnet 18332
-bind=<addr>                #监听地址,使用[host]:port标识ipv6地址
-datadir=<dir>              #数据保存目录,建议500G以上
-daemon                     #运行为守护进程(配置文件里可以daemon=1)
-dbcache=<n>                #设置数据缓存大小,单位百万字节,默认450
-debuglogfile=<file>        #指定debug级别日志保存的位置。
-includeconf=<file>         #指定额外配置文件路径。只能用于配置文件,不能用于命令行。
-loadblock=<file>           #启动时从外部的名为blk000??.dat加载数据块
-reindex                    #从磁盘上的blk*.dat文件重建链状态和块索引
-reindex-chainstate         #从当前索引的块重建链状态
-version                    #查看当前程序版本并退出
-txindex                    #默认情况下,比特币核心只创建与使用者钱包相关的交易索引,如果需要维护全部交易的索引,需要设置该选项。
-maxmempool=<n>             #将事务内存保持在<n> mb以下(default: 300)
-maxorphantx=<n>            #在内存中最多保存<n>不可连接事务(default: 100)
-mempoolexpiry=<n>          #在内存池中保存事务的时间不要超过<n>小时(default:336)
-server                     #接受命令行和JSON-RPC命令
-rpcuser=<user>             #JSON-RPC连接时使用的用户名
-rpcpassword=<pw>           #JSON-RPC连接时使用的密码
-rpcport=<port>             #JSON-RPC连接监听的端口,默认8332或testnet 18332
-rpcallowip=<ip>            #允许JSON-RPC连接从外部连接。可以是一个单独IP(e.g. 1.2.3.4)、网络地址/掩码(e.g.1.2.3.4/255.255.255.0)或网络地址/掩码长度(e.g. 1.2.3.4/24)。该选项可指定多次。
-rpcbind=<addr>[:port]      #JSON-RPC连接的服务监听地址和端口。不指定-rpcallowip参数时,该参数无效。端口参数可选,若指定,则覆盖-rpcport选项。使用[host]:port标识ipv6地址。地址格式与-rpcallowip相同

钱包选项

-addresstype                #使用什么类型的地址("legacy", "p2sh-segwit", or "bech32",default: "p2sh-segwit")
-disablewallet              #不加载钱包并禁用钱包RPC调用
-discardfee=<amt>           #费率(以BTC/kB表示)
-fallbackfee=<amt>          #收费比率(以BTC/kB为单位),当收费估计数据不足时,会使用该比率(默认值:0.0002)
-keypool=<n>                #将密钥池大小设置为<n>
-mintxfee=<amt>             #如果费用(以BTC/kB为单位)小于此值,则认为创建事务的费用为零(默认值为0.00001)。
-paytxfee=<amt>             #向您发送的交易中添加的费用(以BTC/kB为单位)(默认值:0.00)
-rescan                     #重新扫描在启动时丢失的钱包事务的块链
-salvagewallet              #尝试在启动时从损坏的钱包中恢复私钥
-wallet=<path>              #指定钱包数据库路径,可以指定多次加载多个钱包。如果路径不是绝对的,则相对于<walletdir>;如果路径不存在,则创建路径(作为包含wallet.dat文件和日志文件的目录)。为了向后兼容,它还将接受<walletdir>中现有数据文件的名称。)
-walletdir=<dir>            #指定保存钱包的目录(默认:<datadir>/wallets,如该目录不存在,则使用<datadir>)
-walletnotify=<cmd>         #当钱包事务发生更改时执行的命令

bitcoin.conf配置文件(优先级低于命令行方式)
bitcoin.conf 配置文件
默认情况下,Bitcoin(或 bitcoind)会在比特币数据文件夹下查找一个名为“bitcoin.conf”的文件,或通过 -conf 命令行参数指定.
配置文件说明 https://github.com/bitcoin/bitcoin/blob/master/doc/bitcoin-conf.md
-conf 指定读取配置文件位置.要跟绝对路径,如-conf=/data/coin_test/.../bitcoin.conf,如果是相对路径,则会自动到用户的根目录下相对路径里去找.
配置文件里指定的项目优先级低于命令行参数设置的值(命令行会覆盖配置文件中的设置).
配置文件不会自动创建.
默认位置: $HOME/.bitcoin/ /home/username/.bitcoin/bitcoin.conf

数据目录配置
datadir=/data/coin_test/bitcoin/bitcoin/bitcoin-data

以daemon后台方式启动
daemon=1.
或者bitcoind后指定 -daemon 也可以.

bitcoind 的 daemon 方式,查看实时输出(输出与直接执行bitcoind控制台输出一致)
tailf debug.log

使用测试网络数据(真实环境需要250GB磁盘,测试环境当前为35GB)
testnet=1

使用指定的钱包(这里是在test环境下,如果正式环境,就不要放到test里.此步骤是第一次启动后,通过rpc创建的钱包,然后重新修改配置文件,加载这个新的钱包.创建钱包在此文后半部分)
[test]
wallet=/data/coin_test/bitcoin/bitcoin/bitcoin-data/testnet3/wallets/wallet-chenxin/

进程执行
bitcoind -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf

以下是官方配置文件示例

最新,参考官方 https://github.com/bitcoin/bitcoin/blob/master/share/examples/bitcoin.conf

##
## bitcoin.conf configuration file. Lines beginning with # are comments.
##

# 指定数据目录位置
datadir=/data/coin_test/bitcoin/bitcoin/bitcoin-data

# Network-related settings:

# Note that if you use testnet or regtest, particularly with the options
# addnode, connect, port, bind, rpcport, rpcbind or wallet, you will also
# want to read "[Sections]" further down.

# Run on the test network instead of the real bitcoin network.
#testnet=0 为1,就是测试环境

# Run a regression test network
#regtest=0

# Connect via a SOCKS5 proxy
#proxy=127.0.0.1:9050

# Bind to given address and always listen on it. Use [host]:port notation for IPv6
#bind=<addr>

# Bind to given address and whitelist peers connecting to it. Use [host]:port notation for IPv6
#whitebind=<addr>

##############################################################
##            Quick Primer on addnode vs connect            ##
##  Let's say for instance you use addnode=4.2.2.4          ##
##  addnode will connect you to and tell you about the      ##
##    nodes connected to 4.2.2.4.  In addition it will tell ##
##    the other nodes connected to it that you exist so     ##
##    they can connect to you.                              ##
##  connect will not do the above when you 'connect' to it. ##
##    It will *only* connect you to 4.2.2.4 and no one else.##
##                                                          ##
##  So if you're behind a firewall, or have other problems  ##
##  finding nodes, add some using 'addnode'.                ##
##                                                          ##
##  If you want to stay private, use 'connect' to only      ##
##  connect to "trusted" nodes.                             ##
##                                                          ##
##  If you run multiple nodes on a LAN, there's no need for ##
##  all of them to open lots of connections.  Instead       ##
##  'connect' them all to one node that is port forwarded   ##
##  and has lots of connections.                            ##
##       Thanks goes to [Noodle] on Freenode.               ##
##############################################################

# Use as many addnode= settings as you like to connect to specific peers
#addnode=69.164.218.197
#addnode=10.0.0.2:8333

# Alternatively use as many connect= settings as you like to connect ONLY to specific peers
#connect=69.164.218.197
#connect=10.0.0.1:8333

# Listening mode, enabled by default except when 'connect' is being used
#listen=1

# Port on which to listen for connections (default: 8333, testnet: 18333, regtest: 18444)
#port=

# Maximum number of inbound+outbound connections.
#maxconnections=

#
# JSON-RPC options (for controlling a running Bitcoin/bitcoind process)
#

# server=1 tells Bitcoin-Qt and bitcoind to accept JSON-RPC commands
#server=0

# Bind to given address to listen for JSON-RPC connections.
# Refer to the manpage or bitcoind -help for further details.
#rpcbind=<addr>

# If no rpcpassword is set, rpc cookie auth is sought. The default `-rpccookiefile` name
# is .cookie and found in the `-datadir` being used for bitcoind. This option is typically used
# when the server and client are run as the same user.
#
# If not, you must set rpcuser and rpcpassword to secure the JSON-RPC API.
#
# The config option `rpcauth` can be added to server startup argument. It is set at initialization time
# using the output from the script in share/rpcauth/rpcauth.py after providing a username:
#
# ./share/rpcauth/rpcauth.py alice
# String to be appended to bitcoin.conf:
# rpcauth=alice:f7efda5c189b999524f151318c0c86$d5b51b3beffbc02b724e5d095828e0bc8b2456e9ac8757ae3211a5d9b16a22ae
# Your password:
# DONT_USE_THIS_YOU_WILL_GET_ROBBED_8ak1gI25KFTvjovL3gAM967mies3E=
#
# On client-side, you add the normal user/password pair to send commands:
#rpcuser=alice
#rpcpassword=DONT_USE_THIS_YOU_WILL_GET_ROBBED_8ak1gI25KFTvjovL3gAM967mies3E=
#
# You can even add multiple entries of these to the server conf file, and client can use any of them:
# rpcauth=bob:b2dd077cb54591a2f3139e69a897ac$4e71f08d48b4347cf8eff3815c0e25ae2e9a4340474079f55705f40574f4ec99

# How many seconds bitcoin will wait for a complete RPC HTTP request.
# after the HTTP connection is established.
#rpcclienttimeout=30

# By default, only RPC connections from localhost are allowed.
# Specify as many rpcallowip= settings as you like to allow connections from other hosts,
# either as a single IPv4/IPv6 or with a subnet specification.

# NOTE: opening up the RPC port to hosts outside your local trusted network is NOT RECOMMENDED,
# because the rpcpassword is transmitted over the network unencrypted.

# server=1 tells Bitcoin-Qt to accept JSON-RPC commands.
# it is also read by bitcoind to determine if RPC should be enabled
#rpcallowip=10.1.1.34/255.255.255.0
#rpcallowip=1.2.3.4/24
#rpcallowip=2001:db8:85a3:0:0:8a2e:370:7334/96

# Listen for RPC connections on this TCP port:
#rpcport=8332

# You can use Bitcoin or bitcoind to send commands to Bitcoin/bitcoind
# running on another host using this option:
#rpcconnect=127.0.0.1

# Wallet options

# Specify where to find wallet, lockfile and logs. If not present, those files will be
# created as new.
#wallet=</path/to/dir>

# Create transactions that have enough fees so they are likely to begin confirmation within n blocks (default: 6).
# This setting is over-ridden by the -paytxfee option.
#txconfirmtarget=n

# Pay a transaction fee every time you send bitcoins.
#paytxfee=0.000x

# Miscellaneous options

# Pre-generate this many public/private key pairs, so wallet backups will be valid for
# both prior transactions and several dozen future transactions.
#keypool=100

# Enable pruning to reduce storage requirements by deleting old blocks.
# This mode is incompatible with -txindex and -rescan.
# 0 = default (no pruning).
# 1 = allows manual pruning via RPC.
# >=550 = target to stay under in MiB.
#prune=550

# User interface options

# Start Bitcoin minimized
#min=1

# Minimize to the system tray
#minimizetotray=1

# [Sections]
# Most options apply to mainnet, testnet and regtest.
# If you want to confine an option to just one network, you should add it in the
# relevant section below.
# EXCEPTIONS: The options addnode, connect, port, bind, rpcport, rpcbind and wallet
# only apply to mainnet unless they appear in the appropriate section below.

# Options only for mainnet
[main]

# Options only for testnet
[test]

# Options only for regtest
[regtest]

bitcoin-cli客户端/管理端使用说明
关闭同步服务
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf stop 相当于直接启动bitcoind后,ctrl+c操作.

bitcoin-cli命令参数

./bitcoin-cli -h
Bitcoin Core RPC client version v0.18.1
Usage:  bitcoin-cli [options] <command> [params]  Send command to Bitcoin Core
or:     bitcoin-cli [options] -named <command> [name=value]...  Send command to Bitcoin Core (with named arguments)
or:     bitcoin-cli [options] help                List commands
or:     bitcoin-cli [options] help <command>      Get help for a command
-conf=<file>                #指定配置文件路径。相对路径将以datadir位置作为前缀。默认文件名:bitcoin.conf
-datadir=<dir>              #指定数据存储位置
-getinfo                    #从远程服务器获取一般信息。与服务器端RPC调用不同,-getinfo的结果是多个非原子请求的结果。结果中的一些条目可能表示来自不同状态的结果(例如,钱包余额可能来自报告的链状态的不同块)
-named                      #传递指定的参数而不是位置参数
-rpcclienttimeout=<n>       #HTTP请求超时(以秒为单位),0表示没有超时。默认900
-rpcconnect=<ip>            #向指定IP的节点发送命令,默认127.0.0.1
-rpccookiefile=<loc>        #认证cookie的路径,相对路径以datadir地址为前缀。默认:data dir
-rpcpassword=<pw>           #JSON-RPC连接的密码
-rpcport=<port>             #JSON-RPC连接的端口
-rpcuser=<user>             #JSON-RPC连接时使用的用户名
-rpcwait                    #等待RPC服务器启动
-rpcwallet=<walletname>     #向非默认RPC服务器发起RPC连接。需要精确匹配传递给bitcoin-cli的参数
-stdin                      #从标准输入读取额外的参数,每行一个,直到EOF/Ctrl-D结束(推荐用于敏感信息,如密码)。当与-stdinrpcpass结合使用时,使用标准输入的第一行作为RPC密码。
-stdinrpcpass               #读取标准输入第一行作为RPC密码。当与-stdin结合使用时,标准输入第一行作为RPC密码。

RPC指令

bitcoin-cli  -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf help #通过RPC,API的方式来获取数据
关闭bitcoin:     bitcoin-cli stop
查看网络状态:   bitcoin-cli getnetworkinfo
查看网络节点:   bitcoin-cli getpeerinfo  #当前能看到有10个节点
查看区块链信息: bitcoin-cli getblockchaininfo #当前同步区块高度,区块hash值,同步进度,总计占用磁盘空间(字节)等
查看所有命令:    bitcoin-cli help

数据文件说明(数据转移)

整体数据文件,以及各种操作对数据影响的说明

  • 终止或启动进程测试
    可以随时终止进程,拷贝或移动数据文件到别处,重新指定配置参数 datadir 就可以了.默认是指向当前用户根目录下的.

  • 切换用户测试
    切换到admin账号,修改文件属组,依旧正常执行.

  • 剪切数据测试
    只要把配置文件+指定的数据文件夹文件一并拷贝就可以了.

数据文件分类说明
参考: https://www.jianshu.com/p/6a8ee6cea3f7
在比特币业务中需要存储的数据主要分为下面四种:

1.blocks/blk*.dat: 这个是直接写文件的.比特币中的blocks,会通过网络的形式dumped到disk上.一般他们在以下情况中被使用:重新扫描wallet中丢失的交易;链的重组;将blocks的数据提供给其它正在同步的节点.
2.blocks/rev*.dat: 这个是直接写文件的.存储的是一些undo的blocks数据(其实还是存储的blocks数据),这里的作用和mysql中的undo log一致,用于“出错”后的错误恢复.(这里的出错需要做特殊理解)
3.blocks/index/*.ldb: 这里主要存储一些blocks的元数据信息以及blocks在disk上的pos信息,这些信息会存储到LevelDB中。
4.chainstate/*.ldb: 这里主要存储当前还没有花费的所有的交易输出以及交易的元数据信息都会在这里存储,在存储的时候会做一些简单的压缩。存储chainstate的数据主要是用来去验证新进来的blocks和tx是否是合法的。如果没有这个操作,就意味着对于每一个被花费的out你都需要去进行全表扫描来验证。这个也是存储到LevelDB上。

文件权限问题
如何防止非法用户获取到数据(管理好钱包,也就是 wallet.dat文件)

dns自动获取种子问题
进程启动后,ctrl+c关闭经常卡几分钟在"dnsseed thread exit"原因.
当bitcoin客户端第一次启动的时候,程序不知道任何活跃的bitcoin全节点.为了发现一些IP地址,需要把一些DNS地址(也叫dns种子)硬编码到比特币源码中.如果没有dns seed,客户端不能自动联上节点.
Dns Seed 由比特币的社区成员维护,其中一些提供动态的dns seed服务,通过扫描网络自动获取活跃的节点IP地址,其中一些提供静态dns seed,这些种子是手动添加的.
dns seed 硬编码在什么地方了?

# src/chainparams.cpp
vSeeds.emplace_back("seed.bitcoin.sipa.be", true);  
vSeeds.emplace_back("dnsseed.bluematt.me", true); 
vSeeds.emplace_back("dnsseed.bitcoin.dashjr.org", false);  
vSeeds.emplace_back("seed.bitcoinstats.com", true);
vSeeds.emplace_back("seed.bitcoin.jonasschnelli.ch", true); 
vSeeds.emplace_back("seed.btc.petertodd.org", true);

比特币测试(交易、地址、钱包、私钥)

修改配置文件与同步
修改配置文件bitcoin.conf
testnet=1 (默认为0)
开始同步 bitcoind -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf
如无意外,同步则开始.测试网络节点数据大概几十G,大概花了1~2个小时完成.

交易测试
1.创建钱包

bitcoin-cli  -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf createwallet "wallet-chenxin"
{
  "name": "wallet-chenxin",
  "warning": ""
}

2.查看钱包
查看当前加载的钱包内容(配置文件里指定)

1.bitcoin-cli  -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf getwalletinfo
{
  "walletname": "",
  "walletversion": 169900,
  "balance": 0.00010000,    #当前BTC数量
  "unconfirmed_balance": 0.00000000,
  "immature_balance": 0.00000000,
  "txcount": 1,
  "keypoololdest": 1568873683,
  "keypoolsize": 1000,
  "keypoolsize_hd_internal": 1000,
  "paytxfee": 0.00000000,
  "hdseedid": "c530a8eea32c6f547d66a00698ed3ded2a14f4e4",
  "private_keys_enabled": true
}
2.bitcoin-cli  -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf listaddressgroupings
[
  [
    [
      "2Msjqu5hjBRtTbyqu25XzoCiPqVKqLc8Q9P",
      0.00010000,
      "chenxin"
    ]
  ]
]

3.备份钱包
就是备份"wallet.dat"文件.GUI上的备份功能,也是直接拷贝这个文件到用户指定目录.
每次有新地址生成后(尤其是这个地址上有币),就一定要重新备份钱包.因为新地址对应着一个新的密钥.

4.加密与解密钱包
加密钱包,会重新根据当前wallet.dat生成新的wallet.dat(加过密的),以前备份的wallet.dat都会失效(密码当前为168.....).转账的时候需要这个密码.
MAC上,GUI支持点击.
Linux上,对应指令:
加密:
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf encryptwallet "168....."
解密:
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf walletpassphrase "168....." 60
解锁后重新锁定说明:

bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf walletpassphrase "168....." 60 #过60秒后,钱包解密密钥将从内存中消失(防止黑客).
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf walletlock #在60s没过完的情况下,手动重新锁定.

5.切换钱包
bitcoin.conf配置文件中指定.
wallet=/data/coin_test/bitcoin/bitcoin/bitcoin-data/testnet3/wallets/wallet-chenxin/
如果是测试网络,则放到"[test]"下面.

bitcoin-cli  -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf getwalletinfo 
{
  "walletname": "/data/coin_test/bitcoin/bitcoin/bitcoin-data/testnet3/wallets/wallet-chenxin/",
  "walletversion": 169900,
  "balance": 0.00140734,
  "unconfirmed_balance": 0.00000000,
  "immature_balance": 0.00000000,
  "txcount": 3,
  "keypoololdest": 1568968231,
  "keypoolsize": 997,
  "keypoolsize_hd_internal": 1000,
  "unlocked_until": 0,
  "paytxfee": 0.00000000,
  "hdseedid": "6aebc532a2d9d0a8b08cbff35888ec0ed03be5e0",
  "private_keys_enabled": true
}

6.钱包与账号关系
现在应该没有account的概念了.

7.新建地址(钱包对应收款地址可以有多个)
创建的地址,就是该钱包的收款地址.官方建议每笔交易使用一个新的地址(虽然可以复用).

8.密钥(地址,公钥,私钥 区别)
收款地址是一个公钥对应的地址.可以通过这个收款地址,导出对应的私钥地址.请见本文档下文说明.

9.导出私钥(收款地址对应的私钥地址)

bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf walletpassphrase "168....." 60 #先解密钱包.说明部分请参考下文.这里从默认钱包导出的.
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf dumpprivkey "2MzG29vB6xRrq7r9R4v9r5gscw9W9zZbGcS" # 根据收款地址或得私钥
cSpyAznMEntPCtvTCsqTGiTxMH37rDVJFQy4PLYe1Fsx4QuFeX1B

9.导入私钥
RPC命令格式: importprivkey "privkey" ( "label" ) ( rescan )
将私钥(dumpprivkey返回)添加到钱包中。需要一个新的钱包备份。
提示:使用importmulti导入多个私钥。
参数:
"privkey":字符串,必须项。私钥(dumpprivkey的输出)
"label":字符串,可选项,默认为空。可选标签。
rescan:布尔值,可选项,默认为true。重新扫描钱包的交易。
注意:如果rescan为真,则此调用可能需要一个多小时才能完成,在此期间,其他rpc调用可能报告导入的密钥存在,但相关事务仍然缺失,导致临时错误/虚假余额和未使用的输出,直到rescan完成。

私钥 cSpyAznMEntPCtvTCsqTGiTxMH37rDVJFQy4PLYe1Fsx4QuFeX1B 导入到 wallet-chenxin 钱包里.
此笔交易对应 0.00000734 BTC 收入
当前 wallet-chenxin钱包含有 0.00100568 BTC
当前 默认钱包含有 0.00147100 BTC

执行导入(在Linux机器上操作)
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf importprivkey "cSpyAznMEntPCtvTCsqTGiTxMH37rDVJFQy4PLYe1Fsx4QuFeX1B"
此操作等待大约20分钟,默认钱包金额发生变化.
默认钱包:私钥那笔是接收币操作,故默认钱包金额增加了(因为默认钱包增加了那笔私钥).
wallet-chenxin钱包:因仍旧有那个私钥(存在钱包中),故金额未发生变化.
MAC端:Mac端GUI上的还没有改变,因为Mac端的没有执行导入私钥.也就是MAC上的钱包没有变动(私钥未增加),两个钱包里的金额都未发生改变.

查看导入后的钱包变化
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf getwalletinfo
{
  "walletname": "",
  "walletversion": 169900,
  "balance": 0.00147834, # 多了0.00000734,之前最初从默认钱包转到wallet-chenxin金额就是 "收入: 0.00000734 BTC".
  "unconfirmed_balance": 0.00000000,
  "immature_balance": 0.00000000,
  "txcount": 5,
  "keypoololdest": 1568873683,
  "keypoolsize": 1000,
  "keypoolsize_hd_internal": 1000,
  "paytxfee": 0.00000000,
  "hdseedid": "c530a8eea32c6f547d66a00698ed3ded2a14f4e4",
  "private_keys_enabled": true
}

说明: 当同一个密钥同时属于A,B两个钱包,在这2个钱包间转账,那么会被无缘无故的扣除手续费,显示在两个钱包上,就是2个钱包都在被扣费.因为转账1个币从A钱包到B钱包,总额没有变化,但手续费需要付给第三方.

10.支付与转账
地址部分,请查看"地址说明".

创建收款地址
生成当前加载的钱包的一个新地址(收款地址)
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf getnewaddress "chenxin"
返回值: 2Msjqu5hjBRtTbyqu25XzoCiPqVKqLc8Q9P

测试币申请
因是测试环境,需要获取测试币.在以下测试币申请地址.
http://bitcoinfaucet.uo1.net/send.php (申请成功,网页提示"0.00010000 coins sent to 2Msjqu5hjBRtTbyqu25XzoCiPqVKqLc8Q9P")
https://coinfaucet.eu/en/btc-testnet/ (这个网址好像不行)
一般在上述网站申请后,mac客户端会立即提示收到币(当然,处于待收阶段,还需要6个区块的验证).

完成转账后,可以从以下网站看收付款:
https://live.blockcypher.com/btc-testnet/tx/302ecc4a3c19a7b2262b07e6a9f0a304ab5288f57dbf49a62e2e28e811aba9d9/

查询当前余额

bitcoin-cli  -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf  getbalance
0.00010000
或
bitcoin-cli  -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf  listaddressgroupings
[
  [
    [
      "2Msjqu5hjBRtTbyqu25XzoCiPqVKqLc8Q9P",
      0.00010000,
      "chenxin"
    ]
  ]
]
且bitcoind进程输出也会提示(或debug.log日志也会)
2019-09-19T10:08:26Z [default wallet] AddToWallet 0b657c6e869a3fdb7775732eee5c40c8dd8eb103ae93f6c110a94844c07c9300  new
2019-09-19T10:24:14Z UpdateTip: new best=00000000be3805064989c9309dc7d625dc71270c5098485897e5211c3cdebf7d height=1578958 version=0x20000000 log2_work=72.220433 tx=52193257 date='2019-09-19T10:24:12Z' progress=1.000000 cache=0.2MiB(1723txo) warning='13 of last 100 blocks have unexpected version'
2019-09-19T10:24:14Z [default wallet] AddToWallet 0b657c6e869a3fdb7775732eee5c40c8dd8eb103ae93f6c110a94844c07c9300  update

支付,执行转账

解锁钱包
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf walletpassphrase "168..." 60 #因是加密钱包,所以先解密
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf sendtoaddress "2NDHhJDXv..SuEbz" 0.0004 #转账
fed9790adaa8c5b4a4c46cb7ac9fe4d86e8c2b37bf57aee9e29e2c4c897c7f8a #返回值是个交易ID

10.助记词有吗?
不同钱包区别不同.bitcore没有.

11.默认钱包和自建的钱包啥区别?
安装节点后,有个默认钱包.可以手动再创建钱包(位置在默认钱包的下一级目录).

12.地址说明
每个地址对应着钱包里的一个私钥.钱包就是所有私钥的集合.官方建议每笔交易新建一个收款地址.
收款地址,付款地址有区别吗?地址应该不分收款地址或付款地址.统称地址.GUI上看不全,需要RPC指令listaddressgroupings.

测试转账流程里的收付款地址情况

将 wallet-chenxin 钱包的部分金额发给默认钱包的 2NF1SsuPBWGh5eGa5RexfAYdKqJqiVULzmZ 地址.
查看支付的具体地址是什么?从 wallet-chenxin 钱包的哪些地址里的金额扣过去的?
(转账后,确认网址 https://live.blockcypher.com/btc-testnet/address/2NF1SsuPBWGh5eGa5RexfAYdKqJqiVULzmZ/ )

转出钱包
0.00000734 BTC from 2MzG29vB6xRrq7r9R4v9r5gscw9W9zZbGcS (output) 地址1
0.00009834 BTC from 2NAycnXJkP3kBTxdgsZUqntkVxDJe1xyr4K (output) 地址2
0.0009 BTC from 2NAkMUZSdn9hht3YAB8XBR8ePjFhukxkK6b (output) 地址3
合计 0.00100568 BTC (其中0.00000568是手续费).
以上是支出钱包 wallet-chenxin 付出的费用.可以看出,款项是从3个地址支出的.其中地址1,3是之前接收币生成的地址.地址2不知道哪里来的.

转入钱包
0.001 BTC to 2NF1SsuPBWGh5eGa5RexfAYdKqJqiVULzmZ (unspent)
以上是接收钱包 默认钱包 收到的费用.该地址是收款地址,付款方指定的.

地址说明

RPC指令:  listaddressgroupings
[
  [
    [
      "2MzG29vB6xRrq7r9R4v9r5gscw9W9zZbGcS", #地址1
      0.00140000,
      ""
    ],
    [
      "2N57gLJSYvTUwbmAfVg6rgS1LrsDB58afgJ", #地址4
      0.00000000,
      ""
    ],
    [
      "2NAkMUZSdn9hht3YAB8XBR8ePjFhukxkK6b", #地址3
      0.00000000,
      ""
    ],
    [
      "2NAycnXJkP3kBTxdgsZUqntkVxDJe1xyr4K", #地址2
      0.00000000
    ]
  ]
]
而从 wallet-chenxin 钱包的GUI里,查看"接收"选项卡,里面只有3个地址,不包含"地址2"

RPC指令: listreceivedbyaddress
能看到的,跟GUI里是一致的,只看到"地址1,3,4".

日常运维

更新程序.
不同步了排查下原因.
钱包就是备份dat文件,加密钱包,解密钱包.转账.
可能会用到导出收款地址公钥对应的私钥,然后将私钥导入其他钱包,那笔交易另一个钱包也看得到了.

常用指令统计(解析请参考具体内容)

bitcoind -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf #启动
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf stop #关停
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf createwallet "wallet-chenxin" #创建钱包
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf getwalletinfo #查看钱包
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf listaddressgroupings #查看钱包内的所有地址(含GUI里看不到,GUI看到的跟listreceivedbyaddress相同)
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf getbalance # 查询余额
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf encryptwallet "168....." #加密钱包
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf walletpassphrase "168....." 60 #解密钱包(转账/导出私钥都需要先解密)
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf dumpprivkey "2MzG29...9zZbGcS" # 根据收款地址获取私钥(这里是默认钱包)
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf importprivkey "cSpyAznMEntPC...4QuFeX1B" #导入私钥.导入到另一个钱包
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf getnewaddress "chenxin" #生成一个收款地址,标签为"chenxin",可以省略标签
bitcoin-cli -conf=/data/coin_test/bitcoin/bitcoin/bitcoin.conf sendtoaddress "2NDHhJDXv..SuEbz" 0.0004 #转账

其他知识

md5sum 和 sha256sum 验证软件安装包完整性

md5sum 和 sha256sum 都用来用来校验软件安装包的完整性.讲解如何使用两个命令进行软件安装包的校验.

sha 是什么?
sha 为 安全散列算法(英语:Secure Hash Algorithm,缩写为SHA)是一个密码散列函数家族,是FIPS所认证的安全散列算法。
能计算出一个数字消息所对应到的,长度固定的字符串(又称消息摘要)的算法。
且若输入的消息不同,计算得出的相同字符串的几率极低。
SHA家族的五个算法,分别是SHA-1、SHA-224、SHA-256、SHA-384,和SHA-512.
由美国国家安全局(NSA)所设计,并由美国国家标准与技术研究院(NIST)发布;是美国的政府标准。后四者有时并称为SHA-2。
SHA-1在许多安全协定中广为使用,包括TLS和SSL、PGP、SSH、S/MIME和IPsec,曾被视为是MD5(更早之前被广为使用的杂凑函数)的后继者。MD4 ->MD5 ->SHA-1 ->SHA-2.

md5 是什么?
md5 为 消息摘要算法(英语:MD5 Message-Digest Algorithm),一种被广泛使用的密码散列函数,可以产生出一个128位(16字节)的散列值(hash value),用于确保信息传输完整一致。
MD5由美国密码学家罗纳德·李维斯特(Ronald Linn Rivest)设计,于1992年公开,用以取代MD4算法。

sha256sum校验软件是否被非法修改过的方法

方法1:
sha256sum bitcoin-0.18.1-x86_64-linux-gnu.tar.gz  列出值,与官方给出的文件或值对比.输出如下
600d1db5e751fa85903e935a01a74f5cc57e1e7473c15fd3e17ed21e202cfe5a  bitcoin-0.18.1-x86_64-linux-gnu.tar.gz
方法2:
sha256sum -c SHA256SUMS.asc 列出当前文件夹下的所有文件校验值,是否跟SHA256SUMS.asc文件里描述一致.输出如下
...
bitcoin-0.18.1-x86_64-linux-gnu.tar.gz: 确定
...
方法3:
sha256sum -c <(grep bitcoin-0.18.1-x86_64-linux-gnu.tar.gz SHA256SUMS.asc )
方法4:
grep bitcoin-0.18.1-x86_64-linux-gnu.tar.gz SHA256SUMS.asc | sha256sum -c

类似的方法还有以下,
md5sum test.txt
sha1sum test.txt

posted @ 2020-04-21 15:11  ChanixChen  阅读(1291)  评论(0编辑  收藏  举报