Merge pull request #3 from jl777/dev

dev merge
This commit is contained in:
ca333
2017-02-19 09:31:08 +01:00
committed by GitHub
7 changed files with 69 additions and 61 deletions

View File

@@ -537,7 +537,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
} else printf("cant get scriptPubKey for ht.%d txi.%d vin.%d\n",height,i,j);
}
numvalid = bitweight(signedmask);
if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || numvalid > (numnotaries/4)) )
if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || numvalid > (numnotaries/5)) )
{
printf("%s ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d <<<<<<<<<<< notarized\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts);
notarized = 1;
@@ -545,7 +545,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
for (j=0; j<numvouts; j++)
{
len = block.vtx[i].vout[j].scriptPubKey.size();
if ( len <= sizeof(scriptbuf) )
if ( len >= sizeof(uint32_t) && len <= sizeof(scriptbuf) )
{
#ifdef KOMODO_ZCASH
memcpy(scriptbuf,block.vtx[i].vout[j].scriptPubKey.data(),len);
@@ -576,7 +576,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
for (j=1; j<numvouts-1; j++)
{
len = block.vtx[i].vout[j].scriptPubKey.size();
if ( len <= sizeof(scriptbuf) )
if ( len >= sizeof(uint32_t) && len <= sizeof(scriptbuf) )
{
#ifdef KOMODO_ZCASH
memcpy(scriptbuf,block.vtx[i].vout[j].scriptPubKey.data(),len);

View File

@@ -507,61 +507,74 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block)
} else printf("komodo_disconnect: ht.%d cant get komodo_state.(%s)\n",pindex->nHeight,ASSETCHAINS_SYMBOL);
}
int32_t komodo_is_notarytx(const CTransaction& tx)
{
uint8_t *ptr,crypto777[33];
#ifdef KOMODO_ZCASH
ptr = (uint8_t *)tx.vout[0].scriptPubKey.data();
#else
ptr = (uint8_t *)&tx.vout[0].scriptPubKey[0];
#endif
decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR);
if ( memcmp(ptr+1,crypto777,33) == 0 )
if ( tx.vout.size() > 0 )
{
//printf("found notarytx\n");
return(1);
#ifdef KOMODO_ZCASH
ptr = (uint8_t *)tx.vout[0].scriptPubKey.data();
#else
ptr = (uint8_t *)&tx.vout[0].scriptPubKey[0];
#endif
if ( ptr != 0 )
{
decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR);
if ( memcmp(ptr+1,crypto777,33) == 0 )
{
//printf("found notarytx\n");
return(1);
}
}
}
else return(0);
return(0);
}
int32_t komodo_block2height(CBlock *block)
{
int32_t i,n,height = 0; uint8_t *ptr;
#ifdef KOMODO_ZCASH
ptr = (uint8_t *)block->vtx[0].vin[0].scriptSig.data();
#else
ptr = (uint8_t *)&block->vtx[0].vin[0].scriptSig[0];
#endif
if ( block->vtx[0].vin[0].scriptSig.size() > 5 )
if ( block->vtx[0].vin.size() > 0 )
{
//for (i=0; i<6; i++)
// printf("%02x",ptr[i]);
n = ptr[0];
for (i=0; i<n; i++)
#ifdef KOMODO_ZCASH
ptr = (uint8_t *)block->vtx[0].vin[0].scriptSig.data();
#else
ptr = (uint8_t *)&block->vtx[0].vin[0].scriptSig[0];
#endif
if ( ptr != 0 && block->vtx[0].vin[0].scriptSig.size() > 5 )
{
//03bb81000101(bb 187) (81 48001) (00 12288256) <- coinbase.6 ht.12288256
height += ((uint32_t)ptr[i+1] << (i*8));
//printf("(%02x %x %d) ",ptr[i+1],((uint32_t)ptr[i+1] << (i*8)),height);
//for (i=0; i<6; i++)
// printf("%02x",ptr[i]);
n = ptr[0];
for (i=0; i<n; i++)
{
//03bb81000101(bb 187) (81 48001) (00 12288256) <- coinbase.6 ht.12288256
height += ((uint32_t)ptr[i+1] << (i*8));
//printf("(%02x %x %d) ",ptr[i+1],((uint32_t)ptr[i+1] << (i*8)),height);
}
//printf(" <- coinbase.%d ht.%d\n",(int32_t)block->vtx[0].vin[0].scriptSig.size(),height);
}
//printf(" <- coinbase.%d ht.%d\n",(int32_t)block->vtx[0].vin[0].scriptSig.size(),height);
//komodo_init(height);
}
//komodo_init(height);
return(height);
}
void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block)
{
int32_t n;
memset(pubkey33,0,33);
if ( block.vtx[0].vout.size() > 0 )
{
#ifdef KOMODO_ZCASH
uint8_t *ptr = (uint8_t *)block.vtx[0].vout[0].scriptPubKey.data();
uint8_t *ptr = (uint8_t *)block.vtx[0].vout[0].scriptPubKey.data();
#else
uint8_t *ptr = (uint8_t *)&block.vtx[0].vout[0].scriptPubKey[0];
uint8_t *ptr = (uint8_t *)&block.vtx[0].vout[0].scriptPubKey[0];
#endif
//komodo_init(0);
n = block.vtx[0].vout[0].scriptPubKey.size();
if ( n == 35 )
memcpy(pubkey33,ptr+1,33);
else memset(pubkey33,0,33);
//komodo_init(0);
n = block.vtx[0].vout[0].scriptPubKey.size();
if ( n == 35 )
memcpy(pubkey33,ptr+1,33);
}
}
int32_t komodo_blockload(CBlock& block,CBlockIndex *pindex)
@@ -672,7 +685,9 @@ int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width)
int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33])
{
int32_t i,notaryid,minerid,limit; uint8_t _pubkey33[33];
int32_t i,notaryid=0,minerid,limit,nid; uint8_t _pubkey33[33];
if ( height >= 225000 )
komodo_chosennotary(&notaryid,height,_pubkey33);
if ( height >= 34000 && notaryid >= 0 )
{
if ( height < 79693 )
@@ -682,11 +697,13 @@ int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33])
else limit = 66;
for (i=1; i<limit; i++)
{
komodo_chosennotary(&notaryid,height-i,_pubkey33);
if ( komodo_minerid(height-i,_pubkey33) == notaryid )
komodo_chosennotary(&nid,height-i,_pubkey33);
if ( nid == notaryid ) //komodo_minerid(height-i,_pubkey33)
{
//fprintf(stderr,"ht.%d notaryid.%d already mined -i.%d\n",height,notaryid,i);
return(-1);
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);

View File

@@ -528,7 +528,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin
int32_t i,nonz=0; int64_t diff; uint64_t price,seed,sum = 0;
if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip() != 0 && height > chainActive.Tip()->nHeight )
{
if ( height != 1381319936 )
if ( height < 1381319936 )
printf("height.%d vs tip.%d\n",height,chainActive.Tip()->nHeight);
return(0);
}

