Merge pull request #77 from jl777/acspeed

Acspeed
This commit is contained in:
jl777
2016-12-04 07:14:35 -03:00
committed by GitHub
16 changed files with 259 additions and 148 deletions

View File

@@ -1256,7 +1256,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
// first suggest a reindex
if (!fReset) {
bool fRet = uiInterface.ThreadSafeMessageBox(
strLoadError + ".\n\n" + _("Do you want to rebuild the block database now?"),
strLoadError + ".\n\n" + _("error in HDD data, might just need to update to latest, if that doesnt work, then you need to resync"),
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
if (fRet) {
fReindex = true;

View File

@@ -511,17 +511,17 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
{
if ( (k= komodo_notarycmp(scriptPubKey,scriptlen,pubkeys,numnotaries,rmd160)) >= 0 )
signedmask |= (1LL << k);
else if ( numvins >= 17 )
else if ( 0 && numvins >= 17 )
{
int32_t k;
for (k=0; k<scriptlen; k++)
printf("%02x",scriptPubKey[k]);
printf(" scriptPubKey doesnt match any notary\n");
printf(" scriptPubKey doesnt match any notary vini.%d of %d\n",j,numvins);
}
} 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/3)) )
if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || numvalid > (numnotaries/4)) )
{
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;

View File

@@ -366,24 +366,41 @@ uint256 komodo_getblockhash(int32_t height)
}
free_json(result);
}
//printf("KMD hash.%d (%s) %x\n",height,jsonstr,*(uint32_t *)&hash);
printf("KMD hash.%d (%s) %x\n",height,jsonstr,*(uint32_t *)&hash);
free(jsonstr);
}
return(hash);
}
uint256 _komodo_getblockhash(int32_t height);
uint64_t komodo_seed(int32_t height)
{
uint256 hash; uint64_t seed = 0; CBlockIndex *pindex;
memset(&hash,0,sizeof(hash));
if ( height > 10 )
height -= 10;
if ( ASSETCHAINS_SYMBOL[0] == 0 )
uint64_t seed = 0;
if ( 0 ) // problem during init time, seeds are needed for loading blockindex, so null seeds...
{
if ( (pindex= chainActive[height]) != 0 )
hash = pindex->GetBlockHash();
} else hash = komodo_getblockhash(height);
seed = arith_uint256(hash.GetHex()).GetLow64();
uint256 hash,zero; CBlockIndex *pindex;
memset(&hash,0,sizeof(hash));
memset(&zero,0,sizeof(zero));
if ( height > 10 )
height -= 10;
if ( ASSETCHAINS_SYMBOL[0] == 0 )
hash = _komodo_getblockhash(height);
if ( memcmp(&hash,&zero,sizeof(hash)) == 0 )
hash = komodo_getblockhash(height);
int32_t i;
for (i=0; i<32; i++)
printf("%02x",((uint8_t *)&hash)[i]);
printf(" seed.%d\n",height);
seed = arith_uint256(hash.GetHex()).GetLow64();
}
else
{
seed = (height << 13) ^ (height << 2);
seed <<= 21;
seed |= (height & 0xffffffff);
seed ^= (seed << 17) ^ (seed << 1);
}
return(seed);
}
@@ -452,7 +469,7 @@ int32_t komodo_block2height(CBlock *block)
}
//printf(" <- coinbase.%d ht.%d\n",(int32_t)block->vtx[0].vin[0].scriptSig.size(),height);
}
komodo_init(height);
//komodo_init(height);
return(height);
}
@@ -464,7 +481,7 @@ void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block)
#else
uint8_t *ptr = (uint8_t *)&block.vtx[0].vout[0].scriptPubKey[0];
#endif
komodo_init(0);
//komodo_init(0);
n = block.vtx[0].vout[0].scriptPubKey.size();
if ( n == 35 )
memcpy(pubkey33,ptr+1,33);
@@ -491,7 +508,7 @@ int32_t komodo_blockload(CBlock& block,CBlockIndex *pindex)
void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height)
{
CBlock block;
komodo_init(height);
//komodo_init(height);
memset(pubkey33,0,33);
if ( pindex != 0 )
{

View File

@@ -82,12 +82,7 @@ struct pax_transaction *komodo_paxmark(int32_t height,uint256 txid,uint16_t vout
//printf("ht.%d create pax.%p mark.%d\n",height,pax,mark);
}
if ( pax != 0 )
{
pax->marked = mark;
//int32_t i; for (i=0; i<32; i++)
// printf("%02x",((uint8_t *)&txid)[i]);
//printf(" paxmark.ht %d vout%d\n",mark,vout);
}
pthread_mutex_unlock(&komodo_mutex);
return(pax);
}
@@ -133,17 +128,6 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t
pax->height = height;
if ( otherheight != 0 )
pax->otherheight = otherheight;
if ( pax->marked == 0 )
{
if ( 0 && addflag != 0 )
{
if ( (pax->approved= approved) != 0 )
s = (char *)"APPROVED";
else s = (char *)((strcmp(pax->symbol,"KMD") == 0) ? "WITHDRAW" : "DEPOSIT");
printf("[%s] addflag.%d ADD %s/%s %s %.8f -> %s TO PAX ht.%d otherht.%d total %.8f\n",ASSETCHAINS_SYMBOL,addflag,s,symbol,source,dstr(strcmp(pax->symbol,"KMD")==0?pax->komodoshis:pax->fiatoshis),pax->coinaddr,pax->height,pax->otherheight,dstr(komodo_paxtotal()));
}
}
//else printf("%p MARKED.%d DEPOSIT %s %.8f -> %s TO PAX ht.%d otherht.%d\n",pax,pax->marked,symbol,dstr(fiatoshis),coinaddr,height,otherheight);
}
else
{
@@ -277,17 +261,13 @@ uint64_t komodo_paxtotal()
pax->fiatoshis = pax2->fiatoshis;
basesp->issued += pax->fiatoshis;
pax->didstats = 1;
//printf("Iset %s dstats %.8f += %.8f\n",str,dstr(basesp->issued),dstr(pax->fiatoshis));
if ( strcmp(str,ASSETCHAINS_SYMBOL) == 0 )
printf("########### %p issued %s += %.8f kmdheight.%d %.8f other.%d\n",basesp,str,dstr(pax->fiatoshis),pax->height,dstr(pax->komodoshis),pax->otherheight);
pax2->marked = pax->height;
pax->marked = pax->height;
}
}
}
/*if ( strcmp(str,"HRK") == 0 || strcmp("HRK",pax->symbol) == 0 || strcmp("HRK",pax->source) == 0 )
{
for (i=0; i<32; i++)
printf("%02x",((uint8_t *)&pax->txid)[i]);
printf(" stats.%d type.%c (%s) k.%d %.8f h.%d %.8f I.%.8f X.%.8f\n",pax->didstats,pax->type,str,pax->height,dstr(pax->komodoshis),pax->otherheight,dstr(pax->fiatoshis),dstr(basesp->issued),dstr(basesp->redeemed));
}*/
}
}
komodo_stateptr(symbol,dest);
@@ -373,7 +353,7 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to
#ifdef KOMODO_ASSETCHAINS_WAITNOTARIZE
struct komodo_state *kmdsp = komodo_stateptrget((char *)"KMD");
if ( kmdsp != 0 && kmdsp->NOTARIZED_HEIGHT >= pax->height ) // assumes same chain as notarize
pax->validated = kmdsp->NOTARIZED_HEIGHT;
pax->validated = pax->komodoshis; //kmdsp->NOTARIZED_HEIGHT;
#endif
}
if ( pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,symbol) != 0 || available < pax->fiatoshis )
@@ -381,8 +361,13 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to
printf("miner: skip %s %.8f when avail %.8f\n",symbol,dstr(pax->fiatoshis),dstr(available));
continue;
}
if ( pax->marked != 0 || strcmp(pax->symbol,symbol) != 0 || pax->validated == 0 )
if ( pax->marked != 0 )
continue;
if ( strcmp(pax->symbol,symbol) != 0 || pax->validated == 0 )
{
//printf("pax->symbol.%s != %s or null pax->validated %.8f\n",pax->symbol,symbol,dstr(pax->validated));
continue;
}
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
printf("pax.%s marked.%d %.8f -> %.8f\n",ASSETCHAINS_SYMBOL,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis));
txNew->vout.resize(numvouts+1);
@@ -527,12 +512,18 @@ int32_t komodo_paxcmp(char *symbol,int32_t kmdheight,uint64_t value,uint64_t che
return(-1);
}
}
else if ( checkvalue != 0 )
{
ratio = ((value << 10) / checkvalue);
if ( ratio >= 1023 && ratio <= 1025 )
return(0);
}
return(value != checkvalue);
}
const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout,char *source)
{
uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax; struct komodo_state *basesp; double diff;
uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff;
const char *typestr = "unknown";
memset(baseids,0xff,sizeof(baseids));
memset(values,0,sizeof(values));
@@ -540,9 +531,10 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
memset(rmd160s,0,sizeof(rmd160s));
memset(kmdheights,0,sizeof(kmdheights));
memset(otherheights,0,sizeof(otherheights));
tokomodo = (komodo_baseid(source) >= 0 && komodo_baseid(source) != 32); //(komodo_is_issuer() == 0);
tokomodo = (komodo_is_issuer() == 0);
if ( opretbuf[0] == 'D' )
{
tokomodo = 0;
if ( opretlen == 38 ) // any KMD tx
{
iguana_rwnum(0,&opretbuf[34],sizeof(kmdheight),&kmdheight);
@@ -551,16 +543,19 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
bitcoin_address(coinaddr,addrtype,rmd160,20);
checktoshis = PAX_fiatdest(&seed,tokomodo,destaddr,pubkey33,coinaddr,kmdheight,base,fiatoshis);
typestr = "deposit";
//printf("(%s) (%s) kmdheight.%d vs height.%d check %.8f vs %.8f tokomodo.%d %d seed.%llx\n",ASSETCHAINS_SYMBOL,base,kmdheight,height,dstr(checktoshis),dstr(value),komodo_is_issuer(),strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0,(long long)seed);
if ( kmdheight <= height )
{
/*for (i=0; i<32; i++)
printf("%02x",((uint8_t *)&txid)[i]);
printf(" <- txid.v%u ",vout);
for (i=0; i<33; i++)
printf("%02x",pubkey33[i]);
printf(" checkpubkey check %.8f v %.8f dest.(%s) kmdheight.%d height.%d\n",dstr(checktoshis),dstr(value),destaddr,kmdheight,height);*/
didstats = 0;
if ( strcmp(base,ASSETCHAINS_SYMBOL) == 0 )
{
printf("(%s) (%s) kmdheight.%d vs height.%d check %.8f vs %.8f tokomodo.%d %d seed.%llx\n",ASSETCHAINS_SYMBOL,base,kmdheight,height,dstr(checktoshis),dstr(value),komodo_is_issuer(),strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0,(long long)seed);
for (i=0; i<32; i++)
printf("%02x",((uint8_t *)&txid)[i]);
printf(" <- txid.v%u ",vout);
for (i=0; i<33; i++)
printf("%02x",pubkey33[i]);
printf(" checkpubkey check %.8f v %.8f dest.(%s) kmdheight.%d height.%d\n",dstr(checktoshis),dstr(value),destaddr,kmdheight,height);
}
if ( komodo_paxcmp(base,kmdheight,value,checktoshis,seed) == 0 )
{
if ( (pax= komodo_paxfind(txid,vout,'D')) == 0 )
@@ -570,12 +565,16 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
basesp->deposited += fiatoshis;
didstats = 1;
if ( strcmp(base,ASSETCHAINS_SYMBOL) == 0 )
printf("########### %p deposited %s += %.8f\n",basesp,base,dstr(fiatoshis));
}
printf("########### %p deposited %s += %.8f kmdheight.%d %.8f\n",basesp,base,dstr(fiatoshis),kmdheight,dstr(value));
} else printf("cant get stateptr.(%s)\n",base);
komodo_gateway_deposit(coinaddr,value,base,fiatoshis,rmd160,txid,vout,'D',kmdheight,height,(char *)"KMD",0);
}
if ( (pax= komodo_paxfind(txid,vout,'D')) != 0 )
{
pax->height = kmdheight;
pax->validated = value;
pax->komodoshis = value;
pax->fiatoshis = fiatoshis;
if ( didstats == 0 && pax->didstats == 0 )
{
if ( (basesp= komodo_stateptrget(base)) != 0 )
@@ -583,18 +582,86 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
basesp->deposited += fiatoshis;
didstats = 1;
if ( strcmp(base,ASSETCHAINS_SYMBOL) == 0 )
printf("########### %p deposited %s += %.8f\n",basesp,base,dstr(fiatoshis));
printf("########### %p deposited %s += %.8f/%.8f kmdheight.%d/%d %.8f/%.8f\n",basesp,base,dstr(fiatoshis),dstr(pax->fiatoshis),kmdheight,pax->height,dstr(value),dstr(pax->komodoshis));
}
}
if ( didstats != 0 )
pax->didstats = 1;
if ( (pax2= komodo_paxfind(txid,vout,'I')) != 0 )
{
pax2->fiatoshis = pax->fiatoshis;
pax2->komodoshis = pax->komodoshis;
pax->marked = pax2->marked = pax->height;
pax->otherheight = height;
if ( pax2->didstats == 0 )
{
if ( (basesp= komodo_stateptrget(base)) != 0 )
{
basesp->issued += pax2->fiatoshis;
pax2->didstats = 1;
if ( strcmp(base,ASSETCHAINS_SYMBOL) == 0 )
printf("########### %p issueda %s += %.8f kmdheight.%d %.8f other.%d\n",basesp,base,dstr(pax2->fiatoshis),pax2->height,dstr(pax2->komodoshis),pax2->otherheight);
}
}
}
}
}
else if ( kmdheight > 91800 )
printf("pax %s deposit %.8f rejected kmdheight.%d %.8f KMD\n",base,dstr(fiatoshis),kmdheight,dstr(value));
}
}
}
else if ( opretbuf[0] == 'I' )
{
tokomodo = 0;
if ( strncmp((char *)"KMD",(char *)&opretbuf[opretlen-4],3) != 0 )
{
if ( (n= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,0)) > 0 )
{
for (i=0; i<n; i++)
{
if ( baseids[i] < 0 )
{
printf("%d of %d illegal baseid.%d\n",i,n,baseids[i]);
continue;
}
bitcoin_address(coinaddr,60,&rmd160s[i*20],20);
komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],'I',height,0,CURRENCIES[baseids[i]],0);
komodo_paxmark(height,txids[i],vouts[i],'I',height);
if ( (pax= komodo_paxfind(txids[i],vouts[i],'I')) != 0 )
{
pax->type = opretbuf[0];
strcpy(pax->source,(char *)&opretbuf[opretlen-4]);
if ( (pax2= komodo_paxfind(txids[i],vouts[i],'D')) != 0 )
{
// realtime path?
pax->fiatoshis = pax2->fiatoshis;
pax->komodoshis = pax2->komodoshis;
pax->marked = pax2->marked = pax2->height;
if ( pax->didstats == 0 )
{
if ( (basesp= komodo_stateptrget(CURRENCIES[baseids[i]])) != 0 )
{
basesp->issued += pax->fiatoshis;
pax->didstats = 1;
pax->height = pax2->height;
pax->otherheight = height;
if ( strcmp(CURRENCIES[baseids[i]],ASSETCHAINS_SYMBOL) == 0 )
printf("########### %p issuedb %s += %.8f kmdheight.%d %.8f other.%d\n",basesp,CURRENCIES[baseids[i]],dstr(pax->fiatoshis),pax->height,dstr(pax->komodoshis),pax->otherheight);
}
}
}
komodo_paxmark(pax->height,txids[i],vouts[i],'D',height);
}
}
} else printf("opreturn none issued?\n");
}
if ( strcmp(source,ASSETCHAINS_SYMBOL) == 0 )
printf("source.%s opreturn[I] matches %s\n",source,(char *)&opretbuf[opretlen-4]);
}
else if ( opretbuf[0] == 'W' && opretlen >= 38 )
{
tokomodo = 1;
iguana_rwnum(0,&opretbuf[34],sizeof(kmdheight),&kmdheight);
memset(base,0,sizeof(base));
PAX_pubkey(0,&opretbuf[1],&addrtype,rmd160,base,&shortflag,&komodoshis);
@@ -622,11 +689,13 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
if ( didstats != 0 )
pax->didstats = 1;
pax->type = opretbuf[0];
pax->validated = komodoshis;
}
}
}
else if ( tokomodo != 0 && opretbuf[0] == 'A' )
{
tokomodo = 1;
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
{
for (i=0; i<opretlen; i++)
@@ -684,34 +753,9 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
}
//printf("extra.[%d] after %.8f\n",n,dstr(komodo_paxtotal()));
}
else if ( opretbuf[0] == 'I' )
{
if ( strncmp((char *)"KMD",(char *)&opretbuf[opretlen-4],3) != 0 )
{
if ( (n= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,0)) > 0 )
{
for (i=0; i<n; i++)
{
if ( baseids[i] < 0 )
{
printf("%d of %d illegal baseid.%d\n",i,n,baseids[i]);
continue;
}
bitcoin_address(coinaddr,60,&rmd160s[i*20],20);
komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],'I',height,0,CURRENCIES[baseids[i]],0);
komodo_paxmark(height,txids[i],vouts[i],'D',height);
komodo_paxmark(height,txids[i],vouts[i],'I',height);
if ( (pax= komodo_paxfind(txids[i],vouts[i],'I')) != 0 )
{
pax->type = opretbuf[0];
strcpy(pax->source,(char *)&opretbuf[opretlen-4]);
}
}
} //else printf("opreturn none issued?\n");
} //else printf("opreturn matches KMD? %s\n",(char *)&opretbuf[opretlen-4]);
}
else if ( opretbuf[0] == 'X' )
{
tokomodo = 1;
if ( (n= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,1)) > 0 )
{
for (i=0; i<n; i++)

View File

@@ -36,7 +36,7 @@ struct komodo_state KOMODO_STATES[34];
int COINBASE_MATURITY = 100;
int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE;
int32_t IS_KOMODO_NOTARY,KOMODO_REWIND,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE;
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES;
uint8_t NOTARY_PUBKEY33[33];

View File

@@ -135,6 +135,7 @@ int32_t komodo_chosennotary(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=0,htind,modval = -1;
komodo_init(0);
*notaryidp = -1;
if ( height < 0 || height >= KOMODO_MAXBLOCKS )
{

View File

@@ -450,7 +450,8 @@ uint64_t _komodo_paxprice(uint64_t *kmdbtcp,uint64_t *btcusdp,int32_t height,cha
uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume)
{
int32_t i,j,k,ind,zeroes,numvotes,wt,nonz; int64_t delta; uint64_t lastprice,seed,tolerance,den,densum,sum=0,votes[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],btcusds[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],kmdbtcs[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],kmdbtc,btcusd;
int32_t i,j,k,ind,zeroes,numvotes,wt,nonz; int64_t delta; uint64_t lastprice,tolerance,den,densum,sum=0,votes[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],btcusds[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],kmdbtcs[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],kmdbtc,btcusd;
*seedp = komodo_seed(height);
if ( basevolume > KOMODO_PAXMAX )
{
printf("komodo_paxprice overflow %.8f\n",dstr(basevolume));
@@ -470,9 +471,8 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin
_komodo_paxprice(&kmdbtcs[numvotes-1-i],&btcusds[numvotes-1-i],height-i,base,rel,100000,0,0);
//printf("(%llu %llu) ",(long long)kmdbtcs[numvotes-1-i],(long long)btcusds[numvotes-1-i]);
}
*seedp = seed = komodo_seed(height);
kmdbtc = komodo_paxcorrelation(kmdbtcs,numvotes,seed) * 539;
btcusd = komodo_paxcorrelation(btcusds,numvotes,seed) * 539;
kmdbtc = komodo_paxcorrelation(kmdbtcs,numvotes,*seedp) * 539;
btcusd = komodo_paxcorrelation(btcusds,numvotes,*seedp) * 539;
//printf("kmdbtc %llu btcusd %llu\n",(long long)kmdbtc,(long long)btcusd);
for (i=nonz=0; i<numvotes; i++)
{
@@ -482,7 +482,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin
}
if ( nonz <= (numvotes >> 1) )
return(0);
return(komodo_paxcorrelation(votes,numvotes,seed) * basevolume / 100000);
return(komodo_paxcorrelation(votes,numvotes,*seedp) * basevolume / 100000);
}
int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel)
@@ -515,15 +515,19 @@ void komodo_paxpricefeed(int32_t height,uint8_t *pricefeed,int32_t opretlen)
uint64_t PAX_fiatdest(uint64_t *seedp,int32_t tokomodo,char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *origbase,int64_t fiatoshis)
{
uint8_t shortflag = 0; char base[4]; int32_t i,baseid; uint8_t addrtype,rmd160[20]; int64_t komodoshis = 0;
*seedp = 0;
if ( (baseid= komodo_baseid(origbase)) < 0 || baseid == MAX_CURRENCIES )
{
printf("PAX_fiatdest illegal base.(%s)\n",origbase);
return(0);
}
for (i=0; i<3; i++)
base[i] = toupper(origbase[i]);
base[i] = 0;
if ( fiatoshis < 0 )
shortflag = 1, fiatoshis = -fiatoshis;
komodoshis = komodo_paxprice(seedp,height,base,(char *)"KMD",(uint64_t)fiatoshis);
//printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f\n",height,base,(double)fiatoshis/COIN,(double)komodoshis/COIN);
//printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f seed.%llx\n",height,base,(double)fiatoshis/COIN,(double)komodoshis/COIN,(long long)*seedp);
if ( bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr) == 20 )
{
PAX_pubkey(1,pubkey33,&addrtype,rmd160,base,&shortflag,tokomodo != 0 ? &komodoshis : &fiatoshis);

View File

@@ -1302,39 +1302,42 @@ void komodo_configfile(char *symbol,uint16_t port)
{
static char myusername[512],mypassword[8192];
FILE *fp; uint8_t buf2[33]; char fname[512],buf[128],username[512],password[8192]; uint32_t crc,r,r2,i;
r = (uint32_t)time(NULL);
r2 = OS_milliseconds();
memcpy(buf,&r,sizeof(r));
memcpy(&buf[sizeof(r)],&r2,sizeof(r2));
memcpy(&buf[sizeof(r)+sizeof(r2)],symbol,strlen(symbol));
crc = calc_crc32(0,(uint8_t *)buf,(int32_t)(sizeof(r)+sizeof(r2)+strlen(symbol)));
OS_randombytes(buf2,sizeof(buf2));
for (i=0; i<sizeof(buf2); i++)
sprintf(&password[i*2],"%02x",buf2[i]);
password[i*2] = 0;
sprintf(buf,"%s.conf",symbol);
BITCOIND_PORT = port;
if ( symbol != 0 && port != 0 )
{
r = (uint32_t)time(NULL);
r2 = OS_milliseconds();
memcpy(buf,&r,sizeof(r));
memcpy(&buf[sizeof(r)],&r2,sizeof(r2));
memcpy(&buf[sizeof(r)+sizeof(r2)],symbol,strlen(symbol));
crc = calc_crc32(0,(uint8_t *)buf,(int32_t)(sizeof(r)+sizeof(r2)+strlen(symbol)));
OS_randombytes(buf2,sizeof(buf2));
for (i=0; i<sizeof(buf2); i++)
sprintf(&password[i*2],"%02x",buf2[i]);
password[i*2] = 0;
sprintf(buf,"%s.conf",symbol);
BITCOIND_PORT = port;
#ifdef WIN32
sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),buf);
sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),buf);
#else
sprintf(fname,"%s/%s",GetDataDir(false).string().c_str(),buf);
sprintf(fname,"%s/%s",GetDataDir(false).string().c_str(),buf);
#endif
if ( (fp= fopen(fname,"rb")) == 0 )
{
if ( (fp= fopen(fname,"wb")) != 0 )
if ( (fp= fopen(fname,"rb")) == 0 )
{
fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%s\nrpcport=%u\nserver=1\ntxindex=1\n\n",crc,password,port);
if ( (fp= fopen(fname,"wb")) != 0 )
{
fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%s\nrpcport=%u\nserver=1\ntxindex=1\n\n",crc,password,port);
fclose(fp);
printf("Created (%s)\n",fname);
} else printf("Couldnt create (%s)\n",fname);
}
else
{
komodo_userpass(myusername,mypassword,fp);
mapArgs["-rpcpassword"] = mypassword;
mapArgs["-rpcusername"] = myusername;
//fprintf(stderr,"myusername.(%s)\n",myusername);
fclose(fp);
printf("Created (%s)\n",fname);
} else printf("Couldnt create (%s)\n",fname);
}
else
{
komodo_userpass(myusername,mypassword,fp);
mapArgs["-rpcpassword"] = mypassword;
mapArgs["-rpcusername"] = myusername;
//fprintf(stderr,"myusername.(%s)\n",myusername);
fclose(fp);
}
}
strcpy(fname,GetDataDir().string().c_str());
#ifdef WIN32
@@ -1346,12 +1349,12 @@ void komodo_configfile(char *symbol,uint16_t port)
fname[strlen(fname)-1] = 0;
strcat(fname,"komodo.conf");
#endif
//printf("KOMODO.(%s)\n",fname);
if ( (fp= fopen(fname,"rb")) != 0 )
{
komodo_userpass(username,password,fp);
sprintf(KMDUSERPASS,"%s:%s",username,password);
fclose(fp);
//printf("KOMODO.(%s) -> userpass.(%s)\n",fname,KMDUSERPASS);
} else printf("couldnt open.(%s)\n",fname);
}
@@ -1447,6 +1450,8 @@ void komodo_args()
if ( strlen(NOTARY_PUBKEY.c_str()) == 66 )
USE_EXTERNAL_PUBKEY = 1;
name = GetArg("-ac_name","");
if ( (KOMODO_REWIND= GetArg("-rewind",0)) != 0 )
;
if ( name.c_str()[0] != 0 )
{
ASSETCHAINS_SUPPLY = GetArg("-ac_supply",10);
@@ -1484,8 +1489,25 @@ void komodo_args()
}
else
{
char fname[512],username[512],password[4096]; FILE *fp;
ASSETCHAINS_PORT = 8777;
//fprintf(stderr,"IS_KOMODO_NOTARY %d %s\n",IS_KOMODO_NOTARY,NOTARY_PUBKEY.c_str());
strcpy(fname,GetDataDir().string().c_str());
#ifdef WIN32
while ( fname[strlen(fname)-1] != '\\' )
fname[strlen(fname)-1] = 0;
strcat(fname,".komodo/komodo.conf");
#else
while ( fname[strlen(fname)-1] != '/' )
fname[strlen(fname)-1] = 0;
strcat(fname,".komodo/komodo.conf");
#endif
if ( (fp= fopen(fname,"rb")) != 0 )
{
komodo_userpass(username,password,fp);
sprintf(KMDUSERPASS,"%s:%s",username,password);
fclose(fp);
//printf("KOMODO.(%s) -> userpass.(%s)\n",fname,KMDUSERPASS);
} else printf("couldnt open.(%s)\n",fname);
}
//fprintf(stderr,"%s chain params initialized\n",ASSETCHAINS_SYMBOL);
}

