Fork the network
Ways to fork the testnet.
Introduction
Sometimes when we want to tests some tool we want to work in a private testnet to keep our tests isolated from the rest of the nodes.
Fork the network
First method:
If you are testing the node before a hard fork, setting a different activation time than the "official" testnets will create your own fork.
For the Nov 15th HardFork the current testnet is using the magneticanomalyactivationtime
= 153500000
. So setting a different activation time before running the Initial Blockchain Download (IBD) will result in your node forking the network alone.
The rest of the nodes of the network will ban you for sending an invalid chain. Different activation times result in nodes with different consensus rules.
Second method:
In case you are not testing a hard fork you can simply let the IBD finish, look for the hash of the last block and invalidate it using ./bitcoin-abc/src/bitcoin-cli
.
For example:
The last block is 1260770
and its hash is 000000000024bd340462fa737887b30131fa8da599f886ef8324dcc761cb9f4e
. So calling invalidate block will set your current height at 1260769
and you'll be able to mine your own 1260770
block.
In case you need to follow the main chain, there is a method called reconsiderblock
that will revalidate the block matching the hash that is passed as parameter.
For example:
Follow the testnet "official" chain after invalidating the block000000000024bd340462fa737887b30131fa8da599f886ef8324dcc761cb9f4e
Block propagation
Using the default networking configuration will result in your node sending its blocks to the rest of the network, so it won't be a real private testnet.
There are a couple of configurations that can be changed in order to avoid connecting to other nodes. The configuration depends on what the user want to test.
For example,
connect = 0
nolisten = 1
maxconnections = 0
Last updated