Bitcoin-Core
官方發布的比特幣核心一般都是用zmq編譯的嗎?
我安裝了二進製文件並嘗試收聽 ZeroMQ 流。但我什麼也沒拿出來。然後我安裝了 ZeroMQ 但仍然一無所獲。
<https://bitcoin.org/en/release/v0.17.1>
那麼,官方比特幣核心版本一般是用 zmq 編譯的嗎?
比特幣.conf
listen=1 upnp=0 txindex=1 maxconnections=40 server=1 rpcthreads=4 rpcuser=alice rpcpassword=alice rpcauth=xxxxx rpcallowip=0.0.0.0/0 rpctimeout=30 txconfirmtarget=6 mempoolexpiry=72 maxmempool=300 maxorphantx=100 debug=rpc logips=1 limitfreerelay=10 minrelaytxfee=0.0001 zmqpubhashblock=tcp://127.0.0.1:28332 zmqpubhashtx=tcp://127.0.0.1:28333 [main] rpcbind=192.168.1.107 [test] rpcbind=0.0.0.0 [regtest] rpcbind=0.0.0.0
我發現這篇文章<https://bitcoin.stackexchange.com/a/65066/33448> 但沒有這樣的文件
config.log
。但我確實安裝成功apt-get --yes install libzmq3-dev
碼頭工人-compose.yml
.... bitcoincore: image: bitcoincore networks: - my-network build: context: bitcoinCore/ volumes: - shared:/rpc ports: - 8332:8332 - 8333:8333 - 18332:18332 - 18333:18333 - 18443:18443 - 18444:18444 - 28332:28332 - 28333:28333 ....
淨統計-褲子
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:18332 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:18333 0.0.0.0:* LISTEN - tcp 0 0 127.0.0.11:35491 0.0.0.0:* LISTEN - tcp 0 0 127.0.0.1:28332 <--- 0.0.0.0:* LISTEN - tcp 0 0 127.0.0.1:28333 <--- 0.0.0.0:* LISTEN - tcp 0 0 172.22.0.2:38722 31.220.15.89:18333 ESTABLISHED - tcp 0 0 172.22.0.2:60910 193.31.24.45:18333 TIME_WAIT - tcp 0 0 172.22.0.2:40730 159.203.125.125:18333 ESTABLISHED - tcp 0 0 172.22.0.2:60938 54.162.188.154:18333 ESTABLISHED - tcp 0 0 127.0.0.1:58746 127.0.0.1:18332 TIME_WAIT - tcp6 0 0 :::18333 :::* LISTEN -
getzmqnotifications(容器內)
# bitcoin-cli -testnet -rpcuser=alice -rpcpassword=alice getzmqnotifications [ { "type": "pubhashblock", "address": "tcp://127.0.0.1:28332" }, { "type": "pubhashtx", "address": "tcp://127.0.0.1:28333" } ]
在主機上測試 RPC
$ curl --user alice:alice -H 'content-type:text/plain;' http://localhost:18332/ --data-binary '{"jsonrpc":"1.0","id":"1","method":"getmininginfo"}' {"result":{"blocks":1348883,"currentblockweight":0,"currentblocktx":0,"difficulty":4194304,"networkhashps":48545593617877.57,"pooledtx":0,"chain":"test","warnings":""},"error":null,"id":"1"}
嘗試使用 lld 來確定依賴關係是否正常,但沒有運氣
# ldd /opt/bitcoin-0.17.1/bin/bitcoind linux-vdso.so.1 (0x00007ffe29b6c000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f6dd6f8c000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f6dd6f82000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6dd6dff000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f6dd6de5000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6dd6c24000) /lib64/ld-linux-x86-64.so.2 (0x00007f6dd7c53000)
tester.js
var zmq = require('zeromq') , sock = zmq.socket('sub') , RpcClient = require('bitcoind-rpc') , bitcoin = require("bitcoinjs-lib"); var config = { protocol: 'http', user: 'alice', pass: 'alice', host: 'localhost', port: '18332', }; var rpc = new RpcClient(config); sock.connect('tcp://localhost:28333'); sock.on('message', function(topic, message) { console.log(topic, message); var tx = bitcoin.Transaction.fromHex(message) if (!tx.isCoinbase()) { rpc.generate(1, console.log) console.log(topic, message) } }) // Subscribe to receive messages for a specific topic. // This can be "hashblock", "hashtx", "rawtx", or "rawblock". //sock.subscribe('rawtx'); sock.subscribe('hashtx'); rpc.getDifficulty( (err, data) => { if (err) { console.log(err); return; } console.log('RPC working Ok; obtain difficulty as followed: ',data); console.log('listening....'); });
@PieterWuille 是對的,它真的與比特幣無關,而是與 ZeroMQ 和 docker 有關。我研究了原始碼和比特幣核心用途
zmq_bind( socket, bindingAddress )
。對於BindingAddress
,我可以將其更改為,tcp://*:28332
因為來自另一個容器或主機的呼叫者將具有不同的 IP,因此最方便的方法是將其設置為一個地址範圍或簡單地tcp://*:28332
有關更多範例,請參閱底部的 ZeroMQ 手冊頁<http://api.zeromq.org/4-1:zmq-tcp>
解答: 發布二進製文件有 ZeroMQ 靜態內置。
您可能想嘗試在系統中安裝 libzmq 並在 bitcoin.conf 中啟用 zmq。