@@ -804,7 +804,7 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height)
|
|||||||
return(komodo_electednotary(&numnotaries,pubkey33,height,timestamp));
|
return(komodo_electednotary(&numnotaries,pubkey33,height,timestamp));
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *nonzpkeysp,int32_t height)
|
int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,uint32_t blocktimes[66],int32_t *nonzpkeysp,int32_t height)
|
||||||
{
|
{
|
||||||
int32_t i,j,n,duplicate; CBlock block; CBlockIndex *pindex; uint8_t notarypubs33[64][33];
|
int32_t i,j,n,duplicate; CBlock block; CBlockIndex *pindex; uint8_t notarypubs33[64][33];
|
||||||
memset(mids,-1,sizeof(*mids)*66);
|
memset(mids,-1,sizeof(*mids)*66);
|
||||||
@@ -813,6 +813,7 @@ int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *non
|
|||||||
{
|
{
|
||||||
if ( (pindex= komodo_chainactive(height-i)) != 0 )
|
if ( (pindex= komodo_chainactive(height-i)) != 0 )
|
||||||
{
|
{
|
||||||
|
blocktimes[i] = pindex->nTime;
|
||||||
if ( komodo_blockload(block,pindex) == 0 )
|
if ( komodo_blockload(block,pindex) == 0 )
|
||||||
{
|
{
|
||||||
komodo_block2pubkey33(pubkeys[i],&block);
|
komodo_block2pubkey33(pubkeys[i],&block);
|
||||||
@@ -849,10 +850,10 @@ int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width) // depre
|
|||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],int32_t height,uint8_t pubkey33[33],uint32_t timestamp)
|
int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],uint32_t blocktimes[66],int32_t height,uint8_t pubkey33[33],uint32_t blocktime)
|
||||||
{
|
{
|
||||||
int32_t i,j,notaryid=0,minerid,limit,nid; uint8_t destpubkey33[33];
|
int32_t i,j,notaryid=0,minerid,limit,nid; uint8_t destpubkey33[33];
|
||||||
komodo_chosennotary(¬aryid,height,pubkey33,timestamp);
|
komodo_chosennotary(¬aryid,height,pubkey33,blocktimes[0]);
|
||||||
if ( height >= 82000 )
|
if ( height >= 82000 )
|
||||||
{
|
{
|
||||||
if ( notaryid >= 0 )
|
if ( notaryid >= 0 )
|
||||||
@@ -861,14 +862,21 @@ int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],int32_t heigh
|
|||||||
{
|
{
|
||||||
if ( mids[i] == notaryid )
|
if ( mids[i] == notaryid )
|
||||||
{
|
{
|
||||||
//for (j=0; j<66; j++)
|
|
||||||
// fprintf(stderr,"%d ",mids[j]);
|
|
||||||
//fprintf(stderr,"ht.%d repeat notaryid.%d in mids[%d]\n",height,notaryid,i);
|
|
||||||
if ( height > 792000 )
|
if ( height > 792000 )
|
||||||
|
{
|
||||||
|
for (j=0; j<66; j++)
|
||||||
|
fprintf(stderr,"%d ",mids[j]);
|
||||||
|
fprintf(stderr,"ht.%d repeat notaryid.%d in mids[%d]\n",height,notaryid,i);
|
||||||
return(-1);
|
return(-1);
|
||||||
else break;
|
} else break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( blocktime != 0 && blocktimes[1] != 0 && blocktime < blocktimes[1]+57 )
|
||||||
|
{
|
||||||
|
//fprintf(stderr,"lag.%d ht.%d n.%d blocktimes[%u vs %u %u]\n",blocktime-blocktimes[1],height,notaryid,blocktime,blocktimes[0],blocktimes[1]);
|
||||||
|
if ( height > 807000 )
|
||||||
|
return(-2);
|
||||||
|
}
|
||||||
return(1);
|
return(1);
|
||||||
} else return(0);
|
} else return(0);
|
||||||
}
|
}
|
||||||
@@ -883,7 +891,7 @@ int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],int32_t heigh
|
|||||||
else limit = 66;
|
else limit = 66;
|
||||||
for (i=1; i<limit; i++)
|
for (i=1; i<limit; i++)
|
||||||
{
|
{
|
||||||
komodo_chosennotary(&nid,height-i,pubkey33,timestamp);
|
komodo_chosennotary(&nid,height-i,pubkey33,blocktimes[i]);
|
||||||
if ( nid == notaryid )
|
if ( nid == notaryid )
|
||||||
{
|
{
|
||||||
//for (j=0; j<66; j++)
|
//for (j=0; j<66; j++)
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ const char *Notaries_elected0[][2] =
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define KOMODO_NOTARIES_TIMESTAMP1 1525132800 // May 1st 2018 1530921600 // 7/7/2017
|
#define KOMODO_NOTARIES_TIMESTAMP1 1525132800 // May 1st 2018 1530921600 // 7/7/2017
|
||||||
#define KOMODO_NOTARIES_HEIGHT1 ((820000 / KOMODO_ELECTION_GAP) * KOMODO_ELECTION_GAP)
|
#define KOMODO_NOTARIES_HEIGHT1 ((814000 / KOMODO_ELECTION_GAP) * KOMODO_ELECTION_GAP)
|
||||||
|
|
||||||
const char *Notaries_elected1[][2] =
|
const char *Notaries_elected1[][2] =
|
||||||
{
|
{
|
||||||
|
|||||||
71
src/main.cpp
71
src/main.cpp
@@ -1678,7 +1678,7 @@ bool ReadBlockFromDisk(int32_t height,CBlock& block, const CDiskBlockPos& pos)
|
|||||||
}
|
}
|
||||||
// Check the header
|
// Check the header
|
||||||
komodo_block2pubkey33(pubkey33,(CBlock *)&block);
|
komodo_block2pubkey33(pubkey33,(CBlock *)&block);
|
||||||
if (!(CheckEquihashSolution(&block, Params()) && CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus())))
|
if (!(CheckEquihashSolution(&block, Params()) && CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus(),block.nTime)))
|
||||||
{
|
{
|
||||||
int32_t i; for (i=0; i<33; i++)
|
int32_t i; for (i=0; i<33; i++)
|
||||||
fprintf(stderr,"%02x",pubkey33[i]);
|
fprintf(stderr,"%02x",pubkey33[i]);
|
||||||
@@ -3748,16 +3748,16 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl
|
|||||||
return state.Invalid(error("CheckBlockHeader(): block timestamp needs to always increase"),REJECT_INVALID, "time-too-new");
|
return state.Invalid(error("CheckBlockHeader(): block timestamp needs to always increase"),REJECT_INVALID, "time-too-new");
|
||||||
}
|
}
|
||||||
// Check block version
|
// Check block version
|
||||||
//if (block.nVersion < MIN_BLOCK_VERSION)
|
if (height > 0 && blockhdr.nVersion < MIN_BLOCK_VERSION)
|
||||||
// return state.DoS(100, error("CheckBlockHeader(): block version too low"),REJECT_INVALID, "version-too-low");
|
return state.DoS(100, error("CheckBlockHeader(): block version too low"),REJECT_INVALID, "version-too-low");
|
||||||
|
|
||||||
// Check Equihash solution is valid
|
// Check Equihash solution is valid
|
||||||
if ( fCheckPOW && !CheckEquihashSolution(&blockhdr, Params()) )
|
/*if ( fCheckPOW && !CheckEquihashSolution(&blockhdr, Params()) )
|
||||||
return state.DoS(100, error("CheckBlockHeader(): Equihash solution invalid"),REJECT_INVALID, "invalid-solution");
|
return state.DoS(100, error("CheckBlockHeader(): Equihash solution invalid"),REJECT_INVALID, "invalid-solution");*/
|
||||||
|
|
||||||
// Check proof of work matches claimed amount
|
// Check proof of work matches claimed amount
|
||||||
/*komodo_index2pubkey33(pubkey33,pindex,height);
|
/*komodo_index2pubkey33(pubkey33,pindex,height);
|
||||||
if ( fCheckPOW && !CheckProofOfWork(height,pubkey33,blockhdr.GetHash(), blockhdr.nBits, Params().GetConsensus()) )
|
if ( fCheckPOW && !CheckProofOfWork(height,pubkey33,blockhdr.GetHash(), blockhdr.nBits, Params().GetConsensus(),blockhdr.nTime) )
|
||||||
return state.DoS(50, error("CheckBlockHeader(): proof of work failed"),REJECT_INVALID, "high-hash");*/
|
return state.DoS(50, error("CheckBlockHeader(): proof of work failed"),REJECT_INVALID, "high-hash");*/
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -3808,11 +3808,13 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat
|
|||||||
// redundant with the call in AcceptBlockHeader.
|
// redundant with the call in AcceptBlockHeader.
|
||||||
if (!CheckBlockHeader(height,pindex,block,state,fCheckPOW))
|
if (!CheckBlockHeader(height,pindex,block,state,fCheckPOW))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"checkblockheader error PoW.%d\n",fCheckPOW);
|
//fprintf(stderr,"checkblockheader error PoW.%d\n",fCheckPOW);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if ( fCheckPOW && !CheckEquihashSolution(&block, Params()) )
|
||||||
|
return state.DoS(100, error("CheckBlockHeader(): Equihash solution invalid"),REJECT_INVALID, "invalid-solution");
|
||||||
komodo_block2pubkey33(pubkey33,(CBlock *)&block);
|
komodo_block2pubkey33(pubkey33,(CBlock *)&block);
|
||||||
if ( fCheckPOW && !CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus()) )
|
if ( fCheckPOW && !CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus(),block.nTime) )
|
||||||
{
|
{
|
||||||
//komodo_reverify_blockcheck(state,height,pindex);
|
//komodo_reverify_blockcheck(state,height,pindex);
|
||||||
return state.DoS(1, error("CheckBlock(): proof of work failed"),REJECT_INVALID, "high-hash");
|
return state.DoS(1, error("CheckBlock(): proof of work failed"),REJECT_INVALID, "high-hash");
|
||||||
@@ -3992,47 +3994,8 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc
|
|||||||
*ppindex = pindex;
|
*ppindex = pindex;
|
||||||
if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK )
|
if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK )
|
||||||
return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate");
|
return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate");
|
||||||
#ifdef DEXcode
|
return true;
|
||||||
if ( pindex != 0 && IsInitialBlockDownload() == 0 ) // jl777 debug test
|
|
||||||
{
|
|
||||||
if (!CheckBlockHeader(pindex->nHeight,pindex, block, state,0))
|
|
||||||
{
|
|
||||||
pindex->nStatus |= BLOCK_FAILED_MASK;
|
|
||||||
fprintf(stderr,"known block failing CheckBlockHeader %d\n",(int32_t)pindex->nHeight);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
CBlockIndex* pindexPrev = NULL;
|
|
||||||
if (hash != chainparams.GetConsensus().hashGenesisBlock)
|
|
||||||
{
|
|
||||||
BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock);
|
|
||||||
if (mi == mapBlockIndex.end())
|
|
||||||
{
|
|
||||||
pindex->nStatus |= BLOCK_FAILED_MASK;
|
|
||||||
fprintf(stderr,"known block.%d failing to find prevblock\n",(int32_t)pindex->nHeight);
|
|
||||||
return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk");
|
|
||||||
}
|
|
||||||
pindexPrev = (*mi).second;
|
|
||||||
if (pindexPrev == 0 || (pindexPrev->nStatus & BLOCK_FAILED_MASK) )
|
|
||||||
{
|
|
||||||
pindex->nStatus |= BLOCK_FAILED_MASK;
|
|
||||||
fprintf(stderr,"known block.%d found invalid prevblock\n",(int32_t)pindex->nHeight);
|
|
||||||
return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!ContextualCheckBlockHeader(block, state, pindexPrev))
|
|
||||||
{
|
|
||||||
pindex->nStatus |= BLOCK_FAILED_MASK;
|
|
||||||
//fprintf(stderr,"known block.%d failing ContextualCheckBlockHeader\n",(int32_t)pindex->nHeight);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( *ppindex == 0 )
|
|
||||||
fprintf(stderr,"unexpected null *ppindex\n");
|
|
||||||
#endif
|
|
||||||
if ( pindex != 0 )
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CheckBlockHeader(*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0))
|
if (!CheckBlockHeader(*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"CheckBlockHeader failed\n");
|
fprintf(stderr,"CheckBlockHeader failed\n");
|
||||||
@@ -4058,7 +4021,9 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc
|
|||||||
if (pindex == NULL)
|
if (pindex == NULL)
|
||||||
{
|
{
|
||||||
if ( (pindex= AddToBlockIndex(block)) == 0 )
|
if ( (pindex= AddToBlockIndex(block)) == 0 )
|
||||||
fprintf(stderr,"couldnt add to block index\n");
|
{
|
||||||
|
//fprintf(stderr,"couldnt add to block index\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (ppindex)
|
if (ppindex)
|
||||||
*ppindex = pindex;
|
*ppindex = pindex;
|
||||||
@@ -4073,12 +4038,12 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
|
|||||||
CBlockIndex *&pindex = *ppindex;
|
CBlockIndex *&pindex = *ppindex;
|
||||||
if (!AcceptBlockHeader(block, state, &pindex))
|
if (!AcceptBlockHeader(block, state, &pindex))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"AcceptBlockHeader rejected\n");
|
//fprintf(stderr,"AcceptBlockHeader rejected\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ( pindex == 0 )
|
if ( pindex == 0 )
|
||||||
{
|
{
|
||||||
fprintf(stderr,"unexpected AcceptBlock error null pindex\n");
|
//fprintf(stderr,"unexpected AcceptBlock error null pindex\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//fprintf(stderr,"acceptblockheader passed\n");
|
//fprintf(stderr,"acceptblockheader passed\n");
|
||||||
@@ -4214,12 +4179,12 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex
|
|||||||
}
|
}
|
||||||
if (!CheckBlock(indexDummy.nHeight,0,block, state, verifier, fCheckPOW, fCheckMerkleRoot))
|
if (!CheckBlock(indexDummy.nHeight,0,block, state, verifier, fCheckPOW, fCheckMerkleRoot))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"TestBlockValidity failure B\n");
|
//fprintf(stderr,"TestBlockValidity failure B\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!ContextualCheckBlock(block, state, pindexPrev))
|
if (!ContextualCheckBlock(block, state, pindexPrev))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"TestBlockValidity failure C\n");
|
//fprintf(stderr,"TestBlockValidity failure C\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW))
|
if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW))
|
||||||
|
|||||||
484
src/miner.cpp
484
src/miner.cpp
@@ -207,12 +207,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
const CTransaction& tx = mi->GetTx();
|
const CTransaction& tx = mi->GetTx();
|
||||||
|
|
||||||
int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST)
|
int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST)
|
||||||
? nMedianTimePast
|
? nMedianTimePast
|
||||||
: pblock->GetBlockTime();
|
: pblock->GetBlockTime();
|
||||||
|
|
||||||
if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight))
|
if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight))
|
||||||
continue;
|
continue;
|
||||||
if ( komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,2) < 0 )
|
if ( komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 )
|
||||||
{
|
{
|
||||||
fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure\n");
|
fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure\n");
|
||||||
continue;
|
continue;
|
||||||
@@ -401,16 +401,16 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked));
|
pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked));
|
||||||
nFees += txfees;
|
nFees += txfees;
|
||||||
pblock->nTime = blocktime;
|
pblock->nTime = blocktime;
|
||||||
if ( GetAdjustedTime()+30 < pblock->nTime )
|
if ( GetAdjustedTime() < pblock->nTime )
|
||||||
{
|
{
|
||||||
//printf("need to wait %d seconds to submit: ",(int32_t)(pblock->nTime - GetAdjustedTime()));
|
printf("need to wait %d seconds to submit: ",(int32_t)(pblock->nTime - GetAdjustedTime()));
|
||||||
/*while ( GetAdjustedTime()+30 < pblock->nTime )
|
while ( GetAdjustedTime()+30 < pblock->nTime )
|
||||||
{
|
{
|
||||||
sleep(30);
|
sleep(30);
|
||||||
fprintf(stderr,"%d ",(int32_t)(pblock->nTime - GetAdjustedTime()));
|
fprintf(stderr,"%d ",(int32_t)(pblock->nTime - GetAdjustedTime()));
|
||||||
}*/
|
}
|
||||||
//fprintf(stderr,"finished waiting\n");
|
fprintf(stderr,"finished waiting\n");
|
||||||
sleep(30);
|
//sleep(pblock->nTime - GetAdjustedTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
} else fprintf(stderr,"no utxos eligible for staking\n");
|
} else fprintf(stderr,"no utxos eligible for staking\n");
|
||||||
@@ -430,28 +430,28 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
txNew.vin[0].scriptSig = CScript() << nHeight << OP_0;
|
txNew.vin[0].scriptSig = CScript() << nHeight << OP_0;
|
||||||
|
|
||||||
/*if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
/*if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||||
{
|
{
|
||||||
int32_t i,opretlen; uint8_t opret[256],*ptr;
|
int32_t i,opretlen; uint8_t opret[256],*ptr;
|
||||||
if ( (nHeight % 60) == 0 || komodo_gateway_deposits(&txNew,(char *)"KMD",1) == 0 )
|
if ( (nHeight % 60) == 0 || komodo_gateway_deposits(&txNew,(char *)"KMD",1) == 0 )
|
||||||
{
|
{
|
||||||
if ( (opretlen= komodo_pax_opreturn((int32_t)nHeight,opret,sizeof(opret))) > 0 ) // have pricefeed
|
if ( (opretlen= komodo_pax_opreturn((int32_t)nHeight,opret,sizeof(opret))) > 0 ) // have pricefeed
|
||||||
{
|
{
|
||||||
txNew.vout.resize(2);
|
txNew.vout.resize(2);
|
||||||
txNew.vout[1].scriptPubKey.resize(opretlen);
|
txNew.vout[1].scriptPubKey.resize(opretlen);
|
||||||
ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data();
|
ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data();
|
||||||
for (i=0; i<opretlen; i++)
|
for (i=0; i<opretlen; i++)
|
||||||
ptr[i] = opret[i];
|
ptr[i] = opret[i];
|
||||||
txNew.vout[1].nValue = 0;
|
txNew.vout[1].nValue = 0;
|
||||||
//fprintf(stderr,"opretlen.%d\n",opretlen);
|
//fprintf(stderr,"opretlen.%d\n",opretlen);
|
||||||
} //else printf("null opretlen for prices\n");
|
} //else printf("null opretlen for prices\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( komodo_is_issuer() != 0 )
|
else if ( komodo_is_issuer() != 0 )
|
||||||
{
|
{
|
||||||
komodo_gateway_deposits(&txNew,ASSETCHAINS_SYMBOL,0);
|
komodo_gateway_deposits(&txNew,ASSETCHAINS_SYMBOL,0);
|
||||||
if ( txNew.vout.size() > 1 )
|
if ( txNew.vout.size() > 1 )
|
||||||
fprintf(stderr,"%s txNew numvouts.%d\n",ASSETCHAINS_SYMBOL,(int32_t)txNew.vout.size());
|
fprintf(stderr,"%s txNew numvouts.%d\n",ASSETCHAINS_SYMBOL,(int32_t)txNew.vout.size());
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
pblock->vtx[0] = txNew;
|
pblock->vtx[0] = txNew;
|
||||||
if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission(pblocktemplate->block)) != 0 )
|
if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission(pblocktemplate->block)) != 0 )
|
||||||
@@ -484,15 +484,22 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
|
UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
|
||||||
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
|
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
|
||||||
}
|
}
|
||||||
|
if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 && pblock->nTime < pindexPrev->nTime+60 )
|
||||||
|
{
|
||||||
|
pblock->nTime = pindexPrev->nTime + 60;
|
||||||
|
fprintf(stderr,"block.nTime %u vs prev.%u, gettime.%u vs adjusted.%u\n",(uint32_t)pblock->nTime,(uint32_t)(pindexPrev->nTime + 60),(uint32_t)pblock->GetBlockTime(),(uint32_t)(GetAdjustedTime() + 60));
|
||||||
|
while ( pblock->GetBlockTime() > GetAdjustedTime() + 60 )
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
pblock->nSolution.clear();
|
pblock->nSolution.clear();
|
||||||
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
|
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
|
||||||
|
|
||||||
CValidationState state;
|
CValidationState state;
|
||||||
if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false))
|
if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false))
|
||||||
{
|
{
|
||||||
static uint32_t counter;
|
//static uint32_t counter;
|
||||||
//if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 )
|
//if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 )
|
||||||
fprintf(stderr,"warning: miner testblockvalidity failed\n");
|
//fprintf(stderr,"warning: miner testblockvalidity failed\n");
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -501,47 +508,47 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
boost::optional<CScript> GetMinerScriptPubKey(CReserveKey& reservekey)
|
boost::optional<CScript> GetMinerScriptPubKey(CReserveKey& reservekey)
|
||||||
#else
|
#else
|
||||||
boost::optional<CScript> GetMinerScriptPubKey()
|
boost::optional<CScript> GetMinerScriptPubKey()
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
CKeyID keyID;
|
CKeyID keyID;
|
||||||
CBitcoinAddress addr;
|
CBitcoinAddress addr;
|
||||||
if (addr.SetString(GetArg("-mineraddress", ""))) {
|
if (addr.SetString(GetArg("-mineraddress", ""))) {
|
||||||
addr.GetKeyID(keyID);
|
addr.GetKeyID(keyID);
|
||||||
} else {
|
} else {
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
CPubKey pubkey;
|
CPubKey pubkey;
|
||||||
if (!reservekey.GetReservedKey(pubkey)) {
|
if (!reservekey.GetReservedKey(pubkey)) {
|
||||||
return boost::optional<CScript>();
|
return boost::optional<CScript>();
|
||||||
}
|
}
|
||||||
keyID = pubkey.GetID();
|
keyID = pubkey.GetID();
|
||||||
#else
|
#else
|
||||||
return boost::optional<CScript>();
|
return boost::optional<CScript>();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
CScript scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
|
CScript scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||||
return scriptPubKey;
|
return scriptPubKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
|
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
|
||||||
{
|
{
|
||||||
boost::optional<CScript> scriptPubKey = GetMinerScriptPubKey(reservekey);
|
boost::optional<CScript> scriptPubKey = GetMinerScriptPubKey(reservekey);
|
||||||
#else
|
#else
|
||||||
CBlockTemplate* CreateNewBlockWithKey()
|
CBlockTemplate* CreateNewBlockWithKey()
|
||||||
{
|
{
|
||||||
boost::optional<CScript> scriptPubKey = GetMinerScriptPubKey();
|
boost::optional<CScript> scriptPubKey = GetMinerScriptPubKey();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!scriptPubKey) {
|
if (!scriptPubKey) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return CreateNewBlock(*scriptPubKey);
|
return CreateNewBlock(*scriptPubKey);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
@@ -657,7 +664,7 @@ static bool ProcessBlockFound(CBlock* pblock)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t komodo_baseid(char *origbase);
|
int32_t komodo_baseid(char *origbase);
|
||||||
int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *nonzpkeysp,int32_t height);
|
int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,uint32_t *blocktimes,int32_t *nonzpkeysp,int32_t height);
|
||||||
arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc);
|
arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc);
|
||||||
int32_t FOUND_BLOCK,KOMODO_MAYBEMINED;
|
int32_t FOUND_BLOCK,KOMODO_MAYBEMINED;
|
||||||
extern int32_t KOMODO_LASTMINED;
|
extern int32_t KOMODO_LASTMINED;
|
||||||
@@ -692,12 +699,11 @@ void static BitcoinMiner()
|
|||||||
if ( komodo_baseid(ASSETCHAINS_SYMBOL) < 0 )
|
if ( komodo_baseid(ASSETCHAINS_SYMBOL) < 0 )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//sleep(60);
|
|
||||||
komodo_chosennotary(¬aryid,chainActive.Tip()->nHeight,NOTARY_PUBKEY33,(uint32_t)chainActive.Tip()->GetBlockTime());
|
komodo_chosennotary(¬aryid,chainActive.Tip()->nHeight,NOTARY_PUBKEY33,(uint32_t)chainActive.Tip()->GetBlockTime());
|
||||||
|
|
||||||
std::string solver;
|
std::string solver;
|
||||||
//if ( notaryid >= 0 || ASSETCHAINS_SYMBOL[0] != 0 )
|
//if ( notaryid >= 0 || ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
solver = "tromp";
|
solver = "tromp";
|
||||||
//else solver = "default";
|
//else solver = "default";
|
||||||
assert(solver == "tromp" || solver == "default");
|
assert(solver == "tromp" || solver == "default");
|
||||||
LogPrint("pow", "Using Equihash solver \"%s\" with n = %u, k = %u\n", solver, n, k);
|
LogPrint("pow", "Using Equihash solver \"%s\" with n = %u, k = %u\n", solver, n, k);
|
||||||
@@ -706,11 +712,11 @@ void static BitcoinMiner()
|
|||||||
std::mutex m_cs;
|
std::mutex m_cs;
|
||||||
bool cancelSolver = false;
|
bool cancelSolver = false;
|
||||||
boost::signals2::connection c = uiInterface.NotifyBlockTip.connect(
|
boost::signals2::connection c = uiInterface.NotifyBlockTip.connect(
|
||||||
[&m_cs, &cancelSolver](const uint256& hashNewTip) mutable {
|
[&m_cs, &cancelSolver](const uint256& hashNewTip) mutable {
|
||||||
std::lock_guard<std::mutex> lock{m_cs};
|
std::lock_guard<std::mutex> lock{m_cs};
|
||||||
cancelSolver = true;
|
cancelSolver = true;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
miningTimer.start();
|
miningTimer.start();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -741,10 +747,10 @@ void static BitcoinMiner()
|
|||||||
miningTimer.start();
|
miningTimer.start();
|
||||||
}
|
}
|
||||||
/*while ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight < ASSETCHAINS_MINHEIGHT )
|
/*while ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight < ASSETCHAINS_MINHEIGHT )
|
||||||
{
|
{
|
||||||
fprintf(stderr,"%s waiting for block 100, ht.%d\n",ASSETCHAINS_SYMBOL,chainActive.Tip()->nHeight);
|
fprintf(stderr,"%s waiting for block 100, ht.%d\n",ASSETCHAINS_SYMBOL,chainActive.Tip()->nHeight);
|
||||||
sleep(3);
|
sleep(3);
|
||||||
}*/
|
}*/
|
||||||
//
|
//
|
||||||
// Create new block
|
// Create new block
|
||||||
//
|
//
|
||||||
@@ -803,7 +809,7 @@ void static BitcoinMiner()
|
|||||||
//
|
//
|
||||||
// Search
|
// Search
|
||||||
//
|
//
|
||||||
uint8_t pubkeys[66][33]; int mids[256],gpucount,nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime();
|
uint8_t pubkeys[66][33]; uint32_t blocktimes[66]; int mids[256],gpucount,nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime();
|
||||||
savebits = pblock->nBits;
|
savebits = pblock->nBits;
|
||||||
HASHTarget = arith_uint256().SetCompact(pblock->nBits);
|
HASHTarget = arith_uint256().SetCompact(pblock->nBits);
|
||||||
roundrobin_delay = ROUNDROBIN_DELAY;
|
roundrobin_delay = ROUNDROBIN_DELAY;
|
||||||
@@ -812,7 +818,7 @@ void static BitcoinMiner()
|
|||||||
j = 65;
|
j = 65;
|
||||||
if ( (Mining_height >= 235300 && Mining_height < 236000) || (Mining_height % KOMODO_ELECTION_GAP) > 64 || (Mining_height % KOMODO_ELECTION_GAP) == 0 )
|
if ( (Mining_height >= 235300 && Mining_height < 236000) || (Mining_height % KOMODO_ELECTION_GAP) > 64 || (Mining_height % KOMODO_ELECTION_GAP) == 0 )
|
||||||
{
|
{
|
||||||
komodo_eligiblenotary(pubkeys,mids,&nonzpkeys,pindexPrev->nHeight);
|
komodo_eligiblenotary(pubkeys,mids,blocktimes,&nonzpkeys,pindexPrev->nHeight);
|
||||||
if ( nonzpkeys > 0 )
|
if ( nonzpkeys > 0 )
|
||||||
{
|
{
|
||||||
for (i=0; i<33; i++)
|
for (i=0; i<33; i++)
|
||||||
@@ -877,11 +883,11 @@ void static BitcoinMiner()
|
|||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
/*if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT ) // skips when it shouldnt
|
/*if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT ) // skips when it shouldnt
|
||||||
{
|
{
|
||||||
fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",ASSETCHAINS_SYMBOL);
|
fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",ASSETCHAINS_SYMBOL);
|
||||||
sleep(10);
|
sleep(10);
|
||||||
break;
|
break;
|
||||||
}*/
|
}*/
|
||||||
// Hash state
|
// Hash state
|
||||||
KOMODO_CHOSEN_ONE = 0;
|
KOMODO_CHOSEN_ONE = 0;
|
||||||
crypto_generichash_blake2b_state state;
|
crypto_generichash_blake2b_state state;
|
||||||
@@ -902,11 +908,11 @@ void static BitcoinMiner()
|
|||||||
//fprintf(stderr,"running solver\n");
|
//fprintf(stderr,"running solver\n");
|
||||||
std::function<bool(std::vector<unsigned char>)> validBlock =
|
std::function<bool(std::vector<unsigned char>)> validBlock =
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
[&pblock, &hashTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams]
|
[&pblock, &hashTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams]
|
||||||
#else
|
#else
|
||||||
[&pblock, &hashTarget, &m_cs, &cancelSolver, &chainparams]
|
[&pblock, &hashTarget, &m_cs, &cancelSolver, &chainparams]
|
||||||
#endif
|
#endif
|
||||||
(std::vector<unsigned char> soln) {
|
(std::vector<unsigned char> soln) {
|
||||||
// Write the solution to the hash and compute the result.
|
// Write the solution to the hash and compute the result.
|
||||||
LogPrint("pow", "- Checking solution against target\n");
|
LogPrint("pow", "- Checking solution against target\n");
|
||||||
pblock->nSolution = soln;
|
pblock->nSolution = soln;
|
||||||
@@ -928,9 +934,9 @@ void static BitcoinMiner()
|
|||||||
if ( Mining_start != 0 && time(NULL) < Mining_start+roundrobin_delay )
|
if ( Mining_start != 0 && time(NULL) < Mining_start+roundrobin_delay )
|
||||||
{
|
{
|
||||||
//printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+roundrobin_delay-time(NULL)));
|
//printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+roundrobin_delay-time(NULL)));
|
||||||
int32_t nseconds = Mining_start+roundrobin_delay-time(NULL);
|
//int32_t nseconds = Mining_start+roundrobin_delay-time(NULL);
|
||||||
if ( nseconds > 0 )
|
//if ( nseconds > 0 )
|
||||||
sleep(nseconds);
|
// sleep(nseconds);
|
||||||
MilliSleep((rand() % 1700) + 1);
|
MilliSleep((rand() % 1700) + 1);
|
||||||
}
|
}
|
||||||
else if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
else if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
@@ -962,178 +968,178 @@ void static BitcoinMiner()
|
|||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
if (ProcessBlockFound(pblock, *pwallet, reservekey)) {
|
if (ProcessBlockFound(pblock, *pwallet, reservekey)) {
|
||||||
#else
|
#else
|
||||||
if (ProcessBlockFound(pblock)) {
|
if (ProcessBlockFound(pblock)) {
|
||||||
#endif
|
#endif
|
||||||
// Ignore chain updates caused by us
|
// Ignore chain updates caused by us
|
||||||
|
std::lock_guard<std::mutex> lock{m_cs};
|
||||||
|
cancelSolver = false;
|
||||||
|
}
|
||||||
|
KOMODO_CHOSEN_ONE = 0;
|
||||||
|
SetThreadPriority(THREAD_PRIORITY_LOWEST);
|
||||||
|
// In regression test mode, stop mining after a block is found.
|
||||||
|
if (chainparams.MineBlocksOnDemand()) {
|
||||||
|
// Increment here because throwing skips the call below
|
||||||
|
ehSolverRuns.increment();
|
||||||
|
throw boost::thread_interrupted();
|
||||||
|
}
|
||||||
|
//if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 )
|
||||||
|
// sleep(1800);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
std::function<bool(EhSolverCancelCheck)> cancelled = [&m_cs, &cancelSolver](EhSolverCancelCheck pos) {
|
||||||
std::lock_guard<std::mutex> lock{m_cs};
|
std::lock_guard<std::mutex> lock{m_cs};
|
||||||
cancelSolver = false;
|
return cancelSolver;
|
||||||
}
|
};
|
||||||
KOMODO_CHOSEN_ONE = 0;
|
|
||||||
SetThreadPriority(THREAD_PRIORITY_LOWEST);
|
|
||||||
// In regression test mode, stop mining after a block is found.
|
|
||||||
if (chainparams.MineBlocksOnDemand()) {
|
|
||||||
// Increment here because throwing skips the call below
|
|
||||||
ehSolverRuns.increment();
|
|
||||||
throw boost::thread_interrupted();
|
|
||||||
}
|
|
||||||
//if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 )
|
|
||||||
// sleep(1800);
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
std::function<bool(EhSolverCancelCheck)> cancelled = [&m_cs, &cancelSolver](EhSolverCancelCheck pos) {
|
|
||||||
std::lock_guard<std::mutex> lock{m_cs};
|
|
||||||
return cancelSolver;
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: factor this out into a function with the same API for each solver.
|
// TODO: factor this out into a function with the same API for each solver.
|
||||||
if (solver == "tromp" ) { //&& notaryid >= 0 ) {
|
if (solver == "tromp" ) { //&& notaryid >= 0 ) {
|
||||||
// Create solver and initialize it.
|
// Create solver and initialize it.
|
||||||
equi eq(1);
|
equi eq(1);
|
||||||
eq.setstate(&curr_state);
|
eq.setstate(&curr_state);
|
||||||
|
|
||||||
// Initialization done, start algo driver.
|
// Initialization done, start algo driver.
|
||||||
eq.digit0(0);
|
eq.digit0(0);
|
||||||
eq.xfull = eq.bfull = eq.hfull = 0;
|
|
||||||
eq.showbsizes(0);
|
|
||||||
for (u32 r = 1; r < WK; r++) {
|
|
||||||
(r&1) ? eq.digitodd(r, 0) : eq.digiteven(r, 0);
|
|
||||||
eq.xfull = eq.bfull = eq.hfull = 0;
|
eq.xfull = eq.bfull = eq.hfull = 0;
|
||||||
eq.showbsizes(r);
|
eq.showbsizes(0);
|
||||||
}
|
for (u32 r = 1; r < WK; r++) {
|
||||||
eq.digitK(0);
|
(r&1) ? eq.digitodd(r, 0) : eq.digiteven(r, 0);
|
||||||
ehSolverRuns.increment();
|
eq.xfull = eq.bfull = eq.hfull = 0;
|
||||||
|
eq.showbsizes(r);
|
||||||
// Convert solution indices to byte array (decompress) and pass it to validBlock method.
|
|
||||||
for (size_t s = 0; s < eq.nsols; s++) {
|
|
||||||
LogPrint("pow", "Checking solution %d\n", s+1);
|
|
||||||
std::vector<eh_index> index_vector(PROOFSIZE);
|
|
||||||
for (size_t i = 0; i < PROOFSIZE; i++) {
|
|
||||||
index_vector[i] = eq.sols[s][i];
|
|
||||||
}
|
}
|
||||||
std::vector<unsigned char> sol_char = GetMinimalFromIndices(index_vector, DIGITBITS);
|
eq.digitK(0);
|
||||||
|
|
||||||
if (validBlock(sol_char)) {
|
|
||||||
// If we find a POW solution, do not try other solutions
|
|
||||||
// because they become invalid as we created a new block in blockchain.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
// If we find a valid block, we rebuild
|
|
||||||
bool found = EhOptimisedSolve(n, k, curr_state, validBlock, cancelled);
|
|
||||||
ehSolverRuns.increment();
|
ehSolverRuns.increment();
|
||||||
if (found) {
|
|
||||||
int32_t i; uint256 hash = pblock->GetHash();
|
// Convert solution indices to byte array (decompress) and pass it to validBlock method.
|
||||||
for (i=0; i<32; i++)
|
for (size_t s = 0; s < eq.nsols; s++) {
|
||||||
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
|
LogPrint("pow", "Checking solution %d\n", s+1);
|
||||||
fprintf(stderr," <- %s Block found %d\n",ASSETCHAINS_SYMBOL,Mining_height);
|
std::vector<eh_index> index_vector(PROOFSIZE);
|
||||||
FOUND_BLOCK = 1;
|
for (size_t i = 0; i < PROOFSIZE; i++) {
|
||||||
KOMODO_MAYBEMINED = Mining_height;
|
index_vector[i] = eq.sols[s][i];
|
||||||
|
}
|
||||||
|
std::vector<unsigned char> sol_char = GetMinimalFromIndices(index_vector, DIGITBITS);
|
||||||
|
|
||||||
|
if (validBlock(sol_char)) {
|
||||||
|
// If we find a POW solution, do not try other solutions
|
||||||
|
// because they become invalid as we created a new block in blockchain.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
// If we find a valid block, we rebuild
|
||||||
|
bool found = EhOptimisedSolve(n, k, curr_state, validBlock, cancelled);
|
||||||
|
ehSolverRuns.increment();
|
||||||
|
if (found) {
|
||||||
|
int32_t i; uint256 hash = pblock->GetHash();
|
||||||
|
for (i=0; i<32; i++)
|
||||||
|
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
|
||||||
|
fprintf(stderr," <- %s Block found %d\n",ASSETCHAINS_SYMBOL,Mining_height);
|
||||||
|
FOUND_BLOCK = 1;
|
||||||
|
KOMODO_MAYBEMINED = Mining_height;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (EhSolverCancelledException&) {
|
||||||
|
LogPrint("pow", "Equihash solver cancelled\n");
|
||||||
|
std::lock_guard<std::mutex> lock{m_cs};
|
||||||
|
cancelSolver = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for stop or if block needs to be rebuilt
|
||||||
|
boost::this_thread::interruption_point();
|
||||||
|
// Regtest mode doesn't require peers
|
||||||
|
if ( FOUND_BLOCK != 0 )
|
||||||
|
{
|
||||||
|
FOUND_BLOCK = 0;
|
||||||
|
fprintf(stderr,"FOUND_BLOCK!\n");
|
||||||
|
//sleep(2000);
|
||||||
|
}
|
||||||
|
if (vNodes.empty() && chainparams.MiningRequiresPeers())
|
||||||
|
{
|
||||||
|
if ( ASSETCHAINS_SYMBOL[0] == 0 || Mining_height > ASSETCHAINS_MINHEIGHT )
|
||||||
|
{
|
||||||
|
fprintf(stderr,"no nodes, break\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (EhSolverCancelledException&) {
|
|
||||||
LogPrint("pow", "Equihash solver cancelled\n");
|
|
||||||
std::lock_guard<std::mutex> lock{m_cs};
|
|
||||||
cancelSolver = false;
|
|
||||||
}
|
}
|
||||||
}
|
if ((UintToArith256(pblock->nNonce) & 0xffff) == 0xffff)
|
||||||
|
|
||||||
// Check for stop or if block needs to be rebuilt
|
|
||||||
boost::this_thread::interruption_point();
|
|
||||||
// Regtest mode doesn't require peers
|
|
||||||
if ( FOUND_BLOCK != 0 )
|
|
||||||
{
|
|
||||||
FOUND_BLOCK = 0;
|
|
||||||
fprintf(stderr,"FOUND_BLOCK!\n");
|
|
||||||
//sleep(2000);
|
|
||||||
}
|
|
||||||
if (vNodes.empty() && chainparams.MiningRequiresPeers())
|
|
||||||
{
|
|
||||||
if ( ASSETCHAINS_SYMBOL[0] == 0 || Mining_height > ASSETCHAINS_MINHEIGHT )
|
|
||||||
{
|
{
|
||||||
fprintf(stderr,"no nodes, break\n");
|
//if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
|
fprintf(stderr,"0xffff, break\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60)
|
||||||
if ((UintToArith256(pblock->nNonce) & 0xffff) == 0xffff)
|
{
|
||||||
{
|
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
//if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
fprintf(stderr,"timeout, break\n");
|
||||||
fprintf(stderr,"0xffff, break\n");
|
break;
|
||||||
break;
|
}
|
||||||
}
|
if ( pindexPrev != chainActive.Tip() )
|
||||||
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60)
|
{
|
||||||
{
|
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
fprintf(stderr,"Tip advanced, break\n");
|
||||||
fprintf(stderr,"timeout, break\n");
|
break;
|
||||||
break;
|
}
|
||||||
}
|
// Update nNonce and nTime
|
||||||
if ( pindexPrev != chainActive.Tip() )
|
pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1);
|
||||||
{
|
pblock->nBits = savebits;
|
||||||
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
if ( ASSETCHAINS_STAKED == 0 || NOTARY_PUBKEY33[0] == 0 )
|
||||||
fprintf(stderr,"Tip advanced, break\n");
|
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
|
||||||
break;
|
if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks)
|
||||||
}
|
{
|
||||||
// Update nNonce and nTime
|
// Changing pblock->nTime can change work required on testnet:
|
||||||
pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1);
|
HASHTarget.SetCompact(pblock->nBits);
|
||||||
pblock->nBits = savebits;
|
}
|
||||||
if ( ASSETCHAINS_STAKED == 0 || NOTARY_PUBKEY33[0] == 0 )
|
|
||||||
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
|
|
||||||
if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks)
|
|
||||||
{
|
|
||||||
// Changing pblock->nTime can change work required on testnet:
|
|
||||||
HASHTarget.SetCompact(pblock->nBits);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
catch (const boost::thread_interrupted&)
|
||||||
catch (const boost::thread_interrupted&)
|
{
|
||||||
{
|
miningTimer.stop();
|
||||||
|
c.disconnect();
|
||||||
|
LogPrintf("KomodoMiner terminated\n");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (const std::runtime_error &e)
|
||||||
|
{
|
||||||
|
miningTimer.stop();
|
||||||
|
c.disconnect();
|
||||||
|
LogPrintf("KomodoMiner runtime error: %s\n", e.what());
|
||||||
|
return;
|
||||||
|
}
|
||||||
miningTimer.stop();
|
miningTimer.stop();
|
||||||
c.disconnect();
|
c.disconnect();
|
||||||
LogPrintf("KomodoMiner terminated\n");
|
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
catch (const std::runtime_error &e)
|
|
||||||
{
|
|
||||||
miningTimer.stop();
|
|
||||||
c.disconnect();
|
|
||||||
LogPrintf("KomodoMiner runtime error: %s\n", e.what());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
miningTimer.stop();
|
|
||||||
c.disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)
|
void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)
|
||||||
#else
|
#else
|
||||||
void GenerateBitcoins(bool fGenerate, int nThreads)
|
void GenerateBitcoins(bool fGenerate, int nThreads)
|
||||||
#endif
|
#endif
|
||||||
{
|
|
||||||
static boost::thread_group* minerThreads = NULL;
|
|
||||||
|
|
||||||
if (nThreads < 0)
|
|
||||||
nThreads = GetNumCores();
|
|
||||||
|
|
||||||
if (minerThreads != NULL)
|
|
||||||
{
|
{
|
||||||
minerThreads->interrupt_all();
|
static boost::thread_group* minerThreads = NULL;
|
||||||
delete minerThreads;
|
|
||||||
minerThreads = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nThreads == 0 || !fGenerate)
|
if (nThreads < 0)
|
||||||
return;
|
nThreads = GetNumCores();
|
||||||
|
|
||||||
minerThreads = new boost::thread_group();
|
if (minerThreads != NULL)
|
||||||
for (int i = 0; i < nThreads; i++) {
|
{
|
||||||
|
minerThreads->interrupt_all();
|
||||||
|
delete minerThreads;
|
||||||
|
minerThreads = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nThreads == 0 || !fGenerate)
|
||||||
|
return;
|
||||||
|
|
||||||
|
minerThreads = new boost::thread_group();
|
||||||
|
for (int i = 0; i < nThreads; i++) {
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet));
|
minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet));
|
||||||
#else
|
#else
|
||||||
minerThreads->create_thread(&BitcoinMiner);
|
minerThreads->create_thread(&BitcoinMiner);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif // ENABLE_MINING
|
#endif // ENABLE_MINING
|
||||||
|
|||||||
46
src/pow.cpp
46
src/pow.cpp
@@ -117,7 +117,7 @@ bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams& param
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp);
|
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp);
|
||||||
int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],int32_t height,uint8_t pubkey33[33],uint32_t timestamp);
|
int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],uint32_t blocktimes[66],int32_t height,uint8_t pubkey33[33],uint32_t blocktime);
|
||||||
int32_t komodo_currentheight();
|
int32_t komodo_currentheight();
|
||||||
CBlockIndex *komodo_chainactive(int32_t height);
|
CBlockIndex *komodo_chainactive(int32_t height);
|
||||||
void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height);
|
void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height);
|
||||||
@@ -126,18 +126,19 @@ extern uint64_t ASSETCHAINS_STAKED;
|
|||||||
extern char ASSETCHAINS_SYMBOL[];
|
extern char ASSETCHAINS_SYMBOL[];
|
||||||
#define KOMODO_ELECTION_GAP 2000
|
#define KOMODO_ELECTION_GAP 2000
|
||||||
|
|
||||||
int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *nonzpkeysp,int32_t height);
|
int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,uint32_t blocktimes[66],int32_t *nonzpkeysp,int32_t height);
|
||||||
int32_t KOMODO_LOADINGBLOCKS = 1;
|
int32_t KOMODO_LOADINGBLOCKS = 1;
|
||||||
|
|
||||||
extern std::string NOTARY_PUBKEY;
|
extern std::string NOTARY_PUBKEY;
|
||||||
|
|
||||||
bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params& params)
|
bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int nBits,const Consensus::Params& params,uint32_t blocktime)
|
||||||
{
|
{
|
||||||
extern int32_t KOMODO_REWIND;
|
extern int32_t KOMODO_REWIND;
|
||||||
bool fNegative,fOverflow; uint8_t origpubkey33[33]; int32_t i,nonzpkeys=0,nonz=0,special=0,special2=0,notaryid=-1,flag = 0, mids[66]; uint32_t timestamp = 0; CBlockIndex *pindex=0;
|
bool fNegative,fOverflow; uint8_t origpubkey33[33]; int32_t i,nonzpkeys=0,nonz=0,special=0,special2=0,notaryid=-1,flag = 0, mids[66]; uint32_t tiptime,blocktimes[66];
|
||||||
arith_uint256 bnTarget; uint8_t pubkeys[66][33];
|
arith_uint256 bnTarget; uint8_t pubkeys[66][33];
|
||||||
memcpy(origpubkey33,pubkey33,33);
|
memcpy(origpubkey33,pubkey33,33);
|
||||||
timestamp = komodo_chainactive_timestamp();
|
memset(blocktimes,0,sizeof(blocktimes));
|
||||||
|
tiptime = komodo_chainactive_timestamp();
|
||||||
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
|
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
|
||||||
if ( height == 0 )
|
if ( height == 0 )
|
||||||
{
|
{
|
||||||
@@ -146,7 +147,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
|
|||||||
}
|
}
|
||||||
if ( height > 34000 && ASSETCHAINS_SYMBOL[0] == 0 ) // 0 -> non-special notary
|
if ( height > 34000 && ASSETCHAINS_SYMBOL[0] == 0 ) // 0 -> non-special notary
|
||||||
{
|
{
|
||||||
special = komodo_chosennotary(¬aryid,height,pubkey33,timestamp);
|
special = komodo_chosennotary(¬aryid,height,pubkey33,tiptime);
|
||||||
for (i=0; i<33; i++)
|
for (i=0; i<33; i++)
|
||||||
{
|
{
|
||||||
if ( pubkey33[i] != 0 )
|
if ( pubkey33[i] != 0 )
|
||||||
@@ -157,8 +158,8 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
|
|||||||
//fprintf(stderr,"ht.%d null pubkey checkproof return\n",height);
|
//fprintf(stderr,"ht.%d null pubkey checkproof return\n",height);
|
||||||
return(true); // will come back via different path with pubkey set
|
return(true); // will come back via different path with pubkey set
|
||||||
}
|
}
|
||||||
flag = komodo_eligiblenotary(pubkeys,mids,&nonzpkeys,height);
|
flag = komodo_eligiblenotary(pubkeys,mids,blocktimes,&nonzpkeys,height);
|
||||||
special2 = komodo_is_special(pubkeys,mids,height,pubkey33,timestamp);
|
special2 = komodo_is_special(pubkeys,mids,blocktimes,height,pubkey33,blocktime);
|
||||||
if ( notaryid >= 0 )
|
if ( notaryid >= 0 )
|
||||||
{
|
{
|
||||||
if ( height > 10000 && height < 80000 && (special != 0 || special2 > 0) )
|
if ( height > 10000 && height < 80000 && (special != 0 || special2 > 0) )
|
||||||
@@ -175,7 +176,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
|
|||||||
flag = 0;
|
flag = 0;
|
||||||
else fprintf(stderr,"ht.%d notaryid.%d special.%d flag.%d special2.%d\n",height,notaryid,special,flag,special2);
|
else fprintf(stderr,"ht.%d notaryid.%d special.%d flag.%d special2.%d\n",height,notaryid,special,flag,special2);
|
||||||
}
|
}
|
||||||
if ( flag != 0 || special2 > 0 )
|
if ( (flag != 0 || special2 > 0) && special2 != -2 )
|
||||||
{
|
{
|
||||||
//fprintf(stderr,"EASY MINING ht.%d\n",height);
|
//fprintf(stderr,"EASY MINING ht.%d\n",height);
|
||||||
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
||||||
@@ -190,11 +191,38 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
|
|||||||
if ( KOMODO_LOADINGBLOCKS != 0 )
|
if ( KOMODO_LOADINGBLOCKS != 0 )
|
||||||
return true;
|
return true;
|
||||||
if ( ASSETCHAINS_SYMBOL[0] != 0 || height > 792000 )
|
if ( ASSETCHAINS_SYMBOL[0] != 0 || height > 792000 )
|
||||||
|
{
|
||||||
|
if ( 0 && height > 792000 )
|
||||||
|
{
|
||||||
|
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 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");
|
||||||
|
for (i=0; i<33; i++)
|
||||||
|
printf("%02x",origpubkey33[i]);
|
||||||
|
printf(" <- origpubkey\n");
|
||||||
|
for (i=0; i<66; i++)
|
||||||
|
printf("%d ",mids[i]);
|
||||||
|
printf(" minerids from ht.%d\n",height);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
/*for (i=31; i>=0; i--)
|
||||||
|
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
|
||||||
|
fprintf(stderr," hash vs ");
|
||||||
|
for (i=31; i>=0; i--)
|
||||||
|
fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]);
|
||||||
|
fprintf(stderr," height.%d notaryid.%d PoW valid\n",height,notaryid);*/
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
arith_uint256 GetBlockProof(const CBlockIndex& block)
|
arith_uint256 GetBlockProof(const CBlockIndex& block)
|
||||||
{
|
{
|
||||||
arith_uint256 bnTarget;
|
arith_uint256 bnTarget;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg,
|
|||||||
bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams&);
|
bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams&);
|
||||||
|
|
||||||
/** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */
|
/** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */
|
||||||
bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params&);
|
bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params&,uint32_t blocktime);
|
||||||
arith_uint256 GetBlockProof(const CBlockIndex& block);
|
arith_uint256 GetBlockProof(const CBlockIndex& block);
|
||||||
|
|
||||||
/** Return the time it would take to redo the work difference between from and to, assuming the current hashrate corresponds to the difficulty at tip, in seconds. */
|
/** Return the time it would take to redo the work difference between from and to, assuming the current hashrate corresponds to the difficulty at tip, in seconds. */
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ UniValue generate(const UniValue& params, bool fHelp)
|
|||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
pblock->nSolution = soln;
|
pblock->nSolution = soln;
|
||||||
solutionTargetChecks.increment();
|
solutionTargetChecks.increment();
|
||||||
return CheckProofOfWork(chainActive.Height(),NOTARY_PUBKEY33,pblock->GetHash(), pblock->nBits, Params().GetConsensus());
|
return CheckProofOfWork(chainActive.Height(),NOTARY_PUBKEY33,pblock->GetHash(), pblock->nBits, Params().GetConsensus(),pblock->nTime);
|
||||||
};
|
};
|
||||||
bool found = EhBasicSolveUncancellable(n, k, curr_state, validBlock);
|
bool found = EhBasicSolveUncancellable(n, k, curr_state, validBlock);
|
||||||
ehSolverRuns.increment();
|
ehSolverRuns.increment();
|
||||||
|
|||||||
@@ -174,6 +174,7 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue&
|
|||||||
out.push_back(Pair("interest", ValueFromAmount(interest)));
|
out.push_back(Pair("interest", ValueFromAmount(interest)));
|
||||||
}
|
}
|
||||||
out.push_back(Pair("valueZat", txout.nValue));
|
out.push_back(Pair("valueZat", txout.nValue));
|
||||||
|
out.push_back(Pair("valueSat", txout.nValue)); // [+] Decker
|
||||||
out.push_back(Pair("n", (int64_t)i));
|
out.push_back(Pair("n", (int64_t)i));
|
||||||
UniValue o(UniValue::VOBJ);
|
UniValue o(UniValue::VOBJ);
|
||||||
ScriptPubKeyToJSON(txout.scriptPubKey, o, true);
|
ScriptPubKeyToJSON(txout.scriptPubKey, o, true);
|
||||||
|
|||||||
@@ -530,7 +530,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
|
|||||||
diskindex.ToString(), pindexNew->ToString());
|
diskindex.ToString(), pindexNew->ToString());
|
||||||
uint8_t pubkey33[33];
|
uint8_t pubkey33[33];
|
||||||
komodo_index2pubkey33(pubkey33,pindexNew,pindexNew->nHeight);
|
komodo_index2pubkey33(pubkey33,pindexNew,pindexNew->nHeight);
|
||||||
if (!CheckProofOfWork(pindexNew->nHeight,pubkey33,pindexNew->GetBlockHash(), pindexNew->nBits, Params().GetConsensus()))
|
if (!CheckProofOfWork(pindexNew->nHeight,pubkey33,pindexNew->GetBlockHash(), pindexNew->nBits, Params().GetConsensus(),pindexNew->nHeight))
|
||||||
return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString());
|
return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString());
|
||||||
pcursor->Next();
|
pcursor->Next();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user