Changes for most chain power rule

This commit is contained in:
miketout
2018-09-28 01:38:14 -07:00
parent f82b75eb8b
commit 4b729ec577
51 changed files with 666 additions and 444 deletions

View File

@@ -402,7 +402,7 @@ BOOST_AUTO_TEST_CASE(PartitionAlert)
indexDummy[i].phashBlock = NULL;
if (i == 0) indexDummy[i].pprev = NULL;
else indexDummy[i].pprev = &indexDummy[i-1];
indexDummy[i].nHeight = i;
indexDummy[i].SetHeight(i);
indexDummy[i].nTime = now - (400-i)*nPowTargetSpacing;
// Other members don't matter, the partition check code doesn't
// use them

View File

@@ -387,13 +387,13 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
// subsidy changing
int nHeight = chainActive.Height();
chainActive.Tip()->nHeight = 209999;
chainActive.Tip()->SetHeight(209999);
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1));
delete pblocktemplate;
chainActive.Tip()->nHeight = 210000;
chainActive.Tip()->SetHeight(210000);
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1));
delete pblocktemplate;
chainActive.Tip()->nHeight = nHeight;
chainActive.Tip()->SetHeight(nHeight);
// non-final txs in mempool
SetMockTime(chainActive.Tip()->GetMedianTimePast()+1);
@@ -404,7 +404,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vin[0].nSequence = 0;
tx.vout[0].nValue = 49000LL;
tx.vout[0].scriptPubKey = CScript() << OP_1;
tx.nLockTime = chainActive.Tip()->nHeight+1;
tx.nLockTime = chainActive.Tip()->GetHeight()+1;
hash = tx.GetHash();
mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
BOOST_CHECK(!CheckFinalTx(tx, LOCKTIME_MEDIAN_TIME_PAST));
@@ -430,7 +430,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
delete pblocktemplate;
// However if we advance height and time by one, both will.
chainActive.Tip()->nHeight++;
chainActive.Tip()->SetHeight(chainActive.Tip()->GetHeight() + 1);
SetMockTime(chainActive.Tip()->GetMedianTimePast()+2);
// FIXME: we should *actually* create a new block so the following test
@@ -442,7 +442,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 2);
delete pblocktemplate;
chainActive.Tip()->nHeight--;
chainActive.Tip()->SetHeight(chainActive.Tip()->GetHeight() - 1);
SetMockTime(0);
mempool.clear();

View File

@@ -78,10 +78,12 @@ BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
std::vector<CBlockIndex> blocks(10000);
for (int i = 0; i < 10000; i++) {
blocks[i].pprev = i ? &blocks[i - 1] : NULL;
blocks[i].nHeight = i;
blocks[i].SetHeight(i);
blocks[i].nTime = 1269211443 + i * params.nPowTargetSpacing;
blocks[i].nBits = 0x207fffff; /* target 0x7fffff000... */
blocks[i].nChainWork = i ? blocks[i - 1].nChainWork + GetBlockProof(blocks[i - 1]) : arith_uint256(0);
blocks[i].chainPower = CChainPower(&blocks[i]);
if (i != 0)
blocks[i].chainPower += GetBlockProof(blocks[i - 1]);
}
for (int j = 0; j < 1000; j++) {

View File

@@ -1291,7 +1291,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_taddr_to_sapling)
block.hashMerkleRoot = block.BuildMerkleTree();
auto blockHash = block.GetHash();
CBlockIndex fakeIndex {block};
fakeIndex.nHeight = 1;
fakeIndex.SetHeight(1);
mapBlockIndex.insert(std::make_pair(blockHash, &fakeIndex));
chainActive.SetTip(&fakeIndex);
BOOST_CHECK(chainActive.Contains(&fakeIndex));

View File

@@ -20,15 +20,15 @@ BOOST_AUTO_TEST_CASE(skiplist_test)
std::vector<CBlockIndex> vIndex(SKIPLIST_LENGTH);
for (int i=0; i<SKIPLIST_LENGTH; i++) {
vIndex[i].nHeight = i;
vIndex[i].SetHeight(i);
vIndex[i].pprev = (i == 0) ? NULL : &vIndex[i - 1];
vIndex[i].BuildSkip();
}
for (int i=0; i<SKIPLIST_LENGTH; i++) {
if (i > 0) {
BOOST_CHECK(vIndex[i].pskip == &vIndex[vIndex[i].pskip->nHeight]);
BOOST_CHECK(vIndex[i].pskip->nHeight < i);
BOOST_CHECK(vIndex[i].pskip == &vIndex[vIndex[i].pskip->GetHeight()]);
BOOST_CHECK(vIndex[i].pskip->GetHeight() < i);
} else {
BOOST_CHECK(vIndex[i].pskip == NULL);
}
@@ -51,12 +51,12 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
std::vector<CBlockIndex> vBlocksMain(100000);
for (unsigned int i=0; i<vBlocksMain.size(); i++) {
vHashMain[i] = ArithToUint256(i); // Set the hash equal to the height, so we can quickly check the distances.
vBlocksMain[i].nHeight = i;
vBlocksMain[i].SetHeight(i);
vBlocksMain[i].pprev = i ? &vBlocksMain[i - 1] : NULL;
vBlocksMain[i].phashBlock = &vHashMain[i];
vBlocksMain[i].BuildSkip();
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksMain[i].GetBlockHash()).GetLow64(), vBlocksMain[i].nHeight);
BOOST_CHECK(vBlocksMain[i].pprev == NULL || vBlocksMain[i].nHeight == vBlocksMain[i].pprev->nHeight + 1);
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksMain[i].GetBlockHash()).GetLow64(), vBlocksMain[i].GetHeight());
BOOST_CHECK(vBlocksMain[i].pprev == NULL || vBlocksMain[i].GetHeight() == vBlocksMain[i].pprev->GetHeight() + 1);
}
// Build a branch that splits off at block 49999, 50000 blocks long.
@@ -64,12 +64,12 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
std::vector<CBlockIndex> vBlocksSide(50000);
for (unsigned int i=0; i<vBlocksSide.size(); i++) {
vHashSide[i] = ArithToUint256(i + 50000 + (arith_uint256(1) << 128)); // Add 1<<128 to the hashes, so GetLow64() still returns the height.
vBlocksSide[i].nHeight = i + 50000;
vBlocksSide[i].SetHeight(i + 50000);
vBlocksSide[i].pprev = i ? &vBlocksSide[i - 1] : &vBlocksMain[49999];
vBlocksSide[i].phashBlock = &vHashSide[i];
vBlocksSide[i].BuildSkip();
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksSide[i].GetBlockHash()).GetLow64(), vBlocksSide[i].nHeight);
BOOST_CHECK(vBlocksSide[i].pprev == NULL || vBlocksSide[i].nHeight == vBlocksSide[i].pprev->nHeight + 1);
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksSide[i].GetBlockHash()).GetLow64(), vBlocksSide[i].GetHeight());
BOOST_CHECK(vBlocksSide[i].pprev == NULL || vBlocksSide[i].GetHeight() == vBlocksSide[i].pprev->GetHeight() + 1);
}
// Build a CChain for the main branch.
@@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
// Entries 1 through 11 (inclusive) go back one step each.
for (unsigned int i = 1; i < 12 && i < locator.vHave.size() - 1; i++) {
BOOST_CHECK_EQUAL(UintToArith256(locator.vHave[i]).GetLow64(), tip->nHeight - i);
BOOST_CHECK_EQUAL(UintToArith256(locator.vHave[i]).GetLow64(), tip->GetHeight() - i);
}
// The further ones (excluding the last one) go back with exponential steps.