View File

@@ -1435,7 +1435,13 @@ bool ReadBlockFromDisk(int32_t height,CBlock& block, const CDiskBlockPos& pos)
// Check the header
komodo_block2pubkey33(pubkey33,block);
if (!(CheckEquihashSolution(&block, Params()) && CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus())))
{
int32_t i; for (i=0; i<33; i++)
printf("%02x",pubkey33[i]);
fprintf(stderr," warning unexpected diff at ht.%d\n",height);
return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString());
}
return true;
}

View File

@@ -128,9 +128,6 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
if ( height == 0 )
height = komodo_currentheight() + 1;
special = komodo_chosennotary(&notaryid,height,pubkey33);
//for (i=0; i<33; i++)
// printf("%02x",pubkey33[i]);
//printf(" <- ht.%d\n",height);
flag = komodo_eligiblenotary(pubkeys,mids,&nonzpkeys,height);
if ( height > 34000 ) // 0 -> non-special notary
{
@@ -142,14 +139,6 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
if ( nonz == 0 )
return(true); // will come back via different path with pubkey set
special2 = komodo_is_special(height,pubkey33);
/*if ( notaryid >= 0 && ((height >= 64000 && height <= 90065) || (height % KOMODO_ELECTION_GAP) > 64) )
{
if ( (height >= 64000 && height <= 90065) || (height % KOMODO_ELECTION_GAP) == 0 || (height < 80000 && (special != 0 || special2 > 0)) || (height >= 80000 && special2 > 0) )
{
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
flag = 1;
}
}*/
if ( notaryid >= 0 )
{
if ( height > 10000 && height < 80000 && (special != 0 || special2 > 0) )
@@ -167,7 +156,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
// Check proof of work matches claimed amount
if ( UintToArith256(hash) > bnTarget )
{
if ( KOMODO_LOADINGBLOCKS == 0 && height > 182507 && KOMODO_REWIND == 0 )//&& komodo_chainactive(height) != 0 && nonzpkeys > 0
if ( KOMODO_LOADINGBLOCKS == 0 && height > 188000 && KOMODO_REWIND == 0 )//186269, 182507&& komodo_chainactive(height) != 0 && nonzpkeys > 0
{
int32_t i;
for (i=31; i>=0; i--)
@@ -182,15 +171,10 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
for (i=0; i<66; i++)
printf("%d ",mids[i]);
printf(" minerids from ht.%d\n",height);
return error("CheckProofOfWork(): hash doesn't match nBits");
if ( notaryid >= 0 )
return error("CheckProofOfWork(): hash doesn't match nBits");
}
}
if ( 0 && height > 180000 && nonzpkeys > 0 && strcmp((char *)NOTARY_PUBKEY.c_str(),"03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828") == 0 )
{
for (i=0; i<66; i++)
fprintf(stderr,"%d ",mids[i]);
fprintf(stderr," minerids from ht.%d\n",height);
}
return true;
}

View File

@@ -654,6 +654,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
// Correct this if GetBlockTemplate changes the order
// entry.push_back(Pair("foundersreward", (int64_t)tx.vout[1].nValue));
//}
entry.push_back(Pair("coinbasevalue", 3*COIN));
entry.push_back(Pair("required", true));
txCoinbase = entry;
} else

View File

@@ -126,7 +126,7 @@ Value getinfo(const Array& params, bool fHelp)
obj.push_back(Pair("errors", GetWarnings("statusbar")));
{
char pubkeystr[65]; int32_t notaryid;
notaryid = komodo_whoami(pubkeystr,longestchain);
notaryid = komodo_whoami(pubkeystr,(int32_t)chainActive.Tip()->nHeight);
obj.push_back(Pair("notaryid", notaryid));
obj.push_back(Pair("pubkey", pubkeystr));
if ( KOMODO_LASTMINED != 0 )