Merge pull request #225 from jl777/dev

fix sync from scratch
This commit is contained in:
jl777
2017-03-12 15:31:31 +02:00
committed by GitHub
3 changed files with 24 additions and 7 deletions

View File

@@ -124,7 +124,7 @@ const char *Notaries_elected[][2] =
int32_t komodo_electednotary(uint8_t *pubkey33,int32_t height) int32_t komodo_electednotary(uint8_t *pubkey33,int32_t height)
{ {
char pubkeystr[67]; int32_t i; char pubkeystr[67]; int32_t i; uint8_t legacy33[33];
for (i=0; i<33; i++) for (i=0; i<33; i++)
sprintf(&pubkeystr[i*2],"%02x",pubkey33[i]); sprintf(&pubkeystr[i*2],"%02x",pubkey33[i]);
pubkeystr[66] = 0; pubkeystr[66] = 0;
@@ -137,6 +137,20 @@ int32_t komodo_electednotary(uint8_t *pubkey33,int32_t height)
return(i); return(i);
} }
} }
/*if ( height < 300000 )
{
for (i=0; i<sizeof(Notaries_genesis)/sizeof(*Notaries_genesis); i++)
{
if ( strcmp(pubkeystr,(char *)Notaries_genesis[i][1]) == 0 )
{
//printf("i.%d -> elected %s\n",i,(char *)Notaries_elected[i][1]);
return(i+64);
}
}
decode_hex(legacy33,33,(char *)"0252b6185bf8ea7efe8bbc345ddc8da87329149f30233088387abd716d4aa9e974");
if ( memcmp(pubkey33,legacy33,33) == 0 )
return(128);
}*/
return(-1); return(-1);
} }
@@ -203,7 +217,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num)
memcpy(kp->pubkey,pubkeys[k],33); memcpy(kp->pubkey,pubkeys[k],33);
kp->notaryid = k; kp->notaryid = k;
HASH_ADD_KEYPTR(hh,N.Notaries,kp->pubkey,33,kp); HASH_ADD_KEYPTR(hh,N.Notaries,kp->pubkey,33,kp);
if ( 0 && height > 10000 ) if ( 1 && height > 10000 )
{ {
for (i=0; i<33; i++) for (i=0; i<33; i++)
printf("%02x",pubkeys[k][i]); printf("%02x",pubkeys[k][i]);
@@ -246,6 +260,8 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33)
return(modval); return(modval);
} }
} }
if ( height >= 300000 )
return(-1);
htind = height / KOMODO_ELECTION_GAP; htind = height / KOMODO_ELECTION_GAP;
pthread_mutex_lock(&komodo_mutex); pthread_mutex_lock(&komodo_mutex);
HASH_FIND(hh,Pubkeys[htind].Notaries,pubkey33,33,kp); HASH_FIND(hh,Pubkeys[htind].Notaries,pubkey33,33,kp);
@@ -258,7 +274,7 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33)
modval = ((height % numnotaries) == kp->notaryid); modval = ((height % numnotaries) == kp->notaryid);
//printf("found notary.%d ht.%d modval.%d\n",kp->notaryid,height,modval); //printf("found notary.%d ht.%d modval.%d\n",kp->notaryid,height,modval);
} else printf("unexpected zero notaries at height.%d\n",height); } else printf("unexpected zero notaries at height.%d\n",height);
} } //else printf("cant find kp at htind.%d ht.%d\n",htind,height);
//int32_t i; for (i=0; i<33; i++) //int32_t i; for (i=0; i<33; i++)
// printf("%02x",pubkey33[i]); // printf("%02x",pubkey33[i]);
//printf(" ht.%d notary.%d special.%d htind.%d num.%d\n",height,*notaryidp,modval,htind,numnotaries); //printf(" ht.%d notary.%d special.%d htind.%d num.%d\n",height,*notaryidp,modval,htind,numnotaries);
@@ -352,7 +368,7 @@ void komodo_init(int32_t height)
// Minerids[i] = -2; // Minerids[i] = -2;
didinit = 1; didinit = 1;
} }
else if ( height == KOMODO_MAINNET_START ) else if ( 0 && height == KOMODO_MAINNET_START )
{ {
n = (int32_t)(sizeof(Notaries_elected)/sizeof(*Notaries_elected)); n = (int32_t)(sizeof(Notaries_elected)/sizeof(*Notaries_elected));
for (k=0; k<n; k++) for (k=0; k<n; k++)

View File

@@ -3872,6 +3872,7 @@ bool LoadBlockIndex()
return false; return false;
} }
KOMODO_LOADINGBLOCKS = 0; KOMODO_LOADINGBLOCKS = 0;
fprintf(stderr,"finished loading blocks\n");
return true; return true;
} }

View File

@@ -447,7 +447,7 @@ Value kvsearch(const Array& params, bool fHelp)
Value minerids(const Array& params, bool fHelp) Value minerids(const Array& params, bool fHelp)
{ {
Object ret; Array a; uint8_t minerids[2000],pubkeys[64][33]; int32_t i,j,n,numnotaries,tally[65]; Object ret; Array a; uint8_t minerids[2000],pubkeys[65][33]; int32_t i,j,n,numnotaries,tally[129];
if ( fHelp || params.size() != 1 ) if ( fHelp || params.size() != 1 )
throw runtime_error("minerids needs height\n"); throw runtime_error("minerids needs height\n");
LOCK(cs_main); LOCK(cs_main);
@@ -463,7 +463,7 @@ Value minerids(const Array& params, bool fHelp)
for (i=0; i<n; i++) for (i=0; i<n; i++)
{ {
if ( minerids[i] >= numnotaries ) if ( minerids[i] >= numnotaries )
tally[64]++; tally[128]++;
else tally[minerids[i]]++; else tally[minerids[i]]++;
} }
for (i=0; i<64; i++) for (i=0; i<64; i++)
@@ -488,7 +488,7 @@ Value minerids(const Array& params, bool fHelp)
} }
Object item; Object item;
item.push_back(Pair("pubkey", (char *)"external miners")); item.push_back(Pair("pubkey", (char *)"external miners"));
item.push_back(Pair("blocks", tally[64])); item.push_back(Pair("blocks", tally[128]));
a.push_back(item); a.push_back(item);
} }
ret.push_back(Pair("mined", a)); ret.push_back(Pair("mined", a));