2

I installed the binary and try to listen to ZeroMQ stream. But I got nothing out. Then I installed ZeroMQ but still got nothing.

https://bitcoin.org/en/release/v0.17.1

so, are official bitcoin core releases compiled with zmq in general?

bitcoin.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

I found this article https://bitcoin.stackexchange.com/a/65066/33448 but there is no such file config.log. but I did install successfully with apt-get --yes install libzmq3-dev

docker-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
....

net stat -pant

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(inside container)

#  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"
  }
]

test RPC at host

$ 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"}

try to use lld to find out if dependency is ok, but no luck

# 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....');
});

Hami
  • 161
  • 6
  • Release binaries are statically linked, so the fact that you don't see a dependency on libzmq is not a surprise. It's also unnecessary to install anything as it's all built into the `bitcoind` binary. If it wasn't included you wouldn't be seeing the TCP listen on those ports. The fact that things don't work is probably due to an unrelated issue. – Pieter Wuille Nov 20 '19 at 20:22

2 Answers2

4

@PieterWuille is right, it is really not related to bitcoin but to ZeroMQ and docker. I look into the source code and bitcoin core uses zmq_bind( socket, bindingAddress ). For BindingAddress, I can change it to tcp://*:28332 because callers from another containers or from host would have different IPs, so the most convenient way is to set it to a range of address or simply tcp://*:28332

please refer to ZeroMQ man page at the bottom for more examples http://api.zeromq.org/4-1:zmq-tcp

ANSWER: Release binaries have ZeroMQ statically built-in.

Hami
  • 161
  • 6
  • 1
    Thanks! To get bitcoind and lnd to operate in seperate docker containers, I had to use `network_mode: "host"`, since as you mentioned. zeromq port binding within bitoind is flawed. – pangyuteng Jun 20 '21 at 21:17
-1

You may want to try install libzmq in your system and enable zmq in bitcoin.conf.

user11567
  • 31
  • 4
  • I did. I used https://github.com/ruimarinho/docker-bitcoin-core and I entered the container and installed ZeroMQ manually and enable the bitcoin.conf `zmqpubhashblock=tcp://127.0.0.1:28332 zmqpubhashtx=tcp://127.0.0.1:28333` no luck – Hami Nov 20 '19 at 13:09
  • I even wrote a mini node.js program to capture the response at the host. – Hami Nov 20 '19 at 13:54
  • `# 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)` it seems that it is not linked even after I installed zmq. how do I link them? – Hami Nov 20 '19 at 14:34
  • 1
    I downvoted. This is unrelated. You need to install libzmq if you're going to compile Bitcoin Core yourself. Release binaries have it statically built-in. It's clear from OP's question that this is the case for him, as ports are opened. – Pieter Wuille Nov 20 '19 at 21:30
  • @PieterWuille thanks, you point me to the right direction. – Hami Nov 21 '19 at 03:17