View File

@@ -2694,6 +2694,7 @@ static void PruneBlockIndexCandidates() {
* pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork.
*/
static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMostWork, CBlock *pblock) {
extern int32_t KOMODO_REWIND;
AssertLockHeld(cs_main);
bool fInvalidFound = false;
const CBlockIndex *pindexOldTip = chainActive.Tip();
@@ -2704,21 +2705,21 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
if (!DisconnectTip(state))
return false;
}
if ( 0 )
{
static int32_t didinit;
if ( didinit++ == 0 )
if ( KOMODO_REWIND != 0 && chainActive.Tip()->nHeight > KOMODO_REWIND )
{
while (chainActive.Tip()->nHeight > 91418 )
static int32_t didinit;
if ( didinit++ == 0 )
{
fprintf(stderr,"rewind ht.%d\n",chainActive.Tip()->nHeight);
if ( !DisconnectTip(state) )
return false;
while (chainActive.Tip()->nHeight > KOMODO_REWIND )
{
fprintf(stderr,"rewind ht.%d\n",chainActive.Tip()->nHeight);
if ( !DisconnectTip(state) )
return false;
}
pindexOldTip = chainActive.Tip();
pindexFork = chainActive.FindFork(pindexMostWork);
}
pindexOldTip = chainActive.Tip();
pindexFork = chainActive.FindFork(pindexMostWork);
}
}
// Build list of new blocks to connect.
std::vector<CBlockIndex*> vpindexToConnect;
bool fContinue = true;

