here we go :D

This commit is contained in:
blackjok3r
2018-11-04 20:18:34 +08:00
parent c9ba061ecb
commit d6dfe03485
3 changed files with 94 additions and 71 deletions

View File

@@ -22,11 +22,6 @@
#define KOMODO_MAINNET_START 178999 #define KOMODO_MAINNET_START 178999
extern char NOTARYADDRS[18][64];
//extern const char *notaries_STAKED[][2];
//extern const int num_notaries_STAKED;
const char *Notaries_genesis[][2] = const char *Notaries_genesis[][2] =
{ {
{ "jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" }, { "jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" },
@@ -206,8 +201,6 @@ const char *Notaries_elected1[][2] =
}; };
#define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9"
bool pubkey2addr(char *destaddr,uint8_t *pubkey33);
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp) int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp)
{ {
static uint8_t elected_pubkeys0[64][33],elected_pubkeys1[64][33],did0,did1; static int32_t n0,n1; static uint8_t elected_pubkeys0[64][33],elected_pubkeys1[64][33],did0,did1; static int32_t n0,n1;
@@ -220,6 +213,7 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam
timestamp = komodo_heightstamp(height); timestamp = komodo_heightstamp(height);
else if ( ASSETCHAINS_SYMBOL[0] == 0 ) else if ( ASSETCHAINS_SYMBOL[0] == 0 )
timestamp = 0; timestamp = 0;
// If this chain is not a staked chain, use the normal Komodo logic to determine notaries. This allows KMD to still sync and use its proper pubkeys for dPoW. // If this chain is not a staked chain, use the normal Komodo logic to determine notaries. This allows KMD to still sync and use its proper pubkeys for dPoW.
if (is_STAKED(ASSETCHAINS_SYMBOL) == 0) if (is_STAKED(ASSETCHAINS_SYMBOL) == 0)
{ {
@@ -232,11 +226,6 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam
n0 = (int32_t)(sizeof(Notaries_elected0)/sizeof(*Notaries_elected0)); n0 = (int32_t)(sizeof(Notaries_elected0)/sizeof(*Notaries_elected0));
for (i=0; i<n0; i++) { for (i=0; i<n0; i++) {
decode_hex(elected_pubkeys0[i],33,(char *)Notaries_elected0[i][1]); decode_hex(elected_pubkeys0[i],33,(char *)Notaries_elected0[i][1]);
#ifdef SERVER
pthread_mutex_lock(&komodo_mutex);
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)elected_pubkeys0[i]);
pthread_mutex_unlock(&komodo_mutex);
#endif
} }
did0 = 1; did0 = 1;
} }
@@ -252,11 +241,6 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam
n1 = (int32_t)(sizeof(Notaries_elected1)/sizeof(*Notaries_elected1)); n1 = (int32_t)(sizeof(Notaries_elected1)/sizeof(*Notaries_elected1));
for (i=0; i<n1; i++) { for (i=0; i<n1; i++) {
decode_hex(elected_pubkeys1[i],33,(char *)Notaries_elected1[i][1]); decode_hex(elected_pubkeys1[i],33,(char *)Notaries_elected1[i][1]);
#ifdef SERVER
pthread_mutex_lock(&komodo_mutex);
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)elected_pubkeys1[i]);
pthread_mutex_unlock(&komodo_mutex);
#endif
} }
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
fprintf(stderr,"%s height.%d t.%u elected.%d notaries2\n",ASSETCHAINS_SYMBOL,height,timestamp,n1); fprintf(stderr,"%s height.%d t.%u elected.%d notaries2\n",ASSETCHAINS_SYMBOL,height,timestamp,n1);
@@ -274,42 +258,28 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam
staked_era = STAKED_era(timestamp); staked_era = STAKED_era(timestamp);
if (staked_era == 1) if (staked_era == 1)
{ {
if (didstaked1 == 0) if (didstaked1 == 0)
{ {
ns1 = num_notaries_STAKED1; ns1 = num_notaries_STAKED1;
for (i=0; i<ns1; i++) { for (i=0; i<ns1; i++)
decode_hex(staked_pubkeys1[i],33,(char *)notaries_STAKED1[i][1]); decode_hex(staked_pubkeys1[i],33,(char *)notaries_STAKED1[i][1]);
#ifdef SERVER didstaked1 = 1;
pthread_mutex_lock(&komodo_mutex); didstaked2 = 0;
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys1[i]); didstaked3 = 0;
pthread_mutex_unlock(&komodo_mutex); didstaked4 = 0;
#endif
} }
didstaked1 = 1; memcpy(pubkeys,staked_pubkeys1,ns1 * 33);
didstaked2 = 0; return(ns1);
didstaked3 = 0;
didstaked4 = 0;
printf("%s IS A STAKED CHAIN and is era 1 \n",ASSETCHAINS_SYMBOL);
}
memcpy(pubkeys,staked_pubkeys1,ns1 * 33);
return(ns1);
} else if (staked_era == 2) } else if (staked_era == 2)
{ {
if (didstaked2 == 0) if (didstaked2 == 0)
{ {
ns2 = num_notaries_STAKED2; ns2 = num_notaries_STAKED2;
for (i=0; i<ns2; i++) { for (i=0; i<ns2; i++)
decode_hex(staked_pubkeys2[i],33,(char *)notaries_STAKED2[i][1]); decode_hex(staked_pubkeys2[i],33,(char *)notaries_STAKED2[i][1]);
#ifdef SERVER
pthread_mutex_lock(&komodo_mutex);
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys2[i]);
pthread_mutex_unlock(&komodo_mutex);
#endif
}
didstaked2 = 1; didstaked2 = 1;
didstaked3 = 0; didstaked3 = 0;
didstaked4 = 0; didstaked4 = 0;
printf("%s IS A STAKED CHAIN and is era 2 \n",ASSETCHAINS_SYMBOL);
} }
memcpy(pubkeys,staked_pubkeys2,ns2 * 33); memcpy(pubkeys,staked_pubkeys2,ns2 * 33);
return(ns2); return(ns2);
@@ -318,17 +288,10 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam
if (didstaked3 == 0) if (didstaked3 == 0)
{ {
ns3 = num_notaries_STAKED3; ns3 = num_notaries_STAKED3;
for (i=0; i<ns3; i++) { for (i=0; i<ns3; i++)
decode_hex(staked_pubkeys3[i],33,(char *)notaries_STAKED3[i][1]); decode_hex(staked_pubkeys3[i],33,(char *)notaries_STAKED3[i][1]);
#ifdef SERVER
pthread_mutex_lock(&komodo_mutex);
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys3[i]);
pthread_mutex_unlock(&komodo_mutex);
#endif
}
didstaked3 = 1; didstaked3 = 1;
didstaked4 = 0; didstaked4 = 0;
printf("%s IS A STAKED CHAIN and is era 3 \n",ASSETCHAINS_SYMBOL);
} }
memcpy(pubkeys,staked_pubkeys3,ns3 * 33); memcpy(pubkeys,staked_pubkeys3,ns3 * 33);
return(ns3); return(ns3);
@@ -337,16 +300,9 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam
if (didstaked4 == 0) if (didstaked4 == 0)
{ {
ns4 = num_notaries_STAKED4; ns4 = num_notaries_STAKED4;
for (i=0; i<ns4; i++) { for (i=0; i<ns4; i++)
decode_hex(staked_pubkeys4[i],33,(char *)notaries_STAKED4[i][1]); decode_hex(staked_pubkeys4[i],33,(char *)notaries_STAKED4[i][1]);
#ifdef SERVER
pthread_mutex_lock(&komodo_mutex);
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys4[i]);
pthread_mutex_unlock(&komodo_mutex);
#endif
}
didstaked4 = 1; didstaked4 = 1;
printf("%s IS A STAKED CHAIN and is era 4 \n",ASSETCHAINS_SYMBOL);
} }
memcpy(pubkeys,staked_pubkeys4,ns4 * 33); memcpy(pubkeys,staked_pubkeys4,ns4 * 33);
return(ns4); return(ns4);

