move initalise notaryaddrs to connect block to stop it being called out
of order
This commit is contained in:
29
src/komodo.h
29
src/komodo.h
@@ -797,6 +797,8 @@ int32_t komodo_notarycmp(uint8_t *scriptPubKey,int32_t scriptlen,uint8_t pubkeys
|
||||
void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
{
|
||||
static int32_t hwmheight;
|
||||
int8_t StakedEra; static int8_t lastStakedEra;
|
||||
|
||||
uint64_t signedmask,voutmask; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
|
||||
uint8_t scriptbuf[10001],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 zero,btctxid,txhash;
|
||||
int32_t i,j,k,numnotaries,notarized,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count;
|
||||
@@ -809,6 +811,27 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
return;
|
||||
}
|
||||
//fprintf(stderr,"%s connect.%d\n",ASSETCHAINS_SYMBOL,pindex->nHeight);
|
||||
if ( is_STAKED(ASSETCHAINS_SYMBOL) != 0 || IS_STAKED_NOTARY != -1 ) {
|
||||
staked_era = STAKED_era(pindex->GetBlockTime());
|
||||
if ( staked_era != lastStakedEra ) {
|
||||
uint8_t tmp_pubkeys[64][33];
|
||||
int8_t numSN = numStakedNotaries(tmp_pubkeys,staked_era);
|
||||
UpdateNotaryAddrs(tmp_pubkeys,numSN);
|
||||
STAKED_ERA = staked_era;
|
||||
if ( NOTARYADDRS[0][0] != 0 )
|
||||
{
|
||||
if ( NOTARY_PUBKEY33[0] != 0 )
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lastStakedEra = staked_era;
|
||||
}
|
||||
numnotaries = komodo_notaries(pubkeys,pindex->nHeight,pindex->GetBlockTime());
|
||||
calc_rmd160_sha256(rmd160,pubkeys[0],33);
|
||||
if ( pindex->nHeight > hwmheight )
|
||||
@@ -831,9 +854,9 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
txn_count = block.vtx.size();
|
||||
for (i=0; i<txn_count; i++)
|
||||
{
|
||||
if ((is_STAKED(ASSETCHAINS_SYMBOL) != 0) && (STAKED_era((uint32_t)pindex->nTime) == 0)) {
|
||||
//printf("ERA 0 SKIP getblocktime: %ld pindex->nTime : %d for %s\n",pindex->GetBlockTime(),(uint32_t)pindex->nTime,ASSETCHAINS_SYMBOL);
|
||||
continue;
|
||||
if ( is_STAKED(ASSETCHAINS_SYMBOL) != 0 && staked_era == 0 ) {
|
||||
// in era gap no point checking any invlaid notarisations.
|
||||
break;
|
||||
}
|
||||
txhash = block.vtx[i].GetHash();
|
||||
numvouts = block.vtx[i].vout.size();
|
||||
|
||||
@@ -121,12 +121,6 @@ int is_STAKED(const char *chain_name) {
|
||||
int STAKED_era(int timestamp)
|
||||
{
|
||||
int8_t era = 0;
|
||||
static uint32_t lasttimestamp;
|
||||
static int didera;
|
||||
// test this, seems to sometimes get called into the past?
|
||||
if ( timestamp < lasttimestamp )
|
||||
timestamp = lasttimestamp;
|
||||
|
||||
if (timestamp <= STAKED_NOTARIES_TIMESTAMP1)
|
||||
era = 1;
|
||||
else if (timestamp <= STAKED_NOTARIES_TIMESTAMP2 && timestamp >= (STAKED_NOTARIES_TIMESTAMP1 + STAKED_ERA_GAP))
|
||||
@@ -135,28 +129,9 @@ int STAKED_era(int timestamp)
|
||||
era = 3;
|
||||
else if (timestamp <= STAKED_NOTARIES_TIMESTAMP4 && timestamp >= (STAKED_NOTARIES_TIMESTAMP3 + STAKED_ERA_GAP))
|
||||
era = 4;
|
||||
else {
|
||||
era = 0; didera = 0;
|
||||
}
|
||||
else
|
||||
era = 0;
|
||||
// if we are in a gap, return era 0, this allows to invalidate notarizations when in GAP.
|
||||
|
||||
if ( era > STAKED_ERA || didera == 0 )
|
||||
{
|
||||
STAKED_ERA = era;
|
||||
if ( NOTARYADDRS[0][0] != 0 )
|
||||
{
|
||||
if ( NOTARY_PUBKEY33[0] != 0 )
|
||||
{
|
||||
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++;
|
||||
}
|
||||
}
|
||||
lasttimestamp = timestamp;
|
||||
return(era);
|
||||
};
|
||||
|
||||
@@ -205,7 +180,6 @@ int8_t numStakedNotaries(uint8_t pubkeys[64][33],int8_t era) {
|
||||
|
||||
if ( ChainName[0] == 0 )
|
||||
{
|
||||
pthread_mutex_init(&staked_mutex,NULL);
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||
strcpy(ChainName,"KMD");
|
||||
else
|
||||
@@ -215,35 +189,22 @@ int8_t numStakedNotaries(uint8_t pubkeys[64][33],int8_t era) {
|
||||
if ( era != 0 ) {
|
||||
switch (era) {
|
||||
case 1:
|
||||
if ( didstaked1 == 0 || NOTARYADDRS[0][0] == 0 )
|
||||
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(&staked_mutex);
|
||||
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys1[i]);
|
||||
NUM_NOTARIES = num_notaries_STAKED1;
|
||||
pthread_mutex_unlock(&staked_mutex);
|
||||
#endif
|
||||
}
|
||||
didstaked1 = 1;
|
||||
printf("%s is a STAKED chain in era 1 \n",ChainName);
|
||||
}
|
||||
|
||||
memcpy(pubkeys,staked_pubkeys1,num_notaries_STAKED1 * 33);
|
||||
retval = num_notaries_STAKED1;
|
||||
break;
|
||||
case 2:
|
||||
if ( didstaked2 == 0 || NOTARYADDRS[0][0] == 0 )
|
||||
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(&staked_mutex);
|
||||
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys2[i]);
|
||||
NUM_NOTARIES = num_notaries_STAKED2;
|
||||
pthread_mutex_unlock(&staked_mutex);
|
||||
#endif
|
||||
}
|
||||
didstaked2 = 1;
|
||||
printf("%s is a STAKED chain in era 2 \n",ChainName);
|
||||
@@ -252,16 +213,10 @@ int8_t numStakedNotaries(uint8_t pubkeys[64][33],int8_t era) {
|
||||
retval = num_notaries_STAKED2;
|
||||
break;
|
||||
case 3:
|
||||
if ( didstaked3 == 0 || NOTARYADDRS[0][0] == 0 )
|
||||
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(&staked_mutex);
|
||||
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys3[i]);
|
||||
NUM_NOTARIES = num_notaries_STAKED3;
|
||||
pthread_mutex_unlock(&staked_mutex);
|
||||
#endif
|
||||
}
|
||||
didstaked3 = 1;
|
||||
printf("%s is a STAKED chain in era 3 \n",ChainName);
|
||||
@@ -270,16 +225,10 @@ int8_t numStakedNotaries(uint8_t pubkeys[64][33],int8_t era) {
|
||||
retval = num_notaries_STAKED3;
|
||||
break;
|
||||
case 4:
|
||||
if ( didstaked4 == 0 || NOTARYADDRS[0][0] == 0 )
|
||||
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(&staked_mutex);
|
||||
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys4[i]);
|
||||
NUM_NOTARIES = num_notaries_STAKED4;
|
||||
pthread_mutex_unlock(&staked_mutex);
|
||||
#endif
|
||||
}
|
||||
didstaked4 = 1;
|
||||
printf("%s is a STAKED chain in era 4 \n",ChainName);
|
||||
@@ -291,18 +240,41 @@ int8_t numStakedNotaries(uint8_t pubkeys[64][33],int8_t era) {
|
||||
}
|
||||
else
|
||||
{
|
||||
// era is zero so we need to null out the notary address's and pubkeys.
|
||||
pthread_mutex_lock(&staked_mutex);
|
||||
memset(NOTARYADDRS,0,sizeof(NOTARYADDRS));
|
||||
NUM_NOTARIES = 0;
|
||||
// era is zero so we need to null out the pubkeys.
|
||||
memset(pubkeys,0,64 * 33);
|
||||
pthread_mutex_unlock(&staked_mutex);
|
||||
printf("%s is a STAKED chain and is in an ERA GAP.\n",ASSETCHAINS_SYMBOL);
|
||||
return(64);
|
||||
}
|
||||
return(retval);
|
||||
}
|
||||
|
||||
void UpdateNotaryAddrs(uint8_t pubkeys[64][33],int8_t numNotaries) {
|
||||
static int didinit;
|
||||
if ( didinit == 0 ) {
|
||||
pthread_mutex_init(&staked_mutex,NULL);
|
||||
}
|
||||
if ( pubkeys[0][0] == 0 )
|
||||
{
|
||||
// null pubkeys, era 0.
|
||||
#ifdef SERVER
|
||||
pthread_mutex_lock(&staked_mutex);
|
||||
memset(NOTARYADDRS,0,sizeof(NOTARYADDRS));
|
||||
NUM_NOTARIES = 0;
|
||||
pthread_mutex_unlock(&staked_mutex);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
// staked era is set.
|
||||
#ifdef SERVER
|
||||
pthread_mutex_lock(&staked_mutex);
|
||||
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)pubkeys[i]);
|
||||
NUM_NOTARIES = numNotaries;
|
||||
pthread_mutex_unlock(&staked_mutex);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int8_t ScanStakedArray(const char *notaries_chosen[][2],int num_notaries,char *Raddress,std::string ¬aryname) {
|
||||
for (size_t i = 0; i < num_notaries; i++) {
|
||||
//fprintf(stderr, "address [%ld]: %s\n",i,NOTARYADDRS[i]);
|
||||
|
||||
@@ -29,6 +29,7 @@ int STAKED_era(int timestamp);
|
||||
int8_t updateStakedNotary();
|
||||
int8_t numStakedNotaries(uint8_t pubkeys[64][33],int8_t era);
|
||||
int8_t StakedNotaryID(std::string ¬aryname, char *Raddress);
|
||||
void UpdateNotaryAddrs(uint8_t pubkeys[64][33],int8_t numNotaries);
|
||||
int8_t ScanStakedArray(const char *notaries_chosen[][2],int num_notaries,char *Raddress,std::string ¬aryname);
|
||||
|
||||
CrosschainAuthority Choose_auth_STAKED(int chosen_era);
|
||||
|
||||
Reference in New Issue
Block a user