View File

@@ -99,7 +99,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams,
}
#define ASSETCHAINS_MINHEIGHT 100
#define ROUNDROBIN_DELAY 59
#define ROUNDROBIN_DELAY 58
extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE;
extern char ASSETCHAINS_SYMBOL[16];
extern std::string NOTARY_PUBKEY;
@@ -133,7 +133,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
}
else if ( deposits != 0 )
{
//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(),isrealtime,KOMODO_ON_DEMAND);
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(),isrealtime,KOMODO_ON_DEMAND);
break;
}
sleep(10);
@@ -378,9 +378,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
if ( ASSETCHAINS_SYMBOL[0] == 0 )
{
int32_t i,opretlen; uint8_t opret[256],*ptr;
if ( komodo_gateway_deposits(&txNew,(char *)"KMD",1) == 0 )
if ( (nHeight % 60) == 0 || komodo_gateway_deposits(&txNew,(char *)"KMD",1) == 0 )
{
if ( (opretlen= komodo_pax_opreturn(opret,sizeof(opret))) > 0 )
if ( (opretlen= komodo_pax_opreturn(opret,sizeof(opret))) > 0 ) // have pricefeed
{
txNew.vout.resize(2);
txNew.vout[1].scriptPubKey.resize(opretlen);

View File

@@ -112,7 +112,8 @@ extern int32_t KOMODO_CHOSEN_ONE;
bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params& params)
{
bool fNegative,fOverflow; int32_t i,nonz=0,special,special2,notaryid,flag = 0;
extern int32_t KOMODO_REWIND;
bool fNegative,fOverflow; int32_t i,nonz=0,special,special2,notaryid=-1,flag = 0;
arith_uint256 bnTarget;
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
@@ -145,10 +146,15 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
// Check proof of work matches claimed amount
if ( UintToArith256(hash) > bnTarget )
{
//for (i=0; i<33; i++)
// printf("%02x",pubkey33[i]);
//printf(" special.%d notaryid.%d ht.%d mod.%d error\n",special,notaryid,height,(height % 35));
return error("CheckProofOfWork(): hash doesn't match nBits");
int32_t i;
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 REWIND.%d special.%d notaryid.%d ht.%d mod.%d error\n",height,KOMODO_REWIND,special,notaryid,height,(height % 35));
if ( height <= KOMODO_REWIND )
return error("CheckProofOfWork(): hash doesn't match nBits");
}
return true;
}

View File

@@ -199,7 +199,7 @@ QT_TRANSLATE_NOOP("bitcoin-core", "Corrupted block database detected"),
QT_TRANSLATE_NOOP("bitcoin-core", "Could not parse -rpcbind value %s as network address"),
QT_TRANSLATE_NOOP("bitcoin-core", "Debugging/Testing options:"),
QT_TRANSLATE_NOOP("bitcoin-core", "Do not load the wallet and disable wallet RPC calls"),
QT_TRANSLATE_NOOP("bitcoin-core", "Do you want to rebuild the block database now?"),
QT_TRANSLATE_NOOP("bitcoin-core", "error with HDD data, maybe just need to update to latest version"),
QT_TRANSLATE_NOOP("bitcoin-core", "Done loading"),
QT_TRANSLATE_NOOP("bitcoin-core", "Error initializing block database"),
QT_TRANSLATE_NOOP("bitcoin-core", "Error initializing wallet database environment %s!"),

View File

@@ -272,6 +272,22 @@ Value getblockhash(const Array& params, bool fHelp)
return pblockindex->GetBlockHash().GetHex();
}
uint256 _komodo_getblockhash(int32_t nHeight)
{
uint256 hash;
LOCK(cs_main);
if ( nHeight >= 0 && nHeight <= chainActive.Height() )
{
CBlockIndex* pblockindex = chainActive[nHeight];
hash = pblockindex->GetBlockHash();
int32_t i;
for (i=0; i<32; i++)
printf("%02x",((uint8_t *)&hash)[i]);
printf(" blockhash.%d\n",nHeight);
} else memset(&hash,0,sizeof(hash));
return(hash);
}
Value getblock(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)

View File

@@ -123,11 +123,9 @@ Value getinfo(const Array& params, bool fHelp)
obj.push_back(Pair("errors", GetWarnings("statusbar")));
{
char pubkeystr[65]; int32_t notaryid;
if ( (notaryid= komodo_whoami(pubkeystr,longestchain)) >= 0 )
{
obj.push_back(Pair("notaryid", notaryid));
obj.push_back(Pair("pubkey", pubkeystr));
}
notaryid = komodo_whoami(pubkeystr,longestchain);
obj.push_back(Pair("notaryid", notaryid));
obj.push_back(Pair("pubkey", pubkeystr));
}
return obj;
}

