Browse Source

Merge branch 'master' into release/v0.1

fix auxpow coins
release/v0.1
jl777 8 years ago
parent
commit
d2e818d531
  1. 2
      crypto777/OS_portable.h
  2. 4
      iguana/coins/genbtc
  3. 30
      iguana/iguana777.c
  4. 52
      iguana/iguana_bundles.c
  5. 56
      iguana/iguana_ramchain.c
  6. 28
      iguana/iguana_recv.c
  7. 17
      iguana/iguana_spendvectors.c
  8. 25
      iguana/iguana_tx.c
  9. 4
      includes/iguana_structs.h

2
crypto777/OS_portable.h

@ -358,7 +358,7 @@ void escape_code(char *escaped,char *str);
void SaM_PrepareIndices();
// iguana_serdes.c
#define IGUANA_LOG2PACKETSIZE 21
#define IGUANA_LOG2PACKETSIZE 22
#define IGUANA_MAXPACKETSIZE (1 << IGUANA_LOG2PACKETSIZE)
struct iguana_msghdr { uint8_t netmagic[4]; char command[12]; uint8_t serdatalen[4],hash[4]; } PACKED;

4
iguana/coins/genbtc

@ -1 +1,5 @@
<<<<<<< HEAD
curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":-1,\"poll\":1,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTC\",\"startpend\":256,\"endpend\":256,\"services\":129,\"maxpeers\":512,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":8333}"
=======
curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":-1,\"poll\":1,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTC\",\"startpend\":512,\"endpend\":512,\"services\":129,\"maxpeers\":512,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":8333}"
>>>>>>> master

30
iguana/iguana777.c

