Local Testnet
Setting up a testnet using just one PC is very easy, and lets you test things out with very minimal setup.
Setup
Setup with Docker
Change config
Before we start we just need to change slight a bit on the cryptonote_config.h
header file with some constants so we don't use our main net to test on.
Open up src/config/cryptonote_config.h
Then we need to change the constants P2P_DEFAULT_PORT and RPC_DEFAULT_PORT to:
And put some different letter or number in one of these CRYPTONOTE_NETWORK uuids:
And also we need to comment out seed nodes:
Now we are good to go to start with Docker. So if we want to setup our own testnet locally on our computer we will need to install Docker on our computer.
Install Docker
On Windows or Mac it's enough to install Docker Desktop and we will have everything we need in order to setup. For GNU/Linux however there is a slight different process. We are going through the steps for doing it on a Ubuntu distribution, it should work on all Debian derived distributions. Read below.
Update our headers:
Installing neccessary dependencies for Docker:
Setting up the keyring:
Updating our sources.list for be able to download Docker:
Installing Docker and Docker Compose:
Start the orchestration of Docker containers
So now we have everything in place in order for us to build and orchestrate up a local testnet. We do not need to install all dependencies mentioned before this section of Docker on your computer. When we start the process of setting up the testnet we will build a Docker Image that installs everything for us automatically.
So to start from scratch we will use the shell script setup-testnet.sh
but before that we must make sure that all our shell scripts that we need are executable on our system. To make the shell scripts executable:
To start:
./setup-testnet.sh
So now the first time when starting the script it will take a while to compile and link all the files (around 15-20 minutes dependening on how powerful computer you have). So when it's done you will see a lot of output of the Daemons starting on three nodes. The miner do not have any output on the terminal.
Stop all Docker containers
So all of these containers running will take up some memory and CPU usage on your system so it could be wise to stop these when not using them. To do that just run the shell script:
./teardown-testnet.sh
This makes sure that we still have the image saved locally so we don't need to build it again when we will start it.
Start all Docker containers again
Instead of using setup-testnet.sh
file we will use the file start-testnet.sh
:
./start-testnet.sh
The difference here is that we will not build the image again and thus has to wait a while. Now this will only take seconds. And now we have our testnet up again!
Removing all data
When we want to do a full cleanup on our system with Docker we can start the script remove-testnet.sh
:
./remove-testnet.sh
Now we will remove networks, volumes, images and containers existing on our system. If you after removing everything want to start again. Just use the file setup-testnet.sh
again.
Setup without Docker
Disabling outside peers
First, we need to disable incoming peers, so they don't interfere with our testnet. This step is not mandatory, but it's likely you'll get other daemons connected to you (or you will connect to the seed nodes), messing up your testnet.
You can block the p2p port of your daemon with ufw
, or another firewall program.
We need to apply this to each daemon p2p port we launch.
Once you're done, and want to re-enable, either disable ufw, or run
Clearing checkpoints
If you're wanting to mine any blocks, you'll want to empty the checkpoints file. Open up src/config/CryptoNoteCheckpoints
, and empty the checkpoints there. Recompile.
Data directories
First, we need three new folders to be the location for the blockchains for each daemon.
In this example, I'm simply going to use the folder a
, b
, and c
.
On linux: mkdir a b c
, to make the folders.
Running
Launching daemons
Next we need to launch three daemons. Each need to have a different p2p port, different rpc port, and different data directory, to not conflict.
In the below commands, replace kryptokrona
with the name of your daemon executable, if you are a kryptokrona fork.
Daemon 1
Daemon 2
Daemon 3
And you're done! The three daemons should connect to each other.
Start up a miner, and test stuff out. Remember to use the rpc port you started one of your daemons on with your wallet/miner.
Last updated