Simulate private bitcoin network with random peer discovery
Asked Answered
P

2

9

I am looking for a way to simulate a 1000 node bitcoin network on my private LAN/Wifi network.

I read the developer's guide: https://bitcoin.org/en/developer-examples#regtest-mode which mentions the regtest mode that works primarily for single nodes or specified nodes and not random nodes like the actual network.

Some people might suggest using the testnet mode but that is not useful for me as I want to check a new protocol for bitcoins that wont be supported by the unknown nodes over the testnet network.

To put it simply, I am looking to simulate a complete bitcoin network within my LAN/Wifi network.

Polarization answered 22/10, 2015 at 2:18 Comment(4)
You can model the whatever network you wish to using the regtest mode right..What other aspect of the network are you looking out for?Nusku
@Nusku What I want is exact simulation of testnet or main net on a private network. That means, I want to start a new blockchain for nodes on my LAN, they should connect only within themselves via the peer discovery method that is exactly like the actual bitcoin network. First time a node joins this custom network, it should connect to custom hardcoded nodes(as I have disabled DNS discovery in my code) by sending version and verack messages and then exchange getaddr and addr messages to discover other nodes on the network.Polarization
Despite the fact that this question should probably be moved to the bitcoin site, it's an interesting one. Did you ever figure this out? According to en.bitcoin.it/wiki/… , the addresses provided via command line (addnode) are not advertised in response to a getaddr request. It seems chicken vs egg: if they are not advertised, then how will the network grow? Or is it simply not part of the regtest mode?Tiatiana
did you figure a way out to form this network? I am using docker containers in regtest mode, but need to find a way to automatically detect and connect to some peers.Cummine
W
0

The trick is to sandbox them if you are trying to connect on a LAN.

  • specify a unique port (if listening) and rpcport (if using rpc) for each node
  • specify a unique data directory for each node

Use mkdir to create directories the first time

mkdir $HOME/regtest/A/
mkdir $HOME/regtest/B/
mkdir $HOME/regtest/C/

Modify & run this bash script(note the port numbers, there are 9 of them in this example) to connect to each other in round-robin.

#!/bin/bash
bitcoind -server -listen -port=17590 -rpcuser=<user> -rpcpassword=<pass> -rpcport=16590 -datadir=$HOME/regtest/A/ -addnode=localhost:17591 -regtest -pid=$HOME/regtest/A/ -daemon -debug
bitcoind -server -listen -port=17591 -rpcuser=<user> -rpcpassword=<pass> -rpcport=16591 -datadir=$HOME/regtest/B/ -addnode=localhost:17592 -regtest -pid=$HOME/regtest/B/ -daemon -debug
bitcoind -server -listen -port=17592 -rpcuser=<user> -rpcpassword=<pass> -rpcport=16592 -datadir=$HOME/regtest/C/ -addnode=localhost:17590 -regtest -pid=$HOME/regtest/A/ -daemon -debug

Since you want to research peer discovery you might want to look at the difference between trying -connect instead of -addnode

Warbeck answered 9/4, 2018 at 23:8 Comment(0)
G
0

I am working on something that will allow you to do that. It is called bitbrew. You can check it out on github: https://github.com/rishkwal/bitbrew#readme

To use it, install node.js(https://nodejs.org/en/download/) and Docker(https://www.docker.com/) on your device.

Then install BitBrew by running:

npm install -g bitbrew

Spin up 10 nodes by running:

bitbrew brew -n 10

This will create 10 containers running 10 bitcoin regtest nodes. Now you can connect the nodes either manually by using:

bitbrew connect node0 node1 node2

This will create an outbound connection from node0 to node1 and node2

Or you can connect all the nodes automatically in a linear fashion using:

bitbrew connect -all

You can attach to any node with:

bitbrew attach <node-name>

You can find a complete guide here: https://rishkwal.github.io/bitbrew/

Gregorygregrory answered 18/7 at 17:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.