Genesis Block (Starting a New Blockchain Instance)
2016-04-10 17:58
435 查看
This guide outlines the steps to manually generate a genesis block and start a new blockchain. Once the genesis block is generated, two nodes must be used to start the blockchain. This guide will show you how to do this on one machine, using two data directories
and two instances of the daemon. Please note that it is also possible to do this using two physical or virtual machines.
Install Dependencies and Mini-UPnP
If Peershares has never been run on your machine, be sure to follow the Dependency and Mini-UPnP installation steps, located on the Linux wiki page: https://github.com/Peershares/Peershares/wiki/Linux
Clean-up Prior Work
If you have already been using your machine to test Peershares builds, it's a good idea to delete your prior working folders and start fresh.
$ rm -r ~/.peershares
$ rm -r ~/Peershares
Clone the Peershares Github Repository
$ git clone https://github.com/Peershares/Peershares.git
Get the current unix epoch time from the command line, or, from using a site like Epoch Converter.
$ date +%s
We'll use this in a few minutes, so copy it down.
Edit main.cpp
$ cd ~/Peershares/src/
$ (text editor) main.cpp
Be sure to turn on line numbering in your text editor. Edit the following lines ...
Main.cpp:L2260 - Change the value for the constant, pszTimestamp, to something unique, up to 91 characters:
const char* pszTimestamp = "YOUR CUSTOM, VERIFIABLE TIMESTAMP GOES HERE";
Main.cpp:L2261 - Change nTimeGenesis value to current epoch time (captured in the previous step). For example, when this guide was written, the epoch time was 1395169964, so it would be inserted as so:
unsigned int nTimeGenesis=1395169964;
Main.cpp:L2262 - Make sure that nNonceGenesis=0
Main.cpp:L2266 - For the TestNet genesis block, change the value for the constant, pszTimestamp, to something unique (same length rules apply as the previous timestamp string):
Main.cpp:L2267 - Change nTimeGenesis value to current epoch time stamp. This can match the value you used for the previous nTimeGenesis variable, or you can use the epoch time for when you modified this step, either is appropriate.
Main.cpp:L2268 - Make sure that nNonceGenesis=0
Complete set of changes from the previous steps:
if (fTestNet)
{
pszTimestamp="YOUR CUSTOM, VERIFIABLE TESTNET TIMESTAMP GOES HERE";
nTimeGenesis=1395170250;
nNonceGenesis=0;
}
Save the file and exit.
Compile the daemon
$ make -f makefile.unix
Run the daemon
$ ./peersharesd --daemon
It should start and run for a few seconds then stop with an error. This error is our notification that the new genesis block has been generated. That was for real-net. Now lets generate one for testnet.
$ ./peersharesd --daemon -testnet
It will start and run for a few seconds then stop with an error like the first one. We now have two debug.log files located at: ~/.peershares/debug.log and ~/.peershares/testnet/debug.log. You will find an entry in both of these files starting with 'PPCoin
Found Genesis Block:'. Under that entry, you will find values for 'genesis hash=', 'merkle root=' and 'nNonce=' ... We need those three values from both real-net and testnet debug.log files.
Edit main.cpp and kernel.cpp
$ cd ~/Peershares/src/
$ (text editor) main.cpp
Edit the following lines ...
Main.cpp:L24 - Change the value for the constant, hashGenesisBlockOfficial, to the new genesis hash value from debug.log. Paste the value in-between the quotation marks, after the leading 0x :
static const uint256 hashGenesisBlockOfficial("0x00000053229d58cdda911f4188240d4843f6bca1d8978d3349d87c38976463dd");
Main.cpp:L25 - Change the value for the constant, hashGenesisBlockTestNet, to the new genesis hash value from TestNet debug.log. Paste the value in-between the quotation marks, after the leading 0x :
static const uint256 hashGenesisBlockTestNet ("0x00000053229d58cdda911f4188240d4843f6bca1d8978d3349d87c38976463dd");
Main.cpp:L2262 - Change the value for nNonceGenesis to the new nNonce value from debug.log:
unsigned int nNonceGenesis=236800;
Main.cpp:L2268 - Change the value for nNonceGenesis to the new nNonce value from the TestNet debug.log:
unsigned int nNonceGenesis=236800;
Main.cpp:L2312 - Change the value for block.hashMerkleRoot == uint256, to the new merkle root hash value from debug.log. Paste the value in-between the quotation marks, after the leading 0x :
assert(block.hashMerkleRoot == uint256("0xf0e9ac2cef9820c036e397c738ae5cea91df3724f5418eb6a7450350f2702278"));
Main.cpp:L2314 - Change the value for block.hashMerkleRoot == uint256, to the new merkle root hash value from TestNet debug.log. Paste the value in-between the quotation marks, after the leading 0x :
assert(block.hashMerkleRoot == uint256("0xf0e9ac2cef9820c036e397c738ae5cea91df3724f5418eb6a7450350f2702278"));
Save and exit main.cpp ... Open kernel.cpp:
$ (text editor) kernel.cpp
nProtocolV03SwitchTime and nProtocolV03TestSwitchTime need to be set to a time in the future, after PoS starts. So just set these to several days in advance. Use the Epoch Converter to get the correct value.
Kernel.cpp:L14 - Change the value for nProtocolV03SwitchTime to the to the correct future time. Edit the number after the '=' sign and update the comment to reflect what it was changed to:
unsigned int nProtocolV03SwitchTime = 1394841600; // 2014-03-15 00:00:00 UTC
Kernel.cpp:L15 - Change the value for nProtocolV03TestSwitchTime to the to the correct future time. Edit the number after the '=' sign and update the comment to reflect what it was changed to:
unsigned int nProtocolV03TestSwitchTime = 1396224000; // 2014-03-31 00:00:00 UTC
Save and exit kernel.cpp
Recompile the daemon
$ make -f makefile.unix BDB_INCLUDE_PATH="/usr/local/BerkeleyDB.4.8/include" BDB_LIB_PATH="/usr/local/BerkeleyDB.4.8/lib"
Remove and recreate working folder
Add a 2nd working folder for instance2, which is needed to start the blockchain.
$ rm -r ~/.peershares/
$ mkdir ~/.peershares/
$ mkdir ~/.peershares2/
Move the newly recompiled daemon to working folder
$ mv peersharesd ~/.peershares
Create conf file and start instance 1
$ cd ~/.peershares
$ touch peershares.conf
$ (text editor) peershares.conf
Add the following lines to the conf file and save:
server=1
rpcallowip=127.0.0.1
listen=1
rpcuser=<anything>
rpcpassword=<anything>
dnsseed=0
port=9090
rpcport=9091
gen=1
Run the daemon
$ ./peersharesd --daemon
If it stops with an error about blkindex.dat when it is run for the first time, simply run it again and it should work. This is a known issue on the first run attempt.
Copy and rename daemon to 2nd instance
$ cp peersharesd ~/.peershares2/peersharesd2
Create conf file for 2nd instance
$ cd ~/.peershares2
$ touch peershares.conf
$ (text editor) peershares.conf
Add the following lines to the conf file and save:
server=1
rpcuser=<anything>
rpcpassword=<anything>
port=19090
rpcport=19091
gen=1
Run the 2nd instance of the daemon
We must specify the data directory so that the 2nd instance doesn't try to use '~/.peershares' and we must also specify that we want to connect to the IP address of our first instance, which, in this case, is localhost. Be sure to replace with your username.
Note that datadir and connect commands can be added to your conf file to simplify things.
$ ./peersharesd2 --daemon -datadir=/home/<user>/.peershares2 -connect=127.0.0.1:9090
If either instance stops with an error about blkindex.dat when it is run for the first time, kill the instance and run again with the same command. It should work on the 2nd try. This is a known issue.
At this point, your new blockchain should be started and both instances should be generating PoW blocks. Check status with:
$ ./peersharesd getinfo
$ ./peersharesd getmininginfo
$ (text editor) debug.log
Or from the 2nd instance dir
$ ./peersharesd2 getinfo
$ ./peersharesd2 getmininginfo
If you wish to start a testnet, add testnet=1 to your conf files, stop and restart the daemons.
Note: If difficulty settings are changed in Main.cpp:L37 and Main.cpp:L38, you'll need to recreate the genesis block because the nonce/hash/merkel root will change.
and two instances of the daemon. Please note that it is also possible to do this using two physical or virtual machines.
Install Dependencies and Mini-UPnP
If Peershares has never been run on your machine, be sure to follow the Dependency and Mini-UPnP installation steps, located on the Linux wiki page: https://github.com/Peershares/Peershares/wiki/Linux
Clean-up Prior Work
If you have already been using your machine to test Peershares builds, it's a good idea to delete your prior working folders and start fresh.
$ rm -r ~/.peershares
$ rm -r ~/Peershares
Clone the Peershares Github Repository
$ git clone https://github.com/Peershares/Peershares.git
Get the current unix epoch time from the command line, or, from using a site like Epoch Converter.
$ date +%s
We'll use this in a few minutes, so copy it down.
Edit main.cpp
$ cd ~/Peershares/src/
$ (text editor) main.cpp
Be sure to turn on line numbering in your text editor. Edit the following lines ...
Main.cpp:L2260 - Change the value for the constant, pszTimestamp, to something unique, up to 91 characters:
const char* pszTimestamp = "YOUR CUSTOM, VERIFIABLE TIMESTAMP GOES HERE";
Main.cpp:L2261 - Change nTimeGenesis value to current epoch time (captured in the previous step). For example, when this guide was written, the epoch time was 1395169964, so it would be inserted as so:
unsigned int nTimeGenesis=1395169964;
Main.cpp:L2262 - Make sure that nNonceGenesis=0
Main.cpp:L2266 - For the TestNet genesis block, change the value for the constant, pszTimestamp, to something unique (same length rules apply as the previous timestamp string):
Main.cpp:L2267 - Change nTimeGenesis value to current epoch time stamp. This can match the value you used for the previous nTimeGenesis variable, or you can use the epoch time for when you modified this step, either is appropriate.
Main.cpp:L2268 - Make sure that nNonceGenesis=0
Complete set of changes from the previous steps:
if (fTestNet)
{
pszTimestamp="YOUR CUSTOM, VERIFIABLE TESTNET TIMESTAMP GOES HERE";
nTimeGenesis=1395170250;
nNonceGenesis=0;
}
Save the file and exit.
Compile the daemon
$ make -f makefile.unix
Run the daemon
$ ./peersharesd --daemon
It should start and run for a few seconds then stop with an error. This error is our notification that the new genesis block has been generated. That was for real-net. Now lets generate one for testnet.
$ ./peersharesd --daemon -testnet
It will start and run for a few seconds then stop with an error like the first one. We now have two debug.log files located at: ~/.peershares/debug.log and ~/.peershares/testnet/debug.log. You will find an entry in both of these files starting with 'PPCoin
Found Genesis Block:'. Under that entry, you will find values for 'genesis hash=', 'merkle root=' and 'nNonce=' ... We need those three values from both real-net and testnet debug.log files.
Edit main.cpp and kernel.cpp
$ cd ~/Peershares/src/
$ (text editor) main.cpp
Edit the following lines ...
Main.cpp:L24 - Change the value for the constant, hashGenesisBlockOfficial, to the new genesis hash value from debug.log. Paste the value in-between the quotation marks, after the leading 0x :
static const uint256 hashGenesisBlockOfficial("0x00000053229d58cdda911f4188240d4843f6bca1d8978d3349d87c38976463dd");
Main.cpp:L25 - Change the value for the constant, hashGenesisBlockTestNet, to the new genesis hash value from TestNet debug.log. Paste the value in-between the quotation marks, after the leading 0x :
static const uint256 hashGenesisBlockTestNet ("0x00000053229d58cdda911f4188240d4843f6bca1d8978d3349d87c38976463dd");
Main.cpp:L2262 - Change the value for nNonceGenesis to the new nNonce value from debug.log:
unsigned int nNonceGenesis=236800;
Main.cpp:L2268 - Change the value for nNonceGenesis to the new nNonce value from the TestNet debug.log:
unsigned int nNonceGenesis=236800;
Main.cpp:L2312 - Change the value for block.hashMerkleRoot == uint256, to the new merkle root hash value from debug.log. Paste the value in-between the quotation marks, after the leading 0x :
assert(block.hashMerkleRoot == uint256("0xf0e9ac2cef9820c036e397c738ae5cea91df3724f5418eb6a7450350f2702278"));
Main.cpp:L2314 - Change the value for block.hashMerkleRoot == uint256, to the new merkle root hash value from TestNet debug.log. Paste the value in-between the quotation marks, after the leading 0x :
assert(block.hashMerkleRoot == uint256("0xf0e9ac2cef9820c036e397c738ae5cea91df3724f5418eb6a7450350f2702278"));
Save and exit main.cpp ... Open kernel.cpp:
$ (text editor) kernel.cpp
nProtocolV03SwitchTime and nProtocolV03TestSwitchTime need to be set to a time in the future, after PoS starts. So just set these to several days in advance. Use the Epoch Converter to get the correct value.
Kernel.cpp:L14 - Change the value for nProtocolV03SwitchTime to the to the correct future time. Edit the number after the '=' sign and update the comment to reflect what it was changed to:
unsigned int nProtocolV03SwitchTime = 1394841600; // 2014-03-15 00:00:00 UTC
Kernel.cpp:L15 - Change the value for nProtocolV03TestSwitchTime to the to the correct future time. Edit the number after the '=' sign and update the comment to reflect what it was changed to:
unsigned int nProtocolV03TestSwitchTime = 1396224000; // 2014-03-31 00:00:00 UTC
Save and exit kernel.cpp
Recompile the daemon
$ make -f makefile.unix BDB_INCLUDE_PATH="/usr/local/BerkeleyDB.4.8/include" BDB_LIB_PATH="/usr/local/BerkeleyDB.4.8/lib"
Remove and recreate working folder
Add a 2nd working folder for instance2, which is needed to start the blockchain.
$ rm -r ~/.peershares/
$ mkdir ~/.peershares/
$ mkdir ~/.peershares2/
Move the newly recompiled daemon to working folder
$ mv peersharesd ~/.peershares
Create conf file and start instance 1
$ cd ~/.peershares
$ touch peershares.conf
$ (text editor) peershares.conf
Add the following lines to the conf file and save:
server=1
rpcallowip=127.0.0.1
listen=1
rpcuser=<anything>
rpcpassword=<anything>
dnsseed=0
port=9090
rpcport=9091
gen=1
Run the daemon
$ ./peersharesd --daemon
If it stops with an error about blkindex.dat when it is run for the first time, simply run it again and it should work. This is a known issue on the first run attempt.
Copy and rename daemon to 2nd instance
$ cp peersharesd ~/.peershares2/peersharesd2
Create conf file for 2nd instance
$ cd ~/.peershares2
$ touch peershares.conf
$ (text editor) peershares.conf
Add the following lines to the conf file and save:
server=1
rpcuser=<anything>
rpcpassword=<anything>
port=19090
rpcport=19091
gen=1
Run the 2nd instance of the daemon
We must specify the data directory so that the 2nd instance doesn't try to use '~/.peershares' and we must also specify that we want to connect to the IP address of our first instance, which, in this case, is localhost. Be sure to replace with your username.
Note that datadir and connect commands can be added to your conf file to simplify things.
$ ./peersharesd2 --daemon -datadir=/home/<user>/.peershares2 -connect=127.0.0.1:9090
If either instance stops with an error about blkindex.dat when it is run for the first time, kill the instance and run again with the same command. It should work on the 2nd try. This is a known issue.
At this point, your new blockchain should be started and both instances should be generating PoW blocks. Check status with:
$ ./peersharesd getinfo
$ ./peersharesd getmininginfo
$ (text editor) debug.log
Or from the 2nd instance dir
$ ./peersharesd2 getinfo
$ ./peersharesd2 getmininginfo
If you wish to start a testnet, add testnet=1 to your conf files, stop and restart the daemons.
Note: If difficulty settings are changed in Main.cpp:L37 and Main.cpp:L38, you'll need to recreate the genesis block because the nonce/hash/merkel root will change.
相关文章推荐
- 02 VoLTE - Domain Selection 和 VoLTE Signaling Overview
- poj3250 Bad Hair Day
- 出现( linker command failed with exit code 1)错误总结
- LeetCode 265. Paint House II(房子涂色)
- Google用不了解决方法(添加gmail用不了的方法)
- mybaits注解
- 非常阔气的Raid磁盘阵列
- email正则表达式 验证邮箱格式
- [人工智能]IBM Watson人工智能API|一步步创建智能微信翻译官|第一章
- 2014年山东省第五届ACM--angry_birds_again_and_again
- mybaits 框架运用
- Mybaits学习过程中出现的错误
- 题目1436:Repair the Wall
- STL学习笔记— —无序容器(Unordered Container)
- Pass-Muraille
- Deeplearning ,AI,Machine Learning 的关系
- [www.51kuaisou.com]最全的maven中央仓库
- 如何逃过taint droid的跟踪
- 一张图系列——从CreateProcess到main函数的过程
- POJ 3421 X-factor Chains