diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 2070e1240..50952af69 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -30,7 +30,7 @@ int32_t komodo_longestchain(); uint64_t komodo_maxallowed(int32_t baseid); int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max); -pthread_mutex_t komodo_mutex; +pthread_mutex_t komodo_mutex,staked_mutex; #define KOMODO_ELECTION_GAP 2000 //((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100) #define KOMODO_ASSETCHAIN_MAXLEN 65 diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 88ce299f7..48eeb6cba 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -204,15 +204,17 @@ const char *Notaries_elected1[][2] = 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 staked_pubkeys1[64][33],staked_pubkeys2[64][33],didstaked1,didstaked2; static int32_t ns1,ns2; - static uint8_t staked_pubkeys3[64][33],staked_pubkeys4[64][33],didstaked3,didstaked4; static int32_t ns3,ns4; - static uint8_t null_pubkeys[64][33] = {0}; - int staked_era; int32_t i,htind,n; uint64_t mask = 0; struct knotary_entry *kp,*tmp; - if ( timestamp == 0 && ASSETCHAINS_SYMBOL[0] != 0 ) + if ( timestamp == 0 ) timestamp = komodo_heightstamp(height); - else if ( ASSETCHAINS_SYMBOL[0] == 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 ) { + // Here we run the staked notaries function to populate the Notary Address's global var on KMD. + if ( IS_STAKED_NOTARY != -1 ) { + uint8_t tmp_pubkeys[64][33]; + numStakedNotaries(tmp_pubkeys,is_STAKED(timestamp)); + } 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 (is_STAKED(ASSETCHAINS_SYMBOL) == 0) @@ -253,67 +255,26 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam } else { // here we can activate our pubkeys for STAKED chains by era. - if (timestamp != 0) - { - staked_era = STAKED_era(timestamp); - if (staked_era == 1) + if (timestamp != 0) { - if (didstaked1 == 0) + int staked_era; int32_t numSN; + uint8_t staked_pubkeys[64][33]; uint8_t null_pubkeys[64][33] = {0}; + staked_era = STAKED_era(timestamp); + + if (staked_era != 0) { - ns1 = num_notaries_STAKED1; - for (i=0; i STAKED_ERA || didera == 0 ) { STAKED_ERA = era; - if ( NOTARY_PUBKEY33[0] != 0 ) + if ( NOTARYADDRS[0][0] != 0 ) { - if ( (IS_STAKED_NOTARY= updateStakedNotary()) > -1 ) + if ( NOTARY_PUBKEY33[0] != 0 ) { - IS_KOMODO_NOTARY = 0; - fprintf(stderr, "Staked Notary Protection Active! INIT.%d RADD.%s ERA.%d didera.%d\n",IS_STAKED_NOTARY,NOTARY_ADDRESS.c_str(),era,didera); + if ( (IS_STAKED_NOTARY= updateStakedNotary()) > -1 ) + { + IS_KOMODO_NOTARY = 0; + fprintf(stderr, "Staked Notary Protection Active! NotaryID.%d RADD.%s ERA.%d\n",IS_STAKED_NOTARY,NOTARY_ADDRESS.c_str(),era); + } } didera++; } @@ -167,89 +170,120 @@ int STAKED_era(int timestamp) }; int8_t StakedNotaryID(std::string ¬aryname, char *Raddress) { - int8_t notaryID = -1; int i; - 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]; + int8_t notaryID = -1; + if ( STAKED_ERA != 0 ) { + switch (STAKED_ERA) { + case 1: + notaryID = ScanStakedArray(notaries_STAKED1,num_notaries_STAKED1,Raddress,notaryname); + break; + case 2: + notaryID = ScanStakedArray(notaries_STAKED2,num_notaries_STAKED2,Raddress,notaryname); + break; + case 3: + notaryID = ScanStakedArray(notaries_STAKED3,num_notaries_STAKED3,Raddress,notaryname); + break; + case 4: + notaryID = ScanStakedArray(notaries_STAKED4,num_notaries_STAKED4,Raddress,notaryname); + break; + } + } + return(notaryID); +} - if ( ChainName[0] == 0 ) { +int8_t numStakedNotaries(uint8_t pubkeys[64][33],int8_t era) { + int i; int8_t retval = 0; + 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 ) + { + pthread_mutex_init(&staked_mutex,NULL); if ( ASSETCHAINS_SYMBOL[0] == 0 ) strcpy(ChainName,"KMD"); else strcpy(ChainName,ASSETCHAINS_SYMBOL); } - if ( STAKED_ERA != 0 ) { - switch (STAKED_ERA) { + if ( era != 0 ) { + switch (era) { case 1: - if ( didstaked1 == 0 ) { - for (i=0; i