Customised Bitcoin core
This customised bitcoin core is created based on bitcoin core v0.15.1. The article will guide you through the steps to create a customised bitcoin core.
- Generate the private key and public key using a script, you must have openssl installed. The script is shown below. To run it, enter the following in command line: ./script <filename>
After that, there are two files generated: <filename>_private.pem and <filename>_public.pem
FILE_NAME=$1PRIVATE_KEY=${FILE_NAME}_private.pemPUBLIC_KEY=${FILE_NAME}_public.pemBITCOIN_PRIVATE_KEY=bitcoin_${FILE_NAME}_private.keyBITCOIN_PUBLIC_KEY=bitcoin_${FILE_NAME}_public.keyecho “Generating private key”
openssl ecparam -genkey -name secp256k1 -rand /dev/urandom -out $PRIVATE_KEYecho “Generating public key”
openssl ec -in $PRIVATE_KEY -pubout -out $PUBLIC_KEYecho “Generating BitCoin private key”
openssl ec -in $PRIVATE_KEY -outform DER|tail -c +8|head -c 32|xxd -p -c 32 > $BITCOIN_PRIVATE_KEYecho “Generating BitCoin public key”
openssl ec -in $PRIVATE_KEY -pubout -outform DER|tail -c 65|xxd -p -c 65 > $BITCOIN_PUBLIC_KEYecho “Files created!”
2. Bitcoin’s block has to satisfy certain difficulty. Download genesisgen program from https://github.com/liveblockchain/genesisgen
The program is used to mine genesis block.
3. Compile the genesisgen program. The run it:
./genesis <public_key>
The program will take a while to find the merkle root and hash of genesis block.
4. Copy the byte swapped merkle root and hash to CMainParams constructor of the mainnet in chainparams.cpp
assert(consensus.hashGenesisBlock == uint256S("00000000395a494f09a2e15dc8c32e0ea69aa60dde5b5a3aafc77cf059063f72"));assert(genesis.hashMerkleRoot == uint256S("e9d3d787cec0e87057ebe72e4c91e1c25fc75f71d45d19eef07dd52bb15af594"));
5. In CreateGenesisBlock in chainparams.cpp, change the pszTimestamp string and the genesisOutputScript
const char* pszTimestamp = "The Indian News 09/June/2018 Mumbai Car Free Day";const CScript genesisOutputScript = CScript() << ParseHex("048c87388e0bf2c831d21a57c872975d3fe46a644f69dd10d9f2ab407a06c3f88901b65b12b1ee007b045d6a65dfca7e36b9dd7a3f7310a7f79575cdf772028458") << OP_CHECKSIG;
6. Change the minimum work required to speed up mining, in chainparams.cpp
consensus.nMinimumChainWork = uint256S("0000000000000000000000000000000000000000000000000000000100010001");
7. Change the max money, in amount.h
static const CAmount MAX_MONEY = 21000000 * COIN;
8. Change the coinbase maturity, in consensus/consensus.h
This will decide coins generated could be spent after how many blocks.
static const int COINBASE_MATURITY = 100;
9. Remove dns seeds, in chainparams.cpp, remove lines starting with
vSeeds.emplace_back
10. Remove checkpoints, in chainparams.cpp,
set checkpointData = { };
11. Choose a different message start signature. This is important, without this change, if you accidentally connect your node to the bitcoin network, it will decide that bitcoin’s chain is longer and starting to download the real bitcoin blocks. In CMainParams constructor in chainparams.cpp
pchMessageStart[0] = 0xf0;
pchMessageStart[1] = 0xb0;
pchMessageStart[2] = 0xb0;
pchMessageStart[3] = 0xd0;
12. Choose your preferred address prefix letter. Refer to the table in https://en.bitcoin.it/wiki/List_of_address_prefixes
In CChainParams::base58Prefixes of chainparams.cpp
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,<new_value>);
13. Mining
Get cpuminer from https://github.com/pooler/cpuminer and build it.
Start mining with the command
./minerd --user <username> --pass <password> --url http://127.0.0.1:<port_number>/ --threads 4 --coinbase-addr XQg3PmNxX9oEbxsymqtQHir6dkPpVPTJ6P --coinbase-sig "my test coins" -a sha256d -D
To have the cpuminer working, you need to run at least two bitcoin core instances, such as
first node:
src/bitcoind -debug=rpc -dns=0 -dnsseed=0 -datadir=../datadir_0/ -connect=0 -maxtipage=432000000 -daemonsecond node:
src/bitcoind -debug=rpc -addnode=127.0.0.1:<first_instance_port_number> -dns=0 -dnsseed=0 -datadir=../datadir_1/ -daemon
Appendix:
A1. You can create docker container that contains customised bitcoin core image, then run it as:
docker run -it -p <outer_port>:<inner_port> <username>/bitcoin:custom
A2. You can change the block size of bitcoin core, in consensus/consensus.h
static const unsigned int MAX_BLOCK_WEIGHT = 8000000
Changed from 400000 to 800000, this will give you 2M size block.
A.3 You can change the mining interval, in chainparams.cpp
Modify the nPowTargetSpacing from 10*60 to 1*60
consensus.nPowTargetSpacing = 1 * 60;