Skip to content

Commit

Permalink
Merge pull request #47 from pepecoinppc/resolve-difficulty-scaling
Browse files Browse the repository at this point in the history
Resolve difficulty scaling
  • Loading branch information
pepecoinppc authored Jan 23, 2024
2 parents db6b181 + 6400cb4 commit c64209d
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 89 deletions.
56 changes: 27 additions & 29 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesi
*/
static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
{
const char* pszTimestamp = "WSJ 1/10/24 - SEC Approves Bitcoin ETFs for Everyday Investors";
const char* pszTimestamp = "WSJ 1/22/24 - Fed Review Clears Central Bank Officials of Violating Rules";
const CScript genesisOutputScript = CScript() << ParseHex("0436d04f40a76a1094ea10b14a513b62bfd0b47472dda1c25aa9cf8266e53f3c4353680146177f8a3b328ed2c6e02f2b8e051d9d5ffc61a4e6ccabd03409109a5a") << OP_CHECKSIG;
return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
}
Expand Down Expand Up @@ -86,9 +86,9 @@ class CMainParams : public CChainParams {
consensus.BIP65Height = 1000;
consensus.BIP66Height = 1000;
consensus.powLimit = uint256S("0x00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // ~uint256(0) >> 20;
consensus.nPowTargetTimespan = 4 * 60 * 60; // pre-digishield: 4 hours
consensus.nPowTargetTimespan = 60; // 1 minute
consensus.nPowTargetSpacing = 60; // 1 minute
consensus.fDigishieldDifficultyCalculation = false;
consensus.fDigishieldDifficultyCalculation = true;
consensus.nCoinbaseMaturity = 30;
consensus.fPowAllowMinDifficultyBlocks = false;
consensus.fPowAllowDigishieldMinDifficultyBlocks = false;
Expand All @@ -114,7 +114,7 @@ class CMainParams : public CChainParams {
consensus.nMinimumChainWork = uint256S("0000000000000000000000000000000000000000000000000000000000010001"); // genesis block

// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0xb8fac7f8275af1072b983884fb128165862d7849d8f7d7841f282fb6f6c0b7a6"); // genesis block
consensus.defaultAssumeValid = uint256S("0x37981c0c48b8d48965376c8a42ece9a0838daadb93ff975cb091f57f8c2a5faa"); // genesis block

// AuxPoW parameters
consensus.nAuxpowChainId = 0x003f; // 63
Expand All @@ -123,18 +123,18 @@ class CMainParams : public CChainParams {
consensus.nHeightEffective = 0;
consensus.fSimplifiedRewards = true;

// Blocks 1000 - 1499 are Digishield without AuxPoW
// Blocks 1000 - 99,999 are Digishield without AuxPoW
digishieldConsensus = consensus;
digishieldConsensus.nHeightEffective = 1000;
digishieldConsensus.fSimplifiedRewards = true;
digishieldConsensus.fDigishieldDifficultyCalculation = true;
digishieldConsensus.nPowTargetTimespan = 60; // post-digishield: 1 minute
digishieldConsensus.nCoinbaseMaturity = 240;

// Blocks 1500+ are AuxPoW
// Blocks 100,000+ are AuxPoW
// Some tests from Dogecoin expect non-auxpow blocks. This allows those tests to pass.
auxpowConsensus = digishieldConsensus;
auxpowConsensus.nHeightEffective = 1500;
auxpowConsensus.nHeightEffective = 100000;
auxpowConsensus.fAllowLegacyBlocks = false;

// Assemble the binary search tree of consensus parameters
Expand All @@ -154,12 +154,12 @@ class CMainParams : public CChainParams {
nDefaultPort = 33874;
nPruneAfterHeight = 100000;

genesis = CreateGenesisBlock(1705384800, 777983, 0x1e0ffff0, 1, 88 * COIN);
genesis = CreateGenesisBlock(1705975200, 427444, 0x1e0ffff0, 1, 88 * COIN);
consensus.hashGenesisBlock = genesis.GetHash();
digishieldConsensus.hashGenesisBlock = consensus.hashGenesisBlock;
auxpowConsensus.hashGenesisBlock = consensus.hashGenesisBlock;
assert(consensus.hashGenesisBlock == uint256S("0xb8fac7f8275af1072b983884fb128165862d7849d8f7d7841f282fb6f6c0b7a6"));
assert(genesis.hashMerkleRoot == uint256S("0xd738744097ee4ee58036e9f500324b6335f3fdc41df704c5579bc5416be4a6eb"));
assert(consensus.hashGenesisBlock == uint256S("0x37981c0c48b8d48965376c8a42ece9a0838daadb93ff975cb091f57f8c2a5faa"));
assert(genesis.hashMerkleRoot == uint256S("0xd22a1ba59a39cbd5904624933efb822c8baa121f97060c4cc9ea2f00a4bc6512"));

// Note that of those with the service bits flag, most only support a subset of possible options
vSeeds.push_back(CDNSSeedData("pepecoin.org", "seeds.pepecoin.org"));
Expand All @@ -179,7 +179,7 @@ class CMainParams : public CChainParams {

checkpointData = (CCheckpointData) {
boost::assign::map_list_of
( 0, uint256S("0xb8fac7f8275af1072b983884fb128165862d7849d8f7d7841f282fb6f6c0b7a6"))
( 0, uint256S("0x37981c0c48b8d48965376c8a42ece9a0838daadb93ff975cb091f57f8c2a5faa"))
};

chainTxData = ChainTxData{ };
Expand All @@ -200,12 +200,6 @@ class CTestNetParams : public CChainParams {
strNetworkID = "test";

// Blocks 0 - 144999 are pre-Digishield
consensus.nHeightEffective = 0;
consensus.nPowTargetTimespan = 4 * 60 * 60; // pre-digishield: 4 hours
consensus.fDigishieldDifficultyCalculation = false;
consensus.nCoinbaseMaturity = 30;
consensus.fPowAllowMinDifficultyBlocks = true;
consensus.fPowAllowDigishieldMinDifficultyBlocks = false;
consensus.nSubsidyHalvingInterval = 100000;
consensus.nMajorityEnforceBlockUpgrade = 501;
consensus.nMajorityRejectBlockOutdated = 750;
Expand All @@ -216,8 +210,12 @@ class CTestNetParams : public CChainParams {
consensus.BIP65Height = 1000; //
consensus.BIP66Height = 1000; // - this is the last block that could be v2, 1900 blocks past the last v2 block
consensus.powLimit = uint256S("0x00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // ~uint256(0) >> 20;
consensus.nPowTargetTimespan = 4 * 60 * 60; // pre-digishield: 4 hours
consensus.nPowTargetTimespan = 60; // 1 minute
consensus.nPowTargetSpacing = 60; // 1 minute
consensus.fDigishieldDifficultyCalculation = true;
consensus.nCoinbaseMaturity = 30;
consensus.fPowAllowMinDifficultyBlocks = true;
consensus.fPowAllowDigishieldMinDifficultyBlocks = false;
consensus.fPowNoRetargeting = false;
consensus.nRuleChangeActivationThreshold = 2880; // 2 days (note this is significantly lower than Bitcoin standard)
consensus.nMinerConfirmationWindow = 10080; // 60 * 24 * 7 = 10,080 blocks, or one week
Expand All @@ -240,7 +238,7 @@ class CTestNetParams : public CChainParams {
consensus.nMinimumChainWork = uint256S("0000000000000000000000000000000000000000000000000000000000010001"); // genesis block

// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0x1cd0b7925f5458a232a81eb10b5af2fccd202d6973d57fc0dd0ccf862cae09d2"); // genesis block
consensus.defaultAssumeValid = uint256S("0xf9f4ea4ae7f6ea4c55040ede2019ba0a53e262f46ec9bce3dcda2cb11f96fc52"); // genesis block

// AuxPoW parameters
consensus.nAuxpowChainId = 0x003f; // 63
Expand All @@ -258,15 +256,15 @@ class CTestNetParams : public CChainParams {
digishieldConsensus.fPowAllowMinDifficultyBlocks = false;
digishieldConsensus.nCoinbaseMaturity = 240;

// Blocks 1250 - 1499 are Digishield with minimum difficulty on all blocks
// Blocks 1250 - 99,999 are Digishield with minimum difficulty on all blocks
minDifficultyConsensus = digishieldConsensus;
minDifficultyConsensus.nHeightEffective = 1250;
minDifficultyConsensus.fPowAllowDigishieldMinDifficultyBlocks = true;
minDifficultyConsensus.fPowAllowMinDifficultyBlocks = true;

// Enable AuxPoW at 1500
// Enable AuxPoW at 100,000
auxpowConsensus = minDifficultyConsensus;
auxpowConsensus.nHeightEffective = 1500;
auxpowConsensus.nHeightEffective = 100000;
auxpowConsensus.fPowAllowDigishieldMinDifficultyBlocks = true;
auxpowConsensus.fAllowLegacyBlocks = false;

Expand All @@ -283,14 +281,14 @@ class CTestNetParams : public CChainParams {
nDefaultPort = 44874;
nPruneAfterHeight = 1000;

genesis = CreateGenesisBlock(1705384860, 326706, 0x1e0ffff0, 1, 88 * COIN);
genesis = CreateGenesisBlock(1705975260, 3476, 0x1e0ffff0, 1, 88 * COIN);
consensus.hashGenesisBlock = genesis.GetHash();
digishieldConsensus.hashGenesisBlock = consensus.hashGenesisBlock;
minDifficultyConsensus.hashGenesisBlock = consensus.hashGenesisBlock;
auxpowConsensus.hashGenesisBlock = consensus.hashGenesisBlock;

assert(consensus.hashGenesisBlock == uint256S("0x1cd0b7925f5458a232a81eb10b5af2fccd202d6973d57fc0dd0ccf862cae09d2"));
assert(genesis.hashMerkleRoot == uint256S("0xd738744097ee4ee58036e9f500324b6335f3fdc41df704c5579bc5416be4a6eb"));
assert(consensus.hashGenesisBlock == uint256S("0xf9f4ea4ae7f6ea4c55040ede2019ba0a53e262f46ec9bce3dcda2cb11f96fc52"));
assert(genesis.hashMerkleRoot == uint256S("0xd22a1ba59a39cbd5904624933efb822c8baa121f97060c4cc9ea2f00a4bc6512"));

vSeeds.clear();
// nodes with support for servicebits filtering should be at the top
Expand All @@ -311,7 +309,7 @@ class CTestNetParams : public CChainParams {

checkpointData = (CCheckpointData) {
boost::assign::map_list_of
( 0, uint256S("0x1cd0b7925f5458a232a81eb10b5af2fccd202d6973d57fc0dd0ccf862cae09d2"))
( 0, uint256S("0xf9f4ea4ae7f6ea4c55040ede2019ba0a53e262f46ec9bce3dcda2cb11f96fc52"))
};

chainTxData = ChainTxData{ };
Expand Down Expand Up @@ -396,8 +394,8 @@ class CRegTestParams : public CChainParams {
consensus.hashGenesisBlock = genesis.GetHash();
digishieldConsensus.hashGenesisBlock = consensus.hashGenesisBlock;
auxpowConsensus.hashGenesisBlock = consensus.hashGenesisBlock;
assert(consensus.hashGenesisBlock == uint256S("0xfda0727b210f4d79f9abec20d95f8e3699e717aba00c37142ee97a8decab404c"));
assert(genesis.hashMerkleRoot == uint256S("0xd738744097ee4ee58036e9f500324b6335f3fdc41df704c5579bc5416be4a6eb"));
assert(consensus.hashGenesisBlock == uint256S("0x770975b0f98319520694563de107ff94fd501c0d1c16f3a405868faf36b51c28"));
assert(genesis.hashMerkleRoot == uint256S("0xd22a1ba59a39cbd5904624933efb822c8baa121f97060c4cc9ea2f00a4bc6512"));

vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds.
vSeeds.clear(); //!< Regtest mode doesn't have any DNS seeds.
Expand All @@ -409,7 +407,7 @@ class CRegTestParams : public CChainParams {

checkpointData = (CCheckpointData){
boost::assign::map_list_of
( 0, uint256S("0xfda0727b210f4d79f9abec20d95f8e3699e717aba00c37142ee97a8decab404c"))
( 0, uint256S("0x770975b0f98319520694563de107ff94fd501c0d1c16f3a405868faf36b51c28"))
};

chainTxData = ChainTxData{
Expand Down
2 changes: 1 addition & 1 deletion src/qt/test/rpcnestedtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void RPCNestedTests::rpcNestedTests()
QVERIFY(result == result2);

RPCConsole::RPCExecuteCommandLine(result, "getblock(getbestblockhash())[tx][0]", &filtered);
QVERIFY(result == "d738744097ee4ee58036e9f500324b6335f3fdc41df704c5579bc5416be4a6eb");
QVERIFY(result == "d22a1ba59a39cbd5904624933efb822c8baa121f97060c4cc9ea2f00a4bc6512");
QVERIFY(filtered == "getblock(getbestblockhash())[tx][0]");

RPCConsole::RPCParseCommandLine(result, "importprivkey", false, &filtered);
Expand Down
98 changes: 50 additions & 48 deletions src/test/miner_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,31 @@ struct {
unsigned char extranonce;
unsigned int nonce;
} blockinfo[] = {
{2, 0x0007c417}, {12, 0x001b9522}, {1, 0x00023c61}, {1, 0x00077366},
{1, 0x0011af77}, {1, 0x001ce11d}, {3, 0x00090ece}, {4, 0x0003acb0},
{1, 0x00026a84}, {1, 0x00000871}, {3, 0x00016a1f}, {1, 0x00006d91},
{1, 0x0008d3e1}, {1, 0x00031c3a}, {1, 0x001806b1}, {1, 0x000054d7},
{1, 0x00009b63}, {3, 0x00151484}, {1, 0x000f55b5}, {1, 0x00104ccc},
{1, 0x00040e31}, {5, 0x00054c0d}, {2, 0x0003f39c}, {3, 0x0002b159},
{4, 0x0004042b}, {4, 0x0009f8ad}, {4, 0x000214bd}, {2, 0x00073712},
{2, 0x0008a071}, {1, 0x0002bf53}, {3, 0x00036d5e}, {2, 0x000b5c52},
{2, 0x0016795d}, {1, 0x0018780a}, {3, 0x00004b97}, {4, 0x000197d7},
{1, 0x000ee8bc}, {3, 0x00117e4c}, {1, 0x002a4418}, {2, 0x0005c535},
{1, 0x0005cf15}, {2, 0x00060417}, {1, 0x00007281}, {4, 0x00005f10},
{3, 0x0012fb88}, {5, 0x0000f589}, {1, 0x00013a84}, {3, 0x001862a1},
{1, 0x0007dda3}, {3, 0x00004493}, {3, 0x000c3659}, {1, 0x00012034},
{1, 0x001220d5}, {1, 0x0001086a}, {1, 0x000d7572}, {1, 0x0017f08c},
{4, 0x000c02b3}, {1, 0x0002cc41}, {1, 0x000e114f}, {3, 0x0004c28f},
{2, 0x000a16e7}, {1, 0x00210025}, {1, 0x00021638}, {4, 0x000ac561},
{1, 0x000c17df}, {1, 0x0016fb9d}, {4, 0x0012e226}, {1, 0x0019c27e},
{2, 0x00233d00}, {2, 0x0009d44e}, {1, 0x00063d30}, {4, 0x00008f9b},
{2, 0x000648cc}, {7, 0x000587b0}, {1, 0x001198c4}, {2, 0x0003dbfe},
{7, 0x00074a98}, {5, 0x00009876}, {5, 0x00029fe5}, {3, 0x00043935},
{4, 0x00124825}, {4, 0x000a244f}, {3, 0x001e3837}, {3, 0x00025c32},
{7, 0x00185da1}, {3, 0x0005f426}, {3, 0x000e59f2}, {1, 0x0005ed50},
{2, 0x00016087}, {8, 0x0001a0b5}, {6, 0x001a48f5}, {2, 0x00026836},
{1, 0x0006626c}, {3, 0x000ccfd0}, {3, 0x00017a59}, {3, 0x00020545},
{4, 0x000308e8}, {2, 0x0004b060}, {3, 0x0005dbc6}, {1, 0x0006fd85}
{2, 0x0003a807}, {12, 0x000317c6}, {1, 0x0006c339}, {1, 0x0012615f},
{1, 0x001eaaa7}, {1, 0x0039a340}, {3, 0x00109dbe}, {4, 0x00050b0e},
{1, 0x00053337}, {1, 0x001fd8de}, {3, 0x000c7df1}, {1, 0x0000f5cb},
{1, 0x000ff609}, {1, 0x000a81e6}, {1, 0x000b2811}, {1, 0x000a0ada},
{1, 0x0007192c}, {3, 0x000c7698}, {1, 0x00117efc}, {1, 0x0009a6b7},
{1, 0x003e3d2b}, {5, 0x0009ac29}, {2, 0x000a2661}, {3, 0x0012f6e6},
{4, 0x000ccb74}, {4, 0x000743f8}, {4, 0x000e9543}, {2, 0x001dba12},
{2, 0x003d223a}, {1, 0x00228416}, {3, 0x000677a1}, {2, 0x00144589},
{2, 0x000de667}, {1, 0x000789a1}, {3, 0x001e2ec3}, {4, 0x002161ee},
{1, 0x001151cb}, {3, 0x000a639e}, {1, 0x0027c35c}, {2, 0x0028c0b5},
{1, 0x0002d4bd}, {2, 0x0001bf45}, {1, 0x00083ac0}, {4, 0x0001f7ca},
{3, 0x00039b53}, {5, 0x00019a07}, {1, 0x0014f693}, {3, 0x000432ad},
{1, 0x0028406a}, {3, 0x00332e99}, {3, 0x0000242d}, {1, 0x000507cf},
{1, 0x0006f1c6}, {1, 0x0012b50e}, {1, 0x0015ddec}, {1, 0x0018b451},
{4, 0x000db113}, {1, 0x00009382}, {1, 0x00123d86}, {3, 0x000a853e},
{2, 0x004c4a44}, {1, 0x0015fd9a}, {1, 0x00098093}, {4, 0x001d1fbb},
{1, 0x000046bb}, {1, 0x0012e36a}, {4, 0x000330e5}, {1, 0x001b76d9},
{2, 0x00184361}, {2, 0x0000cafa}, {1, 0x000daf34}, {4, 0x003d6499},
{2, 0x00092455}, {7, 0x0006865e}, {1, 0x00071e24}, {2, 0x00002369},
{7, 0x0007a38a}, {5, 0x00102937}, {5, 0x0001674e}, {3, 0x000239f4},
{4, 0x000893e9}, {4, 0x0036215b}, {3, 0x0001d6b5}, {3, 0x0004425d},
{7, 0x001688f0}, {3, 0x00019b65}, {3, 0x0020b8b5}, {1, 0x00087efb},
{2, 0x000e62a2}, {8, 0x0012bac0}, {6, 0x00026b24}, {2, 0x0001b958},
{1, 0x00037339}, {3, 0x000a64ee}, {3, 0x00024ceb}, {3, 0x000e4af4},
{4, 0x000ac24e}, {2, 0x000d76c0}, {3, 0x00055a58}, {1, 0x000d13a5}

};

Expand Down Expand Up @@ -228,30 +228,32 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock);
pblock->nNonce = blockinfo[i].nonce;

// CValidationState state;
// pblock->fChecked = false;
// std::cout << "Checked? " << pblock->fChecked << std::endl;
BlockMap::iterator mi = mapBlockIndex.find(pblock->hashPrevBlock);
CBlockIndex* pindexPrev = (*mi).second;
CValidationState state;
if (!TestBlockValidity(state, chainparams, *pblock, pindexPrev, false, true) || !CheckProofOfWork(pblock->GetPoWHash(), pblock->nBits, chainparams.GetConsensus(chainActive.Height()))) {
pblock->nNonce = 0;
std::cout << "Mining Block " << i+1 << std::endl;
while (!TestBlockValidity(state, chainparams, *pblock, pindexPrev, false, true) || !CheckProofOfWork(pblock->GetPoWHash(), pblock->nBits, chainparams.GetConsensus(chainActive.Height()))) {
++pblock->nNonce;
if (pblock->nNonce % 100000 == 0) {
printf("Block %d: %d, %d\n", i+1, blockinfo[i].extranonce, pblock->nNonce);
}
}
printf("Block %d mined: %d, 0x%08x\n", i+1, blockinfo[i].extranonce, pblock->nNonce);
// CheckBlock();
}
// Uncomment this code and it will generate the blockinfo at the top of this file.
// It grabs the extranonce (the first value of each tuple) and uses it to generate the nonce (the second value)
// You can run this in parallel incrementing the extranonces each time you run it, to generate the block info faster
// This is why you see many different values for the extra nonces. If you want, you can set them all to 1.
// It doesn't matter. This code will find the nonces for each extranonce.


// std::cout << "Block Valid? " << CheckBlock(*pblock, state) << std::endl;
// std::cout << "Adding block " << i << "... " << std::endl;
// std::cout << "Hash: " << pblock->GetHash().ToString() << "Prev Hash: " << pblock->hashPrevBlock.ToString() << std::endl;
// std::cout << pblock->ToString() << std::endl;
//DO NOT FORGET TO COMMENT THIS OUT DURING BUILDS.
//If the code below isn't commented out, it will make "make check" run for hours looking for 100 blocks
//It will also make your github action builds run for hours
//If your tests are hanging and you don't know why, it's probably this code

// pblock->fChecked = false;
// BlockMap::iterator mi = mapBlockIndex.find(pblock->hashPrevBlock);
// CBlockIndex* pindexPrev = (*mi).second;
// CValidationState state;
// if (!TestBlockValidity(state, chainparams, *pblock, pindexPrev, false, true) || !CheckProofOfWork(pblock->GetPoWHash(), pblock->nBits, chainparams.GetConsensus(chainActive.Height()))) {
// pblock->nNonce = 0;
// std::cout << "Mining Block " << i+1 << std::endl;
// while (!TestBlockValidity(state, chainparams, *pblock, pindexPrev, false, true) || !CheckProofOfWork(pblock->GetPoWHash(), pblock->nBits, chainparams.GetConsensus(chainActive.Height()))) {
// ++pblock->nNonce;
// if (pblock->nNonce % 100000 == 0) {
// printf("Block %d: %d, %d\n", i+1, blockinfo[i].extranonce, pblock->nNonce);
// }
// }
// printf("Block %d mined: %d, 0x%08x\n", i+1, blockinfo[i].extranonce, pblock->nNonce);
// }

std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock);

Expand Down
Loading

0 comments on commit c64209d

Please sign in to comment.