日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

探索比特币源码2-配置Bitcoin Core节点

發(fā)布時間:2024/7/23 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 探索比特币源码2-配置Bitcoin Core节点 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

探索比特幣源碼2-配置Bitcoin Core節(jié)點

回顧上文探索比特幣源碼1-運行比特幣核心

我們已經(jīng)運行上了Bitcoin Core,開始同步區(qū)塊鏈數(shù)據(jù)

這個過程會持續(xù)一兩天,我也不能干等著,便開始進行一些小練習,比如區(qū)塊信息的查詢,交易信息的查詢等等。

一個小插曲

一切本來很順利,但是似乎是由于我運行如下命令后與Bitcoind產(chǎn)生了沖突

$ curl https://blockchain.info/unspent?active=1Cdid9KFAaatwczBwBttQcwXYCpvK8h7FK

這個命令查詢指定賬戶所有的可用未消費輸出utxo

在這之后,我再運行命令行幫助程序bitcoin-cli訪問比特幣核心客戶端的RPC接口時,如bitcoin-cli getblockchaininfo等命令,無一例外的報了如下的錯誤,甚至是bitcoin-cli stop。

$ bitcoin-cli getblockchaininfo error: Could not locate RPC credentials. No authentication cookie could be found, and RPC password is not set. See -rpcpassword and -stdinrpcpass. Configuration file: (/home/username/.bitcoin/bitcoin.conf) $ bitcoin-cli stop error: Could not locate RPC credentials. No authentication cookie could be found, and RPC password is not set. See -rpcpassword and -stdinrpcpass. Configuration file: (/home/username/.bitcoin/bitcoin.conf)

這個錯誤看似是由于我們之前沒有配置bitcoin.conf導致的,我嘗試配置了bitcoin.conf,但并沒有效果

經(jīng)過一番的探索,我發(fā)現(xiàn)了報錯的真正原因是Bitcoin Core客戶端意外的關(guān)閉了,很可能是剛剛執(zhí)行的命令,即HTTP命令行客戶端curl進行通信的過程中與比特幣節(jié)點存在某些沖突(這僅僅只是我個人的猜測,還望了解的大佬告知)

但無論如何,問題被找到了,解決方案簡單到爆炸,重新運行客戶端即可…

因此,如果你也遇到了這個問題,首先檢查客戶端是否正在運行是個明智的舉動。

配置bitcoind并重建索引

配置bitcoind

雖然剛剛的小插曲被證實與Bitcoin Core的配置無關(guān),但為了避免后面還會遇到什么問題,這里還是打算將上一文忽略的配置問題解決。

這里手動創(chuàng)建并編輯配置文件bitcoin.conf,該文件通常要放在~/.bitcoin/bitcoin.conf路徑下

無論進行何種配置,配置文件bitcoin.conf必須包含rpcuser和rpcpassword兩個條目。

如下是一個完整索引節(jié)點的配置示例:

txindex=1 rpcuser=bitcoinrpc rpcpassward=CHANGE_THIS

默認情況下,Bitcoin Core構(gòu)建一個僅包含與用戶錢包有關(guān)的交易的數(shù)據(jù)庫。如果想要使用諸如getrawtransaction之類的命令訪問任何交易的信息(后面會慢慢介紹),則需要配置Bitcoin Core以構(gòu)建完整的交易索引,這可以通過在配置文件中設(shè)置txindex = 1來實現(xiàn)。

這里是一個當設(shè)備資源有限時的配置示例:

maxconnections=15 prune=5000 minrelaytxfee=0.0001 maxmempool=200 maxreceivebuffer=2500 maxsendbuffer=500 rpcuser=bitcoinrpc rpcpassword=CHANGE_THIS

更多的配置選項及相關(guān)解釋可以通過bitcoind --help命令查看

顯然,為了擁有完整的功能我們需要配置一個完整索引節(jié)點。

重建索引

編輯好配置文件后,重新運行bitcoind客戶端,并將輸出打印到屏幕上

$ bitcoind -printtoconsole......2018-07-20 08:01:43 LoadBlockIndexDB: last block file info: CBlockFileInfo(blocks=1005, size=90286441, heights=182434...184177, time=2012-06-01...2012-06-12)2018-07-20 08:01:43 Checking all blk files are present...2018-07-20 08:01:43 LoadBlockIndexDB: transaction index disabled2018-07-20 08:01:43 : You need to rebuild the database using -reindex to change -txindex.Please restart with -reindex or -reindex-chainstate to recover.: You need to rebuild the database using -reindex to change -txindex.Please restart with -reindex or -reindex-chainstate to recover.2018-07-20 08:01:43 Aborted block database rebuild. Exiting.2018-07-20 08:01:43 Shutdown: In progress...2018-07-20 08:01:43 scheduler thread interrupt2018-07-20 08:01:43 Shutdown: done

可以看到,按照提示,我們需要使用-reindex選項重新啟動bitcoind,并等待它重建索引

$ bitcoind -printtoconsole -reindex......2018-07-20 08:06:10 Reindexing block file blk00006.dat...2018-07-20 08:06:15 Loaded 7472 blocks from external file in 4869ms2018-07-20 08:06:15 Reindexing block file blk00007.dat...2018-07-20 08:06:19 Loaded 6097 blocks from external file in 4374ms2018-07-20 08:06:19 Reindexing block file blk00008.dat...2018-07-20 08:06:26 Loaded 6127 blocks from external file in 6473ms2018-07-20 08:06:26 Reindexing block file blk00009.dat.........

現(xiàn)在我們等待重建索引的完成就可以了。

注:當我們的bitcoind客戶端出現(xiàn)過問題并嘗試解決之后,一個好的習慣是首先使用bitcoind -printtoconsole將運行過程打印到終端上,這樣可以直觀的了解錯誤是否解決,確認無誤后再重新運行,轉(zhuǎn)為后臺守護進程的模式。

總結(jié)

以上是生活随笔為你收集整理的探索比特币源码2-配置Bitcoin Core节点的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。