From 791d8dc13b4b75800f1f7caf38892ec340e13f2e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 15 Feb 2019 11:01:10 +0800 Subject: [PATCH] remove dynamic notary pay reward and revert to static amounts, cannot work! --- src/komodo.h | 36 ++++++++++----------------------- src/komodo_bitcoind.h | 46 ++++++++----------------------------------- src/komodo_notary.h | 5 +---- src/komodo_structs.h | 2 +- src/main.cpp | 30 +++++++--------------------- src/miner.cpp | 5 +++-- src/rpc/misc.cpp | 6 +++--- 7 files changed, 33 insertions(+), 97 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 34051f173..82341a369 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -267,11 +267,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long memset(&MoM,0,sizeof(MoM)); MoMdepth = 0; } - sp->PPPNOTARIZED_HEIGHT = sp->PPNOTARIZED_HEIGHT; - sp->PPNOTARIZED_HEIGHT = sp->PNOTARIZED_HEIGHT; - sp->PNOTARIZED_HEIGHT = sp->NOTARIZED_HEIGHT; komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height,MoM,MoMdepth); - printf("komodo_parsestatefiledata: [%s] NOTARIZED.%d PNOTARIZED_HEIGHT.%d PPNOTARIZED_HEIGHT.%d PPPNOTARIZED_HEIGHT.%d\n",ASSETCHAINS_SYMBOL,sp->NOTARIZED_HEIGHT,sp->PNOTARIZED_HEIGHT,sp->PPNOTARIZED_HEIGHT,sp->PPPNOTARIZED_HEIGHT); } else if ( func == 'U' ) // deprecated { @@ -701,22 +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); - // On the first notarization initilise previous previous to 0. - if ( sp->NUM_NPOINTS == 1 ) - sp->PPPNOTARIZED_HEIGHT = 0; - - sp->PPPNOTARIZED_HEIGHT = sp->PPNOTARIZED_HEIGHT; - sp->PPNOTARIZED_HEIGHT = sp->PNOTARIZED_HEIGHT; - sp->PNOTARIZED_HEIGHT = sp->NOTARIZED_HEIGHT; sp->NOTARIZED_HEIGHT = *notarizedheightp; sp->NOTARIZED_HASH = srchash; sp->NOTARIZED_DESTTXID = desttxid; @@ -727,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 NUM_NPOINTS.%d NOTARIZED.%d PNOTARIZED_HEIGHT.%d PPNOTARIZED_HEIGHT.%d %s.%s %sTXID.%s lens.(%d %d) MoM.%s %d\n",ASSETCHAINS_SYMBOL,height,sp->NUM_NPOINTS,sp->NOTARIZED_HEIGHT,sp->PNOTARIZED_HEIGHT,sp->PPNOTARIZED_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); + 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 ) { @@ -753,8 +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 ( 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); } @@ -893,7 +879,7 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) } // Notary pay chains need notarisation in position 1, ignore the rest on validation. Check notarisation is 1 on check. // make sure for first 3 notarizations, that we check all tx in block! - if ( !fJustCheck && i > 1 && ASSETCHAINS_NOTARY_PAY[0] != 0 && check_pprevnotarizedht() ) + if ( !fJustCheck && i > 1 && ASSETCHAINS_NOTARY_PAY[0] != 0 ) break; txhash = block.vtx[i].GetHash(); numvouts = block.vtx[i].vout.size(); @@ -971,12 +957,11 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) { memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len); notaryid = komodo_voutupdate(fJustCheck,&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.LastTip()->GetBlockTime()); - if ( fJustCheck && (notaryid == -2 || notaryid == -3) ) + 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; kGetHeight()); 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 ) return(-1); } else return(0); } - #endif diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ce6d03076..e1ef2c21d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1776,11 +1776,9 @@ 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,int32_t *ppNotarizedHt,int32_t *pppNotarizedHt); - uint64_t komodo_notarypayamount(int32_t nHeight, int64_t notarycount) { - int8_t curEra = 0; + 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 ) { @@ -1798,39 +1796,11 @@ uint64_t komodo_notarypayamount(int32_t nHeight, int64_t notarycount) fprintf(stderr, "komodo_notarypayamount failed num notaries is 0!\n"); return(0); } - // fetch notarised height, the previous, and the one before that. - int32_t notarizedht=0,prevMoMheight,prevnotarizedht=0,pprevnotarizedht=0,ppprevnotarizedht=0,n=0; uint256 notarizedhash,txid; - uint64_t AmountToPay=0,ret=0; - notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid,&prevnotarizedht,&pprevnotarizedht,&ppprevnotarizedht); - fprintf(stderr, "notarizedht.%d prevnotarizedht.%d pprevnotarizedht.%d ppprevnotarizedht.%d\n",notarizedht,prevnotarizedht,pprevnotarizedht,ppprevnotarizedht); - - // We cannot pay out if 4 notarisation's have not yet happened! - // redundant now... should never happen. - if ( ppprevnotarizedht == 0 ) - { - fprintf(stderr, "need 4 notarizations to happen before notaries can be paid.\n"); - return(0); - } - if ( prevnotarizedht == pprevnotarizedht ) - return(0); // cant happen, sanity check. - - if ( notarizedht == nHeight ) - { - // we need to use the previous previous previous notarized heights, to make sure the payment is the same, if trying to use a reorged nota. - n = ppprevnotarizedht - pprevnotarizedht; - } - else - { - // use the previous height and the height before that to guarentee that the notarzations used to calculate these values, - // are them selves actually notarised and cannot be reorged. - n = prevnotarizedht - pprevnotarizedht; - } - - // 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[curEra]*n; - fprintf(stderr, "era.%i paying total of %lu for %i blocks\n",curEra,AmountToPay,n); - ret = AmountToPay / notarycount; + // 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); } @@ -1852,6 +1822,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, "<<<<< &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]; @@ -1880,7 +1850,7 @@ uint64_t komodo_notarypay(CMutableTransaction &txNew, std::vector &Notar // resize coinbase vouts to number of notary nodes +1 for coinbase itself. txNew.vout.resize(NotarisationNotaries.size()+1); - // Calcualte the amount to pay. If 0, means not enough notarizations to calcuate amount. + // Calcualte the amount to pay according to the current era. AmountToPay = komodo_notarypayamount(height,NotarisationNotaries.size()); if ( AmountToPay == 0 ) return(0); diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 5c3372193..c4984cee2 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -452,16 +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 *ppNotarizedHt,int32_t *pppNotarizedHt) +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->PNOTARIZED_HEIGHT; - *ppNotarizedHt = sp->PPNOTARIZED_HEIGHT; - *pppNotarizedHt = sp->PPPNOTARIZED_HEIGHT; *prevMoMheightp = komodo_prevMoMheight(); return(sp->NOTARIZED_HEIGHT); } diff --git a/src/komodo_structs.h b/src/komodo_structs.h index 793957756..6b7c316b6 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -119,7 +119,7 @@ struct komodo_ccdata struct komodo_state { uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID,MoM; - int32_t SAVEDHEIGHT,CURRENT_HEIGHT,NOTARIZED_HEIGHT,PNOTARIZED_HEIGHT,PPNOTARIZED_HEIGHT,PPPNOTARIZED_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; diff --git a/src/main.cpp b/src/main.cpp index b31a1be80..ab95e5b34 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3248,22 +3248,6 @@ static int64_t nTimeTotal = 0; bool FindBlockPos(int32_t tmpflag,CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false); bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBlockIndex *pindexNew, const CDiskBlockPos& pos); -bool check_pprevnotarizedht() -{ - static bool init; - if ( init ) - return(true); - int32_t notarizedht,prevMoMheight,prevnotarizedht,pprevnotarizedht,ppprevnotarizedht; uint256 notarizedhash,txid; - notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid,&prevnotarizedht,&pprevnotarizedht,&ppprevnotarizedht); - if ( ppprevnotarizedht > 0 ) - { - init = true; - return(true); - } - else - return(false); -} - bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck,bool fCheckPOW) { @@ -3299,7 +3283,7 @@ 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] != 0 && pindex->GetHeight() > 10 && check_pprevnotarizedht() ) + if ( ASSETCHAINS_NOTARY_PAY[0] != 0 && pindex->GetHeight() > 10 ) { // 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. @@ -3925,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 notarizedht,prevMoMheight,prevnotarizedht,pprevnotarizedht,ppprevnotarizedht; uint256 notarizedhash,txid; - notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid,&prevnotarizedht,&pprevnotarizedht,&ppprevnotarizedht); + int32_t notarizedht,prevMoMheight; uint256 notarizedhash,txid; + notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid); if ( block.GetHash() == notarizedhash ) { fprintf(stderr,"DisconnectTip trying to disconnect notarized block at ht.%d\n",(int32_t)pindexDelete->GetHeight()); @@ -4260,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,prevMoMheight,prevnotarizedht,pprevnotarizedht,ppprevnotarizedht; uint256 notarizedhash,txid; - notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid,&prevnotarizedht,&pprevnotarizedht,&ppprevnotarizedht); + int32_t notarizedht,prevMoMheight; uint256 notarizedhash,txid; + notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid); if ( pindexFork->GetHeight() < notarizedht ) { fprintf(stderr,"pindexFork->GetHeight().%d is < notarizedht %d, so ignore it\n",(int32_t)pindexFork->GetHeight(),notarizedht); @@ -5612,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,prevNotarizedHt,pprevNotarizedHt; - notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid,&prevnotarized_height,&prevNotarizedHt,&pprevNotarizedHt); + uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height; + notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid); //fprintf(stderr, "pruneblockfile.%i\n",fileNumber); sleep(15); for (BlockMap::iterator it = mapBlockIndex.begin(); it != mapBlockIndex.end(); ++it) { diff --git a/src/miner.cpp b/src/miner.cpp index 540aee622..539b039c3 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -392,7 +392,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize); - if ( fNotarisation && check_pprevnotarizedht() ) + if ( fNotarisation ) { // check if the notarization found is actually valid. if ( tx.vout.size() == 2 && tx.vout[1].nValue == 0 ) @@ -402,6 +402,7 @@ 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 ) { @@ -435,11 +436,11 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 } 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; } - Notarisations++; } } } diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 9bc2c0785..b7f202cb4 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -63,7 +63,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 *ppNotarizedHt,int32_t *pppNotarizedHt); +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); @@ -164,7 +164,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,prevNotarizedHt,pprevNotarizedHt,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" @@ -200,7 +200,7 @@ UniValue getinfo(const UniValue& params, bool fHelp) proxyType proxy; GetProxy(NET_IPV4, proxy); - notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid,&prevnotarized_height,&prevNotarizedHt,&pprevNotarizedHt); + notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid); //fprintf(stderr,"after notarized_height %u\n",(uint32_t)time(NULL)); UniValue obj(UniValue::VOBJ);