這篇文章給出了Fastcoin多節點環境的搭建文檔,FastCoin是一個由@harrywu修改BitCoin源代碼產生的一個簡單的山寨幣。該山寨幣在原有BitCoin源碼基礎上,對BitCoin相關網絡參數、創世塊信息、工作量機制等進行了修改,從而構建出了一個簡單的山寨幣系統,該系統加快了原有的挖礦速度,能夠更方便的進行區塊鏈開發的相關測試。
1 FastCoin簡介
FastCoin是一個由@harrywu修改BitCoin源代碼產生的一個簡單的山寨幣。該山寨幣在原有BitCoin源碼基礎上,對BitCoin相關網絡參數、創世塊信息、工作量機制等進行了修改,從而構建出了一個簡單的山寨幣系統,該系統加快了原有的挖礦速度,能夠更方便的進行區塊鏈開發的相關測試。
2 系統環境
該文檔的採用了兩個節點進行測試,兩個節點的系統環境如下:
OS: Ubuntu
Linux Kernel: Linux 4.4.0
Memory: 1G
gcc Version: 5.4.0
g++ Version: 5.4.0
3 安裝準備
該文檔採用兩個節點對FastCoin山寨幣進行搭建,兩個節點做同樣的配置。
3.1 獲取FastCoin源碼
git clone https://github.com/imharrywu/fastcoin.git
3.2 安裝項目構建依賴
sudo apt-get install build-essential libtool autotools-dev autoconf pkg-config libssl-dev
3.3 安裝Berkeley DB 4.8
cd fastcoin/
BITCOIN_ROOT=$(pwd)
# 選擇 Berkeley DB安裝路徑,此處爲fastcoin子目錄下
BDB_PREFIX="${BITCOIN_ROOT}/db4"
mkdir -p $BDB_PREFIX
# 獲取源碼
wget 'http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz'
# 校驗
echo '12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef db-4.8.30.NC.tar.gz' | sha256sum -c
# 輸出結應該爲: -> db-4.8.30.NC.tar.gz: OK
# 解壓
tar -xzvf db-4.8.30.NC.tar.gz
# 構建安裝
cd db-4.8.30.NC/build_unix/
../dist/configure --enable-cxx --disable-shared --with-pic --prefix=$BDB_PREFIX
make install
3.4 安裝Boost
sudo apt-get install libboost-all-dev
3.5 安裝miniupnp
wget http://miniupnp.tuxfamily.org/files/download.php?file=miniupnpc-1.6.20120410.tar.gz
tar -xzvf miniupnpc-1.6.20120410.tar.gz
cd miniupnpc-1.6
make
sudo make install
也可以使用Ubuntu源進行安裝:
sudo apt-get install libminiupnpc-dev
4 搭建過程
4.1 編譯源碼
./autogen.sh
./configure --with-miniupnpc --without-gui --enable-upnp-default LDFLAGS="-L${BDB_PREFIX}/lib/" CPPFLAGS="-I${BDB_PREFIX}/include/" --enable-wallet
make
make install
編譯安裝之後,在src
目錄下會生成相應的二進制文件,主要用到的二進制文件有:
- bitcoind:fastcoin主程序
- bitcoin-cli:fastcoin RPC控制檯程序
如果在編譯過程中遭遇如下報錯信息,詳見【6.1 Boost依賴庫引起的報錯】:
/usr/include/boost/variant/get.hpp:178:5: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>'
BOOST_STATIC_ASSERT_MSG(
^
Makefile:3654: recipe for target 'libbitcoin_server_a-rpcrawtransaction.o' failed
make[2]: *** [libbitcoin_server_a-rpcrawtransaction.o] Error 1
4.2 相關configuration參數
--without-gui
:不使用GUI,如果需要圖形化界面,詳見【6.6 圖形化界面錢包的構建】--enable-wallet:
啓用錢包(不啓用錢包--disable-wallet
也可以進行挖礦,如果不啓用錢包,則無需安裝Berkeley DB)--enable-debug:
啓用debug模式--enable-tests:
對測試程序進行編譯CPPFLAGS
、LDFLAGS
:指定Berkeley DB的路徑
5 FastCoin測試
5.1 FastCoin配置文件
vi ~/.fastcoin/fastcoin.conf
在fastcoin.conf
文件中添加如下配置信息:
# 用戶名
rpcuser=user
# 密碼
rpcpassword=password
daemon=1
txindex=1
server=1
5.2 啓動bitcoind
在其中一個節點中執行:
cd fastcoin/src
./bincoind -gen=1 -reindex -checkpoints=0
另一個節點執行:
./bincoind -gen=1 -reindex -checkpoints=0 -addnode="另一個節點的IP,例:192.169.1.233"
5.3 bitcoind相關啓動參數
-rpcuser=
:指定用戶名-rpcpassword=
:指定密碼-daemon=
:bitcoind作爲daemon進程在後臺運行-gen=
:生成山寨幣(挖礦)-addnode=
:添加節點-reindex
:bitcoind啓動時從當前blk000??.dat
文件中的index重建區塊鏈-server
:啓用RPC服務器
5.4 bitcoin-cli
使用./bitcoin-cli <parameters>
可以查看當前區塊鏈、網絡、錢包等信息。
相關參數有:
== Blockchain ==
getbestblockhash
getblock "hash" ( verbose )
getblockchaininfo
getblockcount
getblockhash index
getchaintips
getdifficulty
getmempoolinfo
getrawmempool ( verbose )
gettxout "txid" n ( includemempool )
gettxoutsetinfo
verifychain ( checklevel numblocks )
== Control ==
getinfo
help ( "command" )
stop
== Generating ==
getgenerate
setgenerate generate ( genproclimit )
== Mining ==
getblocktemplate ( "jsonrequestobject" )
getmininginfo
getnetworkhashps ( blocks height )
prioritisetransaction <txid> <priority delta> <fee delta>
submitblock "hexdata" ( "jsonparametersobject" )
== Network ==
addnode "node" "add|remove|onetry"
getaddednodeinfo dns ( "node" )
getconnectioncount
getnettotals
getnetworkinfo
getpeerinfo
ping
== Rawtransactions ==
createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,...}
decoderawtransaction "hexstring"
decodescript "hex"
getrawtransaction "txid" ( verbose )
sendrawtransaction "hexstring" ( allowhighfees )
signrawtransaction "hexstring" ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] ["privatekey1",...] sighashtype )
== Util ==
createmultisig nrequired ["key",...]
estimatefee nblocks
estimatepriority nblocks
validateaddress "fastcoinaddress"
verifymessage "fastcoinaddress" "signature" "message"
== Wallet ==
addmultisigaddress nrequired ["key",...] ( "account" )
backupwallet "destination"
dumpprivkey "fastcoinaddress"
dumpwallet "filename"
encryptwallet "passphrase"
getaccount "fastcoinaddress"
getaccountaddress "account"
getaddressesbyaccount "account"
getbalance ( "account" minconf includeWatchonly )
getnewaddress ( "account" )
getrawchangeaddress
getreceivedbyaccount "account" ( minconf )
getreceivedbyaddress "fastcoinaddress" ( minconf )
gettransaction "txid" ( includeWatchonly )
getunconfirmedbalance
getwalletinfo
importaddress "address" ( "label" rescan )
importprivkey "fastcoinprivkey" ( "label" rescan )
importwallet "filename"
keypoolrefill ( newsize )
listaccounts ( minconf includeWatchonly)
listaddressgroupings
listlockunspent
listreceivedbyaccount ( minconf includeempty includeWatchonly)
listreceivedbyaddress ( minconf includeempty includeWatchonly)
listsinceblock ( "blockhash" target-confirmations includeWatchonly)
listtransactions ( "account" count from includeWatchonly)
listunspent ( minconf maxconf ["address",...] )
lockunspent unlock [{"txid":"txid","vout":n},...]
move "fromaccount" "toaccount" amount ( minconf "comment" )
sendfrom "fromaccount" "tofastcoinaddress" amount ( minconf "comment" "comment-to" )
sendmany "fromaccount" {"address":amount,...} ( minconf "comment" )
sendtoaddress "fastcoinaddress" amount ( "comment" "comment-to" )
setaccount "fastcoinaddress" "account"
settxfee amount
signmessage "fastcoinaddress" "message"
具體的RPC調用可以參考BitCoin RPC API文檔。
6 注意事項
6.1 Boost依賴庫引起的報錯
如果在編譯FastCoin源碼過程中遭遇如下報錯信息,則需要我們對FastCoin源碼進行修改:
/usr/include/boost/variant/get.hpp:178:5: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>'
BOOST_STATIC_ASSERT_MSG(
^
Makefile:3654: recipe for target 'libbitcoin_server_a-rpcrawtransaction.o' failed
make[2]: *** [libbitcoin_server_a-rpcrawtransaction.o] Error 1
將src/rpcrawtransaction.c
文件中的第288行:
const CScriptID& hash = boost::get<const CScriptID&>(address);
修改爲:
const CScriptID& hash = boost::get<CScriptID>(address);
6.2 Berkeley DB安裝問題
如果不想對Berkeley DB的源碼進行編譯安裝,還可以直接採用Debian源進行安裝:
sudo add-apt-repository ppa:bitcoin/bitcoin
sudo apt-get update
sudo apt-get install libdb4.8-dev libdb4.8++-dev
6.3 nTXConfirmTarget參數
該參數是確認目標值,用於計算礦工費用,默認值爲1,適用於雙節點的系統,如需對該參數進行修改。可以在執行./bitcoind
時添加參數-txconfirmtarget=number
進行配置。
6.4 txindex參數問題
如果在~/.fastcoin/fastcoin.conf
配置文件中添加了txindex
參數,則需要在啓動bitcoind
時添加啓動參數—reindex
。
6.5 圖形化界面錢包的構建
如需使用圖形化界面的錢包,需要安裝QT並且在./congfiguration
時不使用--without-gui
選項,FastCoin默認使用QT4:
sudo apt-get install libqt4-dev libprotobuf-dev protobuf-compiler
如需使用QT5,需要採用--with-gui=qt5
選項,並安裝QT5:
sudo apt-get install libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools libprotobuf-dev protobuf-compiler
本文的版權歸作者 羅遠航 所有,採用 Attribution-NonCommercial 3.0 License。任何人可以進行轉載、分享,但不可在未經允許的情況下用於商業用途;轉載請註明出處。感謝配合!