Browse Source

Improve comments per review

pull/4/head
Jack Grigg 8 years ago
parent
commit
5e207f4ea5
  1. 11
      src/rpcmining.cpp
  2. 6
      src/test/miner_tests.cpp
  3. 10
      src/test/pow_tests.cpp

11
src/rpcmining.cpp

@ -45,16 +45,13 @@ Value GetNetworkHashPS(int lookup, int height) {
if (pb == NULL || !pb->nHeight)
return 0;
// If lookup is -1, then use difficulty averaging window.
// If lookup is nonpositive, then use difficulty averaging window.
if (lookup <= 0)
lookup = pb->nHeight - Params().GetConsensus().nPowAveragingWindow;
// If lookup is still negative, then use blocks since genesis.
if (lookup <= 0)
lookup = pb->nHeight;
// 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;

6
src/test/miner_tests.cpp

@ -158,7 +158,11 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
pblock->nVersion = 4;
// Fake the blocks taking at least nPowTargetSpacing
// 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;

10
src/test/pow_tests.cpp

@ -22,7 +22,7 @@ BOOST_AUTO_TEST_CASE(get_next_work)
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), 0x1d011998);
}
@ -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);
@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual)
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), 0x1c05306f);
}
@ -65,7 +65,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual)
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), 0x1c418995);
}

Loading…
Cancel
Save