@@ -514,7 +514,10 @@ void CleanupBlockRevFiles()
|
|||||||
remove(it->path());
|
remove(it->path());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
path komodostate = GetDataDir() / "komodostate";
|
||||||
|
remove(komodostate);
|
||||||
|
path minerids = GetDataDir() / "minerids";
|
||||||
|
remove(minerids);
|
||||||
// Remove all block files that aren't part of a contiguous set starting at
|
// Remove all block files that aren't part of a contiguous set starting at
|
||||||
// zero by walking the ordered map (keys are block file indices) by
|
// zero by walking the ordered map (keys are block file indices) by
|
||||||
// keeping a separate counter. Once we hit a gap (or if 0 doesn't exist)
|
// keeping a separate counter. Once we hit a gap (or if 0 doesn't exist)
|
||||||
|
|||||||
89
src/komodo.h
89
src/komodo.h
@@ -17,12 +17,12 @@
|
|||||||
#define H_KOMODO_H
|
#define H_KOMODO_H
|
||||||
|
|
||||||
// Todo:
|
// Todo:
|
||||||
|
// 0. optimize assetchains RT loop
|
||||||
// 1. error check fiat redeem amounts
|
// 1. error check fiat redeem amounts
|
||||||
// 2. net balance limiter
|
// 2. net balance limiter
|
||||||
// 3. new RR algo
|
// 3. verify: interest payment, ratification, reorgs
|
||||||
// 4. verify: interest payment, ratification, reorgs
|
// 4. automate notarization fee payouts
|
||||||
// 5. automate notarization fee payouts
|
// 5. automated distribution of test REVS snapshot
|
||||||
// 6. automated distribution of test REVS snapshot
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -33,6 +33,7 @@
|
|||||||
#define GENESIS_NBITS 0x1f00ffff
|
#define GENESIS_NBITS 0x1f00ffff
|
||||||
#define KOMODO_MINRATIFY 7
|
#define KOMODO_MINRATIFY 7
|
||||||
|
|
||||||
|
FILE *Minerfp;
|
||||||
int8_t Minerids[1024 * 1024 * 5]; // 5 million blocks
|
int8_t Minerids[1024 * 1024 * 5]; // 5 million blocks
|
||||||
|
|
||||||
#include "komodo_globals.h"
|
#include "komodo_globals.h"
|
||||||
@@ -48,14 +49,28 @@ int8_t Minerids[1024 * 1024 * 5]; // 5 million blocks
|
|||||||
|
|
||||||
void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout)
|
void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout)
|
||||||
{
|
{
|
||||||
static FILE *fp; static int32_t errs; char fname[512]; int32_t ht,func; uint8_t num,pubkeys[64][33];
|
static FILE *fp; static int32_t errs; char fname[512],fname2[512]; int32_t ht,func; uint8_t num,pubkeys[64][33];
|
||||||
#ifdef WIN32
|
|
||||||
sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"komodostate");
|
|
||||||
#else
|
|
||||||
sprintf(fname,"%s/%s",GetDataDir(false).string().c_str(),(char *)"komodostate");
|
|
||||||
#endif
|
|
||||||
if ( fp == 0 )
|
if ( fp == 0 )
|
||||||
{
|
{
|
||||||
|
#ifdef WIN32
|
||||||
|
sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"komodostate");
|
||||||
|
sprintf(fname2,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"minerids");
|
||||||
|
#else
|
||||||
|
sprintf(fname,"%s/%s",GetDataDir(false).string().c_str(),(char *)"komodostate");
|
||||||
|
sprintf(fname2,"%s/%s",GetDataDir(false).string().c_str(),(char *)"minerids");
|
||||||
|
#endif
|
||||||
|
memset(Minerids,0xfe,sizeof(Minerids));
|
||||||
|
if ( (Minerfp= fopen(fname2,"rb+")) == 0 )
|
||||||
|
{
|
||||||
|
if ( (Minerfp= fopen(fname2,"wb")) != 0 )
|
||||||
|
{
|
||||||
|
fwrite(Minerids,1,sizeof(Minerids),Minerfp);
|
||||||
|
fclose(Minerfp);
|
||||||
|
}
|
||||||
|
Minerfp = fopen(fname2,"rb+");
|
||||||
|
}
|
||||||
|
if ( Minerfp != 0 && fread(Minerids,1,sizeof(Minerids),Minerfp) != sizeof(Minerids) )
|
||||||
|
printf("read error Minerids\n");
|
||||||
if ( (fp= fopen(fname,"rb+")) != 0 )
|
if ( (fp= fopen(fname,"rb+")) != 0 )
|
||||||
{
|
{
|
||||||
while ( (func= fgetc(fp)) != EOF )
|
while ( (func= fgetc(fp)) != EOF )
|
||||||
@@ -259,9 +274,9 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value)
|
int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value)
|
||||||
{
|
{
|
||||||
static uint256 zero; int32_t opretlen,nid,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33];
|
static uint256 zero; int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33];
|
||||||
if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
|
if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
|
||||||
{
|
{
|
||||||
decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR);
|
decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR);
|
||||||
@@ -274,7 +289,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,
|
|||||||
if ( memcmp(crypto777,scriptbuf+1,33) == 0 )
|
if ( memcmp(crypto777,scriptbuf+1,33) == 0 )
|
||||||
{
|
{
|
||||||
*specialtxp = 1;
|
*specialtxp = 1;
|
||||||
printf(">>>>>>>> ");
|
//printf(">>>>>>>> ");
|
||||||
}
|
}
|
||||||
else if ( komodo_chosennotary(&nid,height,scriptbuf + 1) >= 0 )
|
else if ( komodo_chosennotary(&nid,height,scriptbuf + 1) >= 0 )
|
||||||
{
|
{
|
||||||
@@ -288,7 +303,9 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,
|
|||||||
}
|
}
|
||||||
else if ( notaryid != nid )
|
else if ( notaryid != nid )
|
||||||
{
|
{
|
||||||
printf("mismatch notaryid.%d k.%d\n",notaryid,nid);
|
//for (i=0; i<33; i++)
|
||||||
|
// printf("%02x",scriptbuf[i+1]);
|
||||||
|
//printf(" %s mismatch notaryid.%d k.%d\n",ASSETCHAINS_SYMBOL,notaryid,nid);
|
||||||
notaryid = 64;
|
notaryid = 64;
|
||||||
*voutmaskp = 0;
|
*voutmaskp = 0;
|
||||||
}
|
}
|
||||||
@@ -326,7 +343,20 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,
|
|||||||
//int32_t k; for (k=0; k<scriptlen; k++)
|
//int32_t k; for (k=0; k<scriptlen; k++)
|
||||||
// printf("%02x",scriptbuf[k]);
|
// printf("%02x",scriptbuf[k]);
|
||||||
//printf(" <- script ht.%d i.%d j.%d value %.8f\n",height,i,j,dstr(value));
|
//printf(" <- script ht.%d i.%d j.%d value %.8f\n",height,i,j,dstr(value));
|
||||||
komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,value,&scriptbuf[len],opretlen,j);
|
if ( opretlen >= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 )
|
||||||
|
{
|
||||||
|
iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid);
|
||||||
|
for (k=0; k<32; k++)
|
||||||
|
if ( scriptbuf[len+k] != 0 )
|
||||||
|
break;
|
||||||
|
if ( k == 32 )
|
||||||
|
{
|
||||||
|
*isratificationp = 1;
|
||||||
|
printf("ISRATIFICATION (%s)\n",(char *)&scriptbuf[len+32*2+4]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( *isratificationp == 0 )
|
||||||
|
komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,value,&scriptbuf[len],opretlen,j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(notaryid);
|
return(notaryid);
|
||||||
@@ -350,8 +380,9 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
|||||||
static int32_t hwmheight;
|
static int32_t hwmheight;
|
||||||
uint64_t signedmask,voutmask;
|
uint64_t signedmask,voutmask;
|
||||||
uint8_t scriptbuf[4096],pubkeys[64][33]; uint256 kmdtxid,btctxid,txhash;
|
uint8_t scriptbuf[4096],pubkeys[64][33]; uint256 kmdtxid,btctxid,txhash;
|
||||||
int32_t i,j,k,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count;
|
int32_t i,j,k,numnotaries,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count;
|
||||||
komodo_init(pindex->nHeight);
|
komodo_init(pindex->nHeight);
|
||||||
|
numnotaries = komodo_notaries(pubkeys,pindex->nHeight);
|
||||||
if ( pindex->nHeight > hwmheight )
|
if ( pindex->nHeight > hwmheight )
|
||||||
hwmheight = pindex->nHeight;
|
hwmheight = pindex->nHeight;
|
||||||
else
|
else
|
||||||
@@ -380,7 +411,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
|||||||
txhash = block.vtx[i].GetHash();
|
txhash = block.vtx[i].GetHash();
|
||||||
numvouts = block.vtx[i].vout.size();
|
numvouts = block.vtx[i].vout.size();
|
||||||
notaryid = -1;
|
notaryid = -1;
|
||||||
voutmask = specialtx = notarizedheight = 0;
|
voutmask = specialtx = notarizedheight = isratification = 0;
|
||||||
for (j=0; j<numvouts; j++)
|
for (j=0; j<numvouts; j++)
|
||||||
{
|
{
|
||||||
len = block.vtx[i].vout[j].scriptPubKey.size();
|
len = block.vtx[i].vout[j].scriptPubKey.size();
|
||||||
@@ -391,12 +422,21 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
|||||||
#else
|
#else
|
||||||
memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len);
|
memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len);
|
||||||
#endif
|
#endif
|
||||||
// signedmask is needed here!
|
notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue);
|
||||||
notaryid = komodo_voutupdate(notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue);
|
|
||||||
if ( i == 0 && j == 0 && komodo_chosennotary(&nid,height,scriptbuf + 1) >= 0 )
|
if ( i == 0 && j == 0 && komodo_chosennotary(&nid,height,scriptbuf + 1) >= 0 )
|
||||||
{
|
{
|
||||||
if ( height < sizeof(Minerids)/sizeof(*Minerids) )
|
if ( height < sizeof(Minerids)/sizeof(*Minerids) )
|
||||||
Minerids[height] = nid;
|
{
|
||||||
|
if ( (Minerids[height]= nid) >= -1 )
|
||||||
|
{
|
||||||
|
if ( Minerfp != 0 )
|
||||||
|
{
|
||||||
|
fseek(Minerfp,height,SEEK_SET);
|
||||||
|
fputc(Minerids[height],Minerfp);
|
||||||
|
fflush(Minerfp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ( 0 && i > 0 )
|
if ( 0 && i > 0 )
|
||||||
{
|
{
|
||||||
@@ -423,11 +463,12 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
|||||||
if ( signedmask != 0 && (notarizedheight != 0 || specialtx != 0) )
|
if ( signedmask != 0 && (notarizedheight != 0 || specialtx != 0) )
|
||||||
{
|
{
|
||||||
printf("NOTARY SIGNED.%llx numvins.%d ht.%d txi.%d notaryht.%d specialtx.%d\n",(long long)signedmask,numvins,height,i,notarizedheight,specialtx);
|
printf("NOTARY SIGNED.%llx numvins.%d ht.%d txi.%d notaryht.%d specialtx.%d\n",(long long)signedmask,numvins,height,i,notarizedheight,specialtx);
|
||||||
if ( specialtx != 0 && numvouts > 2 && komodo_ratify_threshold(height,signedmask) > 0 )
|
printf("ht.%d specialtx.%d isratification.%d numvouts.%d signed.%llx numnotaries.%d\n",height,specialtx,isratification,numvouts,(long long)signedmask,numnotaries);
|
||||||
|
if ( specialtx != 0 && isratification != 0 && numvouts > 2 )
|
||||||
{
|
{
|
||||||
numvalid = 0;
|
numvalid = 0;
|
||||||
memset(pubkeys,0,sizeof(pubkeys));
|
memset(pubkeys,0,sizeof(pubkeys));
|
||||||
for (j=1; j<numvouts; j++)
|
for (j=1; j<numvouts-1; j++)
|
||||||
{
|
{
|
||||||
len = block.vtx[i].vout[j].scriptPubKey.size();
|
len = block.vtx[i].vout[j].scriptPubKey.size();
|
||||||
if ( len <= sizeof(scriptbuf) )
|
if ( len <= sizeof(scriptbuf) )
|
||||||
@@ -446,12 +487,12 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( komodo_isratify(1,numvalid) >= KOMODO_MINRATIFY && numvouts > 13 )
|
if ( ((signedmask & 1) != 0 && numvalid >= KOMODO_MINRATIFY) || bitweight(signedmask) > (numnotaries>>1) )
|
||||||
{
|
{
|
||||||
memset(&txhash,0,sizeof(txhash));
|
memset(&txhash,0,sizeof(txhash));
|
||||||
komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0);
|
komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0);
|
||||||
|
printf("RATIFIED! >>>>>>>>>> new notaries.%d newheight.%d from height.%d\n",numvalid,(((height+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP,height);
|
||||||
}
|
}
|
||||||
printf("new notaries.%d newheight.%d from height.%d\n",numvouts-1,KOMODO_PUBKEYS_HEIGHT(height),height);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -388,6 +388,23 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block)
|
|||||||
//komodo_stateupdate(-pindex->nHeight,0,0,0,zero,0,0,0,0,0,0,0);
|
//komodo_stateupdate(-pindex->nHeight,0,0,0,zero,0,0,0,0,0,0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 )
|
||||||
|
{
|
||||||
|
//printf("found notarytx\n");
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
else return(0);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t komodo_block2height(CBlock *block)
|
int32_t komodo_block2height(CBlock *block)
|
||||||
{
|
{
|
||||||
int32_t i,n,height = 0; uint8_t *ptr;
|
int32_t i,n,height = 0; uint8_t *ptr;
|
||||||
@@ -453,11 +470,26 @@ int8_t komodo_minerid(int32_t height)
|
|||||||
int32_t notaryid; CBlockIndex *pindex; uint8_t pubkey33[33];
|
int32_t notaryid; CBlockIndex *pindex; uint8_t pubkey33[33];
|
||||||
if ( depth < 3 && height <= CURRENT_HEIGHT )//chainActive.Tip()->nHeight )
|
if ( depth < 3 && height <= CURRENT_HEIGHT )//chainActive.Tip()->nHeight )
|
||||||
{
|
{
|
||||||
|
if ( Minerids[height] >= -1 )
|
||||||
|
{
|
||||||
|
printf("cached[%d] -> %d\n",height,Minerids[height]);
|
||||||
|
return(Minerids[height]);
|
||||||
|
}
|
||||||
if ( (pindex= chainActive[height]) != 0 )
|
if ( (pindex= chainActive[height]) != 0 )
|
||||||
{
|
{
|
||||||
depth++;
|
depth++;
|
||||||
komodo_index2pubkey33(pubkey33,pindex,height);
|
komodo_index2pubkey33(pubkey33,pindex,height);
|
||||||
komodo_chosennotary(¬aryid,height,pubkey33);
|
komodo_chosennotary(¬aryid,height,pubkey33);
|
||||||
|
if ( notaryid >= -1 )
|
||||||
|
{
|
||||||
|
Minerids[height] = notaryid;
|
||||||
|
if ( Minerfp != 0 )
|
||||||
|
{
|
||||||
|
fseek(Minerfp,height,SEEK_SET);
|
||||||
|
fputc(Minerids[height],Minerfp);
|
||||||
|
fflush(Minerfp);
|
||||||
|
}
|
||||||
|
}
|
||||||
depth--;
|
depth--;
|
||||||
return(notaryid);
|
return(notaryid);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above
|
|||||||
for (j=0; j<32; j++)
|
for (j=0; j<32; j++)
|
||||||
printf("%02x",((uint8_t *)&hash)[j]);
|
printf("%02x",((uint8_t *)&hash)[j]);
|
||||||
printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i);
|
printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i);
|
||||||
// validate amount!
|
// validate amount! via fiat chain
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -288,7 +288,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above
|
|||||||
for (j=0; j<32; j++)
|
for (j=0; j<32; j++)
|
||||||
printf("%02x",((uint8_t *)&txids[i-1])[j]);
|
printf("%02x",((uint8_t *)&txids[i-1])[j]);
|
||||||
printf(" cant paxfind txid\n");
|
printf(" cant paxfind txid\n");
|
||||||
// validate amount!
|
// validate amount! via fiat chain
|
||||||
} else if ( opcode == 'I' )
|
} else if ( opcode == 'I' )
|
||||||
matched++;
|
matched++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33)
|
|||||||
|
|
||||||
int COINBASE_MATURITY = 100;
|
int COINBASE_MATURITY = 100;
|
||||||
|
|
||||||
int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,CURRENT_HEIGHT,ASSETCHAINS_SEED;
|
int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,CURRENT_HEIGHT,ASSETCHAINS_SEED,KOMODO_ON_DEMAND;
|
||||||
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES;
|
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES;
|
||||||
uint8_t NOTARY_PUBKEY33[33];
|
uint8_t NOTARY_PUBKEY33[33];
|
||||||
|
|
||||||
|
|||||||
@@ -52,8 +52,7 @@ const char *Notaries_genesis[][2] =
|
|||||||
{ "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" },
|
{ "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" },
|
||||||
};
|
};
|
||||||
|
|
||||||
#define KOMODO_ELECTION_GAP 2000
|
#define KOMODO_ELECTION_GAP ((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100)
|
||||||
#define KOMODO_PUBKEYS_HEIGHT(height) ((int32_t)(((((height)+KOMODO_ELECTION_GAP*.5)/KOMODO_ELECTION_GAP) + 1) * KOMODO_ELECTION_GAP))
|
|
||||||
|
|
||||||
struct nutxo_entry { UT_hash_handle hh; uint256 txhash; uint64_t voutmask; int32_t notaryid,height; } *NUTXOS;
|
struct nutxo_entry { UT_hash_handle hh; uint256 txhash; uint64_t voutmask; int32_t notaryid,height; } *NUTXOS;
|
||||||
struct knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; };
|
struct knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; };
|
||||||
@@ -94,8 +93,7 @@ int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask)
|
|||||||
int32_t htind,numnotaries,i,wt = 0;
|
int32_t htind,numnotaries,i,wt = 0;
|
||||||
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
return(2);
|
return(2);
|
||||||
if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 1 )
|
htind = height / KOMODO_ELECTION_GAP;
|
||||||
htind = 0;
|
|
||||||
numnotaries = Pubkeys[htind].numnotaries;
|
numnotaries = Pubkeys[htind].numnotaries;
|
||||||
for (i=0; i<numnotaries; i++)
|
for (i=0; i<numnotaries; i++)
|
||||||
if ( ((1LL << i) & signedmask) != 0 )
|
if ( ((1LL << i) & signedmask) != 0 )
|
||||||
@@ -108,8 +106,7 @@ int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask)
|
|||||||
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height)
|
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height)
|
||||||
{
|
{
|
||||||
int32_t i,htind,n; uint64_t mask = 0; struct knotary_entry *kp,*tmp;
|
int32_t i,htind,n; uint64_t mask = 0; struct knotary_entry *kp,*tmp;
|
||||||
if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 1 )
|
htind = height / KOMODO_ELECTION_GAP;
|
||||||
htind = 0;
|
|
||||||
pthread_mutex_lock(&komodo_mutex);
|
pthread_mutex_lock(&komodo_mutex);
|
||||||
n = Pubkeys[htind].numnotaries;
|
n = Pubkeys[htind].numnotaries;
|
||||||
HASH_ITER(hh,Pubkeys[htind].Notaries,kp,tmp)
|
HASH_ITER(hh,Pubkeys[htind].Notaries,kp,tmp)
|
||||||
@@ -129,8 +126,16 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height)
|
|||||||
|
|
||||||
void komodo_notarysinit(int32_t height,uint8_t pubkeys[64][33],int32_t num)
|
void komodo_notarysinit(int32_t height,uint8_t pubkeys[64][33],int32_t num)
|
||||||
{
|
{
|
||||||
int32_t k,i,htind; struct knotary_entry *kp; struct knotaries_entry N;
|
static int32_t hwmheight;
|
||||||
|
int32_t k,i,htind,nonz; struct knotary_entry *kp; struct knotaries_entry N;
|
||||||
memset(&N,0,sizeof(N));
|
memset(&N,0,sizeof(N));
|
||||||
|
if ( height > 0 )
|
||||||
|
{
|
||||||
|
height += KOMODO_ELECTION_GAP/2;
|
||||||
|
height /= KOMODO_ELECTION_GAP;
|
||||||
|
height = ((height + 1) * KOMODO_ELECTION_GAP);
|
||||||
|
htind = (height / KOMODO_ELECTION_GAP);
|
||||||
|
} else htind = 0;
|
||||||
pthread_mutex_lock(&komodo_mutex);
|
pthread_mutex_lock(&komodo_mutex);
|
||||||
for (k=0; k<num; k++)
|
for (k=0; k<num; k++)
|
||||||
{
|
{
|
||||||
@@ -138,22 +143,24 @@ void komodo_notarysinit(int32_t height,uint8_t pubkeys[64][33],int32_t num)
|
|||||||
memcpy(kp->pubkey,pubkeys[k],33);
|
memcpy(kp->pubkey,pubkeys[k],33);
|
||||||
kp->notaryid = k;
|
kp->notaryid = k;
|
||||||
HASH_ADD_KEYPTR(hh,N.Notaries,kp->pubkey,33,kp);
|
HASH_ADD_KEYPTR(hh,N.Notaries,kp->pubkey,33,kp);
|
||||||
//if ( height > 10000 )
|
if ( height > 0 )
|
||||||
{
|
{
|
||||||
for (i=0; i<33; i++)
|
for (i=0; i<33; i++)
|
||||||
printf("%02x",pubkeys[k][i]);
|
printf("%02x",pubkeys[k][i]);
|
||||||
printf(" notarypubs.[%d] ht.%d\n",k,height);
|
printf(" notarypubs.[%d] ht.%d active at %d\n",k,height,htind*KOMODO_ELECTION_GAP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
N.numnotaries = num;
|
N.numnotaries = num;
|
||||||
if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 1 )
|
|
||||||
htind = 0;
|
|
||||||
for (i=htind; i<sizeof(Pubkeys)/sizeof(*Pubkeys); i++)
|
for (i=htind; i<sizeof(Pubkeys)/sizeof(*Pubkeys); i++)
|
||||||
{
|
{
|
||||||
|
if ( Pubkeys[i].height != 0 && height < hwmheight )
|
||||||
|
break;
|
||||||
Pubkeys[i] = N;
|
Pubkeys[i] = N;
|
||||||
Pubkeys[i].height = i * KOMODO_ELECTION_GAP;
|
Pubkeys[i].height = i * KOMODO_ELECTION_GAP;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&komodo_mutex);
|
pthread_mutex_unlock(&komodo_mutex);
|
||||||
|
if ( height > hwmheight )
|
||||||
|
hwmheight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33)
|
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33)
|
||||||
@@ -163,8 +170,7 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33)
|
|||||||
*notaryidp = -1;
|
*notaryidp = -1;
|
||||||
if ( height < 0 || height/KOMODO_ELECTION_GAP >= sizeof(Pubkeys)/sizeof(*Pubkeys) )
|
if ( height < 0 || height/KOMODO_ELECTION_GAP >= sizeof(Pubkeys)/sizeof(*Pubkeys) )
|
||||||
return(-1);
|
return(-1);
|
||||||
if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 1 )
|
htind = height / KOMODO_ELECTION_GAP;
|
||||||
htind = 0;
|
|
||||||
pthread_mutex_lock(&komodo_mutex);
|
pthread_mutex_lock(&komodo_mutex);
|
||||||
HASH_FIND(hh,Pubkeys[htind].Notaries,pubkey33,33,kp);
|
HASH_FIND(hh,Pubkeys[htind].Notaries,pubkey33,33,kp);
|
||||||
pthread_mutex_unlock(&komodo_mutex);
|
pthread_mutex_unlock(&komodo_mutex);
|
||||||
@@ -273,7 +279,7 @@ void komodo_assetchain_pubkeys(char *jsonstr)
|
|||||||
{
|
{
|
||||||
komodo_init(-1);
|
komodo_init(-1);
|
||||||
komodo_notarysinit(0,pubkeys,n);
|
komodo_notarysinit(0,pubkeys,n);
|
||||||
printf("initialize pubkeys[%d]\n",n);
|
//printf("initialize pubkeys[%d]\n",n);
|
||||||
} else fprintf(stderr,"komodo_assetchain_pubkeys i.%d vs n.%d\n",i,n);
|
} else fprintf(stderr,"komodo_assetchain_pubkeys i.%d vs n.%d\n",i,n);
|
||||||
} else fprintf(stderr,"assetchain pubkeys n.%d\n",n);
|
} else fprintf(stderr,"assetchain pubkeys n.%d\n",n);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -807,6 +807,15 @@ int32_t komodo_is_issuer()
|
|||||||
else return(0);
|
else return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t bitweight(uint64_t x)
|
||||||
|
{
|
||||||
|
int i,wt = 0;
|
||||||
|
for (i=0; i<64; i++)
|
||||||
|
if ( (1LL << i) & x )
|
||||||
|
wt++;
|
||||||
|
return(wt);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t _unhex(char c)
|
int32_t _unhex(char c)
|
||||||
{
|
{
|
||||||
if ( c >= '0' && c <= '9' )
|
if ( c >= '0' && c <= '9' )
|
||||||
|
|||||||
@@ -1044,6 +1044,7 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio
|
|||||||
|
|
||||||
CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree)
|
CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree)
|
||||||
{
|
{
|
||||||
|
extern int32_t KOMODO_ON_DEMAND;
|
||||||
{
|
{
|
||||||
LOCK(mempool.cs);
|
LOCK(mempool.cs);
|
||||||
uint256 hash = tx.GetHash();
|
uint256 hash = tx.GetHash();
|
||||||
@@ -1268,6 +1269,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Store transaction in memory
|
// Store transaction in memory
|
||||||
|
if ( komodo_is_notarytx(tx) == 0 )
|
||||||
|
KOMODO_ON_DEMAND++;
|
||||||
pool.addUnchecked(hash, entry, !IsInitialBlockDownload());
|
pool.addUnchecked(hash, entry, !IsInitialBlockDownload());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,12 +99,18 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define ASSETCHAINS_MINHEIGHT 100
|
#define ASSETCHAINS_MINHEIGHT 100
|
||||||
|
#define ROUNDROBIN_DELAY 45
|
||||||
|
extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,ASSETCHAINS_SHORTFLAG,KOMODO_REALTIME;
|
||||||
|
extern char ASSETCHAINS_SYMBOL[16];
|
||||||
|
extern std::string NOTARY_PUBKEY;
|
||||||
|
extern uint8_t NOTARY_PUBKEY33[33];
|
||||||
|
uint32_t Mining_start,Mining_height;
|
||||||
|
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33);
|
||||||
|
int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]);
|
||||||
int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize);
|
int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize);
|
||||||
uint64_t komodo_paxtotal();
|
uint64_t komodo_paxtotal();
|
||||||
int32_t komodo_is_issuer();
|
int32_t komodo_is_issuer();
|
||||||
int32_t komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char *symbol,int32_t tokomodo);
|
int32_t komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char *symbol,int32_t tokomodo);
|
||||||
extern int32_t KOMODO_INITDONE,ASSETCHAINS_SHORTFLAG,KOMODO_REALTIME;
|
|
||||||
extern char ASSETCHAINS_SYMBOL[16];
|
|
||||||
|
|
||||||
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||||
{
|
{
|
||||||
@@ -114,11 +120,10 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
if(!pblocktemplate.get())
|
if(!pblocktemplate.get())
|
||||||
return NULL;
|
return NULL;
|
||||||
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
|
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
|
||||||
//fprintf(stderr,"create new block %d\n",chainActive.Tip()->nHeight);
|
|
||||||
if ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight >= 100 )
|
if ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight >= 100 )
|
||||||
{
|
{
|
||||||
fprintf(stderr,"start CreateNewBlock %s initdone.%d deposit %.8f mempool.%d RT.%u\n",ASSETCHAINS_SYMBOL,KOMODO_INITDONE,(double)komodo_paxtotal()/COIN,(int32_t)mempool.GetTotalTxSize(),KOMODO_REALTIME);
|
fprintf(stderr,"start CreateNewBlock %s initdone.%d deposit %.8f mempool.%d RT.%u KOMODO_ON_DEMAND.%d\n",ASSETCHAINS_SYMBOL,KOMODO_INITDONE,(double)komodo_paxtotal()/COIN,(int32_t)mempool.GetTotalTxSize(),KOMODO_REALTIME,KOMODO_ON_DEMAND);
|
||||||
while ( mempool.GetTotalTxSize() <= 0 )
|
while ( KOMODO_ON_DEMAND == 0 )//mempool.GetTotalTxSize() <= 0 )
|
||||||
{
|
{
|
||||||
deposits = komodo_paxtotal();
|
deposits = komodo_paxtotal();
|
||||||
if ( KOMODO_INITDONE == 0 || KOMODO_REALTIME == 0 )
|
if ( KOMODO_INITDONE == 0 || KOMODO_REALTIME == 0 )
|
||||||
@@ -129,6 +134,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
break;
|
break;
|
||||||
sleep(10);
|
sleep(10);
|
||||||
}
|
}
|
||||||
|
KOMODO_ON_DEMAND = 0;
|
||||||
if ( 0 && deposits != 0 )
|
if ( 0 && deposits != 0 )
|
||||||
printf("miner KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)komodo_paxtotal(),(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize());
|
printf("miner KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)komodo_paxtotal(),(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize());
|
||||||
}
|
}
|
||||||
@@ -439,13 +445,6 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int&
|
|||||||
//
|
//
|
||||||
// Internal miner
|
// Internal miner
|
||||||
//
|
//
|
||||||
#define ROUNDROBIN_DELAY 45
|
|
||||||
extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE;
|
|
||||||
extern std::string NOTARY_PUBKEY;
|
|
||||||
extern uint8_t NOTARY_PUBKEY33[33];
|
|
||||||
uint32_t Mining_start,Mining_height;
|
|
||||||
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33);
|
|
||||||
int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]);
|
|
||||||
|
|
||||||
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
|
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -132,6 +132,8 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
|
|||||||
if ( notaryid >= 0 )
|
if ( notaryid >= 0 )
|
||||||
{
|
{
|
||||||
special2 = komodo_is_special(height,pubkey33);
|
special2 = komodo_is_special(height,pubkey33);
|
||||||
|
if ( 0 && special2 == -2 )
|
||||||
|
printf("height.%d special2.%d special.%d\n",height,special2,special);
|
||||||
if ( special2 == -2 || (height < 70000 && (special != 0 || special2 > 0)) ||
|
if ( special2 == -2 || (height < 70000 && (special != 0 || special2 > 0)) ||
|
||||||
(height >= 70000 && special2 > 0) )
|
(height >= 70000 && special2 > 0) )
|
||||||
{
|
{
|
||||||
@@ -153,6 +155,8 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
|
|||||||
}
|
}
|
||||||
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))
|
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))
|
||||||
return error("CheckProofOfWork(): nBits below minimum work");
|
return error("CheckProofOfWork(): nBits below minimum work");
|
||||||
|
if ( height > 70000 )
|
||||||
|
bnTarget /= 64;
|
||||||
// Check proof of work matches claimed amount
|
// Check proof of work matches claimed amount
|
||||||
if ( UintToArith256(hash) > bnTarget )
|
if ( UintToArith256(hash) > bnTarget )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ Value getinfo(const Array& params, bool fHelp)
|
|||||||
obj.push_back(Pair("protocolversion", PROTOCOL_VERSION));
|
obj.push_back(Pair("protocolversion", PROTOCOL_VERSION));
|
||||||
obj.push_back(Pair("notarized", NOTARIZED_HEIGHT));
|
obj.push_back(Pair("notarized", NOTARIZED_HEIGHT));
|
||||||
obj.push_back(Pair("notarizedhash", NOTARIZED_HASH.ToString()));
|
obj.push_back(Pair("notarizedhash", NOTARIZED_HASH.ToString()));
|
||||||
obj.push_back(Pair("notarizedbtc", NOTARIZED_DESTTXID.ToString()));
|
obj.push_back(Pair("notarizedtxid", NOTARIZED_DESTTXID.ToString()));
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
if (pwalletMain) {
|
if (pwalletMain) {
|
||||||
obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
|
obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
|
||||||
|
|||||||
Reference in New Issue
Block a user