Skip to content

Commit ec765b3

Browse files
Merge pull request #28 from samadsajanlal/master
fix testnet, clean up minor komodo notary logic
2 parents 6e072e1 + 9089d88 commit ec765b3

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

src/chainparams.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ class CTestNetParams : public CChainParams {
238238
fRequireStandard = false;
239239
fMineBlocksOnDemand = false;
240240

241+
// Hardfork params
242+
consensus.nSwitchKGW2 = 0;
243+
consensus.nSwitchKGW2prefork = 0;
244+
consensus.nSwitchKGW2postfork = 0;
245+
consensus.nSwitchDGW = 1;
246+
241247
checkpointData = (CCheckpointData) {
242248
{
243249
//{10000, uint256S("0x")},
@@ -308,6 +314,12 @@ class CRegTestParams : public CChainParams {
308314
fRequireStandard = false;
309315
fMineBlocksOnDemand = true;
310316

317+
// Hardfork params
318+
consensus.nSwitchKGW2 = 0;
319+
consensus.nSwitchKGW2prefork = 0;
320+
consensus.nSwitchKGW2postfork = 0;
321+
consensus.nSwitchDGW = 1;
322+
311323
checkpointData = (CCheckpointData) {
312324
{
313325
{0, uint256S("0x2574af5d531ba2c7b1b2994de62ae356699cb579cd744cf5dc8a565fce6db638")},

src/komodo_validation015.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555

5656
#include <wallet/wallet.h>
5757
//#include <key_io.h>
58+
#include <chainparams.h>
5859
#include <base58.h>
5960

6061
#define SATOSHIDEN ((uint64_t)100000000L)
@@ -1028,11 +1029,14 @@ void komodo_notarized_update(int32_t nHeight,int32_t notarized_height,uint256 no
10281029
char fname[512];int32_t latestht = 0;
10291030
//decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str());
10301031
pthread_mutex_init(&komodo_mutex,NULL);
1032+
std::string suffix = Params().NetworkIDString() == "main" ? "" : "_" + Params().NetworkIDString();
1033+
std::string sep;
10311034
#ifdef _WIN32
1032-
sprintf(fname,"%s\\notarizations",GetDataDir().string().c_str());
1035+
sep = "\\";
10331036
#else
1034-
sprintf(fname,"%s/notarizations",GetDataDir().string().c_str());
1037+
sep = "/";
10351038
#endif
1039+
sprintf(fname,"%s%snotarizations%s",GetDefaultDataDir().string().c_str(), sep.c_str(), suffix.c_str());
10361040
printf("fname.(%s)\n",fname);
10371041
if ( (fp= fopen(fname,"rb+")) == 0 )
10381042
fp = fopen(fname,"wb+");

src/pow.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,27 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
280280
int64_t PastSecondsMin = TimeDaySeconds * 0.01;
281281
int64_t PastSecondsMax = TimeDaySeconds * 0.14;
282282

283-
//unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact();
283+
unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact();
284284

285285
// Genesis block
286-
//if (pindexLast == NULL)
287-
// return nProofOfWorkLimit;
286+
if (pindexLast == NULL)
287+
return nProofOfWorkLimit;
288+
if (params.fPowAllowMinDifficultyBlocks)
289+
{
290+
// Special difficulty rule for testnet:
291+
// If the new block's timestamp is more than 2* 10 minutes
292+
// then allow mining of a min-difficulty block.
293+
if (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2)
294+
return nProofOfWorkLimit;
295+
else
296+
{
297+
// Return the last non-special-min-difficulty-rules-block
298+
const CBlockIndex* pindex = pindexLast;
299+
while (pindex->pprev && pindex->nHeight % params.DifficultyAdjustmentInterval() != 0 && pindex->nBits == nProofOfWorkLimit)
300+
pindex = pindex->pprev;
301+
return pindex->nBits;
302+
}
303+
}
288304

289305
if(pindexLast->nHeight+1 < params.nSwitchKGW2)
290306
{
@@ -365,4 +381,4 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&
365381
return false;
366382

367383
return true;
368-
}
384+
}

0 commit comments

Comments
 (0)