View File

@@ -493,7 +493,7 @@ Value paxdeposit(const Array& params, bool fHelp)
if (!EnsureWalletIsAvailable(fHelp))
return Value::null;
if (fHelp || params.size() != 3)
throw runtime_error("paxdeposit \"address\" fiatoshis base");
throw runtime_error("paxdeposit address fiatoshis base");
LOCK2(cs_main, pwalletMain->cs_wallet);
CBitcoinAddress address(params[0].get_str());
if (!address.IsValid())
@@ -510,8 +510,8 @@ Value paxdeposit(const Array& params, bool fHelp)
if (!destaddress.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address");
for (i=0; i<33; i++)
printf("%02x",pubkey37[i]);
printf(" ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) komodoshis.%llu seed.%llx\n",height,(char *)params[0].get_str().c_str(),(char *)base.c_str(),(long long)fiatoshis,destaddr,(long long)komodoshis,(long long)seed);
fprintf(stderr,"%02x",pubkey37[i]);
fprintf(stderr," ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) komodoshis.%llu seed.%llx\n",height,(char *)params[0].get_str().c_str(),(char *)base.c_str(),(long long)fiatoshis,destaddr,(long long)komodoshis,(long long)seed);
EnsureWalletIsUnlocked();
CWalletTx wtx;
uint8_t opretbuf[64]; int32_t opretlen; uint64_t fee = komodoshis / 1000;
@@ -531,7 +531,7 @@ Value paxwithdraw(const Array& params, bool fHelp)
if (!EnsureWalletIsAvailable(fHelp))
return 0;
if (fHelp || params.size() != 2)
throw runtime_error("paxwithdraw \"address\" fiatamount");
throw runtime_error("paxwithdraw address fiatamount");
if ( komodo_isrealtime(&kmdheight) == 0 )
return(0);
LOCK2(cs_main, pwalletMain->cs_wallet);

View File

@@ -748,6 +748,7 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,
void CWallet::DecrementNoteWitnesses()
{
extern int32_t KOMODO_REWIND;
{
LOCK(cs_wallet);
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) {
@@ -770,12 +771,13 @@ void CWallet::DecrementNoteWitnesses()
}
}
// TODO: If nWitnessCache is zero, we need to regenerate the caches (#1302)
assert(nWitnessCacheSize > 0);
if ( nWitnessCacheSize <= 0 )
{
extern char ASSETCHAINS_SYMBOL[16];
fprintf(stderr,"%s nWitnessCacheSize.%d\n",ASSETCHAINS_SYMBOL,(int32_t)nWitnessCacheSize);
}
if ( KOMODO_REWIND == 0 )
assert(nWitnessCacheSize > 0);
if (fFileBacked) {
CWalletDB walletdb(strWalletFile);
WriteWitnessCache(walletdb);