From f6a51145f59315d8303fdb47709aabdaf4943a06 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 12 Feb 2019 23:28:13 +0800 Subject: [PATCH 01/19] New notary pay mechanisim... --- src/komodo.h | 17 +++++++++++------ src/komodo_bitcoind.h | 42 +++++++++++++++++++++++------------------ src/komodo_notary.h | 5 +++-- src/komodo_structs.h | 2 +- src/main.cpp | 20 +++++++++++--------- src/miner.cpp | 8 ++++++-- src/notaries_staked.cpp | 4 ++-- src/rpc/misc.cpp | 6 +++--- 8 files changed, 61 insertions(+), 43 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index b97e4d205..d88b53c2a 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -266,7 +266,10 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long memset(&MoM,0,sizeof(MoM)); MoMdepth = 0; } + 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\n",ASSETCHAINS_SYMBOL,sp->NOTARIZED_HEIGHT,sp->PNOTARIZED_HEIGHT,sp->PPNOTARIZED_HEIGHT); } else if ( func == 'U' ) // deprecated { @@ -697,7 +700,7 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar 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 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) return(-2); @@ -705,7 +708,8 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar { if ( fJustCheck ) return(-2); - sp->prevNOTARIZED_HEIGHT = sp->NOTARIZED_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; @@ -716,7 +720,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 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); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { @@ -742,7 +746,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); } @@ -958,7 +963,7 @@ 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 ) + if ( fJustCheck && (notaryid == -2 || notaryid == -3) ) { // We see a valid notarisation here, save its location. notarisations.push_back(i); @@ -1025,7 +1030,7 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) { if (notarisations.size() == 0) return(0); - if ( notarisations.size() == 1 && notarisations[0] == 1 ) + if ( notarisations.size() >= 1 && notarisations[0] == 1 ) return(1); else return(-1); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index caa2c4460..e3e99d7c4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1776,35 +1776,39 @@ 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 komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp,int32_t *prevNotarizedHt,int32_t *ppNotarizedHt); -uint64_t komodo_notarypayamount(int32_t height, int64_t notarycount) +uint64_t komodo_notarypayamount(int64_t notarycount) { 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; + // fetch notarised height, the previous, and the one before that. + int32_t notarizedht,prevMoMheight,prevnotarizedht,pprevnotarizedht; uint256 notarizedhash,txid; uint64_t AmountToPay=0,ret=0; - notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&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 = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid,&prevnotarizedht,&pprevnotarizedht); + //fprintf(stderr, "notarizedht.%d prevnotarizedht.%d pprevnotarizedht.%d \n",notarizedht,prevnotarizedht,pprevnotarizedht); + + // We cannot pay out if 3 notarisation's have not yet happened! + if ( pprevnotarizedht == 0 ) { - notarizedht = prevnotarizedht; - fprintf(stderr, "using the current checkpoint, calculating based on previous notarized height!\n"); + fprintf(stderr, "need 3 notarizations to happen before notaries can be paid.\n"); + return(0); } - // how many block since last notarisation. - int32_t n = height - notarizedht; + if ( prevnotarizedht == pprevnotarizedht ) + return(0); // cant happen, sanity check. + + // 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. + int32_t n = prevnotarizedht - pprevnotarizedht; + 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); return(ret); } @@ -1846,7 +1850,7 @@ uint64_t komodo_notarypay(CMutableTransaction &txNew, std::vector &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); @@ -1854,8 +1858,10 @@ 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. - AmountToPay = komodo_notarypayamount(notarizedheight,NotarisationNotaries.size()); + // Calcualte the amount to pay. If 0, means not enough notarizations to calcuate amount. + AmountToPay = komodo_notarypayamount(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. @@ -1932,7 +1938,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. diff --git a/src/komodo_notary.h b/src/komodo_notary.h index dcd99bea1..88a079348 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -452,14 +452,15 @@ 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,int32_t *prevNotarizedHt,int32_t *ppNotarizedHt) { 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; + *prevNotarizedHt = sp->PNOTARIZED_HEIGHT; + *ppNotarizedHt = sp->PPNOTARIZED_HEIGHT; *prevMoMheightp = komodo_prevMoMheight(); return(sp->NOTARIZED_HEIGHT); } diff --git a/src/komodo_structs.h b/src/komodo_structs.h index 2f8ba0850..b7a0ddd24 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,prevNOTARIZED_HEIGHT,MoMdepth; + int32_t SAVEDHEIGHT,CURRENT_HEIGHT,NOTARIZED_HEIGHT,PNOTARIZED_HEIGHT,PPNOTARIZED_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 054313a21..283e8ee38 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3284,14 +3284,16 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin // Do this here before the block is moved to the main block files. if ( ASSETCHAINS_NOTARY_PAY != 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. if ( notarisationTx == -1 ) return state.DoS(100, error("ConnectBlock(): Notarisation is not in TX position 1! 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. @@ -3906,8 +3908,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,¬arizedhash,&txid,&prevnotarizedht); + int32_t prevMoMheight,prevnotarizedht,prevNotarizedHt; uint256 notarizedhash,txid; + komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid,&prevnotarizedht,&prevNotarizedHt); if ( block.GetHash() == notarizedhash ) { fprintf(stderr,"DisconnectTip trying to disconnect notarized block at ht.%d\n",(int32_t)pindexDelete->GetHeight()); @@ -4241,8 +4243,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,¬arizedhash,&txid,&prevnotarizedht); + int32_t notarizedht,prevnotarizedht,prevNotarizedHt,prevMoMheight; uint256 notarizedhash,txid; + notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid,&prevnotarizedht,&prevNotarizedHt); if ( pindexFork->GetHeight() < notarizedht ) { fprintf(stderr,"pindexFork->GetHeight().%d is < notarizedht %d, so ignore it\n",(int32_t)pindexFork->GetHeight(),notarizedht); @@ -5593,8 +5595,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,¬arized_hash,¬arized_desttxid,&prevnotarized_height); + uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,prevnotarized_height,prevNotarizedHt; + notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid,&prevnotarized_height,&prevNotarizedHt); //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 a0934ce96..36ef947d3 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -432,6 +432,12 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 fprintf(stderr, "Notarisation %s set to maximum priority replacing notarization %s\n",hash.ToString().c_str(), Tx.GetHash().ToString().c_str()); } } + else if ( fNotarisationBlock == true ) + { + // 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; + } } } } @@ -723,12 +729,10 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 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); diff --git a/src/notaries_staked.cpp b/src/notaries_staked.cpp index 422d0da18..868956f8a 100644 --- a/src/notaries_staked.cpp +++ b/src/notaries_staked.cpp @@ -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, "LABST2") == 0) ) + if ( (strcmp(chain_name, "LABS") == 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; diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index bda9da062..15386d42a 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 komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp,int32_t *prevNotarizedHt,int32_t *ppNotarizedHt); 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,longestchain,kmdnotarized_height,txid_height; + uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,prevnotarized_height,prevNotarizedHt,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); + notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid,&prevnotarized_height,&prevNotarizedHt); //fprintf(stderr,"after notarized_height %u\n",(uint32_t)time(NULL)); UniValue obj(UniValue::VOBJ); From d9ad59f566a33e2d0dba5079704856258a0ec441 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 12 Feb 2019 23:36:31 +0800 Subject: [PATCH 02/19] fix --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index d88b53c2a..0ec83579c 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -1030,7 +1030,7 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) { if (notarisations.size() == 0) return(0); - if ( notarisations.size() >= 1 && notarisations[0] == 1 ) + if ( notarisations.size() == 1 && notarisations[0] == 1 ) return(1); else return(-1); From f993140b2d52a537c8ad45c66f390aa503b19213 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 14 Feb 2019 12:25:01 +0800 Subject: [PATCH 03/19] ORKL --- src/notaries_staked.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/notaries_staked.cpp b/src/notaries_staked.cpp index 868956f8a..c2f902c82 100644 --- a/src/notaries_staked.cpp +++ b/src/notaries_staked.cpp @@ -17,7 +17,7 @@ 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) ) + if ( (strcmp(chain_name, "LABS") == 0) || (strcmp(chain_name, "ORKL") == 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. From 498e6154a592dd43afecda118bb1a49fc065ba47 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 14 Feb 2019 16:46:15 +0800 Subject: [PATCH 04/19] Add notarypay to eras, for main chain. --- src/komodo.h | 2 +- src/komodo_bitcoind.h | 29 +++++++++++++++++++++-------- src/komodo_defs.h | 4 ++-- src/komodo_globals.h | 4 ++-- src/komodo_utils.h | 24 ++++++++++++++++-------- src/main.cpp | 2 +- src/miner.cpp | 2 +- 7 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 0ec83579c..17c98f203 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -885,7 +885,7 @@ 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) + if ( !fJustCheck && i > 1 && ASSETCHAINS_NOTARY_PAY[0] != 0 ) break; txhash = block.vtx[i].GetHash(); numvouts = block.vtx[i].vout.size(); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e3e99d7c4..1bf909cf6 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1778,8 +1778,21 @@ bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height) int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp,int32_t *prevNotarizedHt,int32_t *ppNotarizedHt); -uint64_t komodo_notarypayamount(int64_t notarycount) +uint64_t komodo_notarypayamount(int32_t nHeight, int64_t notarycount) { + int8_t curEra = 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"); @@ -1798,16 +1811,16 @@ uint64_t komodo_notarypayamount(int64_t notarycount) return(0); } if ( prevnotarizedht == pprevnotarizedht ) - return(0); // cant happen, sanity check. + return(0); // cant happen, sanity check. // 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. + // are them selves actually notarised and cannot be reorged. int32_t n = prevnotarizedht - pprevnotarizedht; - 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; + AmountToPay = ASSETCHAINS_NOTARY_PAY[curEra]*n; + fprintf(stderr, "era.%i paying total of %lu for %i blocks\n",curEra,AmountToPay,n); ret = AmountToPay / notarycount; return(ret); } @@ -1859,7 +1872,7 @@ uint64_t komodo_notarypay(CMutableTransaction &txNew, std::vector &Notar txNew.vout.resize(NotarisationNotaries.size()+1); // Calcualte the amount to pay. If 0, means not enough notarizations to calcuate amount. - AmountToPay = komodo_notarypayamount(NotarisationNotaries.size()); + AmountToPay = komodo_notarypayamount(height,NotarisationNotaries.size()); if ( AmountToPay == 0 ) return(0); @@ -1973,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]); } @@ -2171,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 ) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 32fb74dab..09490f3f0 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -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; 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[]; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 13caee41d..c00247da5 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -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; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index fd312e527..6e4a09546 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1764,6 +1764,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++ ) { @@ -1777,6 +1778,11 @@ void komodo_args(char *argv0) ASSETCHAINS_DECAY[i] = 0; printf("ERA%u: ASSETCHAINS_DECAY cant be more than 100000000\n", i); } + if ( ASSETCHAINS_NOTARY_PAY[i] < 64 ) + { + ASSETCHAINS_NOTARY_PAY[i] = 64; + printf("ERA%u: ASSETCHAINS_NOTARY_PAY cant be less than 64. Set to 64.\n", i); + } } MAX_BLOCK_SIGOPS = 60000; @@ -1869,6 +1875,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()); @@ -1894,9 +1905,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; @@ -1913,7 +1921,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 ) + 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 ) { 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; @@ -1922,17 +1930,19 @@ 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]); + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_NOTARY_PAY[i]),(void *)&ASSETCHAINS_NOTARY_PAY[i]); } if (ASSETCHAINS_LASTERA > 0) @@ -2008,8 +2018,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); } addn = GetArg("-seednode",""); diff --git a/src/main.cpp b/src/main.cpp index 283e8ee38..cd42e109a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3282,7 +3282,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 && pindex->GetHeight() > 10 ) + 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. diff --git a/src/miner.cpp b/src/miner.cpp index 36ef947d3..ba946fe58 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -722,7 +722,7 @@ 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]; From b9b3afcbe67759298bcacb309dcd3505a7d5cd12 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 14 Feb 2019 17:37:37 +0800 Subject: [PATCH 05/19] notarypay in getinfo --- src/rpc/misc.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 15386d42a..2c8d17138 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -82,7 +82,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) @@ -287,7 +287,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) @@ -296,6 +296,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 { @@ -303,6 +304,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) @@ -311,6 +313,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 ) From 497302dc75ed5ee52466b928a5fb8d02e3ccd4b1 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 14 Feb 2019 19:04:28 +0800 Subject: [PATCH 06/19] Fix not being able to mine first 3 notarizations. --- src/main.cpp | 20 +++++++++++++++++++- src/miner.cpp | 3 +++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index cd42e109a..eafde8df6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3248,6 +3248,24 @@ 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; uint256 notarizedhash,txid; + uint64_t AmountToPay=0,ret=0; + notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid,&prevnotarizedht,&pprevnotarizedht); + if ( pprevnotarizedht > 0 ) + { + init = true; + return(true); + } + else + return(false); +} + + bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck,bool fCheckPOW) { CDiskBlockPos blockPos; @@ -3282,7 +3300,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 ) + if ( ASSETCHAINS_NOTARY_PAY[0] != 0 && pindex->GetHeight() > 10 && check_pprevnotarizedht() ) { // 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. diff --git a/src/miner.cpp b/src/miner.cpp index ba946fe58..a0174a884 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -393,6 +393,9 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if (fNotarisation) { + // Can't make payment until 3 notarizations have happened. + if ( !check_pprevnotarizedht() ) + fNotarisation = false; // check if the notarization found is actually valid. if ( tx.vout.size() == 2 && tx.vout[1].nValue == 0 ) { From dc343dfd97ea0c4bda74bf7505862f3ac4673eae Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 14 Feb 2019 19:06:11 +0800 Subject: [PATCH 07/19] fix --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index a0174a884..00270dcd8 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -155,6 +155,7 @@ CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk); int32_t komodo_is_notarytx(const CTransaction& tx); uint64_t komodo_notarypay(CMutableTransaction &txNew, std::vector &NotarisationNotaries, uint32_t timestamp, int32_t height, uint8_t *script, int32_t len); int32_t komodo_getnotarizedheight(uint32_t timestamp,int32_t height, uint8_t *script, int32_t len); +bool check_pprevnotarizedht(); CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { From 2b86a48372ffc41e37200735cdc9422ded6a93bc Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 14 Feb 2019 19:19:13 +0800 Subject: [PATCH 08/19] fix --- src/komodo.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 17c98f203..45dc80948 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -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" @@ -885,7 +886,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 && i > 1 && ASSETCHAINS_NOTARY_PAY[0] != 0 ) + // make sure for first 3 notarizations, that we check all tx in block! + if ( !fJustCheck && i > 1 && ASSETCHAINS_NOTARY_PAY[0] != 0 && check_pprevnotarizedht() ) break; txhash = block.vtx[i].GetHash(); numvouts = block.vtx[i].vout.size(); From 695eb871bb8cb0bb7b5bbbabab2f844019cedb8c Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 14 Feb 2019 19:52:58 +0800 Subject: [PATCH 09/19] Fix miner --- src/komodo_bitcoind.h | 1 + src/miner.cpp | 82 +++++++++++++++++++++++-------------------- 2 files changed, 45 insertions(+), 38 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1bf909cf6..91ffc9043 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1805,6 +1805,7 @@ uint64_t komodo_notarypayamount(int32_t nHeight, int64_t notarycount) //fprintf(stderr, "notarizedht.%d prevnotarizedht.%d pprevnotarizedht.%d \n",notarizedht,prevnotarizedht,pprevnotarizedht); // We cannot pay out if 3 notarisation's have not yet happened! + // redundant now... should never happen. if ( pprevnotarizedht == 0 ) { fprintf(stderr, "need 3 notarizations to happen before notaries can be paid.\n"); diff --git a/src/miner.cpp b/src/miner.cpp index 00270dcd8..60c4086dd 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -396,52 +396,58 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 { // Can't make payment until 3 notarizations have happened. if ( !check_pprevnotarizedht() ) - fNotarisation = false; - // check if the notarization found is actually valid. - if ( tx.vout.size() == 2 && tx.vout[1].nValue == 0 ) { - // Get the OP_RETURN for the notarisation - uint8_t *script = (uint8_t *)&tx.vout[1].scriptPubKey[0]; - int32_t scriptlen = (int32_t)tx.vout[1].scriptPubKey.size(); - if ( script[0] == OP_RETURN ) + fNotarisation = false; + fNotarisationBlock = false; + } + else + { + // check if the notarization found is actually valid. + if ( tx.vout.size() == 2 && tx.vout[1].nValue == 0 ) { - int32_t notarizedheight = komodo_getnotarizedheight(pblock->nTime, nHeight, script, scriptlen); - if ( notarizedheight != 0 ) + // Get the OP_RETURN for the notarisation + uint8_t *script = (uint8_t *)&tx.vout[1].scriptPubKey[0]; + int32_t scriptlen = (int32_t)tx.vout[1].scriptPubKey.size(); + if ( script[0] == OP_RETURN ) { - if ( last_notarizedheight == 0 ) + int32_t notarizedheight = komodo_getnotarizedheight(pblock->nTime, nHeight, script, scriptlen); + if ( 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()); + 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 + { + // we need to remove the last seen notarzation from block + const CTransaction& Tx = *(vecPriority.front().get<2>()); + TxPriorityCompare comparer(0); + std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); + std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer); + vecPriority.pop_back(); + // add this one as its valid before the other one. + NotarisationNotaries = TMP_NotarisationNotaries; + dPriority = 1e16; + fNotarisationBlock = true; + fprintf(stderr, "Notarisation %s set to maximum priority replacing notarization %s\n",hash.ToString().c_str(), Tx.GetHash().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 ( fNotarisationBlock == true ) { - // we need to remove the last seen notarzation from block - const CTransaction& Tx = *(vecPriority.front().get<2>()); - TxPriorityCompare comparer(0); - std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); - std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer); - vecPriority.pop_back(); - // add this one as its valid before the other one. - NotarisationNotaries = TMP_NotarisationNotaries; - dPriority = 1e16; - fNotarisationBlock = true; - fprintf(stderr, "Notarisation %s set to maximum priority replacing notarization %s\n",hash.ToString().c_str(), Tx.GetHash().ToString().c_str()); + // 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; } } - else if ( fNotarisationBlock == true ) - { - // 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; - } } } } From 52450bf20292f572bd7759f944850725d1a36abe Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 14 Feb 2019 21:59:05 +0800 Subject: [PATCH 10/19] fix miner better --- src/komodo.h | 4 +++ src/miner.cpp | 85 +++++++++++++++++++++++---------------------------- 2 files changed, 42 insertions(+), 47 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 45dc80948..1e69504d0 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -709,6 +709,10 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar { if ( fJustCheck ) return(-2); + // On the first notarization initilise previous previous to 0. + if ( sp->NUM_NPOINTS == 1 ) + sp->PPNOTARIZED_HEIGHT = 0; + sp->PPNOTARIZED_HEIGHT = sp->PNOTARIZED_HEIGHT; sp->PNOTARIZED_HEIGHT = sp->NOTARIZED_HEIGHT; sp->NOTARIZED_HEIGHT = *notarizedheightp; diff --git a/src/miner.cpp b/src/miner.cpp index 60c4086dd..e10ba290c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -392,62 +392,53 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize); - if (fNotarisation) + if ( fNotarisation && check_pprevnotarizedht() ) { - // Can't make payment until 3 notarizations have happened. - if ( !check_pprevnotarizedht() ) + // check if the notarization found is actually valid. + if ( tx.vout.size() == 2 && tx.vout[1].nValue == 0 ) { - fNotarisation = false; - fNotarisationBlock = false; - } - else - { - // check if the notarization found is actually valid. - if ( tx.vout.size() == 2 && tx.vout[1].nValue == 0 ) + // Get the OP_RETURN for the notarisation + uint8_t *script = (uint8_t *)&tx.vout[1].scriptPubKey[0]; + int32_t scriptlen = (int32_t)tx.vout[1].scriptPubKey.size(); + if ( script[0] == OP_RETURN ) { - // Get the OP_RETURN for the notarisation - uint8_t *script = (uint8_t *)&tx.vout[1].scriptPubKey[0]; - int32_t scriptlen = (int32_t)tx.vout[1].scriptPubKey.size(); - if ( script[0] == OP_RETURN ) + int32_t notarizedheight = komodo_getnotarizedheight(pblock->nTime, nHeight, script, scriptlen); + if ( notarizedheight != 0 ) { - int32_t notarizedheight = komodo_getnotarizedheight(pblock->nTime, nHeight, script, scriptlen); - if ( notarizedheight != 0 ) + if ( last_notarizedheight == 0 ) { - 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 - { - // we need to remove the last seen notarzation from block - const CTransaction& Tx = *(vecPriority.front().get<2>()); - TxPriorityCompare comparer(0); - std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); - std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer); - vecPriority.pop_back(); - // add this one as its valid before the other one. - NotarisationNotaries = TMP_NotarisationNotaries; - dPriority = 1e16; - fNotarisationBlock = true; - fprintf(stderr, "Notarisation %s set to maximum priority replacing notarization %s\n",hash.ToString().c_str(), Tx.GetHash().ToString().c_str()); - } + // 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 ( fNotarisationBlock == true ) + 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 { - // 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; + // we need to remove the last seen notarzation from block + const CTransaction& Tx = *(vecPriority.front().get<2>()); + TxPriorityCompare comparer(0); + std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); + std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer); + vecPriority.pop_back(); + // add this one as its valid before the other one. + NotarisationNotaries = TMP_NotarisationNotaries; + dPriority = 1e16; + fNotarisationBlock = true; + fprintf(stderr, "Notarisation %s set to maximum priority replacing notarization %s\n",hash.ToString().c_str(), Tx.GetHash().ToString().c_str()); } } + else if ( fNotarisationBlock == true ) + { + // 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; + } } } } From d7a122c548c01b9eaa7e4b58694ef332b84c4e94 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 15 Feb 2019 00:13:48 +0800 Subject: [PATCH 11/19] fix reorged notarisation to use the same data points --- src/komodo.h | 8 +++++--- src/komodo_bitcoind.h | 30 +++++++++++++++++++----------- src/komodo_notary.h | 3 ++- src/komodo_structs.h | 2 +- src/main.cpp | 19 +++++++++---------- src/rpc/misc.cpp | 6 +++--- 6 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 1e69504d0..34051f173 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -267,10 +267,11 @@ 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\n",ASSETCHAINS_SYMBOL,sp->NOTARIZED_HEIGHT,sp->PNOTARIZED_HEIGHT,sp->PPNOTARIZED_HEIGHT); + 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 { @@ -711,8 +712,9 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar return(-2); // On the first notarization initilise previous previous to 0. if ( sp->NUM_NPOINTS == 1 ) - sp->PPNOTARIZED_HEIGHT = 0; - + 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; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 91ffc9043..ce6d03076 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1776,7 +1776,7 @@ 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 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) { @@ -1799,24 +1799,32 @@ uint64_t komodo_notarypayamount(int32_t nHeight, int64_t notarycount) return(0); } // fetch notarised height, the previous, and the one before that. - int32_t notarizedht,prevMoMheight,prevnotarizedht,pprevnotarizedht; uint256 notarizedhash,txid; + 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); - //fprintf(stderr, "notarizedht.%d prevnotarizedht.%d pprevnotarizedht.%d \n",notarizedht,prevnotarizedht,pprevnotarizedht); + 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 3 notarisation's have not yet happened! + // We cannot pay out if 4 notarisation's have not yet happened! // redundant now... should never happen. - if ( pprevnotarizedht == 0 ) + if ( ppprevnotarizedht == 0 ) { - fprintf(stderr, "need 3 notarizations to happen before notaries can be paid.\n"); + fprintf(stderr, "need 4 notarizations to happen before notaries can be paid.\n"); return(0); } if ( prevnotarizedht == pprevnotarizedht ) return(0); // cant happen, sanity check. - - // 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. - int32_t n = prevnotarizedht - pprevnotarizedht; + + 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. diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 88a079348..5c3372193 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -452,7 +452,7 @@ 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 komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp,int32_t *prevNotarizedHt,int32_t *ppNotarizedHt,int32_t *pppNotarizedHt) { char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) @@ -461,6 +461,7 @@ int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 * *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 b7a0ddd24..793957756 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,MoMdepth; + int32_t SAVEDHEIGHT,CURRENT_HEIGHT,NOTARIZED_HEIGHT,PNOTARIZED_HEIGHT,PPNOTARIZED_HEIGHT,PPPNOTARIZED_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 eafde8df6..b31a1be80 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3253,10 +3253,9 @@ bool check_pprevnotarizedht() static bool init; if ( init ) return(true); - int32_t notarizedht,prevMoMheight,prevnotarizedht,pprevnotarizedht; uint256 notarizedhash,txid; - uint64_t AmountToPay=0,ret=0; - notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid,&prevnotarizedht,&pprevnotarizedht); - if ( pprevnotarizedht > 0 ) + 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); @@ -3926,8 +3925,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,prevNotarizedHt; uint256 notarizedhash,txid; - komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid,&prevnotarizedht,&prevNotarizedHt); + int32_t notarizedht,prevMoMheight,prevnotarizedht,pprevnotarizedht,ppprevnotarizedht; uint256 notarizedhash,txid; + notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid,&prevnotarizedht,&pprevnotarizedht,&ppprevnotarizedht); if ( block.GetHash() == notarizedhash ) { fprintf(stderr,"DisconnectTip trying to disconnect notarized block at ht.%d\n",(int32_t)pindexDelete->GetHeight()); @@ -4261,8 +4260,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,prevNotarizedHt,prevMoMheight; uint256 notarizedhash,txid; - notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid,&prevnotarizedht,&prevNotarizedHt); + int32_t notarizedht,prevMoMheight,prevnotarizedht,pprevnotarizedht,ppprevnotarizedht; uint256 notarizedhash,txid; + notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid,&prevnotarizedht,&pprevnotarizedht,&ppprevnotarizedht); if ( pindexFork->GetHeight() < notarizedht ) { fprintf(stderr,"pindexFork->GetHeight().%d is < notarizedht %d, so ignore it\n",(int32_t)pindexFork->GetHeight(),notarizedht); @@ -5613,8 +5612,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; - notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid,&prevnotarized_height,&prevNotarizedHt); + 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); //fprintf(stderr, "pruneblockfile.%i\n",fileNumber); sleep(15); for (BlockMap::iterator it = mapBlockIndex.begin(); it != mapBlockIndex.end(); ++it) { diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 2c8d17138..9bc2c0785 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 komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp,int32_t *prevNotarizedHt,int32_t *ppNotarizedHt,int32_t *pppNotarizedHt); 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,longestchain,kmdnotarized_height,txid_height; + uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,prevnotarized_height,prevNotarizedHt,pprevNotarizedHt,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); + notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid,&prevnotarized_height,&prevNotarizedHt,&pprevNotarizedHt); //fprintf(stderr,"after notarized_height %u\n",(uint32_t)time(NULL)); UniValue obj(UniValue::VOBJ); From 3c605c86a027f5880335211c09cb07b8b999caa0 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 15 Feb 2019 00:19:27 +0800 Subject: [PATCH 12/19] fix mergetoaddress --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c6bf320a2..5996eb870 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5093,7 +5093,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) size_t numNotes = sproutNoteInputs.size() + saplingNoteInputs.size(); //fprintf(stderr, "num utxos.%li\n", numUtxos); - if (numUtxos < 1 && numNotes == 0) { + if (numUtxos < 2 && numNotes == 0) { throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Could not find any funds to merge."); } From 2172cb6742dcda47fa1c5b6a653c5be0fde1f9ac Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 15 Feb 2019 00:32:44 +0800 Subject: [PATCH 13/19] fix --- src/miner.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index e10ba290c..540aee622 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -418,7 +418,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 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>()); @@ -433,12 +433,13 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 fprintf(stderr, "Notarisation %s set to maximum priority replacing notarization %s\n",hash.ToString().c_str(), Tx.GetHash().ToString().c_str()); } } - else if ( fNotarisationBlock == true ) + else if ( Notarisations > 1 ) { // 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++; } } } From 791d8dc13b4b75800f1f7caf38892ec340e13f2e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 15 Feb 2019 11:01:10 +0800 Subject: [PATCH 14/19] 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); From f577aa00330f4de75bd9899bbe041c26e469f554 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 15 Feb 2019 11:12:17 +0800 Subject: [PATCH 15/19] fix validation --- src/komodo.h | 2 +- src/main.cpp | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 82341a369..93e0d9eb2 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -1025,7 +1025,7 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) return(0); if ( notarisations.size() == 1 && notarisations[0] == 1 ) return(1); - if ( notarisations.size() > 1 ) + if ( notarisations.size() > 1 || (notarisations.size() == 1 && notarisations[0] != 1) ) return(-1); } else return(0); diff --git a/src/main.cpp b/src/main.cpp index ab95e5b34..66766e795 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3248,7 +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 ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck,bool fCheckPOW) { CDiskBlockPos blockPos; @@ -3288,9 +3287,9 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin // 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 the valid notarization isnt in position 1. + // -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 and its in position 1. // its no longer possible for any attempted notarization to be in a block with a valid one! From 98fe10d12c6cfa925ef60e5425980b3aed0752bf Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 15 Feb 2019 14:29:59 +0800 Subject: [PATCH 16/19] enable prints for network hack --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 66766e795..46d259568 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5488,11 +5488,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); } } From e6d764b081e3c18d954d3b1538b15a9ee405b789 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 15 Feb 2019 17:20:48 +0800 Subject: [PATCH 17/19] fix miner getting stuck --- src/miner.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 539b039c3..aa19c3bd7 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -406,13 +406,13 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 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 ) @@ -433,6 +433,7 @@ 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 ) { @@ -441,6 +442,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 // 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); } } } From f6be5ec6480b35deef11c07c7fc1629580c67844 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 16 Feb 2019 16:06:35 +0800 Subject: [PATCH 18/19] LASTH to group1 --- src/miner.cpp | 1 - src/notaries_staked.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index aa19c3bd7..344ef6431 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -155,7 +155,6 @@ CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk); int32_t komodo_is_notarytx(const CTransaction& tx); uint64_t komodo_notarypay(CMutableTransaction &txNew, std::vector &NotarisationNotaries, uint32_t timestamp, int32_t height, uint8_t *script, int32_t len); int32_t komodo_getnotarizedheight(uint32_t timestamp,int32_t height, uint8_t *script, int32_t len); -bool check_pprevnotarizedht(); CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { diff --git a/src/notaries_staked.cpp b/src/notaries_staked.cpp index c2f902c82..c44d89df2 100644 --- a/src/notaries_staked.cpp +++ b/src/notaries_staked.cpp @@ -17,7 +17,7 @@ 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. From 61d7ede6b44b6a3bbf987163e74e4a74dece8f37 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 18 Feb 2019 18:23:47 +0800 Subject: [PATCH 19/19] enable miner only for notary pay, and fix magic values for non notary pay chains. --- src/komodo_utils.h | 8 ++------ src/miner.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 6e4a09546..fed8cfcca 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1778,11 +1778,6 @@ void komodo_args(char *argv0) ASSETCHAINS_DECAY[i] = 0; printf("ERA%u: ASSETCHAINS_DECAY cant be more than 100000000\n", i); } - if ( ASSETCHAINS_NOTARY_PAY[i] < 64 ) - { - ASSETCHAINS_NOTARY_PAY[i] = 64; - printf("ERA%u: ASSETCHAINS_NOTARY_PAY cant be less than 64. Set to 64.\n", i); - } } MAX_BLOCK_SIGOPS = 60000; @@ -1942,7 +1937,8 @@ void komodo_args(char *argv0) 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]); - extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_NOTARY_PAY[i]),(void *)&ASSETCHAINS_NOTARY_PAY[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) diff --git a/src/miner.cpp b/src/miner.cpp index 344ef6431..f35fb160c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -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); } @@ -393,7 +395,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 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