View File

@@ -1507,8 +1507,12 @@ void komodo_args(char *argv0)
extern int64_t MAX_MONEY; extern int64_t MAX_MONEY;
extern const char *Notaries_elected1[][2]; extern const char *Notaries_elected1[][2];
std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[256],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,baseid,len,n,extralen = 0; std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[256],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,baseid,len,n,extralen = 0;
IS_KOMODO_NOTARY = GetBoolArg("-notary", false);
IS_STAKED_NOTARY = GetArg("-stakednotary", -1); IS_STAKED_NOTARY = GetArg("-stakednotary", -1);
IS_KOMODO_NOTARY = GetBoolArg("-notary", false);
if ( IS_STAKED_NOTARY != -1 && IS_KOMODO_NOTARY == true ) {
fprintf(stderr, "Cannot be STAKED and KMD notary at he same time!\n");
exit(0);
}
if ( GetBoolArg("-gen", false) != 0 ) if ( GetBoolArg("-gen", false) != 0 )
KOMODO_MININGTHREADS = GetArg("-genproclimit",1); KOMODO_MININGTHREADS = GetArg("-genproclimit",1);
else KOMODO_MININGTHREADS = -1; else KOMODO_MININGTHREADS = -1;
@@ -1516,7 +1520,7 @@ void komodo_args(char *argv0)
fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n"); fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n");
DONATION_PUBKEY = GetArg("-donation", ""); DONATION_PUBKEY = GetArg("-donation", "");
NOTARY_PUBKEY = GetArg("-pubkey", ""); NOTARY_PUBKEY = GetArg("-pubkey", "");
if ( strlen(NOTARY_PUBKEY.c_str()) == 66 ) if ( strlen(NOTARY_PUBKEY.c_str()) == 66 )
{ {
USE_EXTERNAL_PUBKEY = 1; USE_EXTERNAL_PUBKEY = 1;
if ( IS_KOMODO_NOTARY == 0 ) if ( IS_KOMODO_NOTARY == 0 )
@@ -1530,9 +1534,8 @@ void komodo_args(char *argv0)
break; break;
} }
} }
//KOMODO_PAX = 1; }
} //else KOMODO_PAX = GetArg("-pax",0); name = GetArg("-ac_name","");
name = GetArg("-ac_name","");
if ( argv0 != 0 ) if ( argv0 != 0 )
{ {
len = (int32_t)strlen(argv0); len = (int32_t)strlen(argv0);

View File

@@ -122,12 +122,10 @@ int is_STAKED(const char *chain_name) {
int8_t updateStakedNotary() { int8_t updateStakedNotary() {
std::string notaryname; std::string notaryname;
char Raddress[18]; uint8_t pubkey33[33]; char Raddress[18]; uint8_t pubkey33[33];
pthread_mutex_lock(&komodo_mutex);
decode_hex(pubkey33,33,(char *)NOTARY_PUBKEY.c_str()); decode_hex(pubkey33,33,(char *)NOTARY_PUBKEY.c_str());
pubkey2addr((char *)Raddress,(uint8_t *)pubkey33); pubkey2addr((char *)Raddress,(uint8_t *)pubkey33);
NOTARY_ADDRESS.clear(); NOTARY_ADDRESS.clear();
NOTARY_ADDRESS.assign(Raddress); NOTARY_ADDRESS.assign(Raddress);
pthread_mutex_unlock(&komodo_mutex);
return(StakedNotaryID(notaryname,Raddress)); return(StakedNotaryID(notaryname,Raddress));
} }
#else #else
@@ -150,39 +148,105 @@ int STAKED_era(int timestamp)
era = 4; era = 4;
else else
era = 0; era = 0;
// if we are in a gap, return era 0, this allows to invalidate notarizations when in GAP. // if we are in a gap, return era 0, this allows to invalidate notarizations when in GAP.
//fprintf(stderr, "era.%d stakedEra.%d didea.%d\n",era,STAKED_ERA,didera);
if ( era > STAKED_ERA || didera == 0 ) if ( era > STAKED_ERA || didera == 0 )
{ {
pthread_mutex_lock(&komodo_mutex);
STAKED_ERA = era; STAKED_ERA = era;
if ( NOTARY_PUBKEY33[0] != 0 && NOTARYADDRS[0][0] != 0 ) if ( NOTARY_PUBKEY33[0] != 0 )
{ {
if ( (IS_STAKED_NOTARY= updateStakedNotary()) > -1 ) if ( (IS_STAKED_NOTARY= updateStakedNotary()) > -1 )
{ {
IS_KOMODO_NOTARY = 0; IS_KOMODO_NOTARY = 0;
fprintf(stderr, "INIT.%d RADD.%s ERA.%d didera.%d\n",IS_STAKED_NOTARY,NOTARY_ADDRESS.c_str(),era,didera); fprintf(stderr, "Staked Notary Protection Active! INIT.%d RADD.%s ERA.%d didera.%d\n",IS_STAKED_NOTARY,NOTARY_ADDRESS.c_str(),era,didera);
} }
didera++; didera++;
} }
pthread_mutex_unlock(&komodo_mutex);
} }
return(era); return(era);
}; };
int8_t StakedNotaryID(std::string &notaryname, char *Raddress) { int8_t StakedNotaryID(std::string &notaryname, char *Raddress) {
int8_t notaryID = -1; int8_t notaryID = -1;
static uint8_t staked_pubkeys1[64][33],staked_pubkeys2[64][33],didstaked1,didstaked2;
static uint8_t staked_pubkeys3[64][33],staked_pubkeys4[64][33],didstaked3,didstaked4;
static char ChainName[65];
if ( ChainName[0] == 0 ) {
if ( ASSETCHAINS_SYMBOL[0] != 0 )
strcpy(ChainName,"KMD");
else
strcpy(ChainName,ASSETCHAINS_SYMBOL);
}
if ( STAKED_ERA != 0 ) { if ( STAKED_ERA != 0 ) {
switch (STAKED_ERA) { switch (STAKED_ERA) {
case 1: case 1:
if ( didstaked1 == 0 ) {
for (i=0; i<num_notaries_STAKED1; i++) {
decode_hex(staked_pubkeys1[i],33,(char *)notaries_STAKED1[i][1]);
#ifdef SERVER
pthread_mutex_lock(&komodo_mutex);
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys1[i]);
pthread_mutex_unlock(&komodo_mutex);
#endif
}
didstaked1 = 1;
didstaked2 = 0;
didstaked3 = 0;
didstaked4 = 0;
printf("%s is a STAKED chain in era 1 \n",ChainName);
}
notaryID = ScanStakedArray(notaries_STAKED1,num_notaries_STAKED1,Raddress,notaryname); notaryID = ScanStakedArray(notaries_STAKED1,num_notaries_STAKED1,Raddress,notaryname);
break; break;
case 2: case 2:
if ( didstaked2 == 0 ) {
for (i=0; i<num_notaries_STAKED2; i++) {
decode_hex(staked_pubkeys2[i],33,(char *)notaries_STAKED2[i][1]);
#ifdef SERVER
pthread_mutex_lock(&komodo_mutex);
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys2[i]);
pthread_mutex_unlock(&komodo_mutex);
#endif
}
didstaked2 = 1;
didstaked3 = 0;
didstaked4 = 0;
printf("%s is a STAKED chain in era 2 \n",ChainName);
}
notaryID = ScanStakedArray(notaries_STAKED2,num_notaries_STAKED2,Raddress,notaryname); notaryID = ScanStakedArray(notaries_STAKED2,num_notaries_STAKED2,Raddress,notaryname);
break; break;
case 3: case 3:
if ( didstaked3 == 0 ) {
for (i=0; i<num_notaries_STAKED3; i++) {
decode_hex(staked_pubkeys3[i],33,(char *)notaries_STAKED3[i][1]);
#ifdef SERVER
pthread_mutex_lock(&komodo_mutex);
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys3[i]);
pthread_mutex_unlock(&komodo_mutex);
#endif
}
didstaked3 = 1;
didstaked4 = 0;
printf("%s is a STAKED chain in era 3 \n",ChainName);
}
notaryID = ScanStakedArray(notaries_STAKED3,num_notaries_STAKED3,Raddress,notaryname); notaryID = ScanStakedArray(notaries_STAKED3,num_notaries_STAKED3,Raddress,notaryname);
break; break;
case 4: case 4:
if ( didstaked4 == 0 ) {
for (i=0; i<num_notaries_STAKED4; i++) {
decode_hex(staked_pubkeys4[i],33,(char *)notaries_STAKED4[i][1]);
#ifdef SERVER
pthread_mutex_lock(&komodo_mutex);
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys4[i]);
pthread_mutex_unlock(&komodo_mutex);
#endif
}
didstaked4 = 1;
printf("%s is a STAKED chain in era 4 \n",ChainName);
}
notaryID = ScanStakedArray(notaries_STAKED4,num_notaries_STAKED4,Raddress,notaryname); notaryID = ScanStakedArray(notaries_STAKED4,num_notaries_STAKED4,Raddress,notaryname);
break; break;
} }