This commit is contained in:
jl777
2017-02-02 17:04:44 +02:00
parent d2be409528
commit 29e60e481f
2 changed files with 36 additions and 18 deletions

View File

@@ -520,6 +520,7 @@ static bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& rese
} }
int32_t komodo_baseid(char *origbase); int32_t komodo_baseid(char *origbase);
int32_t komodo_eligiblenotary(int32_t *mids,int32_t *nonzpkeysp,int32_t height);
void static BitcoinMiner(CWallet *pwallet) void static BitcoinMiner(CWallet *pwallet)
{ {
@@ -614,15 +615,25 @@ void static BitcoinMiner(CWallet *pwallet)
// //
// Search // Search
// //
uint32_t savebits; int64_t nStart = GetTime(); int mids[66],nonzpkeys,j; uint32_t savebits; int64_t nStart = GetTime();
savebits = pblock->nBits; savebits = pblock->nBits;
arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits); arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits);
if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_is_special(pindexPrev->nHeight+1,NOTARY_PUBKEY33) > 0 ) if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_is_special(pindexPrev->nHeight+1,NOTARY_PUBKEY33) > 0 )
{ {
if ( (Mining_height % KOMODO_ELECTION_GAP) > 64 || (Mining_height % KOMODO_ELECTION_GAP) == 0 ) if ( (Mining_height % KOMODO_ELECTION_GAP) > 64 || (Mining_height % KOMODO_ELECTION_GAP) == 0 )
{ {
hashTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS); komodo_eligiblenotary(mids,&nonzpkeys,pindexPrev->nHeight);
fprintf(stderr,"I am the chosen one for %s ht.%d\n",ASSETCHAINS_SYMBOL,pindexPrev->nHeight+1); if ( nonzpkeys > 0 )
{
for (j=0; j<65; j++)
if ( mids[j] == notaryid )
break;
if ( j == 65 )
{
hashTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS);
fprintf(stderr,"I am the chosen one for %s ht.%d\n",ASSETCHAINS_SYMBOL,pindexPrev->nHeight+1);
}
}
} else Mining_start = 0; } else Mining_start = 0;
} else Mining_start = 0; } else Mining_start = 0;
while (true) while (true)

View File

@@ -113,6 +113,26 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height)
extern int32_t KOMODO_CHOSEN_ONE; extern int32_t KOMODO_CHOSEN_ONE;
#define KOMODO_ELECTION_GAP 2000 #define KOMODO_ELECTION_GAP 2000
int32_t komodo_eligiblenotary(int32_t *mids,int32_t *nonzpkeysp,int32_t height)
{
int32_t i,duplicate; CBlockIndex *pindex; uint8_t pubkey33[33];
memset(mids,-1,sizeof(*mids)*66);
for (i=duplicate=0; i<66; i++)
{
if ( (pindex= komodo_chainactive(height-i)) != 0 )
{
komodo_index2pubkey33(pubkey33,pindex,height-i);
if ( (mids[i]= komodo_minerid(height-i,pubkey33)) >= 0 )
(*nonzpkeysp)++;
if ( mids[0] >= 0 && i > 0 && mids[i] == mids[0] )
duplicate++;
}
}
if ( i == 66 && duplicate == 0 && nonzpkeys > 0 )
return(1);
else return(0);
}
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)
{ {
extern int32_t KOMODO_REWIND; extern int32_t KOMODO_REWIND;
@@ -126,20 +146,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
//for (i=0; i<33; i++) //for (i=0; i<33; i++)
// printf("%02x",pubkey33[i]); // printf("%02x",pubkey33[i]);
//printf(" <- ht.%d\n",height); //printf(" <- ht.%d\n",height);
memset(mids,-1,sizeof(mids)); flag = komodo_eligiblenotary(mids,&nonzpkeys,height);
for (i=duplicate=0; i<66; i++)
{
if ( (pindex= komodo_chainactive(height-i)) != 0 )
{
komodo_index2pubkey33(pubkey33,pindex,height-i);
if ( (mids[i]= komodo_minerid(height-i,pubkey33)) >= 0 )
nonzpkeys++;
if ( mids[0] >= 0 && i > 0 && mids[i] == mids[0] )
duplicate++;
}
}
if ( i == 66 && duplicate == 0 && nonzpkeys > 0 )
flag = 1;
if ( height > 34000 ) // 0 -> non-special notary if ( height > 34000 ) // 0 -> non-special notary
{ {
for (i=0; i<33; i++) for (i=0; i<33; i++)
@@ -193,7 +200,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
return error("CheckProofOfWork(): hash doesn't match nBits"); return error("CheckProofOfWork(): hash doesn't match nBits");
} }
} }
if ( height > 180000 ) if ( height > 180000 && nonzpkeys > 0 )
{ {
for (i=0; i<66; i++) for (i=0; i<66; i++)
fprintf(stderr,"%d ",mids[i]); fprintf(stderr,"%d ",mids[i]);