Move 99% of staked notary code to its own file
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<ns1; i++)
|
||||
decode_hex(staked_pubkeys1[i],33,(char *)notaries_STAKED1[i][1]);
|
||||
didstaked1 = 1;
|
||||
didstaked2 = 0;
|
||||
didstaked3 = 0;
|
||||
didstaked4 = 0;
|
||||
numSN = numStakedNotaries(staked_pubkeys,staked_era);
|
||||
memcpy(pubkeys,staked_pubkeys,numSN * 33);
|
||||
return(numSN);
|
||||
}
|
||||
else
|
||||
{
|
||||
// this means we are in a gap, so we set the array of pubkeys to zero, this does't seem to correctly work, so added exeption to komodo.h aswell.
|
||||
printf("%s is a STAKED chain and is in an ERA GAP.\n",ASSETCHAINS_SYMBOL);
|
||||
memcpy(pubkeys,null_pubkeys,64 * 33);
|
||||
return(64);
|
||||
}
|
||||
memcpy(pubkeys,staked_pubkeys1,ns1 * 33);
|
||||
return(ns1);
|
||||
} else if (staked_era == 2)
|
||||
{
|
||||
if (didstaked2 == 0)
|
||||
{
|
||||
ns2 = num_notaries_STAKED2;
|
||||
for (i=0; i<ns2; i++)
|
||||
decode_hex(staked_pubkeys2[i],33,(char *)notaries_STAKED2[i][1]);
|
||||
didstaked2 = 1;
|
||||
didstaked3 = 0;
|
||||
didstaked4 = 0;
|
||||
}
|
||||
memcpy(pubkeys,staked_pubkeys2,ns2 * 33);
|
||||
return(ns2);
|
||||
} else if (staked_era == 3)
|
||||
{
|
||||
if (didstaked3 == 0)
|
||||
{
|
||||
ns3 = num_notaries_STAKED3;
|
||||
for (i=0; i<ns3; i++)
|
||||
decode_hex(staked_pubkeys3[i],33,(char *)notaries_STAKED3[i][1]);
|
||||
didstaked3 = 1;
|
||||
didstaked4 = 0;
|
||||
}
|
||||
memcpy(pubkeys,staked_pubkeys3,ns3 * 33);
|
||||
return(ns3);
|
||||
} else if (staked_era == 4)
|
||||
{
|
||||
if (didstaked4 == 0)
|
||||
{
|
||||
ns4 = num_notaries_STAKED4;
|
||||
for (i=0; i<ns4; i++)
|
||||
decode_hex(staked_pubkeys4[i],33,(char *)notaries_STAKED4[i][1]);
|
||||
didstaked4 = 1;
|
||||
}
|
||||
memcpy(pubkeys,staked_pubkeys4,ns4 * 33);
|
||||
return(ns4);
|
||||
} else if (staked_era == 0)
|
||||
{
|
||||
// this means we are in a gap, so we set the array of pubkeys to zero, this does't seem to correctly work, so added exeption to komodo.h aswell.
|
||||
printf("%s IS A STAKED CHAIN and is in an ERA GAP.\n",ASSETCHAINS_SYMBOL);
|
||||
memcpy(pubkeys,null_pubkeys,64 * 33);
|
||||
return(64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
htind = height / KOMODO_ELECTION_GAP;
|
||||
|
||||
@@ -1507,10 +1507,10 @@ void komodo_args(char *argv0)
|
||||
extern int64_t MAX_MONEY;
|
||||
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;
|
||||
IS_STAKED_NOTARY = GetArg("-stakednotary", -1);
|
||||
IS_KOMODO_NOTARY = GetBoolArg("-notary", false);
|
||||
IS_STAKED_NOTARY = GetArg("-stakednotary", -1);
|
||||
if ( IS_STAKED_NOTARY != -1 && IS_KOMODO_NOTARY == true ) {
|
||||
fprintf(stderr, "Cannot be STAKED and KMD notary at he same time!\n");
|
||||
fprintf(stderr, "Cannot be STAKED and KMD notary at the same time!\n");
|
||||
exit(0);
|
||||
}
|
||||
if ( GetBoolArg("-gen", false) != 0 )
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
extern char NOTARYADDRS[18][64];
|
||||
extern std::string NOTARY_ADDRESS,NOTARY_PUBKEY;
|
||||
extern int32_t STAKED_ERA,IS_STAKED_NOTARY,IS_KOMODO_NOTARY;
|
||||
extern pthread_mutex_t komodo_mutex;
|
||||
extern pthread_mutex_t staked_mutex;
|
||||
extern uint8_t NOTARY_PUBKEY33[33];
|
||||
|
||||
// Era 1 set of pubkeys
|
||||
@@ -153,12 +153,15 @@ int STAKED_era(int timestamp)
|
||||
if ( era > 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<num_notaries_STAKED1; i++) {
|
||||
decode_hex(staked_pubkeys1[i],33,(char *)notaries_STAKED1[i][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);
|
||||
pthread_mutex_lock(&staked_mutex);
|
||||
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys1[i]);
|
||||
pthread_mutex_unlock(&staked_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);
|
||||
memcpy(pubkeys,staked_pubkeys1,num_notaries_STAKED1 * 33);
|
||||
retval = num_notaries_STAKED1;
|
||||
break;
|
||||
case 2:
|
||||
if ( didstaked2 == 0 ) {
|
||||
for (i=0; i<num_notaries_STAKED2; i++) {
|
||||
decode_hex(staked_pubkeys2[i],33,(char *)notaries_STAKED2[i][1]);
|
||||
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);
|
||||
pthread_mutex_lock(&staked_mutex);
|
||||
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys2[i]);
|
||||
pthread_mutex_unlock(&staked_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);
|
||||
memcpy(pubkeys,staked_pubkeys2,num_notaries_STAKED2 * 33);
|
||||
retval = num_notaries_STAKED2;
|
||||
break;
|
||||
case 3:
|
||||
if ( didstaked3 == 0 ) {
|
||||
for (i=0; i<num_notaries_STAKED3; i++) {
|
||||
decode_hex(staked_pubkeys3[i],33,(char *)notaries_STAKED3[i][1]);
|
||||
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);
|
||||
pthread_mutex_lock(&staked_mutex);
|
||||
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys3[i]);
|
||||
pthread_mutex_unlock(&staked_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);
|
||||
memcpy(pubkeys,staked_pubkeys3,num_notaries_STAKED3 * 33);
|
||||
retval = num_notaries_STAKED3;
|
||||
break;
|
||||
case 4:
|
||||
if ( didstaked4 == 0 ) {
|
||||
for (i=0; i<num_notaries_STAKED4; i++) {
|
||||
decode_hex(staked_pubkeys4[i],33,(char *)notaries_STAKED4[i][1]);
|
||||
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);
|
||||
pthread_mutex_lock(&staked_mutex);
|
||||
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys4[i]);
|
||||
pthread_mutex_unlock(&staked_mutex);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
didstaked4 = 1;
|
||||
printf("%s is a STAKED chain in era 4 \n",ChainName);
|
||||
}
|
||||
notaryID = ScanStakedArray(notaries_STAKED4,num_notaries_STAKED4,Raddress,notaryname);
|
||||
memcpy(pubkeys,staked_pubkeys4,num_notaries_STAKED4 * 33);
|
||||
retval = num_notaries_STAKED4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return(notaryID);
|
||||
return(retval);
|
||||
}
|
||||
|
||||
int8_t ScanStakedArray(const char *notaries_chosen[][2],int num_notaries,char *Raddress,std::string ¬aryname) {
|
||||
|
||||
@@ -27,6 +27,7 @@ extern int num_notaries_STAKED4;
|
||||
int is_STAKED(const char *chain_name);
|
||||
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);
|
||||
int8_t ScanStakedArray(const char *notaries_chosen[][2],int num_notaries,char *Raddress,std::string ¬aryname);
|
||||
|
||||
|
||||
@@ -1229,8 +1229,9 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl
|
||||
}
|
||||
}
|
||||
}
|
||||
// Now we know if it was a tx we sent, if it was all ours, we leave and let add to wallet.
|
||||
fprintf(stderr, "address: %s sent vouts: %d\n",NOTARY_ADDRESS.c_str(),numvinIsOurs);
|
||||
// Now we know if it was a tx sent to us, that wasnt from ourself.
|
||||
fprintf(stderr, "We sent from address: %s vouts: %d\n",NOTARY_ADDRESS.c_str(),numvinIsOurs);
|
||||
// Count vouts, check if OUR notary address is the receiver.
|
||||
if ( numvinIsOurs == 0 ) {
|
||||
for (size_t i = 0; i < tx.vout.size() ; i++) {
|
||||
CTxDestination address2;
|
||||
@@ -1242,6 +1243,9 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl
|
||||
}
|
||||
}
|
||||
}
|
||||
// If no vouts are to the notary address we will ignore them.
|
||||
if ( numvoutIsOurs == 0 )
|
||||
return false;
|
||||
fprintf(stderr, "address: %s received %ld sats from %d vouts.\n",NOTARY_ADDRESS.c_str(),totalvoutvalue,numvoutIsOurs);
|
||||
// here we add calculation for number if vouts received, average size and determine if we accept them to wallet or not.
|
||||
int64_t avgVoutSize = totalvoutvalue / numvoutIsOurs;
|
||||
@@ -1252,10 +1256,8 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl
|
||||
}
|
||||
|
||||
} else if ( numvinIsOurs < tx.vin.size() ) {
|
||||
// this means we were in a multi sig, we wil remove the utxo we spent from our wallet,
|
||||
// IF there exisited a function for that.
|
||||
// Maybe check if there are any vouts unspetn in this TX
|
||||
// then purge the TX from wallet if all spent?
|
||||
// this means we were in a multi sig, ideally we would remove the utxo we spent from our wallet, but you cant do that.
|
||||
// this will be removed later... RPC call PurgeWalletSpents will be created instead.
|
||||
fprintf(stderr, "There are vins that are not ours, notarisation?\n");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user