4

I am testing some Bitcoin related code and in order to test it have installed bitcoin-testnet-box within a docker container.

It's running fine, and, within the container I can execute commands and see the results.

The Dockerfile is exposing port 19001, which I am mapping to port 49155 as the RPC port for one of the bitcond instances and I am trying to communicate with it using node-bitcoin.

I've written a simple test which aims simply to get the current difficulty.

var bitcoin = require('bitcoin'),
    client = new bitcoin.Client({
      host: "192.168.59.103",
      port: 49155,
      user: "admin1",
      pass: "123"
    });

describe("Core Wallet Functions", function() {

  it("can get the current bitcoin difficulty", function(done){
    client.getDifficulty(function(err, difficulty){
      console.log("got response", err, difficulty);
      expect(err).to.equal(null);
      expect(difficulty).to.equal(1);
      done();
    });
  });
});

This was failing (see update below) with the error:

{ [Error: connect ECONNREFUSED] code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect' }

A quick look at docker ps shows

CONTAINER ID        IMAGE                                COMMAND             CREATED             STATUS              PORTS                                                NAMES
8b04ed26d9e3        freewil/bitcoin-testnet-box:latest   /bin/bash           3 hours ago         Up 8 minutes        0.0.0.0:49155->19001/tcp, 0.0.0.0:49156->19011/tcp   bitcoind            

I tried changing the host to both "localhost" and to "0.0.0.0" but got the same result.

Clearly I am missing something simple as the node-bitcoin tests are not really doing anything different.

The command used to run the bitcoin-testnet-box was

docker run -ti --name bitcoind -P -p 49155:19001 freewil/bitcoin-testnet-box

What might I be doing wrong?

Update

I changed bitcoin.conf as suggested below and now the error message is

[Error: Invalid params, response status code: 403]

My bitcoin.conf looks like

# testnet-box functionality
testnet=1
dnsseed=0
upnp=0

rpcallowip=192.168.59.103
rpcallowip=192.168.1.4
rpcallowip=0.0.0.0

# listen on different ports than default testnet
port=19000
rpcport=19001

# always run a server, even with bitcoin-qt
server=1

# enable SSL for RPC server
#rpcssl=1

rpcuser=admin1
rpcpassword=123

another update

It's worth explaining that I am running docker on my Mac using boot2docker so the IP number I am referring to is the IP that is displayed when I run docker ip, not the IP of my Mac itself. I'm running the test using NodeJS on my Mac, not in the boot2docker VM or the actual Docker container. So, I've tried adding rpcallowip=192.168.1.4 (where 192.168.1.4 is my Mac's IP) to my bitcoind.conf files too just in case. Alas that made no difference, I am still getting the { [Error: Invalid params, response status code: 403] code: -32602 } response.

I have also triple-checked my username and password against what's in the bitcoin.conf file.

Per Chris McKinnel's suggestion below I have run netstat -tunlp within the docker container and it shows:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:19000           0.0.0.0:*               LISTEN      65/bitcoind     
tcp6       0      0 :::19000                :::*                    LISTEN      65/bitcoind     
tcp6       0      0 :::19001                :::*                    LISTEN      65/bitcoind     
tcp6       0      0 :::19011                :::*                    LISTEN      75/bitcoind     

So I also added rpcallowip=0.0.0.0 to my bitcoin.conf file. Alas still no difference.

finally a solution

Thanks again to Chris McKinnel below setting rpcallowip=* solved the problem. Of course this raises a whole new problem but I'll burn that bridge when I get to it. For now I can test my Bitcoin processes quite happily.

4

2 回答 2

1

我认为您需要为节点添加rpcallowip=192.168.59.103两个bitcoin.conf文件。默认情况下bitcoind,只会监听 localhost 上的 RPC 连接(根据文档)。

将 IP 添加到允许列表后,您可以通过执行telnet 192.168.59.103 19001.

要查看您的 PC 打开哪些端口(以及它们从哪里接受连接)的列表,请执行netstat -tunlp.

于 2014-08-04T13:02:04.180 回答
1

我只想改变

rpcallowip=192.168.*.*

这样它至少在 C 类范围内

于 2014-08-06T11:18:17.753 回答