Merge branch 'notarypay_new'

This commit is contained in:
blackjok3r
2019-02-18 19:26:50 +08:00
11 changed files with 100 additions and 87 deletions

View File

@@ -38,6 +38,7 @@
int32_t gettxout_scriptPubKey(uint8_t *scriptPubkey,int32_t maxsize,uint256 txid,int32_t n);
void komodo_event_rewind(struct komodo_state *sp,char *symbol,int32_t height);
int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block);
bool check_pprevnotarizedht();
#include "komodo_structs.h"
#include "komodo_globals.h"
@@ -696,16 +697,12 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar
else if ( ASSETCHAINS_SYMBOL[0] == 0 && matched != 0 && notarized != 0 && validated != 0 )
komodo_rwccdata((char *)"KMD",1,&ccdata,0);
// If we are checking a reorged notarisation tx we need to return true. So the coinbase can be recreated, otherwise notaries are not paid,
// if a notarisation TX is reorged before the next notarization happens!
if ( fJustCheck && matched != 0 && *notarizedheightp == sp->NOTARIZED_HEIGHT && sp->NOTARIZED_DESTTXID == desttxid && sp->NOTARIZED_HASH == srchash)
// Because of reorgs its not possible to use notarizations that are in order. If its validated pay the notaries!
if ( fJustCheck )
return(-2);
if ( matched != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height )
{
if ( fJustCheck )
return(-2);
sp->prevNOTARIZED_HEIGHT = sp->NOTARIZED_HEIGHT;
sp->NOTARIZED_HEIGHT = *notarizedheightp;
sp->NOTARIZED_HASH = srchash;
sp->NOTARIZED_DESTTXID = desttxid;
@@ -716,7 +713,7 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar
}
komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0,sp->MoM,sp->MoMdepth);
if ( ASSETCHAINS_SYMBOL[0] != 0 )
printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d) MoM.%s %d\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,srchash.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),opretlen,len,sp->MoM.ToString().c_str(),sp->MoMdepth);
printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d) MoM.%s %d\n",ASSETCHAINS_SYMBOL,height,sp->NOTARIZED_HEIGHT,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,srchash.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),opretlen,len,sp->MoM.ToString().c_str(),sp->MoMdepth);
if ( ASSETCHAINS_SYMBOL[0] == 0 )
{
@@ -742,7 +739,8 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar
komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen-len+4+3+(scriptbuf[1] == 0x4d),j,zero,0);
}
}
}
} //else if ( fJustCheck )
// return (-3); // if the notarisation is only invalid because its out of order it cannot be mined in a block with a valid one!
} else if ( opretlen != 149 && height > 600000 && matched != 0 )
printf("%s validated.%d notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s len.%d opretlen.%d\n",ccdata.symbol,validated,notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,srchash.ToString().c_str(),desttxid.ToString().c_str(),len,opretlen);
}
@@ -880,7 +878,8 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block)
break;
}
// Notary pay chains need notarisation in position 1, ignore the rest on validation. Check notarisation is 1 on check.
if ( !fJustCheck && ASSETCHAINS_NOTARY_PAY != 0 && i > 1)
// make sure for first 3 notarizations, that we check all tx in block!
if ( !fJustCheck && i > 1 && ASSETCHAINS_NOTARY_PAY[0] != 0 )
break;
txhash = block.vtx[i].GetHash();
numvouts = block.vtx[i].vout.size();
@@ -960,10 +959,9 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block)
notaryid = komodo_voutupdate(fJustCheck,&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,&notarizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.LastTip()->GetBlockTime());
if ( fJustCheck && notaryid == -2 )
{
// We see a valid notarisation here, save its location.
// We see a valid notarisation here, save its location.
notarisations.push_back(i);
}
//fprintf(stderr, "notaryid.%i\n",notaryid);
if ( 0 && i > 0 )
{
for (k=0; k<len; k++)
@@ -1023,15 +1021,14 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block)
//fprintf(stderr,"%s end connect.%d\n",ASSETCHAINS_SYMBOL,pindex->GetHeight());
if (fJustCheck)
{
if (notarisations.size() == 0)
if ( notarisations.size() == 0 )
return(0);
if ( notarisations.size() == 1 && notarisations[0] == 1 )
return(1);
else
if ( notarisations.size() > 1 || (notarisations.size() == 1 && notarisations[0] != 1) )
return(-1);
}
else return(0);
}
#endif

