diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index f69d7a776..7e1526cf3 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -390,12 +390,15 @@ struct iguana_txid *iguana_bundletx(struct iguana_info *coin,struct iguana_bundl { static const bits256 zero; int32_t hdrsi,iter; struct iguana_txid *T; int64_t Toffset; char fname[1024]; FILE *fp; struct iguana_ramchaindata rdata,*rptr; - if ( (rptr= bp->ramchain.H.data) != 0 )//|| (bp == coin->current && (rptr= coin->RTramchain.H.data) != 0) ) + portable_mutex_lock(&coin->special_mutex); + if ( (rptr= bp->ramchain.H.data) != 0 || (bp == coin->current && (rptr= coin->RTramchain.H.data) != 0) ) { T = RAMCHAIN_PTR(rptr,Toffset); *tx = T[txidind]; + portable_mutex_unlock(&coin->special_mutex); return(tx); } + portable_mutex_unlock(&coin->special_mutex); printf("bundletx without ramchain\n"); for (iter=0; iter<2; iter++) { diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index b10e0d4a2..9c3614a81 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -73,6 +73,7 @@ void iguana_initcoin(struct iguana_info *coin,cJSON *argjson) usleep(1); coin->startutc++; printf("start.%u\n",coin->startutc); + portable_mutex_init(&coin->special_mutex); coin->startmillis = OS_milliseconds(), coin->starttime = tai_now(); coin->avetime = 1 * 100; //coin->R.maxrecvbundles = IGUANA_INITIALBUNDLES; diff --git a/iguana/iguana_volatiles.c b/iguana/iguana_volatiles.c index bba065623..d6abe281e 100755 --- a/iguana/iguana_volatiles.c +++ b/iguana/iguana_volatiles.c @@ -209,7 +209,6 @@ int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struc } } printf("iguana_volatileupdate.%d: [%d] spent.(u%u %.8f pkind.%d) double spend? at ht.%d [%d] spendind.%d (%p %p)\n",incremental,spent_hdrsi,spent_unspentind,dstr(spent_value),spent_pkind,fromheight,fromheight/coin->chain->bundlesize,spendind,spentchain->Uextras,spentchain->A2); - coin->RTdatabad = 1; /*if ( coin->current != 0 && fromheight >= coin->current->bundleheight ) coin->RTdatabad = 1; else @@ -220,12 +219,23 @@ int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struc coin->spendvectorsaved = 0; coin->started = 0; coin->active = 0;*/ + coin->RTdatabad = 1; if ( coin->current != 0 && spent_hdrsi != coin->current->hdrsi && spent_hdrsi != fromheight/coin->chain->bundlesize ) { printf("restart iguana\n"); - iguana_bundleremove(coin,spent_hdrsi,0); - iguana_bundleremove(coin,fromheight/coin->chain->bundlesize,0); - //sleep(3); + struct iguana_bundle *bp; + portable_mutex_lock(&coin->special_mutex); + if ( (bp= coin->bundles[spent_hdrsi]) != 0 ) + { + iguana_bundleremove(coin,spent_hdrsi,0); + bp->ramchain.H.data = 0; + } + if ( (bp= coin->bundles[fromheight/coin->chain->bundlesize]) != 0 ) + { + iguana_bundleremove(coin,fromheight/coin->chain->bundlesize,0); + bp->ramchain.H.data = 0; + } + portable_mutex_unlock(&coin->special_mutex); exit(-1); } } diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h index 20c7ce0c9..987a4b64c 100755 --- a/includes/iguana_structs.h +++ b/includes/iguana_structs.h @@ -401,7 +401,7 @@ struct iguana_info struct OS_memspace TXMEM,MEM,MEMB[IGUANA_MAXBUNDLESIZE]; queue_t acceptQ,hdrsQ,blocksQ,priorityQ,possibleQ,cacheQ,recvQ,msgrequestQ; double parsemillis,avetime; uint32_t Launched[8],Terminated[8]; - portable_mutex_t peers_mutex,blocks_mutex; + portable_mutex_t peers_mutex,blocks_mutex,special_mutex; char changeaddr[64]; struct iguana_bundle *bundles[IGUANA_MAXBUNDLES],*current,*lastpending; struct iguana_ramchain RTramchain; struct OS_memspace RTmem,RThashmem; bits256 RThash1;