gpt4 book ai didi

bitcoin - 如何创建我的altercoin的创世 block ?

转载 作者:行者123 更新时间:2023-12-04 10:00:39 26 4
gpt4 key购买 nike

我创建了我的新altercoin,但是当我第一次运行它时,它已经显示:“5周后没有可用的块源”。
我在局域网中启动另一台计算机,它们连接成功。
我使用Datacoin的代码。

static const uint256 hashGenesisBlockOfficial("f9f6d9a689f7a4093c71f397d8fe3fbef3a05cd6f919d51b4a9447aa22743dfb");
static const uint256 hashGenesisBlockTestNet("f9f6d9a689f7a4093c71f397d8fe3fbef3a05cd6f919d51b4a9447aa22743dfb");

// Genesis block
qDebug()<<"Genesis block";
const char* pszStartTopic = "The Times 26/Dec/2013 Chancellor on brink of second bailout for banks";//https://bitcointalk.org/index.php?topic=325735.0";
CTransaction txNew;
txNew.vin.resize(1);
txNew.vout.resize(1);
txNew.vin[0].scriptSig = CScript() << 0 << CBigNum(999) << vector<unsigned char>((const unsigned char*)pszStartTopic, (const unsigned char*)pszStartTopic + strlen(pszStartTopic));
txNew.vout[0].nValue = COIN;
txNew.vout[0].scriptPubKey = CScript();
CBlock block;
block.vtx.push_back(txNew);
block.hashPrevBlock = 0;
block.hashMerkleRoot = block.BuildMerkleTree();
block.nTime = 1387977869 ;//http://www.unixtimestamp.com/index.php
block.nBits = TargetFromInt(6);
block.nNonce = 49030125;
block.bnPrimeChainMultiplier = (uint64) 5651310;

if (fTestNet)
{
block.nTime = 1387977869 ;
block.nBits = TargetFromInt(4);
block.nNonce = 46032;
block.bnPrimeChainMultiplier = (uint64) 211890;
}

//// debug print
uint256 hash = block.GetHash();
printf("%s\n", hash.ToString().c_str());

qDebug()<<"hash:"<<hash.ToString().c_str();
printf("%s\n", hashGenesisBlock.ToString().c_str());
qDebug()<<"hashGenesisBlock:"<<hashGenesisBlock.ToString().c_str();
printf("%s\n", block.hashMerkleRoot.ToString().c_str());
qDebug()<<"block.hashMerkleRoot:"<<block.hashMerkleRoot.ToString().c_str();
assert(block.hashMerkleRoot == uint256("a0c44c1b6dd50fcaa2bc1c4d7f8ca406506caee88578d751fb3824b41bc34d84"));
block.print();

assert(hash == hashGenesisBlock);
{
CValidationState state;
assert(block.CheckBlock(state, true, true));
assert(CheckProofOfWork(block.GetHeaderHash(), block.nBits, block.bnPrimeChainMultiplier, block.nPrimeChainType, block.nPrimeChainLength));
}

断言失败(CheckProofOfWork(block.GetHeaderHash(), block.nBits, block.bnPrimeChainMultiplier, block.nPrimeChainType, block.nPrimeChainLength));。
debug.log 说:
    CBlock(hash=f9f6d9a689f7a4093c71f397d8fe3fbef3a05cd6f919d51b4a9447aa22743dfb, hashBlockHeader=7d6aeeb7ca2b87d2f48bbd7a675c8374691c4f44f0db1a10de66436bfbcb0188, ver=2, hashPrevBlock=0000000000000000000000000000000000000000000000000000000000000000, hashMerkleRoot=a0c44c1b6dd50fcaa2bc1c4d7f8ca406506caee88578d751fb3824b41bc34d84, nTime=1387977869, nBits=06000000, nNonce=49030125, vtx=1)
CTransaction(hash=a0c44c1b6dd50fcaa2bc1c4d7f8ca406506caee88578d751fb3824b41bc34d84, ver=1, vin.size=1, vout.size=1, nLockTime=0, data.size=0)
CTxIn(COutPoint(0000000000000000000000000000000000000000000000000000000000000000, 4294967295), coinbase 0002e703455468652054696d65732032362f4465632f32303133204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73)
CTxOut(error)
ERROR: CheckPrimeProofOfWork() : block header hash under limit
ERROR: CheckProofOfWork() : check failed for prime proof-of-work

我还能改变什么来使创世块工作?

最佳答案

你必须挖掘创世区块。在最新的山寨币源头中没有代码可以为您进行挖掘,尽管源代码的早期版本会在那时自动创建一个新的创世块,而不是使断言失败。这被删除了,因为它不是必需的,而且如果他们的本地数据库变得不可用,实际上可能会给普通矿工带来更多的麻烦。

你可以尝试在你的源代码树上回到过去,找到你 fork 的源代码的早期版本,并尝试找到创建创世块的代码。当它运行时,它会尝试挖掘一个新的创世块,当它运行时,它会在该断言处再次失败。然后,您必须将该哈希和随机数放入 main.h 文件中,并为您的主网和测试网执行此操作。之后,断言将不再失败,并且您现在在代码中拥有了创世块的哈希值。

这是执行此操作的代码,以防您在旧源中找不到它。

    // If genesis block hash does not match, then generate new genesis hash.
if (block.GetHash() != hashGenesisBlock)
{
printf("Searching for genesis block...\n");
// This will figure out a valid hash and Nonce if you're
// creating a different genesis block:
uint256 hashTarget = CBigNum().SetCompact(block.nBits).getuint256();
uint256 thash;

while(true)
{
thash = scrypt_blockhash(BEGIN(block.nVersion));
if (thash <= hashTarget)
break;
if ((block.nNonce & 0xFFF) == 0)
{
printf("nonce %08X: hash = %s (target = %s)\n", block.nNonce, thash.ToString().c_str(), hashTarget.ToString().c_str());
}
++block.nNonce;
if (block.nNonce == 0)
{
printf("NONCE WRAPPED, incrementing time\n");
++block.nTime;
}
}
printf("block.nTime = %u \n", block.nTime);
printf("block.nNonce = %u \n", block.nNonce);
printf("block.GetHash = %s\n", block.GetHash().ToString().c_str());

一旦找到满足目标的哈希值的随机数,它将停止并打印随机数和哈希值。您需要将这些新的创世块 nonce 和哈希值放入您的代码中,以便下次通过断言。

如果您的代码基于旧的(未优化的)源代码,那么您将没有函数 scrypt_blockhash()并且您可能需要使用原始功能。所以修改代码:
            thash = scrypt_blockhash(BEGIN(block.nVersion));


            static char scratchpad[SCRYPT_SCRATCHPAD_SIZE];
scrypt_1024_1_1_256_sp(BEGIN(block.nVersion), BEGIN(thash), scratchpad);

如果您确实需要使用旧功能 scrypt_1024_1_1_256_sp那么你还应该找到 SCRYPT_SCRATCHPAD_SIZE 的定义在头文件中也是如此。

最后,所有这些都打印在 debug.log 文件中。您需要在那里寻找才能找到它。

干杯!

关于bitcoin - 如何创建我的altercoin的创世 block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20772606/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com