View File

@@ -1797,35 +1797,31 @@ bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height)
return(isPOS);
}
int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp,int32_t *prevNotarizedHt);
uint64_t komodo_notarypayamount(int32_t height, int64_t notarycount)
uint64_t komodo_notarypayamount(int32_t nHeight, int64_t notarycount)
{
int8_t curEra = 0; int64_t ret = 0;
// if we have an end block in the first era, find our current era
if ( ASSETCHAINS_ENDSUBSIDY[0] > 1 )
{
for ( curEra = 0; curEra <= ASSETCHAINS_LASTERA; curEra++ )
{
if ( ASSETCHAINS_ENDSUBSIDY[curEra] > nHeight || ASSETCHAINS_ENDSUBSIDY[curEra] == 0 )
break;
}
}
if ( curEra > ASSETCHAINS_LASTERA )
return(0);
if ( notarycount == 0 )
{
fprintf(stderr, "komodo_notarypayamount failed num notaries is 0!\n");
return(0);
}
// fetch notarised height
int32_t notarizedht,prevMoMheight,prevnotarizedht; uint256 notarizedhash,txid;
uint64_t AmountToPay=0,ret=0;
notarizedht = komodo_notarized_height(&prevMoMheight,&notarizedhash,&txid,&prevnotarizedht);
// if this is the current checkpoint we will use the previous height.
// incase of reorgs, we still need to create the notary payment.
if ( height == notarizedht )
{
notarizedht = prevnotarizedht;
fprintf(stderr, "using the current checkpoint, calculating based on previous notarized height!\n");
}
// how many block since last notarisation.
int32_t n = height - notarizedht;
fprintf(stderr, "blocks since last notarization: %i\n",n);
// multiply the amount possible to be used for each block by the amount of blocks passed
// to get the total posible to be paid for this notarisation.
AmountToPay = ASSETCHAINS_NOTARY_PAY*n;
//fprintf(stderr, "AmountToPay.%lu\n",AmountToPay);
ret = AmountToPay / notarycount;
fprintf(stderr, "payment per notary.%lu\n",ret);
// Because of reorgs we cannot use the notarized height value.
// We need to basically guess here and just pay some static amount.
// Has the unwanted effect of varying coin emission, but cannot be helped.
fprintf(stderr, "era.%i paying total of %lu\n",curEra, ASSETCHAINS_NOTARY_PAY[curEra]);
ret = ASSETCHAINS_NOTARY_PAY[curEra] / notarycount;
return(ret);
}
@@ -1847,6 +1843,7 @@ int32_t komodo_getnotarizedheight(uint32_t timestamp,int32_t height, uint8_t *sc
}
else
{
// This should no longer happen. Unless notaries are making actual invalid notarizations.
fprintf(stderr, "<<<<<<INVALID NOTARIZATION ht.%i\n",notarizedheight);
return(0);
}
@@ -1857,7 +1854,6 @@ int32_t komodo_getnotarizedheight(uint32_t timestamp,int32_t height, uint8_t *sc
uint64_t komodo_notarypay(CMutableTransaction &txNew, std::vector<int8_t> &NotarisationNotaries, uint32_t timestamp, int32_t height, uint8_t *script, int32_t len)
{
// fetch notary pubkey array.
// Need a better/safer way for notaries era, should really be height based rather than timestamp?
uint64_t total = 0, AmountToPay = 0;
int32_t staked_era; int8_t numSN;
uint8_t staked_pubkeys[64][33];
@@ -1867,7 +1863,7 @@ uint64_t komodo_notarypay(CMutableTransaction &txNew, std::vector<int8_t> &Notar
return(0);
numSN = numStakedNotaries(staked_pubkeys,staked_era);
// Check the notarisation is valid and get the notarized height to calcualte the payment.
// Check the notarisation is valid.
int32_t notarizedheight = komodo_getnotarizedheight(timestamp, height, script, len);
if ( notarizedheight == 0 )
return(0);
@@ -1875,8 +1871,10 @@ uint64_t komodo_notarypay(CMutableTransaction &txNew, std::vector<int8_t> &Notar
// resize coinbase vouts to number of notary nodes +1 for coinbase itself.
txNew.vout.resize(NotarisationNotaries.size()+1);
// Calcualte the amount to pay.
AmountToPay = komodo_notarypayamount(notarizedheight,NotarisationNotaries.size());
// Calcualte the amount to pay according to the current era.
AmountToPay = komodo_notarypayamount(height,NotarisationNotaries.size());
if ( AmountToPay == 0 )
return(0);
// loop over notarisation vins and add transaction to coinbase.
// Commented prints here can be used to verify manually the pubkeys match.
@@ -1953,7 +1951,7 @@ uint64_t komodo_checknotarypay(CBlock *pblock,int32_t height)
fprintf(stderr, "vout 2 of notarisation is not OP_RETURN scriptlen.%i\n", scriptlen);
return(0);
}
}
} else return(0);
// if notarypay fails, because the notarisation is not valid, exit now as txNew was not created.
// This should never happen, as the notarisation is checked before this function is called.
@@ -1988,7 +1986,7 @@ uint64_t komodo_checknotarypay(CBlock *pblock,int32_t height)
{
matches++;
total += txout.nValue;
fprintf(stderr, "MATCHED AmountPaid.%lu notaryid.%i\n",AmountToPay,NotarisationNotaries[n-1]);
//fprintf(stderr, "MATCHED AmountPaid.%lu notaryid.%i\n",AmountToPay,NotarisationNotaries[n-1]);
}
else fprintf(stderr, "NOT MATCHED AmountPaid.%lu AmountToPay.%lu notaryid.%i\n", pblock->vtx[0].vout[n].nValue, AmountToPay, NotarisationNotaries[n-1]);
}
@@ -2186,7 +2184,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
// the default daemon miner, checks the actual vins so the only way this will fail, is if someone changes the miner,
// and then creates txs to the crypto address meeting min sigs and puts it in tx position 1.
// If they go through this effort, the block will still fail at connect block, and will be auto purged by the temp file fix.
if ( failed == 0 && ASSETCHAINS_NOTARY_PAY != 0 && pblock->vtx[0].vout.size() > 1 )
if ( failed == 0 && ASSETCHAINS_NOTARY_PAY[0] != 0 && pblock->vtx[0].vout.size() > 1 )
{
// We check the full validation in ConnectBlock directly to get the amount for coinbase. So just approx here.
if ( slowflag == 0 )

View File

@@ -40,7 +40,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;
extern uint32_t ASSETCHAIN_INIT, ASSETCHAINS_MAGIC,ASSETCHAINS_BLOCKTIME;
extern int32_t VERUS_BLOCK_POSUNITS, ASSETCHAINS_LWMAPOS, ASSETCHAINS_SAPLING, ASSETCHAINS_OVERWINTER;
extern uint64_t ASSETCHAINS_SUPPLY, ASSETCHAINS_FOUNDERS_REWARD, ASSETCHAINS_NOTARY_PAY;
extern uint64_t ASSETCHAINS_SUPPLY, ASSETCHAINS_FOUNDERS_REWARD;
extern uint64_t ASSETCHAINS_TIMELOCKGTE;
extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH,ASSETCHAINS_EQUIHASH,KOMODO_INITDONE;
@@ -48,7 +48,7 @@ extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH,ASSETCHAINS_EQUIHASH,KOM
extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,KOMODO_ON_DEMAND,KOMODO_PASSPORT_INITDONE,ASSETCHAINS_STAKED;
extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_LASTERA;
extern bool VERUS_MINTBLOCKS;
extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[];
extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[];
extern const char *ASSETCHAINS_ALGORITHMS[];
extern int32_t VERUS_MIN_STAKEAGE;
extern uint32_t ASSETCHAINS_VERUSHASH, ASSETCHAINS_VERUSHASHV2, ASSETCHAINS_NONCESHIFT[], ASSETCHAINS_HASHESPERROUND[];

View File

@@ -69,7 +69,7 @@ uint64_t ASSETCHAINS_TIMELOCKGTE = _ASSETCHAINS_TIMELOCKOFF;
uint64_t ASSETCHAINS_TIMEUNLOCKFROM = 0, ASSETCHAINS_TIMEUNLOCKTO = 0;
uint64_t ASSETCHAINS_LASTERA = 1;
uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS];
uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS];
uint8_t ASSETCHAINS_CCDISABLES[256];
#define _ASSETCHAINS_EQUIHASH 0
@@ -97,7 +97,7 @@ int32_t ASSETCHAINS_OVERWINTER = -1;
uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE;
int32_t ASSETCHAINS_STAKED;
uint64_t ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY = 10,MIN_RECV_SATS,ASSETCHAINS_FOUNDERS_REWARD,ASSETCHAINS_NOTARY_PAY;
uint64_t ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY = 10,MIN_RECV_SATS,ASSETCHAINS_FOUNDERS_REWARD;
uint32_t KOMODO_INITDONE;
char KMDUSERPASS[8192+512+1],BTCUSERPASS[8192]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771;

