This commit is contained in:
jl777
2016-11-18 08:07:26 -03:00
parent 29eccc7caf
commit e21ffa1d2f
4 changed files with 15 additions and 51 deletions

View File

@@ -170,19 +170,19 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char
void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout) void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout)
{ {
static FILE *fp; static int32_t errs; static FILE *fp; static int32_t errs;
struct komodo_state *sp; char fname[512],fname2[512],symbol[16],dest[16]; int32_t ht,func; uint8_t num,pubkeys[64][33]; struct komodo_state *sp; char fname[512],symbol[16],dest[16]; int32_t ht,func; uint8_t num,pubkeys[64][33];
if ( (sp= komodo_stateptr(symbol,dest)) == 0 ) if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
return; return;
if ( fp == 0 ) if ( fp == 0 )
{ {
#ifdef WIN32 #ifdef WIN32
sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"komodostate"); sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"komodostate");
sprintf(fname2,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"minerids"); //sprintf(fname2,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"minerids");
#else #else
sprintf(fname,"%s/%s",GetDataDir(false).string().c_str(),(char *)"komodostate"); sprintf(fname,"%s/%s",GetDataDir(false).string().c_str(),(char *)"komodostate");
sprintf(fname2,"%s/%s",GetDataDir(false).string().c_str(),(char *)"minerids"); //sprintf(fname2,"%s/%s",GetDataDir(false).string().c_str(),(char *)"minerids");
#endif #endif
memset(Minerids,0xfe,sizeof(Minerids)); /*memset(Minerids,0xfe,sizeof(Minerids));
if ( (Minerfp= fopen(fname2,"rb+")) == 0 ) if ( (Minerfp= fopen(fname2,"rb+")) == 0 )
{ {
if ( (Minerfp= fopen(fname2,"wb")) != 0 ) if ( (Minerfp= fopen(fname2,"wb")) != 0 )
@@ -193,7 +193,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
Minerfp = fopen(fname2,"rb+"); Minerfp = fopen(fname2,"rb+");
} }
if ( Minerfp != 0 && fread(Minerids,1,sizeof(Minerids),Minerfp) != sizeof(Minerids) ) if ( Minerfp != 0 && fread(Minerids,1,sizeof(Minerids),Minerfp) != sizeof(Minerids) )
printf("read error Minerids\n"); printf("read error Minerids\n");*/
if ( (fp= fopen(fname,"rb+")) != 0 ) if ( (fp= fopen(fname,"rb+")) != 0 )
{ {
while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 )
@@ -456,7 +456,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len); memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len);
#endif #endif
notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,&notarizedheight,(uint64_t)block.vtx[i].vout[j].nValue); notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,&notarizedheight,(uint64_t)block.vtx[i].vout[j].nValue);
if ( i == 0 && j == 0 && komodo_chosennotary(&nid,height,scriptbuf + 1) >= 0 ) /*if ( i == 0 && j == 0 && komodo_chosennotary(&nid,height,scriptbuf + 1) >= 0 )
{ {
if ( height < sizeof(Minerids)/sizeof(*Minerids) ) if ( height < sizeof(Minerids)/sizeof(*Minerids) )
{ {
@@ -470,7 +470,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
} }
} }
} }
} }*/
if ( 0 && i > 0 ) if ( 0 && i > 0 )
{ {
for (k=0; k<len; k++) for (k=0; k<len; k++)

View File

@@ -377,7 +377,7 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block)
{ {
//int32_t i; uint256 hash; //int32_t i; uint256 hash;
komodo_init(pindex->nHeight); komodo_init(pindex->nHeight);
Minerids[pindex->nHeight] = -2; //Minerids[pindex->nHeight] = -2;
//hash = block.GetHash(); //hash = block.GetHash();
//for (i=0; i<32; i++) //for (i=0; i<32; i++)
// printf("%02x",((uint8_t *)&hash)[i]); // printf("%02x",((uint8_t *)&hash)[i]);
@@ -492,53 +492,17 @@ int8_t komodo_minerid(int32_t height)
} }
} }
return(-1); return(-1);
/*if ( Minerids[height] >= -1 )
{
printf("cached[%d] -> %d\n",height,Minerids[height]);
return(Minerids[height]);
}
if ( depth < 1 )
{
if ( (pindex= chainActive[height]) != 0 )
{
depth++;
komodo_index2pubkey33(pubkey33,pindex,height);
komodo_chosennotary(&notaryid,height,pubkey33);
if ( notaryid >= -1 )
{
Minerids[height] = notaryid;
if ( Minerfp != 0 )
{
fseek(Minerfp,height,SEEK_SET);
fputc(Minerids[height],Minerfp);
fflush(Minerfp);
}
}
depth--;
return(notaryid);
}
}
return(-2);*/
} }
int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]) int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33])
{ {
int32_t i,notaryid; int32_t i,notaryid,minerid;
komodo_chosennotary(&notaryid,height,pubkey33); komodo_chosennotary(&notaryid,height,pubkey33);
if ( height >= 34000 && notaryid >= 0 ) if ( height >= 34000 && notaryid >= 0 )
{ {
for (i=1; i<64; i++) for (i=1; i<64; i++)
{ {
if ( Minerids[height-i] == -2 ) if ( komodo_minerid(height-i) == notaryid )
{
Minerids[height-i] = komodo_minerid(height-i);
if ( Minerids[height - i] == -2 )
{
fprintf(stderr,"second -2 for Minerids[%d] current.%d\n",height-i,height);
return(-2);
}
}
if ( Minerids[height-i] == notaryid )
return(-1); return(-1);
} }
return(1); return(1);
@@ -567,7 +531,7 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has
return(-1); return(-1);
} }
} else fprintf(stderr,"unexpected error notary_hash %s ht.%d at ht.%d\n",notarized_hash.ToString().c_str(),notarized_height,notary->nHeight); } else fprintf(stderr,"unexpected error notary_hash %s ht.%d at ht.%d\n",notarized_hash.ToString().c_str(),notarized_height,notary->nHeight);
} else if ( notarized_height > 0 ) } else if ( notarized_height > 0 && notarized_height != 73880 )
fprintf(stderr,"couldnt find notary_hash %s ht.%d\n",notarized_hash.ToString().c_str(),notarized_height); fprintf(stderr,"couldnt find notary_hash %s ht.%d\n",notarized_hash.ToString().c_str(),notarized_height);
return(0); return(0);
} }

View File

@@ -23,8 +23,8 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33)
pthread_mutex_t komodo_mutex; pthread_mutex_t komodo_mutex;
FILE *Minerfp; //FILE *Minerfp;
int8_t Minerids[KOMODO_MAXBLOCKS]; // 5 million blocks //int8_t Minerids[KOMODO_MAXBLOCKS]; // 5 million blocks
#define KOMODO_ELECTION_GAP ((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100) #define KOMODO_ELECTION_GAP ((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100)
int32_t KMDHEIGHT = 43000; int32_t KMDHEIGHT = 43000;

View File

@@ -264,8 +264,8 @@ void komodo_init(int32_t height)
komodo_notarysinit(0,pubkeys,k); komodo_notarysinit(0,pubkeys,k);
} }
memset(&zero,0,sizeof(zero)); memset(&zero,0,sizeof(zero));
for (i=0; i<sizeof(Minerids); i++) //for (i=0; i<sizeof(Minerids); i++)
Minerids[i] = -2; // Minerids[i] = -2;
didinit = 1; didinit = 1;
} }
komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,0,0,0,0); komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,0,0,0,0);