This commit is contained in:
jl777
2016-10-20 06:49:35 -03:00
parent f2dd868d93
commit 9997caa0a4
2 changed files with 37 additions and 17 deletions

View File

@@ -213,7 +213,7 @@ int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numno
{ {
if ( fread(&ht,1,sizeof(ht),fp) != sizeof(ht) ) if ( fread(&ht,1,sizeof(ht),fp) != sizeof(ht) )
errs++; errs++;
printf("func.(%d %c) ht.%d\n",func,func,height); //printf("func.(%d %c) ht.%d\n",func,func,height);
if ( func == 'P' ) if ( func == 'P' )
{ {
if ( (num= fgetc(fp)) < 64 ) if ( (num= fgetc(fp)) < 64 )
@@ -223,7 +223,7 @@ int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numno
else printf("updated %d pubkeys\n",num); else printf("updated %d pubkeys\n",num);
} }
else printf("illegal num.%d\n",num); else printf("illegal num.%d\n",num);
printf("P[%d]\n",num); //printf("P[%d]\n",num);
} }
else if ( func == 'N' ) else if ( func == 'N' )
{ {
@@ -240,7 +240,7 @@ int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numno
uint8_t n,nid; uint256 hash; uint64_t mask; uint8_t n,nid; uint256 hash; uint64_t mask;
n = fgetc(fp); n = fgetc(fp);
nid = fgetc(fp); nid = fgetc(fp);
printf("U %d %d\n",n,nid); //printf("U %d %d\n",n,nid);
if ( fread(&mask,1,sizeof(mask),fp) != sizeof(mask) ) if ( fread(&mask,1,sizeof(mask),fp) != sizeof(mask) )
errs++; errs++;
if ( fread(&hash,1,sizeof(hash),fp) != sizeof(hash) ) if ( fread(&hash,1,sizeof(hash),fp) != sizeof(hash) )
@@ -249,7 +249,7 @@ int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numno
} }
else if ( func == 'D' ) else if ( func == 'D' )
{ {
printf("D[%d]\n",ht); //printf("D[%d]\n",ht);
} }
else printf("illegal func.(%d %c)\n",func,func); else printf("illegal func.(%d %c)\n",func,func);
} }
@@ -260,14 +260,15 @@ int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numno
{ {
if ( height < 0 ) if ( height < 0 )
{ {
printf("func D[%d] errs.%d\n",height,errs); height = -height;
//printf("func D[%d] errs.%d\n",height,errs);
fputc('D',fp); fputc('D',fp);
if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
errs++; errs++;
} }
if ( notarypubs != 0 && numnotaries > 0 ) else if ( notarypubs != 0 && numnotaries > 0 )
{ {
printf("func P[%d] errs.%d\n",numnotaries,errs); //printf("func P[%d] errs.%d\n",numnotaries,errs);
fputc('P',fp); fputc('P',fp);
if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
errs++; errs++;
@@ -277,7 +278,7 @@ int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numno
} }
else if ( voutmask != 0 && numvouts > 0 ) else if ( voutmask != 0 && numvouts > 0 )
{ {
printf("func U %d %d errs.%d hashsize.%ld\n",numvouts,notaryid,errs,sizeof(txhash)); //printf("func U %d %d errs.%d hashsize.%ld\n",numvouts,notaryid,errs,sizeof(txhash));
fputc('U',fp); fputc('U',fp);
if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
errs++; errs++;
@@ -290,7 +291,7 @@ int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numno
} }
else else
{ {
printf("func N ht.%d errs.%d\n",NOTARIZED_HEIGHT,errs); //printf("func N ht.%d errs.%d\n",NOTARIZED_HEIGHT,errs);
fputc('N',fp); fputc('N',fp);
if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
errs++; errs++;
@@ -509,15 +510,16 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
void komodo_disconnect(CBlockIndex *pindex,CBlock& block) void komodo_disconnect(CBlockIndex *pindex,CBlock& block)
{ {
uint256 zero; //uint256 zero;
printf("disconnect ht.%d\n",pindex->nHeight); //printf("disconnect ht.%d\n",pindex->nHeight);
memset(&zero,0,sizeof(zero)); //memset(&zero,0,sizeof(zero));
komodo_stateupdate(-pindex->nHeight,0,0,0,zero,0,0); //komodo_stateupdate(-pindex->nHeight,0,0,0,zero,0,0);
} }
void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex) int32_t komodo_heightnotary(int32_t height,uint8_t *pubkey33)
{ {
return(0);
// -1 if not notary, 0 if notary, 1 if special notary
} }
void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block) void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block)
@@ -527,6 +529,13 @@ void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block)
memcpy(pubkey33,ptr+1,33); memcpy(pubkey33,ptr+1,33);
} }
void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex)
{
CBlock block;
if ( ReadBlockFromDisk(block,(const CBlockIndex *)pindex) != 0 )
komodo_block2pubkey33(pubkey33,block);
}
/*int32_t komodo_blockindexcheck(CBlockIndex *pindex,uint32_t *nBitsp) /*int32_t komodo_blockindexcheck(CBlockIndex *pindex,uint32_t *nBitsp)
{ {
// 1 -> valid notary block, change nBits to KOMODO_MINDIFF_NBITS // 1 -> valid notary block, change nBits to KOMODO_MINDIFF_NBITS

View File

@@ -106,13 +106,24 @@ bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams& param
return true; return true;
} }
int32_t komodo_heightnotary(int32_t height,uint8_t *pubkey33);
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)
{ {
bool fNegative; bool fNegative,fOverflow; int32_t special;
bool fOverflow;
arith_uint256 bnTarget; arith_uint256 bnTarget;
bnTarget.SetCompact(nBits, &fNegative, &fOverflow); bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
if ( (special= komodo_heightnotary(height,pubkey33)) != 0 )
{
int32_t i;
for (i=0; i<33; i++)
fprintf(stderr,"%02x",pubkey33[i]);
fprintf(stderr," height.%d special.%d\n",height,special);
if ( special < 0 )
bnTarget /= 8;
else bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
}
// Check range // Check range
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))