View File

@@ -452,14 +452,13 @@ int32_t komodo_prevMoMheight()
return(0);
}
int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp,int32_t *prevNotarizedHt)
int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp)
{
char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
if ( (sp= komodo_stateptr(symbol,dest)) != 0 )
{
*hashp = sp->NOTARIZED_HASH;
*txidp = sp->NOTARIZED_DESTTXID;
*prevNotarizedHt = sp->prevNOTARIZED_HEIGHT;
*prevMoMheightp = komodo_prevMoMheight();
return(sp->NOTARIZED_HEIGHT);
}

View File

@@ -119,7 +119,7 @@ struct komodo_ccdata
struct komodo_state
{
uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID,MoM;
int32_t SAVEDHEIGHT,CURRENT_HEIGHT,NOTARIZED_HEIGHT,prevNOTARIZED_HEIGHT,MoMdepth;
int32_t SAVEDHEIGHT,CURRENT_HEIGHT,NOTARIZED_HEIGHT,MoMdepth;
uint32_t SAVEDTIMESTAMP;
uint64_t deposited,issued,withdrawn,approved,redeemed,shorted;
struct notarized_checkpoint *NPOINTS; int32_t NUM_NPOINTS,last_NPOINTSi;

View File

@@ -1766,6 +1766,7 @@ void komodo_args(char *argv0)
Split(GetArg("-ac_reward",""), ASSETCHAINS_REWARD, 0);
Split(GetArg("-ac_halving",""), ASSETCHAINS_HALVING, 0);
Split(GetArg("-ac_decay",""), ASSETCHAINS_DECAY, 0);
Split(GetArg("-ac_notarypay",""), ASSETCHAINS_NOTARY_PAY, 0);
for ( int i = 0; i < ASSETCHAINS_MAX_ERAS; i++ )
{
@@ -1879,6 +1880,11 @@ void komodo_args(char *argv0)
}
if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 || ASSETCHAINS_SCRIPTPUB.size() > 1 )
{
if ( ASSETCHAINS_NOTARY_PAY[0] != 0 )
{
printf("Assetchains NOTARY PAY cannot be used with ac_pubkey or ac_script.\n");
exit(0);
}
if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 )
{
decode_hex(ASSETCHAINS_OVERRIDE_PUBKEY33,33,(char *)ASSETCHAINS_OVERRIDE_PUBKEY.c_str());
@@ -1904,9 +1910,6 @@ void komodo_args(char *argv0)
}
else
{
ASSETCHAINS_NOTARY_PAY = GetArg("-ac_notarypay",0);
if ( ASSETCHAINS_NOTARY_PAY != 0 )
printf("Assetchains NOTARY PAY set to %lu sats per notarisation per notary. Cannot work with ac_script or ac_pubkey!\n",ASSETCHAINS_NOTARY_PAY);
if ( ASSETCHAINS_COMMISSION != 0 )
{
ASSETCHAINS_COMMISSION = 0;
@@ -1923,7 +1926,7 @@ void komodo_args(char *argv0)
fprintf(stderr,"-ac_script and -ac_marmara are mutually exclusive\n");
exit(0);
}
if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY != 0 || ASSETCHAINS_BLOCKTIME != 60 )
if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 )
{
fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size());
extraptr = extrabuf;
@@ -1932,17 +1935,20 @@ void komodo_args(char *argv0)
// if we have one era, this should create the same data structure as it used to, same if we increase _MAX_ERAS
for ( int i = 0; i <= ASSETCHAINS_LASTERA; i++ )
{
printf("ERA%u: end.%llu reward.%llu halving.%llu decay.%llu\n", i,
printf("ERA%u: end.%llu reward.%llu halving.%llu decay.%llu notarypay.%llu\n", i,
(long long)ASSETCHAINS_ENDSUBSIDY[i],
(long long)ASSETCHAINS_REWARD[i],
(long long)ASSETCHAINS_HALVING[i],
(long long)ASSETCHAINS_DECAY[i]);
(long long)ASSETCHAINS_DECAY[i],
(long long)ASSETCHAINS_NOTARY_PAY[i]);
// TODO: Verify that we don't overrun extrabuf here, which is a 256 byte buffer
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_ENDSUBSIDY[i]),(void *)&ASSETCHAINS_ENDSUBSIDY[i]);
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_REWARD[i]),(void *)&ASSETCHAINS_REWARD[i]);
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_HALVING[i]),(void *)&ASSETCHAINS_HALVING[i]);
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_DECAY[i]),(void *)&ASSETCHAINS_DECAY[i]);
if ( ASSETCHAINS_NOTARY_PAY[0] != 0 )
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_NOTARY_PAY[i]),(void *)&ASSETCHAINS_NOTARY_PAY[i]);
}
if (ASSETCHAINS_LASTERA > 0)
@@ -2018,8 +2024,6 @@ void komodo_args(char *argv0)
}
fprintf(stderr," <- CCLIB name\n");
}
if ( ASSETCHAINS_NOTARY_PAY != 0 )
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_NOTARY_PAY),(void *)&ASSETCHAINS_NOTARY_PAY);
if ( ASSETCHAINS_BLOCKTIME != 60 )
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_BLOCKTIME),(void *)&ASSETCHAINS_BLOCKTIME);
}

