7

Even though it might be a bit soon for use in production, but all I find about setting up a private blockchain seems to be for testing.

But the fact we have a genesis.json should mean that anyone has the freedom to make their own ethereum blockchain.

The only thing that is not clear, is how the chain will connect to others. As I understand it will look in the local network first, but how can I limit the first node from connection to just any node?

I understand that only nodes with the same genesis block will join in, but I would want at least some initial control over how it propagates.

3 Answers 3

5
geth --networkid 1234 --ipcpath /home/roland/.ethereum/geth.ipc --datadir /home/roland/.ethereum/testnet

It's the networkid, it will indentify your network and only nodes with the same id will join the network.

6
  • Ok, so this networkid is how the instance advertises itself? This id is not centrally registered anywhere I assume?
    – Cubedj
    Jun 2, 2016 at 12:02
  • 1
    Exactly like you said! Jun 2, 2016 at 12:04
  • Just out of curiosity, what would happen if two nodes with the same id connect to eachother, but the blocks/genesis are different. Will it keep trying or is it smart enough to remember or blacklist it on the spot? Can't test this atm, because I don't have enough nodes.
    – Cubedj
    Jun 2, 2016 at 12:05
  • 1
    I really don't know, interesting question. A fork that can never be resolved I guess. Jun 2, 2016 at 12:10
  • @Cubedj you can run multiple nodes on a single workstation. Each node should should have a different working directory (--datadir). So, an empty folder and some space is all you need. To answer your question: if two nodes have same network ID but different genesis blocks, they work on different blockchains. So, they can't be connected to each other. Remember that the blockchain is constructed from the genesis block we provide. To be connected, two nodes should have same network ID and same genesis block.
    – galahad
    Jun 10, 2016 at 20:51
2
but how can I limit the first node from connection to just any node?

This can be achieved by using the --nodiscover option while starting the geth instance. This way, your node won't be discovered by default. You have to add peers manually through the unique enode information of each node. You can also use --maxpeers option to limit the no. of nodes that can connect to your private network. The following links have more information about this: Connecting to the network,

Setting up private network or local cluster, and

how to create a private Ethereum chain.

1

You need a combination of unique --networkid and unique genesis .json. To have a unique genesis json file, you can use a random nonce which in Ruby is easily generated via:

puts "0x" + "%016X" % Random.rand(16**16)

In addition the --nodiscover option means that your nodes will not be discovered by any outside nodes, and forces you to manually connect your nodes together using the enode data. Fyi, one way to do this is to preload the enode info, for example by attaching to an already running instance via:

geth --preload ..path..\(here).js attach ipc:\\.\pipe\geth.(here).ipc

where the .js contains

admin.addPeer("endoe:..");
admin.addPeer("enode:..");

Finally, the --maxpeers option just adds one additional (limited) layer of protection. If all your nodes are up then maxpeers will work, but if one or more of your nodes are down then it will no longer be effective. So make sure you do use --nodiscover.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.