Fix DGW v1 and v2 architecture issues.

This commit is contained in:
vertoe 2014-12-04 14:33:48 +01:00
parent 5a77c79d24
commit f8105535fe
2 changed files with 30 additions and 14 deletions

16
TODO.md
View File

@ -1,7 +1,7 @@
Porting Bitcoin 0.9.3 to Darkcoin Porting Bitcoin 0.9.3 to Darkcoin
================================= =================================
Staging tree for Darkcoin-0.9.3. Staging tree for Darkcoin-0.11.0.
DONE: DONE:
@ -17,19 +17,19 @@ DONE:
- Adjusted algorithm (X11) - Adjusted algorithm (X11)
- Updated subsidity function (Block value) - Updated subsidity function (Block value)
- Adjusted wallet keypool size to 1000 and added loading indicator on fresh wallet load - Adjusted wallet keypool size to 1000 and added loading indicator on fresh wallet load
- Adjusted difficulty and blockvalue (KGW, DGW based on blockheight)
MUST-HAVE: MANDATORY:
---------- ----------
- Adjust difficulty (KGW, DGW based on blockheight)
- Add masternode payment checks a.k.a. enforcement (based on blockheight) - Add masternode payment checks a.k.a. enforcement (based on blockheight)
OPTIONAL:
---------
- Remove Bitcoin dead weight (SHA256, hardcoded keys, nodes) - Remove Bitcoin dead weight (SHA256, hardcoded keys, nodes)
ADD-ON:
-------
- All the above for Testnet (including complete testnet reset) - All the above for Testnet (including complete testnet reset)
- Update strings and wallet layout/branding - Update strings and wallet layout/branding
- Include Evan's public key for msg signing - Include Evan's public key for msg signing

View File

@ -2081,10 +2081,10 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
if (fBenchmark) if (fBenchmark)
LogPrintf("- Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin)\n", (unsigned)block.vtx.size(), 0.001 * nTime, 0.001 * nTime / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * nTime / (nInputs-1)); LogPrintf("- Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin)\n", (unsigned)block.vtx.size(), 0.001 * nTime, 0.001 * nTime / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * nTime / (nInputs-1));
if (block.vtx[0].GetValueOut() > GetBlockValue(pindex->nBits, pindex->nHeight, nFees)) if (block.vtx[0].GetValueOut() > GetBlockValue(pindex->pprev->nBits, pindex->pprev->nHeight, nFees))
return state.DoS(100, return state.DoS(100,
error("ConnectBlock() : coinbase pays too much (actual=%d vs limit=%d)", error("ConnectBlock() : coinbase pays too much (actual=%d vs limit=%d)",
block.vtx[0].GetValueOut(), GetBlockValue(pindex->nBits, pindex->nHeight, nFees)), block.vtx[0].GetValueOut(), GetBlockValue(pindex->pprev->nBits, pindex->pprev->nHeight, nFees)),
REJECT_INVALID, "bad-cb-amount"); REJECT_INVALID, "bad-cb-amount");
if (!control.Wait()) if (!control.Wait())
@ -2619,10 +2619,26 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CDiskBlockPos* dbp)
pindexPrev = (*mi).second; pindexPrev = (*mi).second;
nHeight = pindexPrev->nHeight+1; nHeight = pindexPrev->nHeight+1;
// Check proof of work if(TestNet()) {
if (block.nBits != GetNextWorkRequired(pindexPrev, &block)) if (block.nBits != GetNextWorkRequired(pindexPrev, &block))
return state.DoS(100, error("AcceptBlock() : incorrect proof of work"), return state.DoS(100, error("AcceptBlock() : incorrect proof of work"),
REJECT_INVALID, "bad-diffbits"); REJECT_INVALID, "bad-diffbits");
} else {
// Check proof of work (Here for the architecture issues with DGW v1 and v2)
if(nHeight <= 68589){
unsigned int nBitsNext = GetNextWorkRequired(pindexPrev, &block);
double n1 = ConvertBitsToDouble(block.nBits);
double n2 = ConvertBitsToDouble(nBitsNext);
if (abs(n1-n2) > n1*0.5)
return state.DoS(100, error("AcceptBlock() : incorrect proof of work (DGW pre-fork) - %f", abs(n1-n2)),
REJECT_INVALID, "bad-diffbits");
} else {
if (block.nBits != GetNextWorkRequired(pindexPrev, &block))
return state.DoS(100, error("AcceptBlock() : incorrect proof of work"),
REJECT_INVALID, "bad-diffbits");
}
}
// Check timestamp against prev // Check timestamp against prev
if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast()) if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast())