1

I'm trying to understand how the private blockchain network concept works.

Scenario:

  • Lets say I have two nodes connected to the internet but not in the same network
  • On the first node using geth I initialize using a new genesis config
  • Then I start the first node with network id set to 5501
  • Now on second node I don't initialize any genesis config
  • Just start the second node geth with same network id i.e. 5501
  • As you can see I am using network id starting with 5 so the block chain is started in a private network

Questions:

  • Will the second node get connected with the first as a peer and be part of that private blockchain?
  • How to create a private block chain network where one can only join after getting the approval or am I thinking in wrong perspective
1

Private blockchain Everyone is equal, and can mine the transactions. Basically you need to share your genesis block with the other party and once they initialize their chain, you have to add their enode addrees as peer.

Permissioned blockchain Permission is built into your blockchain client, where you can decide based on the other party cryptographic information what access will they have. Monax, Hyperledger fabric, jpmorgan quorum are some examples of permissioned chains.. Based on your comment , you are trying to create a private blockchain.

  1. Initialize your blockchain in Node A as, geth --datadir geth_data init genesis.json Note : Alloc section should be empty in your genesis block This will initialize your chain in your data directory.
  2. Now start the geth again , this time without the init geth --datadir geth_data --port 54259 console

Note, Once geth starts in console mode, enable personal API and create your 1st account, seed your account with some ether in your genesis alloc block. For adding a peer via console you should enable admin API.

  1. Get your enode address of Node A with the command

    admin.nodeInfo.enode
    "enode://fc542dd3209dd73da7b4282990e1ad39ad9d61d772bc844d416d58ae97bdbb02aa40f65 5f7565276dab552e9cc363376a6e76ebbf08f7f665b9b9d4a8b286d18@[::]:54259"

replace the [::] with your IP of Node A. Now you are ready to connect to another Node B.

4.In Node B,keep your genesis.json , your A node's enode address handy. Initialize the chain with the genesis block that you have from A.

Once initialized, you can check in either machines if they have any peers

admin.peers []

  1. Then add in Node B, Node A

    admin.addPeer("enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@52.16.188.185:30303") true

Once this is done, the two Nodes now are connected and would receive any contracts or events happening in either A or B.

You can check this by,

admin.peers

  1. Please note this linkage between the nodes would only stay until one of the node goes down. To make the linkage permanent- Add the node as a static peer.
  2. Create a file static_nodes.json and place it your data directory. Please refer to the links below.

References -

https://github.com/ethereum/go-ethereum/wiki/Connecting-to-the-network How to use static-nodes.json / trusted-nodes.json to prevent connection loss on private network? https://github.com/ethereum/go-ethereum/wiki/Management-APIs

  • Lets say I start the first node with these commands Commands: * geth init genesis.json * geth --networkid=5501 console What should be done on second node to load the first node's location * Should the other node also execute below * geth init genesis.json * geth --networkid=5501 console If you can give an example how to grant permission to other party will be great – Susmit Mar 18 '17 at 12:42
  • I have edited my answer to provide you some directions. That said, for a production grade application, a private chain having POW mining as a consensus mechanism is bad(open to abuse via double spending). You should look at either modifying the geth client to implement your own consensus mechanism or use a fork like Monax or Quorum. – Hitesh Joshi Mar 19 '17 at 14:57
  • Thanks a lot Hitesh for that great detailed answer. This is really helpful. Do you have any sample example of a custom consensus mechanism, It will be really helpful if you could share something in that line. This makes me think that private block chain in Prod mode is not quite a feasible solution. The link shared by Richard is really helpful as well. It talks about using --bootnode parameter – Susmit Mar 19 '17 at 17:01
  • Susmit, your current question does not encompass Custom consensus. I think it is important for us as community members that we do not discuss other solutions in the same thread. I suggest that you open a new question for Consensus. Also if any of the above answers actually answered your question. You should accept that answer. – Hitesh Joshi Mar 22 '17 at 9:00
1

From your comment on the other answer...

Lets say I start the first node with these commands Commands:

  • geth init genesis.json
  • geth --networkid=5501 console

The above part looks good.

What should be done on second node to load the first node's location?

Should the other node also execute below:

  • geth init genesis.json
  • geth --networkid=5501 console

This is fine, but you also need to tell it where the first node is. To do this you can either use the --bootnodes option, or create an entry in the static-nodes.json file. See this previous answer for more details.

  • Thanks Richard, this link is pretty helpful which I got from the post shared by you. link But frankly going through these features, it doesn't seem to be a regular feature to be used. So is it not quite common to create a private network to provide a dapp to be used by a closed community? When required others can join based on a combined approval process provided by the members of that group. What do you think? – Susmit Mar 18 '17 at 13:46
  • For someone to use the Dapp itself, the user isn't required to run a node in the network. The nodes are there to host the blockchain, run the transactions, etc. But a Dapp could just be a front-end (e.g. a webpage) which is accessible by anyone, and which connects to one of the nodes via Web3/RPC. – Richard Horrocks Mar 18 '17 at 13:57
  • "So is it not quite common to create a private network to provide a dapp to be used by a closed community?" Nothing is particularly common yet :-) – Richard Horrocks Mar 18 '17 at 13:58
  • You mean like I build a web application to interact with my private block chain, by providing the IP and port of one of the nodes. That web application could be accessed by multiple people but all will be accessing via same node? But the question is whether that is a feasible solution which will be utilizing the features of blockchain. To be more wider in this same concept I can have a centralized application which also has a blockchain for providing some specific features? Exactly that is the reason it becomes a bit vague to visualize the overall design to provide a solution – Susmit Mar 18 '17 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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