Public Network
--maxpeers
would work, as would shutting off your network connection to the Internet. If you want to mine, you will have to run a miner, either in geth
or a GPU miner like ethminer
. But note that the difficulty set in the public network blockchain is very high as this difficulty is adjusted to cater for the many thousands of computers mining the public blockchain.
Once you shut off your connection from the public network and switch on your mining, it will take a very very long time for your single miner to solve a block. But if you leave your private mining operation on for another very very long time, the difficulty will adjust downward back so your single miner mining blocks every 15 seconds.
Private Network
If you are want to try creating smart contracts, your easiest path is to spin up a Dev blockchain. This will just run on your local computer and you can set it to mine to receive some ethers in your account so you can use it to send the contract creation transactions.
See Deploying the Greeter contract via the geth CLI is not registering in my private blockchain for an example of deploying contracts to a Dev blockchain.
The --dev
parameter will tell geth
that you want to only run a Dev blockchain. The --mine
and --minerthreads 1
parameters will tell your geth
instance to mine the blockchain.
The difficulty is set low so you will mine blocks quite frequently.
The executable to run a bootnode is bootnode
. In Ubuntu, this installed alongside /usr/bin/geth
in /usr/bin/bootnode
.
You will have to generate a key to run your bootnode:
user@Kumquat:/tmp$ bootnode -genkey nodekeyfile
user@Kumquat:/tmp$ cat nodekeyfile
3bed8e0fa771475049cddac0fcc20a6cf1005e271e2b12ef339f213218b2dbdb
user@Kumquat:/tmp$ bootnode -nodekey nodekeyfile
I1001 23:17:42.874776 p2p/discover/udp.go:217] Listening, enode://d3b75b24a4fd718b1358d28ba576b2e98f73a7465326c4504f21cc0d124466a91919de18fb72a634f9108f0eedd5ef943aea5c250b41c974c4a7fb7c159b9968@[::]:30301
In a separate window, I ran the netstat
command to view the UDP 30301 port that bootnode
is listening on:
user@Kumquat:/tmp$ sudo netstat -anp | grep boot
[sudo] password for user:
udp6 0 0 :::30301 :::* 8317/bootnode
This bootnode
program only serves as a bootstrapping node and will not provide any blockchain data transfers.
You should now be able to use enode://d3b75b24a4fd718b1358d28ba576b2e98f73a7465326c4504f21cc0d124466a91919de18fb72a634f9108f0eedd5ef943aea5c250b41c974c4a7fb7c159b9968@[::]:30301
as your geth --bootnodes
parameter value, where you replace [::]
with the IP address of your bootnode computer.
Update
If you have issues getting the peer-to-peer discovery to work, add the --verbosity 6
before the console
parameter of geth
. You should see the communications to the bootnode in action.
You can also add the verbosity parameter to the bootnode
command:
user@Kumquat:/tmp$ bootnode -nodekey nodekeyfile -verbosity 9
I1001 23:17:42.874776 p2p/discover/udp.go:217] Listening, enode://d3b75b24a4fd718b1358d28ba576b2e98f73a7465326c4504f21cc0d124466a91919de18fb72a634f9108f0eedd5ef943aea5c250b41c974c4a7fb7c159b9968@[::]:30301
I1001 23:39:12.546003 p2p/discover/udp.go:453] >>> 192.168.1.14:54991 discover.pong
I1001 23:39:12.546145 p2p/discover/udp.go:521] <<< 192.168.1.14:54991 *discover.ping: ok
I1001 23:39:12.546226 p2p/discover/database.go:183] failed to retrieve node b68ed408e685e6dc75ea457b65f945fa2c6f2171c8bfaf26e32d6362c3ebe9ed3ef3aeb682991e3a01250f93f2a68ea8ca1a98676e669cc007ed227c35d7c3f1: leveldb: not found
I1001 23:39:12.546337 p2p/discover/table.go:473] Bonding b68ed408e685e6dc: known=false, fails=0 age=409813h39m12.54632801s
I1001 23:39:12.547012 p2p/discover/udp.go:453] >>> 192.168.1.14:54991 discover.ping
I1001 23:39:12.549582 p2p/discover/udp.go:521] <<< 192.168.1.14:54991 *discover.pong: ok
I1001 23:39:12.556974 p2p/discover/udp.go:453] >>> 192.168.1.14:54991 discover.neighbors
I1001 23:39:12.557059 p2p/discover/udp.go:521] <<< 192.168.1.14:54991 *discover.findnode: ok
And the latest P2P discovery protocol documentation can be found at RLPx: Cryptographic Network & Transport Protocol.
Best Answer
Does the number of maxpeers of geth option include it's own node?
No. Specifying the parameter:
--maxpeers 0
will not allow yourgeth
instance to connect to any other peer--maxpeers 1
will allow yourgeth
instance to connect to one other peer--maxpeers n
will allow yourgeth
instance to connect to n other nodesDoes --maxpeers "1" means 2 peers in the network including the node which executed the geth command with --maxpeers "1"?
No. Your
geth
instance where you specified--maxpeers 1
will have at maximum 1 connection to another peer instance. However the other peer instance may have connections to many another instances.Details below.
Test Environment
geth
instances running on ports 30301, 30302, 30303, 30304 and 30305 .--networkid 8888
and--genesis CustomGenesis.json
files - a private network.--datadir {directory}
parameter.geth
instances 2, 3, 4 and 5 all have their enode URL information listed instatic-nodes.json
in the--datadir {directory}
.geth
instance 1 is also listed in thestatic-nodes.json
and a copy of this file is also available in it's--datadir {directory}
, all 4 othergeth
instances will be connected to it as peers, regardless of the number specified in each of thegeth
instance's--maxpeer
parameter.geth
instance 1 does not have thestatic-nodes.json
file but instead uses the--bootnodes {enode URL}
and the--maxpeers {n}
parameters, the number of connections thatgeth
instance 1 will be connected to is n separategeth
nodes.geth
instance 1 does not have thestatic-nodes.json
file but instead uses the--bootnodes {enode URL}
and the--maxpeers {n}
followed by the--nodiscover
parameter,geth
instance 1 will connect to n separategeth
nodes.--nodiscover
does not rungeth
in stand-alone mode.