Patch 790833 bug

This commit is contained in:
jl777
2018-04-13 14:18:51 +03:00
parent 52e780cc10
commit c54cb7d57b
2 changed files with 63 additions and 54 deletions

View File

@@ -840,31 +840,51 @@ int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width) // depre
return(-1);
}
int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33],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 i,notaryid=0,minerid,limit,nid; //uint8_t _pubkey33[33];
if ( height >= 225000 )
komodo_chosennotary(&notaryid,height,pubkey33,timestamp);
if ( height >= 34000 && notaryid >= 0 )
{
if ( height < 79693 )
limit = 64;
else if ( height < 82000 )
limit = 8;
else limit = 66;
for (i=1; i<limit; i++)
if ( mids[0] >= 0 )
{
komodo_chosennotary(&nid,height-i,pubkey33,timestamp);
if ( nid == notaryid )
for (i=1; i<66; i++)
{
//if ( (0) && notaryid > 0 )
fprintf(stderr,"komodo_is_special: ht.%d notaryid.%d already mined -i.%d nid.%d\n",height,notaryid,i,nid);
if ( height > 225000 )
return(-1);
if ( mids[i] == mids[0] )
{
fprintf(stderr,"ht.%d repeat notaryid.%d in mids[%d]\n",height,mids[0],i);
if ( height > 790000 )
return(-1);
else break;
}
}
return(1);
} else return(0);
}
else
{
if ( height >= 225000 )
komodo_chosennotary(&notaryid,height,pubkey33,timestamp);
if ( height >= 34000 && notaryid >= 0 )
{
if ( height < 79693 )
limit = 64;
else if ( height < 82000 )
limit = 8;
else limit = 66;
for (i=1; i<limit; i++)
{
komodo_chosennotary(&nid,height-i,pubkey33,timestamp);
if ( nid == notaryid )
{
if ( (0) && notaryid > 0 )
fprintf(stderr,"ht.%d notaryid.%d already mined -i.%d nid.%d\n",height,notaryid,i,nid);
if ( height > 225000 )
return(-1);
}
}
//fprintf(stderr,"special notaryid.%d ht.%d limit.%d\n",notaryid,height,limit);
return(1);
}
fprintf(stderr,"special notaryid.%d ht.%d limit.%d\n",notaryid,height,limit);
return(1);
}
return(0);
}

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_is_special(int32_t height,uint8_t pubkey33[33],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_currentheight();
CBlockIndex *komodo_chainactive(int32_t height);
void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height);
@@ -125,7 +125,7 @@ extern int32_t KOMODO_CHOSEN_ONE;
extern uint64_t ASSETCHAINS_STAKED;
extern char ASSETCHAINS_SYMBOL[];
#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_LOADINGBLOCKS;
@@ -134,27 +134,31 @@ 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;
bool fNegative,fOverflow; int32_t i,nonzpkeys=0,nonz=0,special=0,special2=0,notaryid=-1,duplicate,flag = 0, mids[66]; uint32_t timestamp = 0;
arith_uint256 bnTarget; CBlockIndex *pindex; uint8_t pubkeys[66][33];
bool fNegative,fOverflow; int32_t i,nonzpkeys=0,nonz=0,special=0,special2=0,notaryid=-1,flag = 0, mids[66]; uint32_t timestamp = 0;
arith_uint256 bnTarget; uint8_t pubkeys[66][33];
timestamp = komodo_chainactive_timestamp();
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
if ( height == 0 )
height = komodo_currentheight() + 1;
special = komodo_chosennotary(&notaryid,height,pubkey33,timestamp);
flag = komodo_eligiblenotary(pubkeys,mids,&nonzpkeys,height);
/*if ( ASSETCHAINS_STAKED != 0 )
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
else*/
if ( height > 34000 && ASSETCHAINS_SYMBOL[0] == 0 ) // 0 -> non-special notary
{
height = komodo_currentheight() + 1;
//fprintf(stderr,"set height to %d\n",height);
}
if ( height > 34000 && ASSETCHAINS_SYMBOL[0] == 0 ) // 0 -> non-special notary
{
special = komodo_chosennotary(&notaryid,height,pubkey33,timestamp);
for (i=0; i<33; i++)
{
if ( pubkey33[i] != 0 )
nonz++;
}
if ( nonz == 0 )
{
//fprintf(stderr,"ht.%d null pubkey checkproof return\n",height);
return(true); // will come back via different path with pubkey set
special2 = komodo_is_special(height,pubkey33,timestamp);
}
flag = komodo_eligiblenotary(pubkeys,mids,&nonzpkeys,height);
special2 = komodo_is_special(pubkeys,mids,height,pubkey33,timestamp);
//fprintf(stderr,"ht.%d notaryid.%d special.%d flag.%d special2.%d\n",height,notaryid,special,flag,special2);
if ( notaryid >= 0 )
{
if ( height > 10000 && height < 80000 && (special != 0 || special2 > 0) )
@@ -163,37 +167,22 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
flag = 1;
else if ( height >= 108000 && special2 > 0 )
flag = ((height % KOMODO_ELECTION_GAP) > 64 || (height % KOMODO_ELECTION_GAP) == 0);
if ( flag != 0 )
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
else if ( height == 790833 )
flag = 1;
else if ( special2 < 0 && height > 800000 )
flag = 0;
}
if ( flag != 0 || special2 > 0 )
{
//fprintf(stderr,"EASY MINING ht.%d\n",height);
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
}
}
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))
return error("CheckProofOfWork(): nBits below minimum work");
// Check proof of work matches claimed amount
if ( UintToArith256(hash) > bnTarget )
{
if ( 0 && (height < 235300 || height >= 236000) && KOMODO_LOADINGBLOCKS == 0 && height > 188000 )
//&& )//186269, 182507&& komodo_chainactive(height) != 0 && nonzpkeys > 0
{
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<66; i++)
printf("%d ",mids[i]);
printf(" minerids from ht.%d\n",height);
if ( KOMODO_REWIND == 0 && (notaryid >= 0 || height > 225000) )
{
fprintf(stderr,"pow error height.%d loading.%d notaryid.%d\n",height,KOMODO_LOADINGBLOCKS,notaryid);
return error("CheckProofOfWork(): hash doesn't match nBits");
} else fprintf(stderr,"skip return error height.%d loading.%d\n",height,KOMODO_LOADINGBLOCKS);
} //else fprintf(stderr,"skip height.%d loading.%d\n",height,KOMODO_LOADINGBLOCKS);
}
return false;
return true;
}