Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DPoW #314

Merged
merged 26 commits into from
Mar 18, 2017
14 changes: 5 additions & 9 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1244,14 +1244,10 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
LogPrintf("Prune: pruned datadir may not have more than %d blocks; -checkblocks=%d may fail\n",
MIN_BLOCKS_TO_KEEP, GetArg("-checkblocks", 288));
}
extern int32_t KOMODO_REWIND;
if ( KOMODO_REWIND == 0 )
{
if (!CVerifyDB().VerifyDB(pcoinsdbview, GetArg("-checklevel", 3),
GetArg("-checkblocks", 288))) {
strLoadError = _("Corrupted block database detected");
break;
}
if (!CVerifyDB().VerifyDB(pcoinsdbview, GetArg("-checklevel", 3),
GetArg("-checkblocks", 288))) {
strLoadError = _("Corrupted block database detected");
break;
}
} catch (const std::exception& e) {
if (fDebug) LogPrintf("%s\n", e.what());
Expand Down Expand Up @@ -1464,7 +1460,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
uiInterface.InitMessage(_("Activating best chain..."));
// scan for better chains in the block chain database, that are not yet connected in the active best chain
CValidationState state;
if (!ActivateBestChain(state))
if ( !ActivateBestChain(state))
strErrors << "Failed to connect best block";

std::vector<boost::filesystem::path> vImportFiles;
Expand Down
6 changes: 3 additions & 3 deletions src/komodo_gateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3

void komodo_passport_iteration()
{
static long lastpos[34]; static char userpass[33][1024]; int32_t maxseconds = 17;
static long lastpos[34]; static char userpass[33][1024]; int32_t maxseconds = 1;
FILE *fp; int32_t baseid,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0;
//printf("PASSPORT.(%s)\n",ASSETCHAINS_SYMBOL);
expired = 0;
Expand Down Expand Up @@ -1176,7 +1176,7 @@ void komodo_passport_iteration()
if ( 0 && lastpos[baseid] == 0 && strcmp(symbol,"KMD") == 0 )
printf("passport refid.%d %s fname.(%s) base.%s\n",refid,symbol,fname,base);
fseek(fp,lastpos[baseid],SEEK_SET);
while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 && n < 10000 )
while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 && n < 1000 )
{
if ( n == 999 )
{
Expand Down Expand Up @@ -1207,7 +1207,7 @@ void komodo_passport_iteration()
isrealtime = 1;
RTmask |= (1LL << baseid);
memcpy(refsp->RTbufs[baseid+1],buf,sizeof(refsp->RTbufs[baseid+1]));
} else if ( (time(NULL)-buf[2]) > 1800 )
} else if ( (time(NULL)-buf[2]) > 1800 && ASSETCHAINS_SYMBOL[0] != 0 )
fprintf(stderr,"[%s]: %s not RT %u %u %d\n",ASSETCHAINS_SYMBOL,base,buf[0],buf[1],(int32_t)(time(NULL)-buf[2]));
} //else fprintf(stderr,"%s size error RT\n",base);
fclose(fp);
Expand Down
2 changes: 1 addition & 1 deletion src/komodo_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct komodo_state KOMODO_STATES[34];
#define _COINBASE_MATURITY 100
int COINBASE_MATURITY = _COINBASE_MATURITY;//100;

