This commit is contained in:
jl777
2018-04-16 20:16:28 +03:00
parent e284540042
commit a30dd993bf
8 changed files with 23 additions and 24 deletions

View File

@@ -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,7 +850,7 @@ 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 tiptime,uint32_t blocktime) 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 tiptime,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(&notaryid,height,pubkey33,tiptime); komodo_chosennotary(&notaryid,height,pubkey33,tiptime);
@@ -869,9 +870,9 @@ int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],int32_t heigh
else break; else break;
} }
} }
if ( blocktime < tiptime+60 ) if ( blocktime < blocktimes[1]+60 )
{ {
fprintf(stderr,"ht.%d n.%d l.%d\n",height,notaryid,blocktime-tiptime); fprintf(stderr,"ht.%d n.%d blocktimes[%u vs %u %u]\n",height,notaryid,blocktime,blocktimes[0],blocktimes[1]);
} else return(1); } else return(1);
} else return(0); } else return(0);
} }

View File

@@ -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] =
{ {

View File

@@ -1655,7 +1655,7 @@ bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos, const CMessageHeader::M
return true; return true;
} }
bool ReadBlockFromDisk(CBlockIndex *pprev,int32_t height,CBlock& block, const CDiskBlockPos& pos) bool ReadBlockFromDisk(int32_t height,CBlock& block, const CDiskBlockPos& pos)
{ {
uint8_t pubkey33[33]; uint8_t pubkey33[33];
block.SetNull(); block.SetNull();
@@ -1678,7 +1678,7 @@ bool ReadBlockFromDisk(CBlockIndex *pprev,int32_t height,CBlock& block, const CD
} }
// 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(),block.nTime,pprev!=0?pprev->nTime:0))) 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]);
@@ -1693,7 +1693,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex)
{ {
if ( pindex == 0 ) if ( pindex == 0 )
return false; return false;
if (!ReadBlockFromDisk(pindex->pprev,pindex->nHeight,block, pindex->GetBlockPos())) if (!ReadBlockFromDisk(pindex->nHeight,block, pindex->GetBlockPos()))
return false; return false;
if (block.GetHash() != pindex->GetBlockHash()) if (block.GetHash() != pindex->GetBlockHash())
return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s", return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s",
@@ -3808,7 +3808,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat
if ( fCheckPOW && !CheckEquihashSolution(&block, Params()) ) if ( fCheckPOW && !CheckEquihashSolution(&block, Params()) )
return state.DoS(100, error("CheckBlock(): Equihash solution invalid"),REJECT_INVALID, "invalid-solution"); return state.DoS(100, error("CheckBlock(): 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(),block.nTime,pindex->pprev!=0?pindex->pprev->nTime:0) ) if ( fCheckPOW && !CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus(),block.nTime) )
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");
// Check the merkle root. // Check the merkle root.
if (fCheckMerkleRoot) { if (fCheckMerkleRoot) {

View File

@@ -657,7 +657,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;
@@ -802,7 +802,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;
@@ -811,7 +811,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++)

View File

@@ -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 tiptime,uint32_t blocktime); 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 tiptime,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,21 +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,uint32_t blocktime,uint32_t tiptime) 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 tiptime = 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] = 0;
arith_uint256 bnTarget; uint8_t pubkeys[66][33]; arith_uint256 bnTarget; uint8_t pubkeys[66][33];
memcpy(origpubkey33,pubkey33,33); memcpy(origpubkey33,pubkey33,33);
//tiptime = komodo_chainactive_timestamp(); tiptime = komodo_chainactive_timestamp();
bnTarget.SetCompact(nBits, &fNegative, &fOverflow); bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
if ( blocktime == 0 || tiptime == 0 )
fprintf(stderr,"nul blocktime.%u or tiptime.%u\n",blocktime,tiptime);
if ( height == 0 ) if ( height == 0 )
{ {
height = komodo_currentheight() + 1; height = komodo_currentheight() + 1;
@@ -159,8 +157,8 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int
//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,tiptime,blocktime); special2 = komodo_is_special(pubkeys,mids,blocktimes,height,pubkey33,tiptime,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) )

View File

@@ -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&,uint32_t blocktime,uint32_t tiptime); 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. */

View File

@@ -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(),pblock->nTime,chainActive.Tip()->nTime); 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();

View File

@@ -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(),pindexNew->nTime,pindexNew->pprev!=0?pindexNew->pprev->nTime:0)) if (!CheckProofOfWork(pindexNew->nHeight,pubkey33,pindexNew->GetBlockHash(), pindexNew->nBits, Params().GetConsensus(),pindexNew->nTime))
return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString()); return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString());
pcursor->Next(); pcursor->Next();
} else { } else {