diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 5f6ae1f52..85889274f 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -26,7 +26,7 @@ typedef int32_t (*blockhashfunc)(uint8_t *blockhashp,uint8_t *serialized,int32_t #define IGUANA_SERIALIZE_SPENDVECTORGEN //#define IGUANA_SERIALIZE_BALANCEGEN //#define IGUANA_DISABLEPEERS -#define _IGUANA_MAXSTUCKTIME 77 +#define _IGUANA_MAXSTUCKTIME 300 #define IGUANA_MAXCOINS 64 #define IGUANA_MAXDELAY_MILLIS (3600 * 1000) diff --git a/iguana/iguana_blocks.c b/iguana/iguana_blocks.c index bfee915f5..64ceb9036 100755 --- a/iguana/iguana_blocks.c +++ b/iguana/iguana_blocks.c @@ -274,7 +274,7 @@ struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_bl if ( newblock == 0 ) return(0); hwmchain = &coin->blocks.hwmchain; - if ( hwmchain->height > 0 && ((bp= coin->current) == 0 || hwmchain->height/coin->chain->bundlesize >= bp->hdrsi-coin->isRT) ) + if ( hwmchain->height > 0 && ((bp= coin->current) == 0 || hwmchain->height/coin->chain->bundlesize >= bp->hdrsi || hwmchain->height > coin->longestchain-bp->n) ) return(0); if ( (block= iguana_blockfind(coin,newblock->RO.hash2)) != 0 ) { diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index cfca282c3..a5c9664c0 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -844,7 +844,7 @@ int32_t iguana_bundlefinish(struct iguana_info *coin,struct iguana_bundle *bp) int32_t iguana_bundleiters(struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,int32_t timelimit) { - int32_t range,starti,lasti,i,n,len,retval=0,max,counter = 0; struct iguana_block *block; struct iguana_bundle *currentbp,*lastbp; uint8_t serialized[512]; struct iguana_peer *addr; long lag; + int32_t range,starti,lasti,i,n,len,retval=0,max,counter = 0; struct iguana_block *block; struct iguana_bundle *currentbp,*lastbp; uint8_t serialized[512]; struct iguana_peer *addr; long lag; struct iguana_blockreq *breq; if ( coin->started == 0 ) { printf("%s not ready yet\n",coin->symbol); @@ -932,16 +932,12 @@ int32_t iguana_bundleiters(struct iguana_info *coin,struct OS_memspace *mem,stru if ( coin->stucktime != 0 ) { lag = time(NULL)-coin->stucktime; - if ( lag == coin->MAXSTUCKTIME/2 || lag == 3*coin->MAXSTUCKTIME/4 ) + if ( (lag % 60) == 30 ) { - //if ( lag > coin->MAXSTUCKTIME/2 ) - { - struct iguana_blockreq *breq; - while ( (breq= queue_dequeue(&coin->blocksQ,0)) != 0 ) - myfree(breq,sizeof(*breq)); - while ( (breq= queue_dequeue(&coin->priorityQ,0)) != 0 ) - myfree(breq,sizeof(*breq)); - } + while ( (breq= queue_dequeue(&coin->blocksQ,0)) != 0 ) + myfree(breq,sizeof(*breq)); + while ( (breq= queue_dequeue(&coin->priorityQ,0)) != 0 ) + myfree(breq,sizeof(*breq)); for (i=n=0; i<bp->n; i++) { if ( (block= bp->blocks[i]) != 0 && (block->RO.recvlen == 0 || block->fpos < 0 || block->fpipbits == 0 || bits256_nonz(block->RO.prev_block) == 0) ) diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index edd02ed77..51f87ba6a 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -88,6 +88,41 @@ int32_t iguana_utxoupdate(struct iguana_info *coin,int16_t spent_hdrsi,uint32_t return(0); } +int32_t iguana_spentflag(struct iguana_info *coin,int32_t *spentheightp,struct iguana_ramchain *ramchain,int16_t spent_hdrsi,uint32_t spent_unspentind,int32_t height) +{ + uint32_t numunspents; struct iguana_hhutxo *hhutxo; struct iguana_utxo utxo; + uint8_t ubuf[sizeof(uint32_t) + sizeof(int16_t)]; + *spentheightp = 0; + numunspents = (ramchain == &coin->RTramchain) ? ramchain->H.unspentind : ramchain->H.data->numunspents; + memset(&utxo,0,sizeof(utxo)); + if ( spent_unspentind != 0 && spent_unspentind < numunspents ) + { + if ( (hhutxo= iguana_hhutxofind(coin,ubuf,spent_hdrsi,spent_unspentind)) != 0 && hhutxo->u.spentflag != 0 ) + utxo = hhutxo->u; + else if ( ramchain->Uextras != 0 ) + utxo = ramchain->Uextras[spent_unspentind]; + else + { + printf("null ramchain->Uextras unspentind.%u vs %u hdrs.%d\n",spent_unspentind,numunspents,spent_hdrsi); + return(-1); + } + } + else + { + printf("illegal unspentind.%u vs %u hdrs.%d\n",spent_unspentind,numunspents,spent_hdrsi); + return(-1); + } + if ( utxo.fromheight == 0 ) + { + printf("illegal unspentind.%u vs %u hdrs.%d zero fromheight?\n",spent_unspentind,numunspents,spent_hdrsi); + return(-1); + } + *spentheightp = utxo.fromheight; + if ( height == 0 || utxo.fromheight < height ) + return(utxo.spentflag); + else return(0); +} + int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struct iguana_ramchain *spentchain,int16_t spent_hdrsi,uint32_t spent_unspentind,uint32_t spent_pkind,uint64_t spent_value,uint32_t spendind,uint32_t fromheight) { struct iguana_account *A2; struct iguana_ramchaindata *rdata; struct iguana_utxo *utxo; @@ -307,7 +342,7 @@ char *iguana_bundleaddrs(struct iguana_info *coin,int32_t hdrsi) int64_t iguana_pkhashbalance(struct iguana_info *coin,cJSON *array,int64_t *spentp,int32_t *nump,struct iguana_ramchain *ramchain,struct iguana_pkhash *p,uint32_t lastunspentind,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t hdrsi,int32_t height) { - struct iguana_unspent *U; uint32_t unspentind; int64_t balance = 0; struct iguana_txid *T; + struct iguana_unspent *U; int32_t spentheight; uint32_t unspentind; int64_t balance = 0; struct iguana_txid *T; *spentp = *nump = 0; if ( ramchain == &coin->RTramchain && coin->RTramchain_busy != 0 ) { @@ -326,8 +361,7 @@ int64_t iguana_pkhashbalance(struct iguana_info *coin,cJSON *array,int64_t *spen { (*nump)++; printf("%s u.%d %.8f\n",jprint(iguana_unspentjson(coin,hdrsi,unspentind,T,&U[unspentind],rmd160,coinaddr,pubkey33),1),unspentind,dstr(U[unspentind].value)); - //if ( iguana_spentflag(coin,ramchain,unspentind,height) == 0 ) - if ( ramchain->Uextras[unspentind].spentflag == 0 ) + if ( iguana_spentflag(coin,&spentheight,ramchain,hdrsi,unspentind,height) == 0 ) { balance += U[unspentind].value; if ( array != 0 )