I created a testnet for mining using several ports in a single machine. However I see that the source codes [CAddrInfo, CAddr] are based on IP and not IP||port. Is there an easy change to make it do mining across ports [under same IP] or this is simply not possible?
1 Answer
I've had to do this, so I'll try to describe exactly what you need to do to get mining on testnet to work in a local setup. For our purposes, we'll have 2 instances of bitcoind running, the first set up to be a miner, the second as a peer.
First, create two directories, one for the miner, the other for the peer:
$ mkdir 1
$ mkdir 2
Now create this file in the 1 directory:
$ <your favorite editor> 1/bitcoin.conf
Here are the contents of the file:
testnet=1
irc=0
dnsseed=0
upnp=0
listen=1
checkpoints=0
server=1
rpcuser=test
rpcpassword=test
rpcallowip=127.0.0.1
port=20000
rpcport=20001
Now go and make the same file for the 2 directory
$ <your favorite editor> 2/bitcoin.conf
Contents:
testnet=1
irc=0
dnsseed=0
upnp=0
listen=0
checkpoints=0
connect=127.0.0.1:20000
rpcuser=test
rpcpassword=test
port=20010
rpcport=20011
Run the first instance:
$ bitcoind -datadir=1 -daemon
Run the second instance:
$ bitcoind -datadir=2 -daemon
You can check to see if everything is up and running by using bitcoin-cli:
$ bitcoin-cli -datadir=1 getinfo
Blocks should be 0 until you mine something.
If you have mining hardware, you can now mine by connecting to 127.0.0.1:20001 with the user/pass of test/test. The actual command to connect will differ based on the mining software you use, but for bfgminer, it would be something like:
$ bfgminer -o http://127.0.0.1:20001 -O test:test --generate-to <a testnet address> --no-longpoll -S all
Note that CPU mining takes several hours to find a block from my experience.
regtest
does not support peer discovery right exactly as thetestnet
right ? For eg: If I start nodes A, B, C, D and E on different ports and make A connect to C, D, and E via-addnode
and B to A, then will the peer discovery mechanism work to form connections between B and C,D,E and similarly for other nodes ?