From d1b6fc98299fb14c38b15aa0e6b32e786c7dd04f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Feb 2018 10:11:16 +0200 Subject: [PATCH] Move free bp to main thread --- iguana/dpow/dpow_fsm.c | 27 +++------------------------ iguana/dpow/dpow_rpc.c | 2 +- iguana/iguana_notary.c | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c index f7d5daa81..fa5fb485e 100755 --- a/iguana/dpow/dpow_fsm.c +++ b/iguana/dpow/dpow_fsm.c @@ -205,6 +205,7 @@ void dpow_statemachinestart(void *ptr) { fprintf(stderr,"cant ratify more than 64 notaries ratified has %d\n",numratified); free(ptr); + free_json(ratified); return; } for (i=0; inumratified = numratified; bp->ratified = ratified; printf("numratified.%d %s\n",numratified,jprint(ratified,0)); - } - else - { - printf("i.%d numratified.%d\n",i,numratified); - free_json(ratified); - } + } else printf("i.%d numratified.%d\n",i,numratified); } + free_json(ratified); } bp->bestk = -1; dp->blocks[checkpoint.blockhash.height] = bp; bp->beacon = rand256(0); vcalc_sha256(0,bp->commit.bytes,bp->beacon.bytes,sizeof(bp->beacon)); - /*if ( checkpoint.blockhash.height >= DPOW_FIRSTRATIFY && dp->blocks[checkpoint.blockhash.height - DPOW_FIRSTRATIFY] != 0 ) - { - printf("purge %s.%d\n",dp->dest,checkpoint.blockhash.height - DPOW_FIRSTRATIFY); - free(dp->blocks[checkpoint.blockhash.height - DPOW_FIRSTRATIFY]); - dp->blocks[checkpoint.blockhash.height - DPOW_FIRSTRATIFY] = 0; - }*/ } if ( bp->isratify != 0 && dp->ratifying != 0 ) { @@ -470,18 +461,6 @@ void dpow_statemachinestart(void *ptr) dp->lastrecvmask = bp->recvmask; dp->ratifying -= bp->isratify; // dp->blocks[bp->height] = 0; - if ( bp->height > 100 ) - { - for (i=bp->height-100; i>=0; i--) - { - if ( (tmp= dp->blocks[i]) != 0 ) - { - dp->blocks[i] = 0; - free(tmp); - Numallocated--; - } - } - } free(ptr); } diff --git a/iguana/dpow/dpow_rpc.c b/iguana/dpow/dpow_rpc.c index 5f695f84a..ec271e5a8 100755 --- a/iguana/dpow/dpow_rpc.c +++ b/iguana/dpow/dpow_rpc.c @@ -569,7 +569,7 @@ char *dpow_sendrawtransaction(struct supernet_info *myinfo,struct iguana_info *c jaddistr(array,signedtx); paramstr = jprint(array,1); retstr = bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"sendrawtransaction",paramstr); - printf(">>>>>>>>>>> %s dpow_sendrawtransaction.(%s) -> (%s)\n",coin->symbol,paramstr,retstr); + printf(">>>>>>>>>>> %s dpow_sendrawtransaction (%s)\n",coin->symbol,retstr); free(paramstr); return(retstr); } diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index 5297e8bed..cac141dd2 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -135,7 +135,7 @@ int32_t dpow_hasnotarization(struct supernet_info *myinfo,struct iguana_info *co void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t height,bits256 hash,uint32_t timestamp,uint32_t blocktime) { - void **ptrs; char str[65]; cJSON *blockjson; struct iguana_info *coin; struct dpow_checkpoint checkpoint; int32_t freq,minsigs; //uint8_t pubkeys[64][33]; + void **ptrs; char str[65]; cJSON *blockjson; struct iguana_info *coin; struct dpow_checkpoint checkpoint; int32_t freq,minsigs,i,ht; struct dpow_block *bp; dpow_checkpointset(myinfo,&dp->last,height,hash,timestamp,blocktime); checkpoint = dp->srcfifo[dp->srcconfirms]; if ( strcmp("BTC",dp->dest) == 0 ) @@ -203,9 +203,22 @@ void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t he ptrs[4] = 0; memcpy(&ptrs[5],&checkpoint,sizeof(checkpoint)); dp->activehash = checkpoint.blockhash.hash; + ht = checkpoint.blockhash.height; if ( OS_thread_create((void *)((uint64_t)&ptrs[5] + sizeof(struct dpow_checkpoint)),NULL,(void *)dpow_statemachinestart,(void *)ptrs) != 0 ) { } + if ( ht > 100 ) + { + for (i=ht-100; i>=0; i--) + { + if ( (bp= dp->blocks[i]) != 0 ) + { + dp->blocks[i] = 0; + Numallocated--; + free(bp); + } + } + } } }