View File

@@ -3283,16 +3283,18 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
fprintf(stderr,"grandfathered exception, until jan 15th 2019\n");
}
// Do this here before the block is moved to the main block files.
if ( ASSETCHAINS_NOTARY_PAY != 0 && pindex->GetHeight() > 10 )
if ( ASSETCHAINS_NOTARY_PAY[0] != 0 && pindex->GetHeight() > 10 )
{
// do a full block scan to get notarisation position and to enforce 1 notarisation is in block only.
// do a full block scan to get notarisation position and to enforce a valid notarization is in position 1.
// if notarisation in the block, must be position 1 and the coinbase must pay notaries.
int notarisationTx = komodo_connectblock(true,pindex,*(CBlock *)&block);
// -1 means that more than 1 notarisation is in a block, or the notarisation is not in order.
// -1 means that the valid notarization isnt in position 1 or there are too many notarizations in this block.
if ( notarisationTx == -1 )
return state.DoS(100, error("ConnectBlock(): Notarisation is not in TX position 1! Invalid Block!"),
return state.DoS(100, error("ConnectBlock(): Notarization is not in TX position 1 or block contains more than 1 notarization! Invalid Block!"),
REJECT_INVALID, "bad-notarization-position");
// 1 means this block contains a valid notarisation
// 1 means this block contains a valid notarisation and its in position 1.
// its no longer possible for any attempted notarization to be in a block with a valid one!
// if notaries create a notarisation even if its not in this chain it will need to be mined inside its own block!
if ( notarisationTx == 1 )
{
// Check if the notaries have been paid.
@@ -3907,8 +3909,8 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
return AbortNode(state, "Failed to read block");
//if ( ASSETCHAINS_SYMBOL[0] != 0 || pindexDelete->GetHeight() > 1400000 )
{
int32_t prevMoMheight,prevnotarizedht; uint256 notarizedhash,txid;
komodo_notarized_height(&prevMoMheight,&notarizedhash,&txid,&prevnotarizedht);
int32_t notarizedht,prevMoMheight; uint256 notarizedhash,txid;
notarizedht = komodo_notarized_height(&prevMoMheight,&notarizedhash,&txid);
if ( block.GetHash() == notarizedhash )
{
fprintf(stderr,"DisconnectTip trying to disconnect notarized block at ht.%d\n",(int32_t)pindexDelete->GetHeight());
@@ -4242,8 +4244,8 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
assert(MAX_REORG_LENGTH > 0);//, "We must be able to reorg some distance");
if (reorgLength > MAX_REORG_LENGTH)
{
int32_t notarizedht,prevnotarizedht,prevMoMheight; uint256 notarizedhash,txid;
notarizedht = komodo_notarized_height(&prevMoMheight,&notarizedhash,&txid,&prevnotarizedht);
int32_t notarizedht,prevMoMheight; uint256 notarizedhash,txid;
notarizedht = komodo_notarized_height(&prevMoMheight,&notarizedhash,&txid);
if ( pindexFork->GetHeight() < notarizedht )
{
fprintf(stderr,"pindexFork->GetHeight().%d is < notarizedht %d, so ignore it\n",(int32_t)pindexFork->GetHeight(),notarizedht);
@@ -5487,11 +5489,11 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo
{
pfrom->nBlocksinARow = 0;
pfrom->nBlocksinARow2 = 0;
//fprintf(stderr, "reset node.%i\n",(int32_t)pfrom->GetId());
fprintf(stderr, "reset node.%i\n",(int32_t)pfrom->GetId());
}
else
{
//fprintf(stderr, "Requesting new peer node.%i blocksinrow.%i blocsinrow2.%i\n",(int32_t)pfrom->GetId(),pfrom->nBlocksinARow,pfrom->nBlocksinARow2);
fprintf(stderr, "Requesting new peer node.%i blocksinrow.%i blocsinrow2.%i\n",(int32_t)pfrom->GetId(),pfrom->nBlocksinARow,pfrom->nBlocksinARow2);
return(false);
}
}
@@ -5594,8 +5596,8 @@ uint64_t CalculateCurrentUsage()
/* Prune a block file (modify associated database entries)*/
bool PruneOneBlockFile(bool tempfile, const int fileNumber)
{
uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,prevnotarized_height;
notarized_height = komodo_notarized_height(&prevMoMheight,&notarized_hash,&notarized_desttxid,&prevnotarized_height);
uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height;
notarized_height = komodo_notarized_height(&prevMoMheight,&notarized_hash,&notarized_desttxid);
//fprintf(stderr, "pruneblockfile.%i\n",fileNumber); sleep(15);
for (BlockMap::iterator it = mapBlockIndex.begin(); it != mapBlockIndex.end(); ++it)
{

View File

@@ -251,8 +251,10 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
// Now we have the block time, we can get the active notaries.
int32_t staked_era = 0; int8_t numSN = 0;
uint8_t staked_pubkeys[64][33] = {0};
if ( is_STAKED(ASSETCHAINS_SYMBOL) != 0 )
if ( is_STAKED(ASSETCHAINS_SYMBOL) < 3 )
{
// Only use speical miner for LABS chains in the actual cluster that use notarypay!
// It wouldnt hurt to use it on other chains, but serves little purpose.
staked_era = STAKED_era(pblock->nTime);
numSN = numStakedNotaries(staked_pubkeys,staked_era);
}
@@ -391,9 +393,9 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize);
if (fNotarisation)
if ( fNotarisation )
{
// check if the notarization found is actually valid.
// Special miner for notary pay chains.
if ( tx.vout.size() == 2 && tx.vout[1].nValue == 0 )
{
// Get the OP_RETURN for the notarisation
@@ -401,23 +403,24 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
int32_t scriptlen = (int32_t)tx.vout[1].scriptPubKey.size();
if ( script[0] == OP_RETURN )
{
Notarisations++;
int32_t notarizedheight = komodo_getnotarizedheight(pblock->nTime, nHeight, script, scriptlen);
if ( notarizedheight != 0 )
{
//fprintf(stderr, "notarizations.%d notarizedheight.%d last_notarizedheight.%d\n",Notarisations,notarizedheight,last_notarizedheight);
if ( last_notarizedheight == 0 )
{
// this is the first one we see, add it to the block as TX1
NotarisationNotaries = TMP_NotarisationNotaries;
dPriority = 1e16;
fNotarisationBlock = true;
last_notarizedheight = notarizedheight;
fprintf(stderr, "Notarisation %s set to maximum priority\n",hash.ToString().c_str());
}
else if ( notarizedheight > last_notarizedheight )
continue; // leave this notarisation for the next block, it will be valid!
else if ( notarizedheight == last_notarizedheight )
continue; // this shouldnt happen, it would mean there are 2 notarisations for the same block!
else
else if ( notarizedheight < last_notarizedheight )
{
// we need to remove the last seen notarzation from block
const CTransaction& Tx = *(vecPriority.front().get<2>());
@@ -431,7 +434,16 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
fNotarisationBlock = true;
fprintf(stderr, "Notarisation %s set to maximum priority replacing notarization %s\n",hash.ToString().c_str(), Tx.GetHash().ToString().c_str());
}
last_notarizedheight = notarizedheight;
}
else if ( Notarisations > 1 )
{
fprintf(stderr, "skipping notarizations.%d\n",Notarisations);
// Any attempted notarization needs to be in its own block!
// If we find a valid one and place it in position 1, an invalid one must wait until the next block to be mined.
continue;
}
//fprintf(stderr, "BOTTOM: notarizations.%d notarizedheight.%d last_notarizedheight.%d\n",Notarisations,notarizedheight,last_notarizedheight);
}
}
}
@@ -716,19 +728,17 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
txNew.vout[1].nValue = 0;
// timelocks and commissions are currently incompatible due to validation complexity of the combination
}
else if ( fNotarisationBlock && ASSETCHAINS_NOTARY_PAY != 0 && pblock->vtx[1].vout.size() == 2 && pblock->vtx[1].vout[1].nValue == 0 )
else if ( fNotarisationBlock && ASSETCHAINS_NOTARY_PAY[0] != 0 && pblock->vtx[1].vout.size() == 2 && pblock->vtx[1].vout[1].nValue == 0 )
{
// Get the OP_RETURN for the notarisation
uint8_t *script = (uint8_t *)&pblock->vtx[1].vout[1].scriptPubKey[0];
int32_t scriptlen = (int32_t)pblock->vtx[1].vout[1].scriptPubKey.size();
if ( script[0] == OP_RETURN )
{
fprintf(stderr, ">>>>>MINER NotarisationNotaries.%li\n",NotarisationNotaries.size());
uint64_t totalsats = komodo_notarypay(txNew, NotarisationNotaries, pblock->nTime, nHeight, script, scriptlen);
if ( totalsats == 0 )
{
fprintf(stderr, "Could not create notary payment, trying again.\n");
// invalidnotarisation = pblock->vtx[1].GetHash().ToString();
if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) )
{
LEAVE_CRITICAL_SECTION(cs_main);

View File

@@ -17,14 +17,14 @@ int8_t is_STAKED(const char *chain_name)
return(0);
if (doneinit == 1 && ASSETCHAINS_SYMBOL[0] != 0)
return(STAKED);
if ( (strcmp(chain_name, "LABS") == 0) || (strcmp(chain_name, "ORKL") == 0) )
if ( (strcmp(chain_name, "LABS") == 0) || (strcmp(chain_name, "LABSTH") == 0) )
STAKED = 1; // These chains are allowed coin emissions.
else if ( (strncmp(chain_name, "LABS", 4) == 0) )
STAKED = 2; // These chains have no coin emission, block subsidy is always 0, and comission is 0. Notary pay is allowed.
else if ( (strcmp(chain_name, "CFEK") == 0) || (strncmp(chain_name, "CFEK", 4) == 0) )
STAKED = 3; // These chains have no speical rules at all.
else if ( (strcmp(chain_name, "TEST") == 0) || (strncmp(chain_name, "TEST", 4) == 0) )
STAKED = 4; // These chains are for testing consensus to create a chain etc. Not meant ot be actually used for anything important.
STAKED = 4; // These chains are for testing consensus to create a chain etc. Not meant to be actually used for anything important.
else if ( (strcmp(chain_name, "THIS_CHAIN_IS_BANNED") == 0) )
STAKED = 255; // Any chain added to this group is banned, no notarisations are valid, as a consensus rule. Can be used to remove a chain from cluster if needed.
doneinit = 1;

View File

@@ -64,7 +64,7 @@ int32_t Jumblr_depositaddradd(char *depositaddr);
int32_t Jumblr_secretaddradd(char *secretaddr);
uint64_t komodo_interestsum();
int32_t komodo_longestchain();
int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp,int32_t *prevNotarizedHt);
int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp);
bool komodo_txnotarizedconfirmed(uint256 txid);
uint32_t komodo_chainactive_timestamp();
int32_t komodo_whoami(char *pubkeystr,int32_t height,uint32_t timestamp);
@@ -83,7 +83,7 @@ extern uint32_t ASSETCHAINS_CC;
extern uint32_t ASSETCHAINS_MAGIC,ASSETCHAINS_ALGO;
extern uint64_t ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY;
extern int32_t ASSETCHAINS_LWMAPOS,ASSETCHAINS_SAPLING,ASSETCHAINS_STAKED;
extern uint64_t ASSETCHAINS_ENDSUBSIDY[],ASSETCHAINS_REWARD[],ASSETCHAINS_HALVING[],ASSETCHAINS_DECAY[];
extern uint64_t ASSETCHAINS_ENDSUBSIDY[],ASSETCHAINS_REWARD[],ASSETCHAINS_HALVING[],ASSETCHAINS_DECAY[],ASSETCHAINS_NOTARY_PAY[];
extern std::string NOTARY_PUBKEY,NOTARY_ADDRESS; extern uint8_t NOTARY_PUBKEY33[];
int32_t getera(int now)
@@ -165,7 +165,7 @@ UniValue getnotarysendmany(const UniValue& params, bool fHelp)
UniValue getinfo(const UniValue& params, bool fHelp)
{
uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,prevnotarized_height,longestchain,kmdnotarized_height,txid_height;
uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,longestchain,kmdnotarized_height,txid_height;
if (fHelp || params.size() != 0)
throw runtime_error(
"getinfo\n"
@@ -201,7 +201,7 @@ UniValue getinfo(const UniValue& params, bool fHelp)
proxyType proxy;
GetProxy(NET_IPV4, proxy);
notarized_height = komodo_notarized_height(&prevMoMheight,&notarized_hash,&notarized_desttxid,&prevnotarized_height);
notarized_height = komodo_notarized_height(&prevMoMheight,&notarized_hash,&notarized_desttxid);
//fprintf(stderr,"after notarized_height %u\n",(uint32_t)time(NULL));
UniValue obj(UniValue::VOBJ);
@@ -288,7 +288,7 @@ UniValue getinfo(const UniValue& params, bool fHelp)
if ( ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_LASTERA > 0 )
{
std::string acReward = "", acHalving = "", acDecay = "", acEndSubsidy = "";
std::string acReward = "", acHalving = "", acDecay = "", acEndSubsidy = "", acNotaryPay = "";
for (int i = 0; i <= ASSETCHAINS_LASTERA; i++)
{
if (i == 0)
@@ -297,6 +297,7 @@ UniValue getinfo(const UniValue& params, bool fHelp)
acHalving = std::to_string(ASSETCHAINS_HALVING[i]);
acDecay = std::to_string(ASSETCHAINS_DECAY[i]);
acEndSubsidy = std::to_string(ASSETCHAINS_ENDSUBSIDY[i]);
acNotaryPay = std::to_string(ASSETCHAINS_NOTARY_PAY[i]);
}
else
{
@@ -304,6 +305,7 @@ UniValue getinfo(const UniValue& params, bool fHelp)
acHalving += "," + std::to_string(ASSETCHAINS_HALVING[i]);
acDecay += "," + std::to_string(ASSETCHAINS_DECAY[i]);
acEndSubsidy += "," + std::to_string(ASSETCHAINS_ENDSUBSIDY[i]);
acNotaryPay += "," + std::to_string(ASSETCHAINS_NOTARY_PAY[i]);
}
}
if (ASSETCHAINS_LASTERA > 0)
@@ -312,6 +314,7 @@ UniValue getinfo(const UniValue& params, bool fHelp)
obj.push_back(Pair("halving", acHalving));
obj.push_back(Pair("decay", acDecay));
obj.push_back(Pair("endsubsidy", acEndSubsidy));
obj.push_back(Pair("notarypay", acNotaryPay));
}
if ( ASSETCHAINS_COMMISSION != 0 )