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.

Dave Sag
  • 13,266
  • 14
  • 86
  • 134

2 Answers2

1

I think you'll need to add rpcallowip=192.168.59.103 to both of your bitcoin.conf files for the nodes. By default bitcoind will only listen for RPC connections on localhost (according to the docs).

Once you've added your IP to the allow list, you can check to see if it has worked by doing a telnet 192.168.59.103 19001.

To see a list of what your PCs open ports (and from where they're accepting connections), do a netstat -tunlp.

Chris McKinnel
  • 14,694
  • 6
  • 64
  • 67
  • Thanks Chris that helped. `telnet 192.168.59.103 49155` was able to connect but got bounced. Running my test again returned `[Error: Invalid params, response status code: 403]` which is better but still not quite there. – Dave Sag Aug 05 '14 at 01:28
  • 403 means forbidden. Are you sure your passing in the password/username like it wants it? – tkone Aug 05 '14 at 13:06
  • Thanks @tkone I've triple checked the `user: "admin1"` and `pass: "123"` values and compared them to the `rpcuser=admin1` and `rpcpassword=123` lines in the `bitcoin.conf` file and they match perfectly. I've also cross referenced with the [test over at the `node-bitcoin` project](https://github.com/freewil/node-bitcoin/blob/master/test/index.js#L90) and I can't see a difference. – Dave Sag Aug 06 '14 at 06:59
  • Ah, you're using `boot2docker` - have you forwarded the range of docker ports from your `boot2docker` VM to your host? What does `netstat -tunlp` look like from within your container? Try setting `rpcallowip=*` in your config to see if that makes a difference. – Chris McKinnel Aug 06 '14 at 09:12
  • w00t! thanks @ChrisMcKinnel setting `rpcallowip=*` worked. So now I need to work out how to narrow that down. That's a whole different question however. – Dave Sag Aug 06 '14 at 09:43
  • You'll be able to see where the connection is coming from by doing an `strace -f -p PID` in your container where PID is the process ID of `bitcoind` – Chris McKinnel Aug 06 '14 at 10:16
1

I would just change

rpcallowip=192.168.*.*

That way it as at least in a C class range

Sam Hodge
  • 11
  • 1
  • Good idea Sam - I'm looking for a way to tell **exactly** what IP `bitcoind` is seeing so I can tighten this up; but for my testing purposes this is okay for now. – Dave Sag Aug 07 '14 at 00:07