This commit is contained in:
jl777
2016-10-21 08:57:30 -03:00
parent b0ae7941be
commit dae9e3bbf1
2 changed files with 14 additions and 8 deletions

View File

@@ -270,11 +270,11 @@ void komodo_notarysinit(int32_t height,uint8_t pubkeys[64][33],int32_t num)
pthread_mutex_unlock(&komodo_mutex);
}
int32_t komodo_heightnotary(int32_t height,uint8_t *pubkey33)
int32_t komodo_heightnotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33)
{
// -1 if not notary, 0 if notary, 1 if special notary
struct knotary_entry *kp; int32_t numnotaries,notaryid = -1,modval = -1;
struct knotary_entry *kp; int32_t numnotaries,modval = -1;
*notaryidp = -1;
pthread_mutex_lock(&komodo_mutex);
HASH_FIND(hh,Pubkeys[height/KOMODO_ELECTION_GAP].Notaries,pubkey33,33,kp);
pthread_mutex_unlock(&komodo_mutex);
@@ -282,7 +282,7 @@ int32_t komodo_heightnotary(int32_t height,uint8_t *pubkey33)
{
if ( (numnotaries= Pubkeys[height/KOMODO_ELECTION_GAP].numnotaries) > 0 )
{
notaryid = kp->notaryid;
*notaryidp = kp->notaryid;
modval = ((height % numnotaries) == kp->notaryid);
//printf("found notary.%d ht.%d modval.%d\n",kp->notaryid,height,modval);
} else printf("unexpected zero notaries at height.%d\n",height);

View File

@@ -104,18 +104,17 @@ bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams& param
return true;
}
int32_t komodo_heightnotary(int32_t height,uint8_t *pubkey33);
int32_t komodo_heightnotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33);
bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params& params)
{
bool fNegative,fOverflow; int32_t special;
bool fNegative,fOverflow; int32_t i,nonz=0,special,notaryid,flag = 0;
arith_uint256 bnTarget;
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
if ( height > 34000 ) // 0 -> non-special notary
{
int32_t i,nonz = 0;
special = komodo_heightnotary(height,pubkey33);
special = komodo_heightnotary(&notaryid,height,pubkey33);
for (i=0; i<33; i++)
{
if ( pubkey33[i] != 0 )
@@ -130,6 +129,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
if (UintToArith256(hash) <= bnTarget) // accept normal diff
return true;
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
flag = 1;
} //else bnTarget /= 8;
}
// Check range
@@ -140,6 +140,12 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
{
return error("CheckProofOfWork(): hash doesn't match nBits");
}
if ( flag != 0 )
{
for (i=0; i<33; i++)
fprintf(stderr,"%02x",pubkey33[i]);
fprintf(stderr," <- Round Robin ht.%d for notary.%d special.%d\n",height,notaryid,special);
}
return true;
}