Auto merge of #1004 - str4d:931-difficulty-algorithm, r=ebfull

Implement new difficulty algorithm

Closes #931. Closes #696.
This commit is contained in:
zkbot 2016-06-15 23:26:49 +00:00
commit 1178df0883
6 changed files with 171 additions and 160 deletions

View File

@ -40,7 +40,9 @@ public:
// TODO generate harder genesis block
//consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
consensus.nPowAveragingWindow = 17;
consensus.nPowMaxAdjustDown = 16; // 16% adjustment down
consensus.nPowMaxAdjustUp = 8; // 8% adjustment up
consensus.nPowTargetSpacing = 2.5 * 60;
consensus.fPowAllowMinDifficultyBlocks = false;
/**
@ -218,6 +220,8 @@ public:
consensus.nMajorityRejectBlockOutdated = 950;
consensus.nMajorityWindow = 1000;
consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowMaxAdjustDown = 0; // Turn off adjustment down
consensus.nPowMaxAdjustUp = 0; // Turn off adjustment up
pchMessageStart[0] = 0xaa;
pchMessageStart[1] = 0xe8;
pchMessageStart[2] = 0x3f;

View File

@ -39,9 +39,13 @@ struct Params {
/** Proof of work parameters */
uint256 powLimit;
bool fPowAllowMinDifficultyBlocks;
int64_t nPowAveragingWindow;
int64_t nPowMaxAdjustDown;
int64_t nPowMaxAdjustUp;
int64_t nPowTargetSpacing;
int64_t nPowTargetTimespan;
int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; }
int64_t AveragingWindowTimespan() const { return nPowAveragingWindow * nPowTargetSpacing; }
int64_t MinActualTimespan() const { return (AveragingWindowTimespan() * (100 - nPowMaxAdjustUp )) / 100; }
int64_t MaxActualTimespan() const { return (AveragingWindowTimespan() * (100 + nPowMaxAdjustDown)) / 100; }
};
} // namespace Consensus

View File

@ -24,8 +24,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
if (pindexLast == NULL)
return nProofOfWorkLimit;
// Only change once per difficulty adjustment interval
if ((pindexLast->nHeight+1) % params.DifficultyAdjustmentInterval() != 0)
{
if (params.fPowAllowMinDifficultyBlocks)
{
@ -34,36 +32,35 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
// then allow mining of a min-difficulty block.
if (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2)
return nProofOfWorkLimit;
else
{
// Return the last non-special-min-difficulty-rules-block
const CBlockIndex* pindex = pindexLast;
while (pindex->pprev && pindex->nHeight % params.DifficultyAdjustmentInterval() != 0 && pindex->nBits == nProofOfWorkLimit)
pindex = pindex->pprev;
return pindex->nBits;
}
}
return pindexLast->nBits;
}
// Go back by what we want to be 14 days worth of blocks
int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1);
assert(nHeightFirst >= 0);
const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst);
assert(pindexFirst);
// Find the first block in the averaging interval
const CBlockIndex* pindexFirst = pindexLast;
for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) {
pindexFirst = pindexFirst->pprev;
}
return CalculateNextWorkRequired(pindexLast, pindexFirst->GetBlockTime(), params);
// Check we have enough blocks
if (pindexFirst == NULL)
return nProofOfWorkLimit;
return CalculateNextWorkRequired(pindexLast, pindexFirst->GetMedianTimePast(), params);
}
unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params& params)
{
// Limit adjustment step
int64_t nActualTimespan = pindexLast->GetBlockTime() - nFirstBlockTime;
LogPrintf(" nActualTimespan = %d before bounds\n", nActualTimespan);
if (nActualTimespan < params.nPowTargetTimespan/4)
nActualTimespan = params.nPowTargetTimespan/4;
if (nActualTimespan > params.nPowTargetTimespan*4)
nActualTimespan = params.nPowTargetTimespan*4;
// Use medians to prevent time-warp attacks
int64_t nActualTimespan = pindexLast->GetMedianTimePast() - nFirstBlockTime;
LogPrint("pow", " nActualTimespan = %d before dampening\n", nActualTimespan);
nActualTimespan = params.AveragingWindowTimespan() + (nActualTimespan - params.AveragingWindowTimespan())/4;
LogPrint("pow", " nActualTimespan = %d before bounds\n", nActualTimespan);
if (nActualTimespan < params.MinActualTimespan())
nActualTimespan = params.MinActualTimespan();
if (nActualTimespan > params.MaxActualTimespan())
nActualTimespan = params.MaxActualTimespan();
// Retarget
const arith_uint256 bnPowLimit = UintToArith256(params.powLimit);
@ -71,17 +68,17 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF
arith_uint256 bnOld;
bnNew.SetCompact(pindexLast->nBits);
bnOld = bnNew;
bnNew /= params.nPowTargetTimespan;
bnNew /= params.AveragingWindowTimespan();
bnNew *= nActualTimespan;
if (bnNew > bnPowLimit)
bnNew = bnPowLimit;
/// debug print
LogPrintf("GetNextWorkRequired RETARGET\n");
LogPrintf("params.nPowTargetTimespan = %d nActualTimespan = %d\n", params.nPowTargetTimespan, nActualTimespan);
LogPrintf("Before: %08x %s\n", pindexLast->nBits, bnOld.ToString());
LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.ToString());
LogPrint("pow", "GetNextWorkRequired RETARGET\n");
LogPrint("pow", "params.AveragingWindowTimespan() = %d nActualTimespan = %d\n", params.AveragingWindowTimespan(), nActualTimespan);
LogPrint("pow", "Before: %08x %s\n", pindexLast->nBits, bnOld.ToString());
LogPrint("pow", "After: %08x %s\n", bnNew.GetCompact(), bnNew.ToString());
return bnNew.GetCompact();
}

