diff --git a/src/komodo.h b/src/komodo.h index b431bda48..e6f44ff02 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -34,6 +34,7 @@ #include "utlist.h" int32_t gettxout_scriptPubKey(uint8_t *scriptPubkey,int32_t maxsize,uint256 txid,int32_t n); +void komodo_event_rewind(struct komodo_state *sp,char *symbol,int32_t height); #include "komodo_structs.h" #include "komodo_globals.h" @@ -83,7 +84,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char //printf("fpos.%ld func.(%d %c) ht.%d ",ftell(fp),func,func,ht); if ( func == 'P' ) { - if ( (num= fgetc(fp)) < 64 ) + if ( (num= fgetc(fp)) <= 64 ) { if ( fread(pubkeys,33,num,fp) != num ) errs++; @@ -241,7 +242,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } else if ( notarypubs != 0 && numnotaries > 0 ) { - //printf("ht.%d func P[%d] errs.%d\n",height,numnotaries,errs); + printf("ht.%d func P[%d] errs.%d\n",height,numnotaries,errs); fputc('P',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5ee55ec29..80b300b3d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -375,16 +375,11 @@ uint64_t komodo_seed(int32_t height) void komodo_disconnect(CBlockIndex *pindex,CBlock& block) { - //int32_t i; uint256 hash; + char base[16],dest[16]; struct komodo_state *sp; komodo_init(pindex->nHeight); - //Minerids[pindex->nHeight] = -2; - //hash = block.GetHash(); - //for (i=0; i<32; i++) - // printf("%02x",((uint8_t *)&hash)[i]); - //printf(" <- disconnect block\n"); - //uint256 zero; - //printf("disconnect ht.%d\n",pindex->nHeight); - //memset(&zero,0,sizeof(zero)); + if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) + komodo_event_rewind(sp,symbol,pindex->nHeight); + komodo_stateupdate(); } int32_t komodo_is_notarytx(const CTransaction& tx) @@ -464,14 +459,6 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) return; } komodo_block2pubkey33(pubkey33,block); -/* if ( ReadBlockFromDisk(block,(const CBlockIndex *)pindex -#ifndef KOMODO_ZCASH - ,Params().GetConsensus() -#endif - ) != 0 ) - { - komodo_block2pubkey33(pubkey33,block); - }*/ } else { diff --git a/src/komodo_events.h b/src/komodo_events.h index fb1ca452c..017fcb145 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -27,6 +27,7 @@ #define KOMODO_EVENT_NOTARIZED 'N' #define KOMODO_EVENT_UTXO 'U' #define KOMODO_EVENT_KMDHEIGHT 'K' +#define KOMODO_EVENT_REWIND 'B' //#define KOMODO_EVENT_DELETE 'D' #define KOMODO_EVENT_PRICEFEED 'V' #define KOMODO_EVENT_OPRETURN 'R' @@ -84,6 +85,7 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig void komodo_eventadd_pubkeys(struct komodo_state *sp,char *symbol,int32_t height,uint8_t num,uint8_t pubkeys[64][33]) { struct komodo_event_pubkeys P; + printf("eventadd pubkeys ht.%d\n",height); memset(&P,0,sizeof(P)); P.num = num; memcpy(P.pubkeys,pubkeys,33 * num); @@ -151,17 +153,22 @@ void komodo_event_undo(struct komodo_event *ep) } } -void komodo_event_rewind(int32_t height) +void komodo_event_rewind(struct komodo_state *sp,char *symbol,int32_t height) { struct komodo_event *ep; - while ( Komodo_numevents > 0 ) + komodo_eventadd(height,symbol,KOMODO_EVENT_REWIND,(uint8_t *)&height,sizeof(height)); + if ( sp != 0 ) { - if ( (ep= Komodo_events[Komodo_numevents-1]) != 0 ) + while ( Komodo_numevents > 0 ) { - if ( ep->height < height ) - break; - komodo_event_undo(ep); - Komodo_numevents--; + if ( (ep= Komodo_events[Komodo_numevents-1]) != 0 ) + { + if ( ep->height < height ) + break; + printf("undo event.%c ht.%d for rewind.%d\n",ep->type,ep->height,height); + komodo_event_undo(ep); + Komodo_numevents--; + } } } } diff --git a/src/komodo_notary.h b/src/komodo_notary.h index e66fec47e..08042abac 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -130,7 +130,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) height /= KOMODO_ELECTION_GAP; height = ((height + 1) * KOMODO_ELECTION_GAP); htind = (height / KOMODO_ELECTION_GAP); - printf("htind.%d activation %d from %d\n",htind,height,origheight); + printf("htind.%d activation %d from %d vs %d\n",htind,height,origheight,(((origheight+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP); } else htind = 0; pthread_mutex_lock(&komodo_mutex); for (k=0; k