int32_t IS_KOMODO_NOTARY,KOMODO_REWIND,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET;
int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET;
int32_t KOMODO_LASTMINED,prevKOMODO_LASTMINED;
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES;
uint8_t NOTARY_PUBKEY33[33];
Expand Down
4 changes: 2 additions & 2 deletions src/komodo_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1463,10 +1463,10 @@ void komodo_args()
KOMODO_PAX = 1;
} else KOMODO_PAX = GetArg("-pax",0);
name = GetArg("-ac_name","");
if ( (KOMODO_REWIND= GetArg("-rewind",0)) != 0 )
/*if ( (KOMODO_REWIND= GetArg("-rewind",0)) != 0 )
{
printf("KOMODO_REWIND %d\n",KOMODO_REWIND);
}
}*/
if ( name.c_str()[0] != 0 )
{
ASSETCHAINS_SUPPLY = GetArg("-ac_supply",10);
Expand Down
40 changes: 18 additions & 22 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1548,8 +1548,8 @@ bool IsInitialBlockDownload()
else if ( pindexBestHeader != 0 && pindexBestHeader->nHeight > ptr->nHeight )
ptr = pindexBestHeader;
if ( ASSETCHAINS_SYMBOL[0] == 0 )
state = (chainActive.Height() < ptr->nHeight - 24*6) ||
ptr->GetBlockTime() < (GetTime() - chainParams.MaxTipAge());
state = ((chainActive.Height() < ptr->nHeight - 24*6) ||
ptr->GetBlockTime() < (GetTime() - chainParams.MaxTipAge()));
else state = (chainActive.Height() < ptr->nHeight - 100);
//fprintf(stderr,"state.%d ht.%d vs %d, t.%u %u\n",state,(int32_t)chainActive.Height(),(uint32_t)ptr->nHeight,(int32_t)ptr->GetBlockTime(),(uint32_t)(GetTime() - chainParams.MaxTipAge()));
if (!state)
Expand Down Expand Up @@ -2758,7 +2758,6 @@ static void PruneBlockIndexCandidates() {
* pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork.
*/
static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMostWork, CBlock *pblock) {
extern int32_t KOMODO_REWIND;
AssertLockHeld(cs_main);
bool fInvalidFound = false;
const CBlockIndex *pindexOldTip = chainActive.Tip();
Expand All @@ -2769,30 +2768,28 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
if (!DisconnectTip(state))
return false;
}
/*fprintf(stderr,"chaintip %d vs rewind.%d\n",(int32_t)chainActive.Tip()->nHeight,KOMODO_REWIND);
if ( KOMODO_REWIND != 0 && chainActive.Tip()->nHeight >= KOMODO_REWIND )
{
//static int32_t didinit;
//if ( didinit++ == 0 )
if ( chainActive.Tip()->nHeight == KOMODO_REWIND+1 )
fprintf(stderr,"rewind ht.%d\n",chainActive.Tip()->nHeight);
while ( chainActive.Tip()->nHeight > KOMODO_REWIND )
{
fprintf(stderr,"reached rewind.%d, best to do: ./komodo-cli stop\n",KOMODO_REWIND);
sleep(3);
return(false);
}
{
while (chainActive.Tip()->nHeight > KOMODO_REWIND )
if ( !DisconnectTip(state) )
{
fprintf(stderr,"rewind ht.%d\n",chainActive.Tip()->nHeight);
if ( !DisconnectTip(state) )
{
InvalidateBlock(state,chainActive.Tip());
return false;
}
//InvalidateBlock(state,chainActive.Tip());
return false;
}
pindexOldTip = chainActive.Tip();
pindexFork = chainActive.FindFork(pindexMostWork);
}
}
fprintf(stderr,"end rewind ht.%d\n",chainActive.Tip()->nHeight);
if ( chainActive.Tip()->nHeight == KOMODO_REWIND )
{
fprintf(stderr,"reached rewind.%d, best to do: ./komodo-cli stop\n",KOMODO_REWIND);
sleep(3);
return(true);
}
pindexOldTip = chainActive.Tip();
pindexFork = chainActive.FindFork(pindexMostWork);
}*/
// Build list of new blocks to connect.
std::vector<CBlockIndex*> vpindexToConnect;
bool fContinue = true;
Expand Down Expand Up @@ -2868,7 +2865,6 @@ bool ActivateBestChain(CValidationState &state, CBlock *pblock) {

if (!ActivateBestChainStep(state, pindexMostWork, pblock && pblock->GetHash() == pindexMostWork->GetBlockHash() ? pblock : NULL))
return false;

pindexNewTip = chainActive.Tip();
fInitialDownload = IsInitialBlockDownload();
}
Expand Down
2 changes: 1 addition & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ void static BitcoinMiner(CWallet *pwallet)
LOCK(cs_vNodes);
fvNodesEmpty = vNodes.empty();
}
if (!fvNodesEmpty && !IsInitialBlockDownload())
if (!fvNodesEmpty )//&& !IsInitialBlockDownload())
break;
MilliSleep(5000);
//fprintf(stderr,"fvNodesEmpty %d IsInitialBlockDownload(%s) %d\n",(int32_t)fvNodesEmpty,ASSETCHAINS_SYMBOL,(int32_t)IsInitialBlockDownload());
Expand Down
7 changes: 4 additions & 3 deletions src/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ extern std::string NOTARY_PUBKEY;

bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params& params)
{
extern int32_t KOMODO_REWIND;
//extern int32_t KOMODO_REWIND;
bool fNegative,fOverflow; int32_t i,nonzpkeys=0,nonz=0,special=0,special2=0,notaryid=-1,duplicate,flag = 0, mids[66];
arith_uint256 bnTarget; CBlockIndex *pindex; uint8_t pubkeys[66][33];

Expand Down Expand Up @@ -155,15 +155,16 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
// Check proof of work matches claimed amount
if ( UintToArith256(hash) > bnTarget )
{
if ( (height < 235300 || height >= 236000) && KOMODO_LOADINGBLOCKS == 0 && height > 188000 && KOMODO_REWIND == 0 )//186269, 182507&& komodo_chainactive(height) != 0 && nonzpkeys > 0
if ( (height < 235300 || height >= 236000) && KOMODO_LOADINGBLOCKS == 0 && height > 188000 )
//&& KOMODO_REWIND == 0 )//186269, 182507&& komodo_chainactive(height) != 0 && nonzpkeys > 0
{
int32_t i;
for (i=31; i>=0; i--)
printf("%02x",((uint8_t *)&hash)[i]);
printf(" hash vs ");
for (i=31; i>=0; i--)
printf("%02x",((uint8_t *)&bnTarget)[i]);
printf(" ht.%d REWIND.%d special.%d notaryid.%d ht.%d mod.%d error\n",height,KOMODO_REWIND,special,notaryid,height,(height % 35));
printf(" ht.%d special.%d notaryid.%d ht.%d mod.%d error\n",height,special,notaryid,height,(height % 35));
for (i=0; i<33; i++)
printf("%02x",pubkey33[i]);
printf(" <- pubkey\n");
Expand Down
4 changes: 2 additions & 2 deletions src/rpcmining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ Value getblocktemplate(const Array& params, bool fHelp)
if (vNodes.empty())
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Zcash is not connected!");

if (IsInitialBlockDownload())
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Zcash is downloading blocks...");
//if (IsInitialBlockDownload())
// throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Zcash is downloading blocks...");

static unsigned int nTransactionsUpdatedLast;

Expand Down
4 changes: 2 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,

void CWallet::DecrementNoteWitnesses(const CBlockIndex* pindex)
{
extern int32_t KOMODO_REWIND;
//extern int32_t KOMODO_REWIND;
{
LOCK(cs_wallet);
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) {
Expand Down Expand Up @@ -806,7 +806,7 @@ void CWallet::DecrementNoteWitnesses(const CBlockIndex* pindex)
extern char ASSETCHAINS_SYMBOL[16];
fprintf(stderr,"%s nWitnessCacheSize.%d\n",ASSETCHAINS_SYMBOL,(int32_t)nWitnessCacheSize);
}
if ( KOMODO_REWIND == 0 )
//if ( KOMODO_REWIND == 0 )
assert(nWitnessCacheSize > 0);
//if (fFileBacked) {
// CWalletDB walletdb(strWalletFile);
Expand Down