C++ 遭遇;ReadBlockFromDisk:CBlockDiskPos(nFile=0,nPos=8)处的块头中出现错误”;运行修改的litecoin chainparams.cpp时出错
首先:我是altcoin开发的新手,接下来从litecoin生成altcoin, 1-我使用git clone制作了litecoin的克隆https://githubcom/litecoin-project/lotecoin.git 2-我在chainparams.cpp中更改了一些链和硬币参数,如下所示:C++ 遭遇;ReadBlockFromDisk:CBlockDiskPos(nFile=0,nPos=8)处的块头中出现错误”;运行修改的litecoin chainparams.cpp时出错,c++,linux,bitcoin,C++,Linux,Bitcoin,首先:我是altcoin开发的新手,接下来从litecoin生成altcoin, 1-我使用git clone制作了litecoin的克隆https://githubcom/litecoin-project/lotecoin.git 2-我在chainparams.cpp中更改了一些链和硬币参数,如下所示: // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2015 The Bitcoin Core developers
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "chainparams.h"
#include "consensus/merkle.h"
#include "tinyformat.h"
#include "util.h"
#include "utilstrencodings.h"
#include <assert.h>
#include "chainparamsseeds.h"
#include "arith_uint256.h"
static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
{
CMutableTransaction txNew;
txNew.nVersion = 1;
txNew.vin.resize(1);
txNew.vout.resize(1);
txNew.vin[0].scriptSig = CScript() << 486604799 << CScriptNum(4) << std::vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
txNew.vout[0].nValue = genesisReward;
txNew.vout[0].scriptPubKey = genesisOutputScript;
CBlock genesis;
genesis.nTime = nTime;
genesis.nBits = nBits;
genesis.nNonce = nNonce;
genesis.nVersion = nVersion;
genesis.vtx.push_back(MakeTransactionRef(std::move(txNew)));
genesis.hashPrevBlock.SetNull();
genesis.hashMerkleRoot = BlockMerkleRoot(genesis);
return genesis;
}
/**
* Build the genesis block. Note that the output of its generation
* transaction cannot be spent since it did not originally exist in the
* database.
*
* CBlock(hash=000000000019d6, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=4a5e1e, nTime=1231006505, nBits=1d00ffff, *nNonce=2083236893, vtx=1)
* CTransaction(hash=4a5e1e, ver=1, vin.size=1, vout.size=1, nLockTime=0)
* CTxIn(COutPoint(000000, -1), coinbase *04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420**666f722062616e6b73)
* CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B)
* vMerkleTree: 4a5e1e
*/
static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
{
const char* pszTimestamp = "Tehran Times, Stonica wins finally";
const CScript genesisOutputScript = CScript() << ParseHex("040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9") << OP_CHECKSIG;
return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
}
void CChainParams::UpdateVersionBitsParameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
{
consensus.vDeployments[d].nStartTime = nStartTime;
consensus.vDeployments[d].nTimeout = nTimeout;
}
/**
* Main network
*/
/**
* What makes a good checkpoint block?
* + Is surrounded by blocks with reasonable timestamps
* (no blocks before with a timestamp after, none after with
* timestamp before)
* + Contains no strange transactions
*/
class CMainParams : public CChainParams {
public:
CMainParams() {
strNetworkID = "main";
consensus.nSubsidyHalvingInterval = 840000;
consensus.BIP34Height = 710000;
consensus.BIP34Hash = uint256S("00000000b2c50d03d4d0bdd38681775ce522f137518145d6b3c913b7dd4423e5");
consensus.BIP65Height = 918684; // bab3041e8977e0dc3eeff63fe707b92bde1dd449d8efafb248c27c8264cc311a
consensus.BIP66Height = 811879; // 7aceee012833fa8952f8835d8b1b3ae233cd6ab08fdb27a771d2bd7bdc491894
consensus.powLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 3.5 * 24 * 60 * 60; // 3.5 days
consensus.nPowTargetSpacing = 2.5 * 60;
consensus.fPowAllowMinDifficultyBlocks = false;
consensus.fPowNoRetargeting = false;
consensus.nRuleChangeActivationThreshold = 6048; // 75% of 8064
consensus.nMinerConfirmationWindow = 8064; // nPowTargetTimespan / nPowTargetSpacing * 4
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
// Deployment of BIP68, BIP112, and BIP113.
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 1485561600; // January 28, 2017
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = 1517356801; // January 31st, 2018
// Deployment of SegWit (BIP141, BIP143, and BIP147)
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1485561600; // January 28, 2017
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1517356801; // January 31st, 2018
// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000000ba50a60f8b56c7fe0");
// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0x29c8c00e1a5f446a6364a29633d3f1ee16428d87c8d3851a1c570be8170b04c2"); //1259849
/**
* The message start string is designed to be unlikely to occur in normal data.
* The characters are rarely used upper ASCII, not valid as UTF-8, and produce
* a large 32-bit integer with any alignment.
*/
pchMessageStart[0] = 0x0b;
pchMessageStart[1] = 0xd0;
pchMessageStart[2] = 0xb6;
pchMessageStart[3] = 0xdb;
nDefaultPort = 9335;
nPruneAfterHeight = 100000;
//static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
genesis = CreateGenesisBlock(1511279793, 1251189192, 0x1d00ffff , 1, 50 * COIN);
consensus.hashGenesisBlock = genesis.GetHash();
/*
// calculate Genesis Block
// Reset genesis
consensus.hashGenesisBlock = uint256S("0x");
std::cout << std::string("Begin calculating Mainnet Genesis Block:\n");
if (true && (genesis.GetHash() != consensus.hashGenesisBlock)) {
LogPrintf("Calculating Mainnet Genesis Block:\n");
arith_uint256 hashTarget = arith_uint256().SetCompact(genesis.nBits);
uint256 hash;
genesis.nNonce = 0;
// This will figure out a valid hash and Nonce if you're
// creating a different genesis block:
// uint256 hashTarget = CBigNum().SetCompact(genesis.nBits).getuint256();
// hashTarget.SetCompact(genesis.nBits, &fNegative, &fOverflow).getuint256();
// while (genesis.GetHash() > hashTarget)
while (UintToArith256(genesis.GetHash()) > hashTarget)
{
++genesis.nNonce;
if (genesis.nNonce == 0)
{
LogPrintf("NONCE WRAPPED, incrementing time");
std::cout << std::string("NONCE WRAPPED, incrementing time:\n");
++genesis.nTime;
}
if (genesis.nNonce % 10000 == 0)
{
LogPrintf("Mainnet: nonce %08u: hash = %s \n", genesis.nNonce, genesis.GetHash().ToString().c_str());
// std::cout << strNetworkID << " nonce: " << genesis.nNonce << " time: " << genesis.nTime << " hash: " << genesis.GetHash().ToString().c_str() << "\n";
}
}
std::cout << "Mainnet ---\n";
std::cout << " nonce: " << genesis.nNonce << "\n";
std::cout << " time: " << genesis.nTime << "\n";
std::cout << " hash: " << genesis.GetHash().ToString().c_str() << "\n";
std::cout << " merklehash: " << genesis.hashMerkleRoot.ToString().c_str() << "\n";
// Mainnet --- nonce: 296277 time: 1390095618 hash: 000000bdd771b14e5a031806292305e563956ce2584278de414d9965f6ab54b0
}
std::cout << std::string("Finished calculating Mainnet Genesis Block:\n");
*/
//printf("%s\n",consensus.hashGenesisBlock.Tostring().c_str());
std::cout << std::string("ENTER:\n");
assert(consensus.hashGenesisBlock == uint256S("0x00000000b2c50d03d4d0bdd38681775ce522f137518145d6b3c913b7dd4423e5"));
assert(genesis.hashMerkleRoot == uint256S("0xf8621e34b0dcd43361fe589702e06aa79992229bfbca57d058d8561635c30fbe"));
std::cout << std::string("PASSED:\n");
printf("min nBit: %08x\n", consensus.powLimit);
// Note that of those with the service bits flag, most only support a subset of possible options
//vSeeds.emplace_back("seed-a.stonicacoin.loshan.co.uk", true);
//vSeeds.emplace_back("dnsseed.thrasher.io", true);
//vSeeds.emplace_back("dnsseed.stonicacointools.com", true);
//vSeeds.emplace_back("dnsseed.stonicacoinpool.org", true);
//vSeeds.emplace_back("dnsseed.koin-project.com", false);
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,127);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,65);
base58Prefixes[SCRIPT_ADDRESS2] = std::vector<unsigned char>(1,56);
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,176);
base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x88, 0xB2, 0x1E};
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x88, 0xAD, 0xE4};
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_main, pnSeed6_main + ARRAYLEN(pnSeed6_main));
fDefaultConsistencyChecks = false;
fRequireStandard = true;
fMineBlocksOnDemand = false;
checkpointData = (CCheckpointData) {
{
{ 0, uint256S("0x00000000b2c50d03d4d0bdd38681775ce522f137518145d6b3c913b7dd4423e5")},
}
};
chainTxData = ChainTxData{
// Data as of block db42d00d824950a125f9b08b6b6c282c484781562fa8b3bd29d6ce4a2627c348 (height 1259851).
1502955334, // * UNIX timestamp of last known number of transactions
1, // * total number of transactions between genesis and that timestamp
// (the tx=... number in the SetBestChain debug.log lines)
0.00 // * estimated number of transactions per second after that timestamp
};
}
};
/**
* Testnet (v3)
*/
class CTestNetParams : public CChainParams {
public:
CTestNetParams() {
strNetworkID = "test";
consensus.nSubsidyHalvingInterval = 840000;
consensus.BIP34Height = 76;
consensus.BIP34Hash = uint256S("8075c771ed8b495ffd943980a95f702ab34fce3c8c54e379548bda33cc8c0573");
consensus.BIP65Height = 76; // 8075c771ed8b495ffd943980a95f702ab34fce3c8c54e379548bda33cc8c0573
consensus.BIP66Height = 76; // 8075c771ed8b495ffd943980a95f702ab34fce3c8c54e379548bda33cc8c0573
consensus.powLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 3.5 * 24 * 60 * 60; // 3.5 days
consensus.nPowTargetSpacing = 2.5 * 60;
consensus.fPowAllowMinDifficultyBlocks = true;
consensus.fPowNoRetargeting = false;
consensus.nRuleChangeActivationThreshold = 1512; // 75% for testchains
consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
// Deployment of BIP68, BIP112, and BIP113.
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 1483228800; // January 1, 2017
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = 1517356801; // January 31st, 2018
// Deployment of SegWit (BIP141, BIP143, and BIP147)
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1483228800; // January 1, 2017
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1517356801; // January 31st, 2018
// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000000000000364b0cbc3568");
// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0xad8ff6c2f5580d2b50bd881e11312425ea84fa99f322bf132beb722f97971bba"); //153490
pchMessageStart[0] = 0xfd;
pchMessageStart[1] = 0xd2;
pchMessageStart[2] = 0xc8;
pchMessageStart[3] = 0xf1;
nDefaultPort = 19335;
nPruneAfterHeight = 1000;
genesis = CreateGenesisBlock(1511279793, 0, 0x1d00ffff , 1, 50 * COIN);
consensus.hashGenesisBlock = genesis.GetHash();
//assert(consensus.hashGenesisBlock == uint256S("0x"));
//assert(genesis.hashMerkleRoot == uint256S("0x"));
vFixedSeeds.clear();
vSeeds.clear();
// nodes with support for servicebits filtering should be at the top
//vSeeds.emplace_back("testnet-seed.stonicacointools.com", true);
//vSeeds.emplace_back("seed-b.stonicacoin.loshan.co.uk", true);
//vSeeds.emplace_back("dnsseed-testnet.thrasher.io", true);
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
base58Prefixes[SCRIPT_ADDRESS2] = std::vector<unsigned char>(1,58);
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);
base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF};
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test));
fDefaultConsistencyChecks = false;
fRequireStandard = false;
fMineBlocksOnDemand = false;
checkpointData = (CCheckpointData) {
{
{0, uint256S("")},
}
};
chainTxData = ChainTxData{
// Data as of block 3351b6229da00b47ad7a8d7e1323b0e2874744b5296e3d6448293463ab758624 (height 153489)
//1502953751,
//382986,
//0.01
};
}
};
/**
* Regression test
*/
class CRegTestParams : public CChainParams {
public:
CRegTestParams() {
strNetworkID = "regtest";
consensus.nSubsidyHalvingInterval = 150;
consensus.BIP34Height = 100000000; // BIP34 has not activated on regtest (far in the future so block v1 are not rejected in tests)
consensus.BIP34Hash = uint256();
consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in rpc activation tests)
consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in rpc activation tests)
consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 3.5 * 24 * 60 * 60; // two weeks
consensus.nPowTargetSpacing = 2.5 * 60;
consensus.fPowAllowMinDifficultyBlocks = true;
consensus.fPowNoRetargeting = true;
consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains
consensus.nMinerConfirmationWindow = 144; // Faster than normal for regtest (144 instead of 2016)
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 999999999999ULL;
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = 999999999999ULL;
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 999999999999ULL;
// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x00");
// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0x00");
pchMessageStart[0] = 0xfa;
pchMessageStart[1] = 0xbf;
pchMessageStart[2] = 0xb5;
pchMessageStart[3] = 0xda;
nDefaultPort = 19444;
nPruneAfterHeight = 1000;
genesis = CreateGenesisBlock(1511279793, 0, 0x1d00ffff , 1, 50 * COIN);
consensus.hashGenesisBlock = genesis.GetHash();
assert(consensus.hashGenesisBlock == uint256S("0x9"));
assert(genesis.hashMerkleRoot == uint256S("0x"));
vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds.
vSeeds.clear(); //!< Regtest mode doesn't have any DNS seeds.
fDefaultConsistencyChecks = true;
fRequireStandard = false;
fMineBlocksOnDemand = true;
checkpointData = (CCheckpointData) {
{
{0, uint256S("530827f38f93b43ed12af0b3ad25a288dc02ed74d6d7857862df51fc56c416f9")},
}
};
chainTxData = ChainTxData{
0,
0,
0
};
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
base58Prefixes[SCRIPT_ADDRESS2] = std::vector<unsigned char>(1,58);
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);
base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF};
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};
}
};
static std::unique_ptr<CChainParams> globalChainParams;
const CChainParams &Params() {
assert(globalChainParams);
return *globalChainParams;
}
std::unique_ptr<CChainParams> CreateChainParams(const std::string& chain)
{
if (chain == CBaseChainParams::MAIN)
return std::unique_ptr<CChainParams>(new CMainParams());
else if (chain == CBaseChainParams::TESTNET)
return std::unique_ptr<CChainParams>(new CTestNetParams());
else if (chain == CBaseChainParams::REGTEST)
return std::unique_ptr<CChainParams>(new CRegTestParams());
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
}
void SelectParams(const std::string& network)
{
SelectBaseParams(network);
globalChainParams = CreateChainParams(network);
}
void UpdateVersionBitsParameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
{
globalChainParams->UpdateVersionBitsParameters(d, nStartTime, nTimeout);
}
2017-12-15 07:31:33
2017-12-15 07:31:33 Stonicacoin version v0.15.0.1-gba8ed3a93be
2017-12-15 07:31:33 InitParameterInteraction: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1
2017-12-15 07:31:33 Assuming ancestors of block 29c8c00e1a5f446a6364a29633d3f1ee16428d87c8d3851a1c570be8170b04c2 have valid signatures.
2017-12-15 07:31:33 Using the 'standard' SHA256 implementation
2017-12-15 07:31:33 Using RdRand as an additional entropy source
2017-12-15 07:31:33 Default data directory /home/kevin/.stonicacoin
2017-12-15 07:31:33 Using data directory /home/kevin/.stonicacoin
2017-12-15 07:31:33 Using config file /home/kevin/.stonicacoin/stonicacoin.conf
2017-12-15 07:31:33 Using at most 125 automatic connections (1024 file descriptors available)
2017-12-15 07:31:33 Using 16 MiB out of 32/2 requested for signature cache, able to store 524288 elements
2017-12-15 07:31:33 Using 16 MiB out of 32/2 requested for script execution cache, able to store 524288 elements
2017-12-15 07:31:33 Using 8 threads for script verification
2017-12-15 07:31:33 scheduler thread start
2017-12-15 07:31:33 HTTP: creating work queue of depth 16
2017-12-15 07:31:33 No rpcpassword set - using random cookie authentication
2017-12-15 07:31:33 Generated RPC authentication cookie /home/kevin/.stonicacoin/.cookie
2017-12-15 07:31:33 HTTP: starting 4 worker threads
2017-12-15 07:31:33 Cache configuration:
2017-12-15 07:31:33 * Using 2.0MiB for block index database
2017-12-15 07:31:33 * Using 8.0MiB for chain state database
2017-12-15 07:31:33 * Using 440.0MiB for in-memory UTXO set (plus up to 4.8MiB of unused mempool space)
2017-12-15 07:31:33 init message: Loading block index...
2017-12-15 07:31:33 Opening LevelDB in /home/kevin/.stonicacoin/blocks/index
2017-12-15 07:31:33 Opened LevelDB successfully
2017-12-15 07:31:33 Using obfuscation key for /home/kevin/.stonicacoin/blocks/index: 0000000000000000
2017-12-15 07:31:33 LoadBlockIndexDB: last block file = 0
2017-12-15 07:31:33 LoadBlockIndexDB: last block file info: CBlockFileInfo(blocks=0, size=0, heights=0...0, time=1970-01-01...1970-01-01)
2017-12-15 07:31:33 Checking all blk files are present...
2017-12-15 07:31:33 LoadBlockIndexDB: transaction index disabled
2017-12-15 07:31:33 Initializing databases...
2017-12-15 07:31:33 Pre-allocating up to position 0x1000000 in blk00000.dat
2017-12-15 07:31:33 Opening LevelDB in /home/kevin/.stonicacoin/chainstate
2017-12-15 07:31:33 Opened LevelDB successfully
2017-12-15 07:31:33 Wrote new obfuscate key for /home/kevin/.stonicacoin/chainstate: 77f259e28117a4e1
2017-12-15 07:31:33 Using obfuscation key for /home/kevin/.stonicacoin/chainstate: 77f259e28117a4e1
2017-12-15 07:31:33 init message: Rewinding blocks...
2017-12-15 07:31:33 block index 11ms
2017-12-15 07:31:33 No wallet support compiled in!
2017-12-15 07:31:33 ERROR: ReadBlockFromDisk: Errors in block header at CBlockDiskPos(nFile=0, nPos=8)
2017-12-15 07:31:33 *** Failed to read block
2017-12-15 07:31:33 Error: Error: A fatal internal error occurred, see debug.log for details
我发现这个错误(例如错误:ReadBlockFromDisk:CBlockDiskPos(nFile=0,nPos=8)的块头中的错误)发生在pow.cpp中的checkproof函数中,感谢您的建议。看来
-reindex
参数解决了这个问题,并给出了错误的主要原因,即Genesis Block没有有效的PoW。在()中建议为损坏的区块链数据问题提供解决方案:
2016年5月21日发表评论使用启动比特币或比特币qt -reindex命令行选项。这将丢弃索引和 从头开始重建,但尽可能重用磁盘上的块 它们是可用的
经过太多的努力,我终于解决了这个问题: (一) 应设置为下限,如
consensus.powLimit = uint256S("00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
并在CreateGenesisBlock函数中设置genesis.nBits为0x1F000FFFF,如
genesis = CreateGenesisBlock(1519394018, 6446, 0x1f0fffff, 1, 1 * COIN);
对于Testnet,我使用了0x1f0fffff
2) 比特币v0.15+应使用以下genesis区块生成代码:
// calculate Genesis Block
// Reset genesis
consensus.hashGenesisBlock = uint256S("0x");
std::cout << std::string("Begin calculating Mainnet Genesis Block:\n");
if (true && (genesis.GetHash(consensus) != consensus.hashGenesisBlock)) {
// LogPrintf("Calculating Mainnet Genesis Block:\n");
arith_uint256 hashTarget = arith_uint256().SetCompact(genesis.nBits);
uint256 hash;
genesis.nNonce = ArithToUint256(0);
while (UintToArith256(genesis.GetHash(consensus)) > hashTarget)
{
genesis.nNonce = ArithToUint256(UintToArith256(genesis.nNonce) + 1);
if (genesis.nNonce == ArithToUint256(arith_uint256(0)))
{
LogPrintf("NONCE WRAPPED, incrementing time");
std::cout << std::string("NONCE WRAPPED, incrementing time:\n");
++genesis.nTime;
}
if ((int)genesis.nNonce.GetUint64(0) % 10000 == 0)
{
std::cout << strNetworkID << " hashTarget: " << hashTarget.ToString() << " nonce: " << genesis.nNonce.ToString() << " time: " << genesis.nTime << " hash: " << genesis.GetHash(consensus).ToString().c_str() << "\r";
}
}
std::cout << "Mainnet ---\n";
std::cout << " nonce: " << genesis.nNonce.ToString() << "\n";
std::cout << " time: " << genesis.nTime << "\n";
std::cout << " hash: " << genesis.GetHash(consensus).ToString().c_str() << "\n";
std::cout << " merklehash: " << genesis.hashMerkleRoot.ToString().c_str() << "\n";
}
std::cout << std::string("Finished calculating Mainnet Genesis Block:\n");
定义
static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward);
函数,以查看它是按上述方式给出还是按
genesis.nNonce = nNonce;
如果给出的是后者,则使用@Hossein Mirheydari的genesis块生成代码。如果它是通过arithtooint256()函数给出的,请使用我上面粘贴的genesis块生成代码
3) 应分别为Mainnet和Testnet生成genesis块。Regtest不需要生成genesis块,因为它的pow限制非常小(但您可能无论如何都想这样做,只是为了确保一切正常),等等
将打印的consensus.hashGenesisBlock和genesis.hashMerkleRoot插入到
assert(consensus.hashGenesisBlock == uint256S("0x0009b0d830d5e13f7a39dd6c30cae59ff95e1a4aa4fc22435dc1fcb92561cd8e"));
assert(genesis.hashMerkleRoot == uint256S("0xf1552bf3d58facdc6d7ec8461aff6b0560d20eb16e41749b9f8f5a7eaa1220fc"));
声明有效
4) 如果你有
consensus.powLimitStart = uint256S("0000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.powLimitLegacy = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
就像比特币黄金(我现在正在使用)中的那些一样,使用与consenses.powLimit相同的pow限制
因此,使用genesis生成代码生成genesis块。在低功率限制下,genesis区块将处于功率范围内,因此不再发生功率验证错误
我希望这会有所帮助。在
main
分支上,此时我的解决方案是将GetHash()
更改为GetPoWHash()
。我还遵循了@Bedri Ozgur Guler对PoWLimit和nBits的回答:
consensus.hashGenesisBlock=uint256S(“0x”);
std::cout hashTarget)/-->这里是GetPoWHash()!!
{
++genesis.nNonce;
如果(genesis.nNonce==0)
{
LogPrintf(“NONCE WRAPPED,incrementing time”);
std::coutFreddyJS,genesis.GetPoWHash()
对litecoin很有效,哈希值与我使用GenesisH0得到的值匹配。但不幸的是,它在我正在测试的另一个硬币上不起作用,在编译时出现错误。有什么想法吗
错误:调用“CBlock::GetPoWHash()”时没有匹配的函数。
经过一些挖掘,代码与litecoin不同。在validation.cpp中:
// Check the header
if (!CheckProofOfWork(block.GetPoWHash(nHeight), block.nBits, consensusParams))
return error("ReadBlockFromDisk: Errors in block header at %s, %d", pos.ToString(), nHeight);
GetPoWHash(nHeight)
vsGetPoWHash()
在litecoin中。你解决了吗?我有同样的问题,我在这里遇到了同样的问题。虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供链接以供参考。如果链接页面发生更改,则仅链接的答案可能无效。-链接也没有解释问题的内容根本问题的原因是。我在玩groestlcoin的代码时遇到了这个问题,在重新设置代码中的变量(如nGenesisBlockRewardCoin以及consensus.HashGenesBlock和genesis.hashMerkleRoot)后遇到了这个问题。我试图启动一个全新的链,但最终遇到了这个问题。但对问题的本质是,很明显,链和/或钱包在某个点上已损坏,-reindex或-reindex-chainstate(由debug.log提出)参数解决了这个问题。这是一个临时解决方案。@Bedriozguler您好,我遇到了同样的OP问题,添加-reindex似乎至少让我迈出了下一步,但现在debug.log连续写入消息“检测到潜在的过时提示,将尝试使用额外的出站对等”,你知道为什么吗?那么,你上一次评论的基本解决方案是什么?@leegody你可能想查看比特币github:[net]上的这篇文章,跳过regtest中的过时提示检查#12484(),以及故意不与对等方连接时的“检测到的潜在过时提示”35;11608()我不确定这两个问题线程是否对您的案例有帮助,但值得检查,也许您可以看到一些对您有帮助的东西。非常感谢!!我现在正在尝试克隆litecoin的最新源代码,所以我今天将对此进行测试,并将向您发送消息。请添加我skype:leegodskypeTested,但是,嗯…我仍然有这个错误。-------2018-02-26 04:50:02错误:ReadBlockFromDisk:CBlockDiskPos的块头错误(nFile=0,nPos=8)2018-02-26 04:50:02***未能读取块2018-02-26 04:50:02错误:错误:发生了致命的内部错误,请参阅debug.log了解详细信息------因此我使用了@Hossein的genesis块生成代码,因为在CreateGenesisBlock中,genesis.nNonce=nNonce;定义如下。现在呢?…嗯…ParseHex(?)之后这个变量的值应该是多少const CScript genesisOutputScript=CScript(),所以它可能需要通过pow.cpp的“checkproofwork”函数的genesis valid check?检查。这段视频(以及本系列中的以下5段视频)对我帮助很大。它将回答我相信的大多数问题。它还告诉我如何创建ParseHex()的值我宁愿使用比特币v0.16(今天发布)而不是litecoin代码库
assert(consensus.hashGenesisBlock == uint256S("0x0009b0d830d5e13f7a39dd6c30cae59ff95e1a4aa4fc22435dc1fcb92561cd8e"));
assert(genesis.hashMerkleRoot == uint256S("0xf1552bf3d58facdc6d7ec8461aff6b0560d20eb16e41749b9f8f5a7eaa1220fc"));
consensus.powLimitStart = uint256S("0000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.powLimitLegacy = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
// Check the header
if (!CheckProofOfWork(block.GetPoWHash(nHeight), block.nBits, consensusParams))
return error("ReadBlockFromDisk: Errors in block header at %s, %d", pos.ToString(), nHeight);