@ -176,7 +176,7 @@ int32_t iguana_peermetrics(struct supernet_info *myinfo,struct iguana_info *coin
}
coin->peers->numranked = n;
portable_mutex_unlock(&coin->peers_mutex);
//printf("NUMRANKED.%d\n",n);
//printf("peer metrics NUMRANKED.%d\n",n);
if ( i > 0 )
{
coin->peers->avemetric = (sum / i);
@ -340,7 +340,7 @@ int32_t iguana_utxofinished(struct iguana_info *coin)
struct iguana_bundle *bp; int32_t i,n = 0;
for (i=0; i<coin->bundlescount-1; i++)
{
if ( (bp= coin->bundles[i]) != 0 && bp->utxofinish > 1 )
if ( (bp= coin->bundles[i]) != 0 && bp->emitfinish > 1 )
n++;
}
return(n);
@ -391,14 +391,14 @@ int32_t iguana_helperA(struct supernet_info *myinfo,struct iguana_info *coin,int
if ( iguana_bundlevalidate(myinfo,coin,bp,0) == bp->n ) //
{
retval = 0;
if ( bp->utxofinish > 1 || (retval= iguana_spendvectors(myinfo,coin,bp,&bp->ramchain,0,bp->n,convertflag,0)) >= 0 )
if ( bp->emitfinish > 1 || (retval= iguana_spendvectors(myinfo,coin,bp,&bp->ramchain,0,bp->n,convertflag,0)) >= 0 )
{
if ( retval > 0 )
{
printf("GENERATED UTXO.%d for ht.%d duration %d seconds\n",bp->hdrsi,bp->bundleheight,(uint32_t)time(NULL) - bp->startutxo);
num++;
}
bp->utxofinish = (uint32_t)time(NULL);
bp->emitfinish = (uint32_t)time(NULL);
} else printf("UTXO gen.[%d] utxo error\n",bp->hdrsi);
}
else
@ -661,7 +661,7 @@ int32_t iguana_coin_mainiter(struct supernet_info *myinfo,struct iguana_info *co
void iguana_helper(void *arg)
{
static uint64_t helperidbits;
cJSON *argjson=0; int32_t iter,n,j,numpeers,polltimeout,type,helperid=rand(),flag,allcurrent,idle=0;
cJSON *argjson=0; int32_t iter,n,i,j,numpeers,polltimeout,type,helperid=rand(),flag,allcurrent,idle=0;
struct iguana_helper *ptr; struct iguana_info *coin,*tmp; struct OS_memspace MEM,*MEMB; struct iguana_bundle *bp; struct supernet_info *myinfo = SuperNET_MYINFO(0);
helperid %= 64;
if ( arg != 0 && (argjson= cJSON_Parse(arg)) != 0 )
@ -707,12 +707,24 @@ void iguana_helper(void *arg)
else
{
for (j=helperid; j<coin->bundlescount; j+=IGUANA_NUMHELPERS)
if ( (bp= coin->bundles[j]) != 0 && bp->startutxo == 0 && bp->numsaved >= coin->chain->bundlesize && iguana_bundleready(myinfo,coin,bp,0) == bp->n )
{
if ( (bp= coin->bundles[j]) != 0 )
{
//printf("finalize.[%d]\n",bp->hdrsi);
if ( iguana_bundlefinalize(myinfo,coin,bp,&MEM,MEMB) > 0 )
continue;
if ( bp->startutxo == 0 && bp->numsaved >= coin->chain->bundlesize && iguana_bundleready(myinfo,coin,bp,0) == bp->n )
iguana_bundlefinalize(myinfo,coin,bp,&MEM,MEMB);
if ( bp->emitfinish != 0 && time(NULL) > bp->emitfinish+60 )
{
if ( bp->validated == 0 )
{
for (i=0; i<j; i++)
if ( coin->bundles[i] == 0 || coin->bundles[i]->validated <= 1 )
break;
if ( i == j )
iguana_bundlevalidate(myinfo,coin,bp,1);
}
}
}
}
}
}
if ( helperid == 0 )

52
iguana/iguana_bundles.c

@ -615,7 +615,7 @@ struct iguana_block *iguana_bundleblock(struct iguana_info *coin,bits256 *hash2p
int32_t iguana_bundleissuemissing(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t priority,double mult)
{
int32_t i,max,nonz,starti,lasti,firsti,lag,num,n=0; uint32_t now; bits256 hash2; double aveduration; struct iguana_peer *addr; struct iguana_block *block;
int32_t i,max,nonz,starti,lasti,firsti,lag,num,n=0; uint32_t now; bits256 hash2; double aveduration; struct iguana_peer *addr; char str[65]; //struct iguana_block *block;
if ( coin->peers == 0 )
{
printf("%s has no peers\n",coin->symbol);
@ -657,10 +657,10 @@ int32_t iguana_bundleissuemissing(struct supernet_info *myinfo,struct iguana_inf
lasti = firsti = -1;
for (i=nonz=0; i<bp->n; i++)
{
if ( (block= bp->blocks[i]) != 0 && block->txvalid != 0 && block->mainchain != 0 )
continue;
//if ( GETBIT(bp->haveblock,i) != 0 )
//if ( (block= bp->blocks[i]) != 0 && block->txvalid != 0 && block->mainchain != 0 )
// continue;
if ( GETBIT(bp->haveblock,i) != 0 )
continue;
nonz++;
if ( firsti < 0 )
firsti = i;
@ -670,10 +670,8 @@ int32_t iguana_bundleissuemissing(struct supernet_info *myinfo,struct iguana_inf
iguana_bundleblock(coin,&hash2,bp,i);
if ( bits256_nonz(hash2) != 0 )
{
if ( (addr= coin->peers->ranked[rand() % max]) != 0 && addr->usock >= 0 && addr->dead == 0 ) //strcmp("BTC",coin->symbol) != 0 || (bp->issued[i] > 1 && now > bp->issued[i]+lag &&
if ( (addr= coin->peers->ranked[rand() % max]) != 0 && addr->usock >= 0 && addr->dead == 0 && addr->msgcounts.verack > 0 )
{
if ( 0 && bp == coin->current )
printf("iguana_bundleissuemissing.[%d:%d]\n",bp->hdrsi,i);
iguana_sendblockreqPT(coin,0,bp,i,hash2,0);
}
struct iguana_blockreq *req = 0;
@ -685,23 +683,27 @@ int32_t iguana_bundleissuemissing(struct supernet_info *myinfo,struct iguana_inf
queue_enqueue("missing",&coin->priorityQ,&req->DL,0);
bp->issued[i] = 1;
n++;
} //else printf("[z%d] ",i);
if ( 0 && bp == coin->current )
printf("%s issuemissing.[%d:%d]\n",bits256_str(str,hash2),bp->hdrsi,i);
} //else printf("[z%d] ",i);
} //else printf("%d ",now - (bp->issued[i]+lag));
}
if ( firsti >= 0 )//&& bp == coin->current )
{
//printf("[%d] first missing.%d of %d\n",bp->hdrsi,firsti,nonz);
if ( 0 && bp == coin->current )
printf("%s [%d] first missing.%d of %d\n",bits256_str(str,hash2),bp->hdrsi,firsti,nonz);
iguana_bundleblock(coin,&hash2,bp,firsti);
if ( bits256_nonz(hash2) != 0 )
{
if ( (addr= coin->peers->ranked[rand() % max]) != 0 && addr->usock >= 0 && addr->dead == 0 )
if ( (addr= coin->peers->ranked[rand() % max]) != 0 && addr->usock >= 0 && addr->dead == 0 && addr->msgcounts.verack > 0 )
{
//if ( bp == coin->current )
// printf("iguana_bundleissuemissing.[%d:%d]\n",bp->hdrsi,i);
n++;
//printf("send reqPT [%d:%d]\n",bp->hdrsi,firsti);
iguana_sendblockreqPT(coin,0,bp,firsti,hash2,0);
}
}
} // else printf("no hash for [%d:%d]\n",bp->hdrsi,firsti);
}
}
//if ( n > 0 || bp == coin->current )
@ -1040,7 +1042,7 @@ int32_t iguana_bundlefinalize(struct supernet_info *myinfo,struct iguana_info *c
if ( bp->emitfinish != 0 )
{
printf("already EMIT for bundle.%d\n",bp->hdrsi);
return(0);
//return(0);
}
bp->emitfinish = 1;
usleep(100000); // make sure new incoming packet didnt overwrite
@ -1064,10 +1066,10 @@ int32_t iguana_bundlefinalize(struct supernet_info *myinfo,struct iguana_info *c
//coin->spendvectorsaved = 0;
for (i=0; i<coin->bundlescount; i++)
if ( (tmpbp= coin->bundles[i]) != 0 )
tmpbp->converted = tmpbp->balancefinish = tmpbp->validated = 0;
//#ifdef __PNACL__
tmpbp->converted = tmpbp->balancefinish = 0;
#ifdef __PNACL__
iguana_bundlevalidate(myinfo,coin,bp,1);
//#endif
#endif
}
else
{
@ -1115,7 +1117,7 @@ int32_t iguana_bundleiters(struct supernet_info *myinfo,struct iguana_info *coin
if ( coin->blockdepth == 0 && coin->blockdepth == 0 && bp->hdrsi == coin->bundlescount-1 )
iguana_autoextend(myinfo,coin,bp);
if ( 0 && bp->hdrsi == 0 )
printf("ITER utxo.%u now.%u spec.%-4d bundle.%-4d h.%-4d r.%-4d s.%-4d F.%d T.%d issued.%d mb.%d/%d\n",bp->utxofinish,(uint32_t)time(NULL),bp->numspec,bp->bundleheight/coin->chain->bundlesize,bp->numhashes,bp->numrecv,bp->numsaved,bp->emitfinish,timelimit,counter,coin->MAXBUNDLES,coin->bundlescount);
printf("ITER utxo.%u now.%u spec.%-4d bundle.%-4d h.%-4d r.%-4d s.%-4d F.%d T.%d issued.%d mb.%d/%d\n",bp->emitfinish,(uint32_t)time(NULL),bp->numspec,bp->bundleheight/coin->chain->bundlesize,bp->numhashes,bp->numrecv,bp->numsaved,bp->emitfinish,timelimit,counter,coin->MAXBUNDLES,coin->bundlescount);
bp->nexttime = (uint32_t)time(NULL) + ((bp->hdrsi > starti) ? 0 : -2);
if ( bp->hdrsi == coin->bundlescount-1 || (bp->numhashes < bp->n && bp->bundleheight < coin->longestchain-coin->chain->bundlesize) )
iguana_bundlehdr(myinfo,coin,bp,starti);
@ -1362,7 +1364,7 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch
numcached += bp->numcached;
numrecv += bp->numrecv;
numsaved += bp->numsaved;
if ( bp->utxofinish > 1 )
if ( bp->emitfinish > 1 )
numutxo++;
if ( bp->balancefinish > 1 )
numbalances++;
@ -1423,20 +1425,20 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch
tmp = (difft.millis * 1000000);
tmp %= 1000000000;
difft.millis = ((double)tmp / 1000000.);
if ( (bp= firstgap) != 0 )//&& coin->PREFETCHLAG < 0 )
if ( (bp= firstgap) != 0 )
{
if ( bp != coin->current )
{
printf("%s new 1st.%d\n",coin->symbol,bp->hdrsi);
iguana_bundleissuemissing(myinfo,coin,bp,1 + (rand() % 3),1.);
iguana_bundleissuemissing(myinfo,coin,bp,3,1.);
if ( bp->queued == 0 )
iguana_bundleQ(myinfo,coin,bp,0);
}
//else printf("issue 1st.%d\n",bp->hdrsi);
//for (i=0; i<bp->n; i++)
// if ( GETBIT(bp->haveblock,i) == 0 )
// bp->issued[i] = 0;
//iguana_bundleissuemissing(myinfo,coin,bp,1 + (rand() % 3),1.);
for (i=j=0; i<bp->n; i++)
if ( GETBIT(bp->haveblock,i) == 0 )
bp->issued[i] = 0, j++;
n = iguana_bundleissuemissing(myinfo,coin,bp,3,1.);
//printf("issued 1st.[%d] %d of %d\n",bp->hdrsi,n,j);
}
if ( (coin->current= firstgap) == 0 )
{
@ -1515,7 +1517,7 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch
{
//printf("bundleQ.[%d]\n",j);
bp->balancefinish = bp->startutxo = 0;
bp->utxofinish = 1;
bp->emitfinish = 1;
iguana_bundleQ(myinfo,coin,bp,1000);
}
}

56
iguana/iguana_ramchain.c

@ -1293,7 +1293,7 @@ int32_t iguana_bundleremove(struct iguana_info *coin,int32_t hdrsi,int32_t tmpfi
sprintf(fname,"%s/%s/accounts/debits.%d",GLOBAL_DBDIR,coin->symbol,bp->bundleheight), OS_removefile(fname,0);
sprintf(fname,"%s/%s/accounts/lastspends.%d",GLOBAL_DBDIR,coin->symbol,bp->bundleheight), OS_removefile(fname,0);
sprintf(fname,"%s/%s/validated/%d",GLOBAL_DBDIR,coin->symbol,bp->bundleheight), OS_removefile(fname,0);
bp->utxofinish = bp->startutxo = bp->balancefinish = bp->validated = bp->emitfinish = bp->converted = 0;
bp->startutxo = bp->balancefinish = bp->validated = bp->emitfinish = bp->converted = 0;
//iguana_ramchain_free(coin,&bp->ramchain,1);
return(0);
}
@ -1334,7 +1334,7 @@ int32_t iguana_Xspendmap(struct iguana_info *coin,struct iguana_ramchain *ramcha
{
ramchain->Xspendptr = ptr;
ramchain->numXspends = (int32_t)((filesize - sizeof(sha256)) / sizeof(*ramchain->Xspendinds));
bp->startutxo = bp->utxofinish = (uint32_t)time(NULL);
bp->startutxo = bp->emitfinish = (uint32_t)time(NULL);
if ( bp->Xvalid == 0 )
{
if ( (rand() % 10) == 0 )
@ -1875,6 +1875,11 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
{
tx = &txarray[i];
iguana_ramchain_addtxid(coin,RAMCHAIN_ARG,tx->txid,tx->tx_out,tx->tx_in,tx->lock_time,tx->version,tx->timestamp,bundlei);
if ( tx->tx_out == 0 && tx->tx_in == 0 )
{
printf("strange tx without any inputs or outputs? ht.%d\n",bp->bundleheight);
break;
}
for (j=0; j<tx->tx_out; j++)
{
memset(rmd160,0,sizeof(rmd160));
@ -1994,10 +1999,10 @@ void iguana_blockdelete(struct iguana_info *coin,bits256 hash2,int32_t i)
if ( fname[0] != 0 )
{
OS_removefile(fname,0);
#ifndef WIN32
/*#ifndef WIN32
strcat(fname,".tmp");
OS_removefile(fname,0);
#endif
#endif*/
}
}
@ -2082,7 +2087,7 @@ int32_t iguana_oldbundlefiles(struct iguana_info *coin,uint32_t *ipbits,void **p
void *iguana_bundlefile(struct iguana_info *coin,char *fname,long *filesizep,struct iguana_bundle *bp,int32_t bundlei,int32_t renameflag)
{
int32_t checki,hdrsi; void *ptr = 0; FILE *fp; char renamed[1024]; static const bits256 zero;
int32_t checki,hdrsi; long checksize; void *ptr = 0; FILE *fp; static const bits256 zero; //char renamed[1024];
*filesizep = 0;
fname[0] = 0;
if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBAL_TMPDIR,fname,0,bp->hashes[bundlei],zero,1,1)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize )
@ -2094,20 +2099,39 @@ void *iguana_bundlefile(struct iguana_info *coin,char *fname,long *filesizep,str
return(0);
else
{
fseek(fp,0,SEEK_END);
checksize = ftell(fp);
fclose(fp);
#ifndef WIN32
/*#ifndef WIN32
if ( renameflag != 0 )
{
sprintf(renamed,"%s.tmp",fname);
OS_renamefile(fname,renamed);
OS_copyfile(fname,renamed,1);
strcpy(fname,renamed);
}
#endif
//#endif*/
if ( (ptr= OS_mapfile(fname,filesizep,0)) == 0 )
{
printf("error mapping.(%s) bundlei.%d\n",fname,bundlei);
return(0);
}
if ( *filesizep != checksize )
{
printf("%s *filesizep %ld != %ld\n",fname,*filesizep,checksize);
OS_releasemap(ptr,*filesizep);
sleep(1);
if ( (ptr= OS_mapfile(fname,filesizep,0)) == 0 )
{
printf("error mapping.(%s) bundlei.%d\n",fname,bundlei);
return(0);
}
if ( *filesizep != checksize )
{
printf("second %s failure *filesizep %ld != %ld\n",fname,*filesizep,checksize);
OS_releasemap(ptr,*filesizep);
return(0);
}
}
}
//printf("mapped.(%s) bundlei.[%d:%d] %p[%ld]\n",fname,hdrsi,bundlei,ptr,*filesizep);
return(ptr);
@ -2255,7 +2279,7 @@ struct iguana_ramchain *iguana_bundleload(struct supernet_info *myinfo,struct ig
{
static const bits256 zero;
struct iguana_blockRO *B; struct iguana_txid *T; int32_t i,firsti = 1; char fname[512];
struct iguana_block *block,*prev,*prev2; struct iguana_ramchain *mapchain; struct iguana_ramchaindata *rdata;
struct iguana_block *block,*prev,*prev2; struct iguana_ramchain *mapchain; struct iguana_ramchaindata *rdata; uint32_t firsttxidind;
if ( bp->emitfinish > 1 )
return(ramchain);
memset(ramchain,0,sizeof(*ramchain));
@ -2264,6 +2288,7 @@ struct iguana_ramchain *iguana_bundleload(struct supernet_info *myinfo,struct ig
iguana_ramchain_link(mapchain,bp->hashes[0],bp->hdrsi,bp->bundleheight,0,bp->n,firsti,1);
//char str[65]; printf("%s bp.%d: T.%d U.%d S.%d P%d X.%d MAPPED %s %p\n",coin->symbol,bp->hdrsi,mapchain->H.data->numtxids,mapchain->H.data->numunspents,mapchain->H.data->numspends,mapchain->H.data->numpkinds,mapchain->H.data->numexternaltxids,mbstr(str,mapchain->H.data->allocsize),mapchain->H.data);
//ramcoder_test(mapchain->H.data,mapchain->H.data->allocsize);
firsttxidind = 1;
if ( (rdata= ramchain->H.data) != 0 )
{
B = RAMCHAIN_PTR(rdata,Boffset);
@ -2287,8 +2312,11 @@ struct iguana_ramchain *iguana_bundleload(struct supernet_info *myinfo,struct ig
block->fpipbits = (uint32_t)calc_ipbits("127.0.0.1");
iguana_blockzcopyRO(coin->chain->zcash,&block->RO,0,B,i);
//printf("%x ",(int32_t)B[i].hash2.ulongs[3]);
iguana_hash2set(coin,"bundleload",bp,i,block->RO.hash2);
bp->blocks[i] = block;
bp->hashes[i] = block->RO.hash2;
block->RO.firsttxidind = firsttxidind;
bp->firsttxidinds[i] = firsttxidind;
iguana_hash2set(coin,"bundleload",bp,i,block->RO.hash2);
if ( (prev= block->hh.prev) != 0 )
{
prev2 = prev->hh.prev;
@ -2304,10 +2332,12 @@ struct iguana_ramchain *iguana_bundleload(struct supernet_info *myinfo,struct ig
//_iguana_chainlink(coin,block); //wrong context
}
prev2 = prev, prev = block;
//printf("%p.%d ",block,block->RO.txn_count);
firsttxidind += block->RO.txn_count;
}
}
}
//printf("mapped bundle.[%d]\n",bp->hdrsi);
//printf("mapped bundle.[%d] numtxn.%d\n",bp->hdrsi,firsttxidind);
bp->emitfinish = (uint32_t)time(NULL) + 1;
iguana_bundlecalcs(myinfo,coin,bp,60);
}
@ -2348,10 +2378,10 @@ int64_t iguana_ramchainopen(char *fname,struct iguana_info *coin,struct iguana_r
if ( rdata->scriptspace > scriptspace )
scriptspace = rdata->scriptspace;
}
#ifndef __APPLE__
//#ifndef __APPLE__
numtxids *= 1.25; numexternaltxids *= 1.25, scriptspace *= 1.25;
numunspents *= 1.25, numspends *= 1.25, numpkinds *= 1.25;
#endif
//#endif
if ( mem->ptr == 0 )
{
while ( (allocsize= _iguana_rdata_action(fname,0,0,0,0,1,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,0,0,0,0,0,RAMCHAIN_ARG,numblocks,coin->chain->zcash)) > 2*1024LL*1024L*1024L )

28
iguana/iguana_recv.c

@ -78,7 +78,7 @@ int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,
return(0);
}
checkbp = 0, j = -2;
if ( (checkbp= iguana_bundlefind(coin,&checkbp,&j,hash2)) != 0 && j >= 0 && j < checkbp->n )
if ( (checkbp= iguana_bundlefind(coin,&checkbp,&j,hash2)) != 0 && j >= 0 && j < checkbp->n && checkbp != coin->current )
{
if ( checkbp->emitfinish != 0 || ((block= checkbp->blocks[j]) != 0 && block->txvalid != 0 && block->mainchain != 0 && block->valid != 0 && block->bundlei != 0 && coin->RTheight == 0) )
return(0);
@ -105,26 +105,29 @@ int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,
{
if ( (rand() % 10000) == 0 )
printf("iguana_sendblockreq (%s) addrind.%d hasn't verack'ed yet\n",addr->ipaddr,addr->addrind);
//iguana_send_version(coin,addr,coin->myservices);
return(-1);
iguana_send_version(coin,addr,coin->myservices);
//return(-1);
}
lastreq2 = lastreq;
lastreq = hash2;
if ( (len= iguana_getdata(coin,serialized,MSG_BLOCK,&hash2,1)) > 0 )
{
iguana_send(coin,addr,serialized,len);
coin->numreqsent++;
addr->pendblocks++;
addr->pendtime = (uint32_t)time(NULL);
if ( bp != 0 && bundlei >= 0 && bundlei < bp->n )
{
if ( coin->RTheight == 0 && bp != coin->current && bp->issued[bundlei] > 1 && addr->pendtime < bp->issued[bundlei]+7 )
{
//printf("SKIP.(%s) [%d:%d] %s n.%d\n",bits256_str(hexstr,hash2),bundlei,bp!=0?bp->hdrsi:-1,addr->ipaddr,addr->pendblocks);
return(0);
}
bp->issued[bundlei] = addr->pendtime;
}
iguana_send(coin,addr,serialized,len);
if ( block != 0 )
block->issued = addr->pendtime;
if ( 0 && coin->RTheight > 0 )//&& coin->current == bp )
if ( 0 && coin->current == bp )
printf("REQ.(%s) [%d:%d] %s n.%d\n",bits256_str(hexstr,hash2),bundlei,bp!=0?bp->hdrsi:-1,addr->ipaddr,addr->pendblocks);
} else printf("MSG_BLOCK null datalen.%d\n",len);
return(len);
@ -503,7 +506,7 @@ void iguana_oldgotblockM(struct supernet_info *myinfo,struct iguana_info *coin,s
{
numtx = origtxdata->zblock.RO.txn_count;
for (i=0; i<coin->bundlescount; i++)
if ( (bp= coin->bundles[i]) != 0 && bp->utxofinish <= 1 )
if ( (bp= coin->bundles[i]) != 0 && bp->emitfinish <= 1 )
break;
if ( (i > coin->bundlescount-2 && coin->blocks.hwmchain.height > coin->longestchain-coin->chain->bundlesize*2) || coin->RTheight > 0 )
{
@ -673,7 +676,7 @@ void iguana_RTgotblock(struct iguana_info *coin,bits256 hash2,uint8_t *data,int3
if ( coin->almostRT == 0 )
{
for (i=0; i<coin->bundlescount; i++)
if ( (bp= coin->bundles[i]) != 0 && bp->utxofinish <= 1 )
if ( (bp= coin->bundles[i]) != 0 && bp->emitfinish <= 1 )
break;
if ( (i > coin->bundlescount-2 && coin->blocks.hwmchain.height > coin->longestchain-coin->chain->bundlesize*2) || coin->RTheight > 0 )
coin->almostRT = 1;
@ -774,6 +777,7 @@ void iguana_gotblockM(struct supernet_info *myinfo,struct iguana_info *coin,stru
}
if ( bp == 0 )
{
printf("gotblockM no bp %s\n",bits256_str(str,origtxdata->zblock.RO.hash2));
req = iguana_recv_bundlereq(coin,addr,0,H,data,recvlen,0,-1,origtxdata);
queue_enqueue("recvQ",&coin->recvQ,&req->DL,0);
return;
@ -787,6 +791,7 @@ void iguana_gotblockM(struct supernet_info *myinfo,struct iguana_info *coin,stru
{
req = iguana_recv_bundlereq(coin,addr,0,H,data,recvlen,0,-1,origtxdata);
queue_enqueue("recvQ",&coin->recvQ,&req->DL,0);
//printf("negative speculative return %s\n",bits256_str(str,origtxdata->zblock.RO.hash2));
return;
}
/*if ( block == 0 )
@ -807,12 +812,14 @@ void iguana_gotblockM(struct supernet_info *myinfo,struct iguana_info *coin,stru
}
numtx = origtxdata->zblock.RO.txn_count;
iguana_RTgotblock(coin,origtxdata->zblock.RO.hash2,data,&recvlen,&numtx);
//printf("getblockM update [%d:%d] %s\n",bp->hdrsi,bundlei,bits256_str(str,origtxdata->zblock.RO.hash2));
if ( 0 && bp == coin->current )
printf("getblockM update [%d:%d] %s %p\n",bp->hdrsi,bundlei,bits256_str(str,origtxdata->zblock.RO.hash2),block);
if ( block != 0 )
{
if ( block->height < 0 )
block->bundlei = -1;
block->txvalid = 1;
block->RO.txn_count = origtxdata->zblock.RO.txn_count;
if ( block->fpipbits != 0 && block->fpos >= 0 )
{
static int32_t numredundant; static double redundantsize; static uint32_t lastdisp;
@ -841,9 +848,8 @@ void iguana_gotblockM(struct supernet_info *myinfo,struct iguana_info *coin,stru
copyflag = (coin->enableCACHE != 0) && (strcmp(coin->symbol,"BTC") != 0);
req = iguana_recv_bundlereq(coin,addr,copyflag,H,data,recvlen,bp,bundlei,txdata);
queue_enqueue("recvQ",&coin->recvQ,&req->DL,0);
if ( 0 && strcmp("BTCD",coin->symbol) == 0 )
if ( 0 && bp->hdrsi == 0 && strcmp("SYS",coin->symbol) == 0 )
printf("[%d:%d].s%d %s Q.(%s) %s\n",bp->hdrsi,bundlei,numsaved,coin->symbol,bits256_str(str,origtxdata->zblock.RO.hash2),addr->ipaddr);
//if ( (bp == coin->current || (coin->peers != 0 && ) && (rand() % coin->chain->bundlesize) < numsaved )
if ( numsaved < coin->chain->bundlesize )
{
for (i=numsaved=0; i<coin->chain->bundlesize; i++)
@ -2086,7 +2092,7 @@ int32_t iguana_blockQ(char *argstr,struct iguana_info *coin,struct iguana_bundle
{
if ( bp->emitfinish != 0 )
return(0);
if ( coin->RTheight == 0 && bp->issued[bundlei] > 0 )
if ( bp != coin->current && coin->RTheight == 0 && bp->issued[bundlei] > 0 )
return(0);
}
if ( priority != 0 )

17
iguana/iguana_spendvectors.c

@ -261,7 +261,7 @@ int32_t iguana_spendvectors(struct supernet_info *myinfo,struct iguana_info *coi
{
bp->tmpspends = ramchain->Xspendinds;
bp->numtmpspends = ramchain->numXspends;
bp->utxofinish = (uint32_t)time(NULL);
bp->emitfinish = (uint32_t)time(NULL);
bp->balancefinish = 0;
//printf("iguana_spendvectors.[%d]: already have Xspendinds[%d]\n",bp->hdrsi,ramchain->numXspends);
return(0);
@ -622,7 +622,7 @@ int32_t iguana_volatilesinit(struct supernet_info *myinfo,struct iguana_info *co
{
if ( (bp= coin->bundles[i]) == 0 )
continue;
if ( bp->emitfinish <= 1 || (i > 0 && bp->utxofinish <= 1) )
if ( bp->emitfinish <= 1 || (i > 0 && bp->emitfinish <= 1) )
{
//printf("hdrsi.[%d] emitfinish.%u utxofinish.%u\n",i,bp->emitfinish,bp->utxofinish);
continue;
@ -753,11 +753,11 @@ void iguana_initfinal(struct supernet_info *myinfo,struct iguana_info *coin,bits
{
if ( (bp= coin->bundles[i]) == 0 || bp->emitfinish <= 1 )
{
printf("%s initfinal break.[%d]: bp.%p or emit.%u utxofinish.%u\n",coin->symbol,i,bp,bp!=0?bp->emitfinish:-1,bp!=0?bp->utxofinish:-1);
printf("%s initfinal break.[%d]: bp.%p or emit.%u utxofinish.%u\n",coin->symbol,i,bp,bp!=0?bp->emitfinish:-1,bp!=0?bp->emitfinish:-1);
break;
}
if ( i == 0 )
bp->utxofinish = bp->startutxo = (uint32_t)time(NULL);
bp->emitfinish = bp->startutxo = (uint32_t)time(NULL);
}
if ( i < coin->bundlescount-1 )
{
@ -765,7 +765,7 @@ void iguana_initfinal(struct supernet_info *myinfo,struct iguana_info *coin,bits
for (i=0; i<coin->bundlescount-1; i++)
{
if ( (bp= coin->bundles[i]) != 0 )
bp->startutxo = bp->utxofinish = bp->converted = bp->balancefinish = bp->validated = 0;
bp->startutxo = bp->emitfinish = bp->converted = bp->balancefinish = bp->validated = 0;
}
}
else
@ -1105,9 +1105,10 @@ int32_t iguana_bundlevalidate(struct supernet_info *myinfo,struct iguana_info *c
if ( coin->chain->zcash != 0 )
{
printf("need to process joinsplits before can validate.%s\n",coin->symbol);
bp->validated = (uint32_t)time(NULL);
return(bp->n);
}
if ( (coin->MAXPEERS > 1 && coin->VALIDATENODE == 0 && coin->FULLNODE == 0) || bp->ramchain.from_ro != 0 || bp == coin->current )
if ( (coin->MAXPEERS > 1 && coin->VALIDATENODE == 0 && coin->FULLNODE == 0) || bp->ramchain.from_ro != 0 )//|| bp == coin->current )
{
bp->validated = (uint32_t)time(NULL);
return(bp->n);
@ -1159,7 +1160,7 @@ int32_t iguana_bundlevalidate(struct supernet_info *myinfo,struct iguana_info *c
printf("%s %s VALIDATED.[%d] ht.%d duration.%d errs.%d total.%lld %u | total errs.%d validated.%d %llx\n",coin->symbol,errs!=0?"NOT":"",bp->hdrsi,bp->bundleheight,(uint32_t)time(NULL) - now,errs,(long long)total,bp->validated,totalerrs,totalvalidated,(long long)validatehash.txid);
if ( errs == 0 )
bp->validated = (uint32_t)time(NULL);
else bp->startutxo = bp->utxofinish = 0;
else bp->startutxo = bp->emitfinish = 0;
//iguana_volatilesmap(coin,&bp->ramchain);
//if ( bp == coin->current )
// coin->RTdatabad = -1;
@ -1178,7 +1179,7 @@ int32_t iguana_bundlevalidate(struct supernet_info *myinfo,struct iguana_info *c
if ( errs != 0 )
{
printf("%s remove.[%d]\n",coin->symbol,bp->hdrsi);
//iguana_bundleremove(coin,bp->hdrsi,0);
iguana_bundleremove(coin,bp->hdrsi,0);
return(-errs);
}
return(bp->n - errs);

25
iguana/iguana_tx.c

@ -152,19 +152,19 @@ struct iguana_txid *iguana_blocktx(struct iguana_info *coin,struct iguana_txid *
struct iguana_bundle *bp; uint32_t txidind;
if ( i >= 0 && i < block->RO.txn_count )
{
if ( block->height >= 0 )
if ( block->height >= 0 && block->bundlei >= 0 && block->bundlei < coin->chain->bundlesize )
{
if ( (bp= coin->bundles[block->hdrsi]) != 0 )
{
if ( (txidind= block->RO.firsttxidind) > 0 )
if ( (txidind= block->RO.firsttxidind) == bp->firsttxidinds[block->bundlei] )
{
if ( iguana_bundletx(coin,bp,block->bundlei,tx,txidind+i) == tx )
return(tx);
printf("error getting txidind.%d + i.%d from hdrsi.%d\n",txidind,i,block->hdrsi);
return(0);
} else printf("iguana_blocktx null txidind [%d:%d] i.%d\n",block->hdrsi,block->bundlei,i);
} else printf("iguana_blocktx null txidind [%d:%d] i.%d txidind.%d vs %d\n",block->hdrsi,block->bundlei,i,txidind,bp->firsttxidinds[block->bundlei]);
} else printf("iguana_blocktx no bp.[%d]\n",block->hdrsi);
} else printf("%s blocktx illegal height.%d\n",coin->symbol,block->height);
} else printf("%s blocktx illegal height.%d or [%d:%d]\n",coin->symbol,block->height,block->hdrsi,block->bundlei);
} else printf("i.%d vs txn_count.%d\n",i,block->RO.txn_count);
return(0);
}
@ -178,16 +178,12 @@ int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t m
version = tx->version;
locktime = tx->locktime;
timestamp = tx->timestamp;
numvins = tx->numvins;
numvouts = tx->numvouts;
}
len += iguana_rwnum(rwflag,&serialized[len],sizeof(version),&version);
if ( coin->chain->isPoS != 0 )
len += iguana_rwnum(rwflag,&serialized[len],sizeof(timestamp),&timestamp);
if ( rwflag == 0 )
{
tx->version = version;
tx->timestamp = timestamp;
}
numvins = tx->numvins, numvouts = tx->numvouts;
len += iguana_rwvarint32(rwflag,&serialized[len],&numvins);
memset(&vin,0,sizeof(vin));
for (i=0; i<numvins; i++)
@ -233,7 +229,13 @@ int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t m
}
len += iguana_rwnum(rwflag,&serialized[len],sizeof(locktime),&locktime);
if ( rwflag == 0 )
{
tx->version = version;
tx->timestamp = timestamp;
tx->numvins = numvins;
tx->numvouts = numvouts;
tx->locktime = locktime;
}
*txidp = bits256_doublesha256(txidstr,serialized,len);
if ( memcmp(txidp,tx->txid.bytes,sizeof(*txidp)) != 0 )
{
@ -272,6 +274,7 @@ int32_t iguana_peerblockrequest(struct supernet_info *myinfo,struct iguana_info
{
if ( (tx= iguana_blocktx(coin,&T,block,i)) != 0 )
{
//printf("ht.%d [%d:%d] txi.%d i.%d o.%d %s\n",block->height,block->hdrsi,block->bundlei,i,tx->numvins,tx->numvouts,bits256_str(str,tx->txid));
if ( (len= iguana_ramtxbytes(coin,&blockspace[sizeof(struct iguana_msghdr) + total],max - total,&checktxid,tx,block->height,0,0,validatesigs)) > 0 )//&& bits256_cmp(checktxid,T.txid) == 0 )
total += len;
else
@ -341,7 +344,7 @@ int32_t iguana_peerblockrequest(struct supernet_info *myinfo,struct iguana_info
//printf("validated.[%d:%d] len.%d\n",bp->hdrsi,bundlei,total);
return(total);
}
} else printf("iguana_peerblockrequest: %s error merkle cmp tx.[%d] for ht.%d\n",coin->symbol,i,bp->bundleheight+bundlei);
} else printf("iguana_peerblockrequest: %s error %s merkle cmp tx.[%d] for ht.%d\n",coin->symbol,bits256_str(str,block->RO.hash2),i,bp->bundleheight+bundlei);
} else printf("iguana_peerblockrequest: error merkle verify tx.[%d] for ht.%d\n",i,bp->bundleheight+bundlei);
}
else

4
includes/iguana_structs.h

@ -374,13 +374,13 @@ struct iguana_bundle
{
struct queueitem DL; struct iguana_info *coin; struct iguana_bundle *nextbp;
struct iguana_bloom16 bloom; int64_t totaldurations,duplicatedurations; int32_t durationscount,duplicatescount;
uint32_t issuetime,hdrtime,emitfinish,mergefinish,purgetime,queued,startutxo,utxofinish,balancefinish,validated,lastspeculative,dirty,nexttime,currenttime,lastprefetch,lastRT,missingstime,unsticktime,converted;
uint32_t issuetime,hdrtime,emitfinish,mergefinish,purgetime,queued,startutxo,balancefinish,validated,lastspeculative,dirty,nexttime,currenttime,lastprefetch,lastRT,missingstime,unsticktime,converted;
int32_t numhashes,numrecv,numsaved,numcached,generrs,currentflag,origmissings,numissued,Xvalid;
int32_t minrequests,n,hdrsi,bundleheight,numtxids,numspends,numunspents,numspec,isRT;
double avetime,threshold,metric; uint64_t datasize,estsize;
struct iguana_block *blocks[IGUANA_MAXBUNDLESIZE];
uint8_t *speculativecache[IGUANA_MAXBUNDLESIZE],haveblock[IGUANA_MAXBUNDLESIZE/3+1];
uint32_t issued[IGUANA_MAXBUNDLESIZE];
uint32_t issued[IGUANA_MAXBUNDLESIZE],firsttxidinds[IGUANA_MAXBUNDLESIZE];
bits256 prevbundlehash2,hashes[IGUANA_MAXBUNDLESIZE+1],nextbundlehash2,allhash,*speculative,validatehash;
struct iguana_ramchain ramchain; uint8_t red,green,blue;
struct iguana_spendvector *tmpspends; int32_t numtmpspends;

Loading…
Cancel
Save