Title: How to actually mine genesis block? Post by: wsxdrfv on February 24, 2018, 01:05:01 PM How to actually mine genesis block?
At old source, there is [ hashTarget ] and seems loop hash until become below than [ hashTarget ] But at new source, there is no [ hashTarget ] variable. What name it changed? Where is the part actually mine block? By reference it, maybe I can write code mine genesis block? And at new source, validation.cpp 986 line, there are code like, Code: bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams) How this [ CheckProofOfWork ] function can be used? There is no prior variable declaration. There is just [ #include "pow.h" ] Is this enough? I used this [ CheckProofOfWork ] function same to chainparams.cpp , but error says undefined reference to `CheckProofOfWork Why? how to use this function in chainparams.cpp? Title: Re: How to actually mine genesis block? Post by: bob123 on February 24, 2018, 04:01:36 PM And at new source, validation.cpp 986 line, there are code like, Code: bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams) How this [ CheckProofOfWork ] function can be used? There is no prior variable declaration. There is just [ #include "pow.h" ] Is this enough? I used this [ CheckProofOfWork ] function same to chainparams.cpp , but error says undefined reference to `CheckProofOfWork To use the function you simply call it. pow.h is necessary, but not the only file you need. To see the CheckProofOfWork() you have to look at pow.cpp (https://github.com/bitcoin/bitcoin/blob/5961b23898ee7c0af2626c46d5d70e80136578d3/src/pow.cpp (https://github.com/bitcoin/bitcoin/blob/5961b23898ee7c0af2626c46d5d70e80136578d3/src/pow.cpp)): Code: bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params) I'd suggest you head over to https://github.com/bitcoin/bitcoin (https://github.com/bitcoin/bitcoin) and use the search function at the top. You should find everything you are looking for. Title: Re: How to actually mine genesis block? Post by: wsxdrfv on February 25, 2018, 04:27:55 AM To use the function you simply call it. pow.h is necessary, but not the only file you need. If simply call it at chainparams.cpp, error says there is no definition of 'CheckProofOfWork'.To see the CheckProofOfWork() you have to look at pow.cpp (https://github.com/bitcoin/bitcoin/blob/5961b23898ee7c0af2626c46d5d70e80136578d3/src/pow.cpp (https://github.com/bitcoin/bitcoin/blob/5961b23898ee7c0af2626c46d5d70e80136578d3/src/pow.cpp)): And if I added #include "pow.cpp" at the top of chainparams.cpp, and wrote like Code: pchMessageStart[3] = 0xaa; then error says ---------- libbitcoin_common.a(libbitcoin_common_a-chainparams.o): In function `GetNextWorkRequired(CBlockIndex const*, CBlockHeader const*, Consensus::Params const&)': /home/lee/Desktop/BitcoinEssence/src/pow.cpp:15: multiple definition of `GetNextWorkRequired(CBlockIndex const*, CBlockHeader const*, Consensus::Params const&)' libbitcoin_server.a(libbitcoin_server_a-pow.o):/home/lee/Desktop/BitcoinEssence/src/pow.cpp:15: first defined here libbitcoin_common.a(libbitcoin_common_a-chainparams.o): In function `CalculateNextWorkRequired(CBlockIndex const*, long, Consensus::Params const&)': /home/lee/Desktop/BitcoinEssence/src/pow.cpp:59: multiple definition of `CalculateNextWorkRequired(CBlockIndex const*, long, Consensus::Params const&)' libbitcoin_server.a(libbitcoin_server_a-pow.o):/home/lee/Desktop/BitcoinEssence/src/pow.cpp:59: first defined here libbitcoin_common.a(libbitcoin_common_a-chainparams.o): In function `CheckProofOfWork(uint256, unsigned int, Consensus::Params const&)': /home/lee/Desktop/BitcoinEssence/src/pow.cpp:92: multiple definition of `CheckProofOfWork(uint256, unsigned int, Consensus::Params const&)' libbitcoin_server.a(libbitcoin_server_a-pow.o):/home/lee/Desktop/BitcoinEssence/src/pow.cpp:92: first defined here ----------- So what now? Strange is, as I mentioned already, validation.cpp just simply call 'CheckProofOfWork' without any prior declaration. How? Title: Re: How to actually mine genesis block? Post by: achow101 on February 25, 2018, 04:13:16 PM The error means that the linker could not find the function declaration. You will need to modify Makefile.am so that the linker can find pow.h when it is linking any compiled units that use chainparams.cpp.
What you actually have to change you will need to figure out yourself. Title: Re: How to actually mine genesis block? Post by: starmyc on February 26, 2018, 06:06:12 AM If simply call it at chainparams.cpp, error says there is no definition of 'CheckProofOfWork'. And if I added #include "pow.cpp" at the top of chainparams.cpp, and wrote like You want to include "pow.h" and only, not "pow.cpp" I used this [ CheckProofOfWork ] function same to chainparams.cpp , but error says undefined reference to `CheckProofOfWork Why? how to use this function in chainparams.cpp? Something like the following will work (Tested against last bitcoin version, commit bf3353de9059): Code: // In src/chainparams.cpp, in headers Title: Re: How to actually mine genesis block? Post by: wsxdrfv on February 26, 2018, 06:26:56 AM If simply call it at chainparams.cpp, error says there is no definition of 'CheckProofOfWork'. And if I added #include "pow.cpp" at the top of chainparams.cpp, and wrote like You want to include "pow.h" and only, not "pow.cpp" I used this [ CheckProofOfWork ] function same to chainparams.cpp , but error says undefined reference to `CheckProofOfWork Why? how to use this function in chainparams.cpp? Something like the following will work (Tested against last bitcoin version, commit bf3353de9059): Code: // In src/chainparams.cpp, in headers Thanks, but still following errors. --------------- lee@newlite:~/Desktop/BitcoinEssence/src$ make make[1]: Entering directory '/home/lee/Desktop/BitcoinEssence/src' make[2]: Entering directory '/home/lee/Desktop/BitcoinEssence' make[2]: Leaving directory '/home/lee/Desktop/BitcoinEssence' CXX libbitcoin_common_a-chainparams.o AR libbitcoin_common.a CXXLD bitcoinessenced CXXLD bitcoinessence-tx libbitcoin_common.a(libbitcoin_common_a-chainparams.o): In function `CMainParams::CMainParams()': /home/lee/Desktop/BitcoinEssence/src/chainparams.cpp:262: undefined reference to `CheckProofOfWork(uint256, unsigned int, Consensus::Params const&)' collect2: error: ld returned 1 exit status Makefile:3663: recipe for target 'bitcoinessence-tx' failed make[1]: *** [bitcoinessence-tx] Error 1 make[1]: Leaving directory '/home/lee/Desktop/BitcoinEssence/src' Makefile:9337: recipe for target 'all-recursive' failed make: *** [all-recursive] Error 1 lee@newlite:~/Desktop/BitcoinEssence/src$ --------------- Of course I added #include "pow.h" or <pow.h> ? -> but anyway both result error above. |