View File

@ -33,7 +33,7 @@ using namespace std;
/**
* Return average network hashes per second based on the last 'lookup' blocks,
* or from the last difficulty change if 'lookup' is nonpositive.
* or over the difficulty averaging window if 'lookup' is nonpositive.
* If 'height' is nonnegative, compute the estimate at the time when a given block was found.
*/
Value GetNetworkHashPS(int lookup, int height) {
@ -45,12 +45,13 @@ Value GetNetworkHashPS(int lookup, int height) {
if (pb == NULL || !pb->nHeight)
return 0;
// If lookup is -1, then use blocks since last difficulty change.
// If lookup is nonpositive, then use difficulty averaging window.
if (lookup <= 0)
lookup = pb->nHeight % Params().GetConsensus().DifficultyAdjustmentInterval() + 1;
lookup = pb->nHeight - Params().GetConsensus().nPowAveragingWindow;
// If lookup is larger than chain, then set it to chain length.
if (lookup > pb->nHeight)
// If lookup is still nonpositive, or is larger than chain, then set it to
// chain length.
if (lookup <= 0 || lookup > pb->nHeight)
lookup = pb->nHeight;
CBlockIndex *pb0 = pb;
@ -79,10 +80,10 @@ Value getnetworkhashps(const Array& params, bool fHelp)
throw runtime_error(
"getnetworkhashps ( blocks height )\n"
"\nReturns the estimated network hashes per second based on the last n blocks.\n"
"Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.\n"
"Pass in [blocks] to override # of blocks, -1 specifies over difficulty averaging window.\n"
"Pass in [height] to estimate the network speed at the time when a certain block was found.\n"
"\nArguments:\n"
"1. blocks (numeric, optional, default=120) The number of blocks, or -1 for blocks since last difficulty change.\n"
"1. blocks (numeric, optional, default=120) The number of blocks, or -1 for blocks over difficulty averaging window.\n"
"2. height (numeric, optional, default=-1) To estimate at the time of the given height.\n"
"\nResult:\n"
"x (numeric) Hashes per second estimated\n"

View File

@ -24,116 +24,116 @@ struct {
const char *nonce_hex;
uint32_t vSolutions[NUM_EQUIHASH_SOLUTIONS];
} blockinfo[] = {
{"0000000000000000000000000000000000000000000000000000000000000000", {216352,1018708,14037601,29429704,2494796,27147383,6675934,20511572,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {7863867,29124064,11004490,28155225,10050349,13402943,28382859,33286112,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {169471,19337013,4335518,10566558,9120654,28984284,22081278,23569130,}},
{"0000000000000000000000000000000000000000000000000000000000000004", {2411047,9766097,5865562,11493500,6886640,24323826,24014251,24058081,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4598434,31961097,26380422,26912453,19178416,30231514,25569745,30024594,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {4744463,23721331,16702646,32948865,12895364,22674052,16757409,20149442,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {375025,13373615,21683106,25856361,10145849,32430429,18173282,29195816,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {477635,5781180,2818347,25938101,6926588,15571188,7564010,25071567,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4551723,25691901,16242780,32913914,12083033,30201015,20164037,22465471,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {16520,20518430,1144707,7742973,5839683,22595129,24007036,26016915,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2837420,33325248,3494727,6897221,6570505,18599905,17580652,30119908,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3394318,12719729,6032280,32034148,7138821,17836282,24312124,28060983,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {10904990,32860971,12667074,27679457,11026753,22450787,13725435,28015877,}},
{"0000000000000000000000000000000000000000000000000000000000000004", {1965928,32593671,11916112,33519589,4439696,5463225,8260156,14753995,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {925306,1295985,18161249,32824347,1050388,15089627,15126153,26162143,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3633579,31983898,15584539,19766186,18004057,18332900,24205383,24465867,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2356723,23976633,4552275,6385134,8493810,28633235,19298870,21378879,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1959888,22654557,6474281,31748858,20082622,26550078,20264918,29712997,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {307453,19358543,29430800,31870134,9498175,17039188,25984927,29708092,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {579973,9373426,2663866,7349169,3818387,33229858,4093608,16461562,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1620139,9122166,5774863,11680063,6050524,13301932,7941532,33366261,}},
{"0000000000000000000000000000000000000000000000000000000000000004", {519956,31587388,1651632,14676460,9920521,30259574,21192494,29159346,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {7639147,30849510,15967391,29514312,12592973,25873044,16751871,24621393,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4321511,7231584,6964789,32516491,16551292,23311962,22749791,29688020,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {6371448,21534533,10676677,18512603,7200641,8736955,9059969,22412246,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {6479146,17442330,15064799,31757229,9917575,26919893,16249039,20185364,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1898548,8102870,27331469,28266576,7601708,15005984,9970478,23179881,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {8824523,32302979,30904324,32883737,12333733,25963100,15288867,18989669,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1548541,8843756,2755641,14485937,10070222,27300259,20569030,28831372,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3933582,32923759,22684416,32681323,5983801,32151279,8763644,20634443,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {5012656,10994861,16721985,30567353,19610350,32717977,25045228,33417764,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {17258015,27707751,26673969,32480251,21175481,31123996,30480722,33028625,}},
{"0000000000000000000000000000000000000000000000000000000000000004", {5903910,8655518,19731306,23870715,15498576,21520194,15566239,31655607,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1204528,11142967,3310310,10014673,8880746,12561187,23675817,33378929,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {76104,12682060,14628085,18171436,14981455,32744303,17056582,18770149,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {2696375,4820503,8559793,21524210,13599169,29147336,28403933,30552155,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1174385,5666437,8157877,12552667,8302517,8738371,12538730,14947174,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {615337,15689090,8431406,23563079,6899168,8800496,12950570,20173266,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1953266,11536716,18339238,29081823,5136210,13720741,19552516,24200164,}},
{"0000000000000000000000000000000000000000000000000000000000000004", {249398,16908574,18360411,30321347,2390792,33342214,5345732,23209599,}},
{"0000000000000000000000000000000000000000000000000000000000000003", {337570,15096899,950807,9258726,14597770,25482699,16338583,21823483,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {439297,19958741,10707482,23185296,5505982,5512387,26746726,28747056,}},
{"0000000000000000000000000000000000000000000000000000000000000003", {382428,20378022,13423578,16438183,8831736,23287565,16349318,22761138,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {997517,13645346,2278610,33102250,9532429,19721796,21163422,28204119,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {5539635,26357897,12410847,21826029,11144620,23084561,18700879,25928799,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2158337,25994688,10504737,30160761,12116158,28319046,12235990,14189630,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1436210,31626744,15898926,20060413,3036399,17054628,6259703,9455811,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {7978656,27534531,12406026,30227378,14747144,18286885,21527525,33038333,}},
{"0000000000000000000000000000000000000000000000000000000000000003", {252422,32197010,21490073,23059780,5455184,25487537,16068719,30014680,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1162839,2194236,29066916,32347888,9164579,29704919,14776042,32786384,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {5926523,26336777,6272293,25047609,8808382,9580150,11741921,32548287,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {485965,10980467,21070152,24146560,6060474,21603491,18854703,26569070,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {5530360,15850286,8323625,24337660,12505543,32524436,24896234,29424945,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {73124,19669640,6186952,11855781,17300508,26211536,19261491,25608557,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {6507045,12369767,9034123,25118377,11405198,13455953,27424266,28503839,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3152039,15920508,18081625,25689141,10744827,32688393,11420166,27045339,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1784239,7595315,30353799,30614116,6328014,30966331,7151736,30452480,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2694538,6650304,26983645,30240551,7990737,18246058,13819126,21461656,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2733076,15474778,6251503,23420762,8640670,26180816,10178088,22017673,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {892285,1051258,1261253,29955713,3813881,25282973,16060177,22704686,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1444629,26910303,6845637,20552767,5303179,13136113,8363446,21013103,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {468002,8189424,4614596,7656344,2759493,32914589,9492978,18142254,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3149773,20501373,13670277,32300221,5578821,27968301,7902924,22937692,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {4566477,22298090,5063792,18054718,5886835,22352284,8371750,22101911,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {8806142,14126367,9902594,24861914,9883421,15488143,10909056,21467314,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {3641746,4933661,14061855,18305499,4640168,11305894,9099587,21233653,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {799647,20796158,25579956,31946189,5316587,13163048,9711550,32526709,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1617653,27387537,28302718,33467915,6866140,19438600,21030899,26326740,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {8367176,12545169,8753130,15613328,11092478,33348288,17044467,30094385,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {6129285,8031962,16253119,16310122,23466613,25508437,27298247,31637071,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {33751,8455478,6478798,15300822,827208,4668740,4275780,6329486,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2569453,10000831,13754977,24337529,7096075,15897346,12488993,25354052,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1441927,29262792,6103777,23944999,9057967,25431237,19255170,30025327,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2349913,16463865,7688257,16505662,12686274,33250102,13899111,30839779,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {375902,22372207,15774817,16851615,19041805,24064402,24981401,25058103,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2282249,26812627,15212454,30604719,6421525,23219112,16909589,17575431,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2509256,22030655,27417447,29733625,3775718,18058391,13755781,26668823,}},
{"0000000000000000000000000000000000000000000000000000000000000004", {41327,27884303,8982554,15544395,1568960,27710196,6097908,11227268,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {427709,33168785,2173145,18463592,2859857,24461152,7706421,18780110,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2402883,4658669,16394321,19995911,9740181,28122698,14738781,30007925,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {359036,15835276,5213590,21161333,5620942,27395400,7805499,20799224,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1160068,23793408,5976768,29689631,15056387,32641235,19689023,23880772,}},
{"0000000000000000000000000000000000000000000000000000000000000003", {2734848,12177394,10302727,22658732,11425715,14641710,14711261,16523355,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {451341,10100671,21021666,27991878,5195582,5618314,5692846,10679709,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2964617,15229319,4076115,19204520,3648554,32697910,20197289,27636639,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {440072,30938322,27084206,30246143,3123795,8858970,16606542,32801246,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {9053804,29580504,11412391,28577156,13177965,13558034,16467244,17597272,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {3193671,25950281,14992426,29625315,7956969,8211246,15166507,27057711,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {334505,22052844,28756749,32918800,1843853,5749604,9399097,21031785,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4993887,11626466,6241557,24278440,11502165,19940637,26408954,29869824,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2407185,3852170,9504479,21953774,10050325,18652017,13951270,24166394,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {5420408,6981585,23870568,25089965,15225571,28209783,15340447,24744678,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1220752,5013344,19880580,29007540,4727548,32095982,5112086,16690708,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {8801517,28319229,11703943,14978087,16018730,16974587,23680776,25500260,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {116915,4812536,22036751,26372345,9620689,28535061,18749446,30769373,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {9814620,21390460,13072117,20767487,16932327,25313517,22832642,28148883,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {266314,838840,10202997,19159789,1488135,23070617,13686162,28880632,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {997789,25683952,23305604,27802671,8083925,11297332,11840318,23127675,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {804277,24368209,4696656,12413559,3664586,8298028,14691095,19302385,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4959792,7181349,11955606,30560922,11411750,12886320,15847408,30714873,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {676011,25074945,23692872,29269897,7294878,26983497,14954385,21473375,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {226406,10830525,10055779,10085800,1901739,3810417,14938451,31256809,}},
{"0000000000000000000000000000000000000000000000000000000000000005", {2995662,32503013,5787679,31858788,9325074,11503306,24879764,28676965,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {8671195,15011818,9378392,11477125,16056563,16400345,17535521,21619280,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2157875,27445165,5155391,30292735,9779645,11488081,20809173,22263281,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {11306513,18468576,30532327,30569445,12343544,20534469,24909512,25840040,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {2018384,14152248,10610344,16134504,10307466,28988177,18649688,29919281,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {3214055,23884942,10169222,14881676,8001971,22015673,22681053,23535540,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {9693164,28139918,15652061,23476135,10114742,31569401,17135058,32756480,}},
{"0000000000000000000000000000000000000000000000000000000000000005", {1276832,26649952,2610435,13194365,1439903,7796192,15145485,28696054,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {6460681,13237162,7709584,31045419,10285519,17375614,15570856,18802679,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4561870,17803565,5142864,27252551,4878460,12303443,7865598,11300160,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1089651,25039626,8810095,9296274,3249918,29008340,24645847,26512131,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {7728372,28861696,9545832,19144166,17556589,24119335,21961452,31035364,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {834238,9184343,13243668,23166288,7981278,26794117,14325463,14669701,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {734172,13569750,3562648,29145860,10283866,23063716,13248910,16359387,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {1587871,17811157,12023427,21207538,5720315,7856396,7103244,24229710,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1888147,27449466,13224507,14518313,15963469,22950485,17952156,24720854,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4302677,18772320,9863528,19410554,12176883,14140896,25924630,26251701,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {197279,32404497,11172719,18080543,15487758,28660859,31764039,32249219,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4024821,20999820,8894371,30988205,7275560,30827261,9405363,21175857,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1976935,18657882,12319377,33437938,2895318,8491699,8562465,9766831,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1205583,22738706,10435172,22796265,16651295,26452611,17851968,21396176,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4703343,12058656,8341840,9642250,12545365,23735257,29717152,30858347,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {692337,24190308,21647683,23770044,6914318,7096840,20965362,26417921,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {474315,31656164,6219098,28125716,5816881,15195781,13568953,29055883,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {31517,29912071,8389728,8760739,8901626,26743223,10511308,31784346,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2869946,23991756,8426881,20564925,5642907,26127833,12441891,22131781,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {5580020,20830652,29410091,32809082,15349511,19331016,18657410,26534999,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {705535,33235971,1184462,26966580,1849828,26167591,18261528,19642580,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {360784,3620708,15346909,27811152,3736810,12736765,9492651,13418606,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1229600,7684048,20079597,24040691,10128962,30769642,15215479,21182096,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1684299,12541147,11247589,28636814,5760908,24056463,13771233,20156600,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {366615,1724571,10566227,11511903,17264833,25873819,22389268,27114210,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2536004,10826889,5554022,25567653,17117623,27087905,24552584,25213783,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {1477713,7756450,10956188,18843116,5280035,23926642,21485984,25409801,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {7944879,30703371,18593785,31681620,17003578,23749264,23251318,24362277,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3151970,16283037,12190544,27031633,16929809,21092626,19126308,20966999,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {11742805,26242944,23697920,25996586,21500488,31327474,26510314,29943352,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3474994,10457317,7857597,9399886,3867550,30337263,7069425,9680763,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4070482,23916700,15699207,32888441,13650427,16462993,13669068,32222979,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1627610,2703221,25539467,26038173,20347871,22002889,27516372,33238984,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {5468299,20890642,15915944,28896368,5606254,30055314,20185515,26677498,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {4462855,25840162,11275769,25729029,4826227,8562549,17814144,29614168,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4650460,13427503,11884796,27041814,8349794,29591502,8987422,28994357,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {2166037,24526315,16259633,18008356,12870736,27719518,18085823,19116447,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3052277,18769667,10791737,29179500,6365222,25640257,12119977,23834845,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {931226,6222676,1981516,29528857,5526494,6437446,10216785,28915484,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {402336,20565306,1583379,17377951,2444738,20364696,20541200,28451640,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {481364,23732599,3623136,30032932,14778581,29656013,16319804,26087720,}},
{"0000000000000000000000000000000000000000000000000000000000000004", {673463,14487660,3861111,12772690,12841615,19331262,18127729,25891349,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2688675,19459330,21829421,33160296,2824435,7396953,21175704,24949453,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {421892,18602015,9591135,12373184,7173347,17694169,7290439,33340580,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3679946,29187321,20720370,29454078,23815548,28025307,24512609,27027920,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {5915260,18635781,13270767,30532080,12087680,29287028,19295798,24363799,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {1379380,7806321,2502697,6908506,4744762,14959880,13980259,22137966,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {803408,20975966,1413482,13231173,3839363,23141291,13060405,18560250,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1947212,33079753,4063708,21246355,11314469,30018165,21961696,31328001,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {6801506,7820458,13124300,19286633,13786873,26395883,24579925,27092845,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {4620414,21545333,24603466,27122394,8013117,19976859,26103775,33462356,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1370285,27998389,15658264,32386855,13657425,28489219,21379429,27671710,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1046241,9720078,22270576,31073443,2249489,18541008,3403135,25347615,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {6628384,15347228,7109798,12299310,13621159,18901367,17361405,24566552,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {485899,7175305,13204288,20383108,4291864,25276227,15428198,22075223,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {4576157,29654495,26010900,27823742,10508010,28828381,18751049,19433359,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {334007,24126201,14043036,28663573,12796738,30384031,23762812,32543448,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1564387,20284844,7145783,29120878,16382945,23659265,24017950,25818664,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1484737,27983306,17749884,21444188,20800690,30784231,28120163,30053577,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2865891,27768876,4204802,17130915,11616277,31257628,32536380,33369091,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1725874,5215139,12692907,19278036,15366567,15828025,21793226,31816514,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {734414,21482967,11953109,25118212,20766944,32456333,25492301,31547478,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {362428,14414265,5075444,27902624,9831174,31212666,13737393,32385081,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {145591,8161454,3423499,6631632,10102448,33473585,23115896,28527903,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {5444772,12807948,22417503,25113898,5895721,31533619,9369957,32708724,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {191145,14692308,10562753,23643852,1755413,2466351,12169279,32286664,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4217796,23246407,8887845,31695154,10533326,30025673,22206874,32714380,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1753102,14244174,8640641,9405374,2166463,9756880,20869865,32394445,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {8201850,31499684,11129001,16748109,14515976,24003883,17165759,32317200,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {6917819,32404441,19271143,21516446,15418960,20868981,24923177,28394671,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {321206,26913076,14302151,33448705,7685964,24523233,22925251,29572618,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {2903820,23498516,15828657,20209266,9829797,25536341,28768552,32421544,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {9083532,16515943,25935474,33429629,12792895,14550317,28467194,32688447,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {4996695,29308066,7380272,28823119,14269104,28218529,21486846,26875541,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {228029,9456103,5531810,9109588,3885858,13450710,11493960,23832083,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {958915,15090644,10493937,26335262,2070393,5579592,18459958,26779385,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3493559,20210149,7605993,29565780,5511822,15350620,12521491,16673167,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {710976,1160173,1850466,12141940,13492316,15225365,27352064,29101085,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {833211,21378874,6103635,22908955,14126213,17853331,21011902,23341861,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {181919,31623201,16582055,19621754,3411910,25415514,12417425,18284193,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {5204608,22166236,7632269,8411635,10740217,26043175,12647988,26574735,}},
{"0000000000000000000000000000000000000000000000000000000000000005", {4664139,29955587,14704709,25453965,4905764,29351642,16659156,23751368,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {5074419,30890716,6339326,28953313,9291001,24375735,15257160,21165865,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {190613,10145278,13714746,18808813,1423680,9382947,4269988,10838567,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {504650,14462835,10620156,24205954,15972669,20658502,16300078,23707181,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {7086481,22486367,28908448,28999017,18308207,19251588,25979812,32255764,}},
{"0000000000000000000000000000000000000000000000000000000000000003", {1172269,3423547,9911856,12439428,8953916,22659976,21037751,30753942,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3184078,22469134,7580931,10118630,9045686,13673962,11524613,33303343,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {342541,746191,25924366,26107112,9690659,21648096,15916528,18201749,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {582456,27300325,15677298,25818305,2923523,31393258,14404095,22050324,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {10098349,15404997,29705933,31559548,11692299,14511261,15242769,23172215,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {6647678,19913634,25164906,26855602,14666922,20168128,24127251,32531463,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {843691,21167176,4272064,8283965,12764152,21618083,24528474,27375014,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {978668,10447726,18233823,25605427,2261375,2637831,2614534,9252646,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {1523033,15567854,31485034,31653930,3636244,29609827,9083361,13896638,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {14773161,24406294,20062169,23703412,19849451,25344930,21297766,21606960,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {10100496,12477457,16853659,28087974,18171731,31136212,22832204,25990125,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {531788,29206121,8960854,25889718,3126134,22174191,8498009,30497485,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {1096424,23770446,8053481,14993175,3764227,10960948,6565175,22844110,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {6429009,13512960,16148076,24871100,8228201,22446947,25288067,28595618,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {1434391,25515128,14612732,17121094,12948147,15232470,18432774,21355020,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {3262210,13836997,4066552,27432736,10722950,27475484,19851879,33265322,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {2137233,17090519,21817897,23680576,4999337,31859639,19266661,21935793,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {11111617,28095860,19042244,26086616,11348636,11733615,12672763,22722616,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3028356,33444135,24052719,33236905,5745448,17228696,12238401,17713606,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {3682992,24667486,8936251,20577232,21868711,24392760,25828087,25912226,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {7856263,26873641,8940072,26662014,18323682,23361977,27035850,31048059,}},
{"0000000000000000000000000000000000000000000000000000000000000001", {4788899,18223624,10534029,17985114,14007906,14374373,18385178,32483622,}},
{"0000000000000000000000000000000000000000000000000000000000000002", {7610807,27213835,11937691,19779229,8510123,27229098,12664187,21714276,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1108792,32718813,27176467,32141527,9222059,17822217,9907758,25989472,}},
{"0000000000000000000000000000000000000000000000000000000000000000", {1797437,9489520,25931087,27014881,9885952,31932732,10063945,20983975,}},
};
// NOTE: These tests rely on CreateNewBlock doing its own self-validation!
@ -159,7 +159,12 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
pblock->nVersion = 4;
pblock->nTime = chainActive.Tip()->GetMedianTimePast()+1;
// Fake the blocks taking at least nPowTargetSpacing to be mined.
// GetMedianTimePast() returns the median of 11 blocks, so the timestamp
// of the next block must be six spacings ahead of that to be at least
// one spacing ahead of the tip. Within 11 blocks of genesis, the median
// will be closer to the tip, and blocks will appear slower.
pblock->nTime = chainActive.Tip()->GetMedianTimePast()+6*Params().GetConsensus().nPowTargetSpacing;
CMutableTransaction txCoinbase(pblock->vtx[0]);
txCoinbase.vin[0].scriptSig = CScript() << (chainActive.Height()+1) << OP_0;
txCoinbase.vout[0].scriptPubKey = CScript();

View File

@ -19,12 +19,12 @@ BOOST_AUTO_TEST_CASE(get_next_work)
SelectParams(CBaseChainParams::MAIN);
const Consensus::Params& params = Params().GetConsensus();
int64_t nLastRetargetTime = 1261130161; // Block #30240
int64_t nLastRetargetTime = 1262149169; // NOTE: Not an actual block time
CBlockIndex pindexLast;
pindexLast.nHeight = 32255;
pindexLast.nTime = 1262152739; // Block #32255
pindexLast.nTime = 1262152739; // Block #32255 of Bitcoin
pindexLast.nBits = 0x1d00ffff;
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1d00d86a);
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1d011998);
}
/* Test the constraint on the upper bound for next work */
@ -33,10 +33,10 @@ BOOST_AUTO_TEST_CASE(get_next_work_pow_limit)
SelectParams(CBaseChainParams::MAIN);
const Consensus::Params& params = Params().GetConsensus();
int64_t nLastRetargetTime = 1231006505; // Block #0
int64_t nLastRetargetTime = 1231006505; // Block #0 of Bitcoin
CBlockIndex pindexLast;
pindexLast.nHeight = 2015;
pindexLast.nTime = 1233061996; // Block #2015
pindexLast.nTime = 1233061996; // Block #2015 of Bitcoin
// TODO change once the harder genesis block is generated
pindexLast.nBits = 0x207fffff;
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x207fffff);
@ -48,12 +48,12 @@ BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual)
SelectParams(CBaseChainParams::MAIN);
const Consensus::Params& params = Params().GetConsensus();
int64_t nLastRetargetTime = 1279008237; // Block #66528
int64_t nLastRetargetTime = 1279295950; // NOTE: Not an actual block time
CBlockIndex pindexLast;
pindexLast.nHeight = 68543;
pindexLast.nTime = 1279297671; // Block #68543
pindexLast.nTime = 1279297671; // Block #68543 of Bitcoin
pindexLast.nBits = 0x1c05a3f4;
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1c0168fc);
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1c05306f);
}
/* Test the constraint on the upper bound for actual time taken */
@ -62,12 +62,12 @@ BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual)
SelectParams(CBaseChainParams::MAIN);
const Consensus::Params& params = Params().GetConsensus();
int64_t nLastRetargetTime = 1263163443; // NOTE: Not an actual block time
int64_t nLastRetargetTime = 1269207250; // NOTE: Not an actual block time
CBlockIndex pindexLast;
pindexLast.nHeight = 46367;
pindexLast.nTime = 1269211443; // Block #46367
pindexLast.nTime = 1269211443; // Block #46367 of Bitcoin
pindexLast.nBits = 0x1c387f6f;
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1d00e1fd);
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1c418995);
}
BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)