diff --git a/src/komodo.h b/src/komodo.h index f8575ade8..7860863d2 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -37,7 +37,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(CBlockIndex *pindex,CBlock& block); +int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block); #include "komodo_structs.h" #include "komodo_globals.h" @@ -531,7 +531,7 @@ int32_t komodo_validate_chain(uint256 srchash,int32_t notarized_height) } else return(1); } -int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,uint64_t signedmask,uint32_t timestamp) +int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,uint64_t signedmask,uint32_t timestamp) { static uint256 zero; static FILE *signedfp; int32_t opretlen,nid,offset,k,MoMdepth,matched,len = 0; uint256 MoM,srchash,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; @@ -616,7 +616,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr if ( j == 1 && opretlen >= len+offset-opoffset ) { memset(&MoMoMdata,0,sizeof(MoMoMdata)); - if ( matched == 0 && bitweight(signedmask) >= KOMODO_MINRATIFY ) + if ( matched == 0 && signedmask != 0 && bitweight(signedmask) >= KOMODO_MINRATIFY ) notarized = 1; if ( strcmp("PIZZA",ccdata.symbol) == 0 || strncmp("TXSCL",ccdata.symbol,5) == 0 ) notarized = 1; @@ -685,7 +685,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr else { komodo_rwccdata(ASSETCHAINS_SYMBOL,1,&ccdata,&MoMoMdata); - if ( matched != 0 ) + if ( !fJustCheck && matched != 0 ) printf("[%s] matched.%d VALID (%s) MoM.%s [%d] CCid.%u\n",ASSETCHAINS_SYMBOL,matched,ccdata.symbol,MoM.ToString().c_str(),MoMdepth&0xffff,(MoMdepth>>16)&0xffff); } if ( MoMoMdata.pairs != 0 ) @@ -695,13 +695,10 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } else if ( ASSETCHAINS_SYMBOL[0] == 0 && matched != 0 && notarized != 0 && validated != 0 ) komodo_rwccdata((char *)"KMD",1,&ccdata,0); - else if ( ASSETCHAINS_NOTARY_PAY != 0 ) - { - fprintf(stderr, "NOT matched NOTARISATION\n"); - return (-2); - } if ( matched != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height ) { + if ( fJustCheck ) + return(-2); sp->NOTARIZED_HEIGHT = *notarizedheightp; sp->NOTARIZED_HASH = srchash; sp->NOTARIZED_DESTTXID = desttxid; @@ -744,7 +741,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } else if ( matched != 0 && i == 0 && j == 1 && opretlen == 149 ) { - if ( notaryid >= 0 && notaryid < 64 ) + if ( !fJustCheck && notaryid >= 0 && notaryid < 64 ) komodo_paxpricefeed(height,&scriptbuf[len],opretlen); } else if ( matched != 0 ) @@ -801,18 +798,18 @@ int32_t komodo_notarycmp(uint8_t *scriptPubKey,int32_t scriptlen,uint8_t pubkeys } // int32_t ! -int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block) +int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) { static int32_t hwmheight; int32_t staked_era; static int32_t lastStakedEra; - + std::vector notarisations; uint64_t signedmask,voutmask; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; uint8_t scriptbuf[10001],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 zero,btctxid,txhash; int32_t i,j,k,numnotaries,notarized,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; if ( pindex == 0 ) { fprintf(stderr,"komodo_connectblock null pindex\n"); - return -1; + return(0); } memset(&zero,0,sizeof(zero)); komodo_init(pindex->GetHeight()); @@ -820,13 +817,13 @@ int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block) if ( (sp= komodo_stateptr(symbol,dest)) == 0 ) { fprintf(stderr,"unexpected null komodostateptr.[%s]\n",ASSETCHAINS_SYMBOL); - return -1; + return(0); } //fprintf(stderr,"%s connect.%d\n",ASSETCHAINS_SYMBOL,pindex->nHeight); if ( is_STAKED(ASSETCHAINS_SYMBOL) != 0 || IS_STAKED_NOTARY > -1 ) { staked_era = STAKED_era(pindex->GetBlockTime()); - if ( staked_era != lastStakedEra ) + if ( !fJustCheck && staked_era != lastStakedEra ) { uint8_t tmp_pubkeys[64][33]; int8_t numSN = numStakedNotaries(tmp_pubkeys,staked_era); @@ -842,8 +839,8 @@ int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block) fprintf(stderr, "Staked Notary Protection Active! NotaryID.%d RADD.%s ERA.%d MIN_TX_VALUE.%lu \n",IS_STAKED_NOTARY,NOTARY_ADDRESS.c_str(),staked_era,MIN_RECV_SATS); } } + lastStakedEra = staked_era; } - lastStakedEra = staked_era; } numnotaries = komodo_notaries(pubkeys,pindex->GetHeight(),pindex->GetBlockTime()); calc_rmd160_sha256(rmd160,pubkeys[0],33); @@ -857,11 +854,13 @@ int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block) komodo_purge_ccdata((int32_t)pindex->GetHeight()); hwmheight = pindex->GetHeight(); } - komodo_event_rewind(sp,symbol,pindex->GetHeight()); - komodo_stateupdate(pindex->GetHeight(),0,0,0,zero,0,0,0,0,-pindex->GetHeight(),pindex->nTime,0,0,0,0,zero,0); + if (!fJustCheck) + { + komodo_event_rewind(sp,symbol,pindex->GetHeight()); + komodo_stateupdate(pindex->GetHeight(),0,0,0,zero,0,0,0,0,-pindex->GetHeight(),pindex->nTime,0,0,0,0,zero,0); + } } komodo_currentheight_set(chainActive.LastTip()->GetHeight()); - int transaction = 0; if ( pindex != 0 ) { height = pindex->GetHeight(); @@ -869,9 +868,12 @@ int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block) for (i=0; i 1) + break; txhash = block.vtx[i].GetHash(); numvouts = block.vtx[i].vout.size(); notaryid = -1; @@ -900,7 +902,7 @@ int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block) (numvalid >= KOMODO_MINRATIFY && ASSETCHAINS_SYMBOL[0] != 0) || numvalid > (numnotaries/5) ) { - if ( ASSETCHAINS_SYMBOL[0] != 0) + if ( !fJustCheck && ASSETCHAINS_SYMBOL[0] != 0) { static FILE *signedfp; if ( signedfp == 0 ) @@ -917,7 +919,6 @@ int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block) fwrite(&signedmask,1,sizeof(signedmask),signedfp); fflush(signedfp); } - transaction = i; printf("[%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d <<<<<<<<<<< notarized\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts); } notarized = 1; @@ -947,9 +948,13 @@ int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block) if ( len >= sizeof(uint32_t) && len <= sizeof(scriptbuf) ) { memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len); - notaryid = komodo_voutupdate(&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 ( notaryid == -2 ) - return(-1); + 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 ) + { + // 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() == hwmheight ) + if ( !fJustCheck && pindex->GetHeight() == hwmheight ) komodo_stateupdate(height,0,0,0,zero,0,0,0,0,height,(uint32_t)pindex->nTime,0,0,0,0,zero,0); } else fprintf(stderr,"komodo_connectblock: unexpected null pindex\n"); //KOMODO_INITDONE = (uint32_t)time(NULL); //fprintf(stderr,"%s end connect.%d\n",ASSETCHAINS_SYMBOL,pindex->GetHeight()); - if (notarized = 1) - return(transaction); - else - return(-1); + if (fJustCheck) + { + if (notarisations.size() == 0) + return(0); + if ( notarisations.size() == 1 && notarisations[0] == 1 ) + return(1); + else + return(-1); + } + else return(0); } diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e679c4084..a139adf90 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1772,17 +1772,67 @@ bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height) return(isPOS); } -uint64_t komodo_notarypay(CMutableTransaction &txNew, std::vector &NotarisationNotaries, uint32_t timestamp) +int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp); + +uint64_t komodo_notarypayamount(int32_t height, int64_t numnotaries) +{ + if ( numnotaries == 0 ) + return(0); + // fetch notarised height + int32_t notarizedht,prevMoMheight; uint256 notarizedhash,txid; + uint64_t AmountToPay=0,ret=0; + notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid); + // dont think this can happen, just sanity check. + if ( height == notarizedht ) + return(0); + // how many block since last notarisation. + int32_t n = height - notarizedht; + fprintf(stderr, "blocks since last notarisation: %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 / numnotaries; + fprintf(stderr, "payment per notary.%lu\n",ret); + return(ret); +} + +int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,uint64_t signedmask,uint32_t timestamp); + +uint64_t komodo_notarypay(CMutableTransaction &txNew, std::vector &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; + uint64_t total = 0, AmountToPay = 0; int32_t staked_era; int8_t numSN; uint8_t staked_pubkeys[64][33]; staked_era = STAKED_era(timestamp); numSN = numStakedNotaries(staked_pubkeys,staked_era); // resize coinbase vouts to number of notary nodes +1 for coinbase itself. txNew.vout.resize(NotarisationNotaries.size()+1); + + // Check the notarisation is valid, and extract notarised height. + uint64_t voutmask; + uint8_t scriptbuf[10001]; + int32_t isratification,specialtx,notarizedheight; + + if ( len >= sizeof(uint32_t) && len <= sizeof(scriptbuf) ) + { + memcpy(scriptbuf,script,len); + if ( komodo_voutupdate(true,&isratification,0,scriptbuf,len,height,uint256(),1,1,&voutmask,&specialtx,¬arizedheight,0,1,0,timestamp) == -2 ) + { + fprintf(stderr, "VALID NOTARIZATION ht.%i\n",notarizedheight); + } + else + { + fprintf(stderr, "INVALID NOTARIZATION ht.%i\n",notarizedheight); + return(0); + } + } else return(0); + + // Calcualte the amount to pay. + AmountToPay = komodo_notarypayamount(notarizedheight,NotarisationNotaries.size()); + // loop over notarisation vins and add transaction to coinbase. // Commented prints here can be used to verify manually the pubkeys match. for (int8_t n = 0; n < NotarisationNotaries.size(); n++) @@ -1798,7 +1848,7 @@ uint64_t komodo_notarypay(CMutableTransaction &txNew, std::vector &Notar } ptr[34] = OP_CHECKSIG; //fprintf(stderr," set notary %i PUBKEY33 into vout[%i]\n",NotarisationNotaries[n],n+1); - txNew.vout[n+1].nValue = ASSETCHAINS_NOTARY_PAY; + txNew.vout[n+1].nValue = AmountToPay; total += txNew.vout[n+1].nValue; } return(total); @@ -1832,35 +1882,69 @@ uint64_t komodo_checknotarypay(CBlock *pblock,int32_t height) } const CChainParams& chainparams = Params(); const Consensus::Params &consensusParams = chainparams.GetConsensus(); + uint64_t totalsats = 0; CMutableTransaction txNew = CreateNewContextualCMutableTransaction(consensusParams, height); - uint64_t totalsats = komodo_notarypay(txNew, NotarisationNotaries, pblock->nTime); - int8_t n = 0, i = 0, matches = 0; - uint64_t total = 0; - //fprintf(stderr, "txNew.vout size = %li\n",txNew.vout.size()); - // Check the created coinbase is equal to the coinbase the miner submitted in the block. - BOOST_FOREACH(const CTxOut& txout, txNew.vout) + if ( pblock->vtx[1].vout.size() == 2 && pblock->vtx[1].vout[1].nValue == 0 ) { - if ( n == 0 ) + // Get the OP_RETURN for the notarisation + uint8_t *script = (uint8_t *)&pblock->vtx[1].vout[1].scriptPubKey[0]; + int32_t scriptlen = (int32_t)pblock->vtx[1].vout[1].scriptPubKey.size(); + if ( script[0] == OP_RETURN ) + { + totalsats = komodo_notarypay(txNew, NotarisationNotaries, pblock->nTime, height, script, scriptlen); + } + else + { + fprintf(stderr, "vout 2 of notarisation is not OP_RETURN scriptlen.%i\n", scriptlen); + return(-1); + } + } + + // if notarypay fails, because the notarisation is not valid, exit now as txNew was not created. + if ( totalsats == 0 ) + { + fprintf(stderr, "notary pay RETURNED 0!\n"); + return(-1); + } + + int8_t n = 0, i = 0, matches = 0; + uint64_t total = 0, AmountToPay = 0; + + // get the pay amount from the created tx. + AmountToPay = txNew.vout[1].nValue; + + //fprintf(stderr, "txNew.vout size = %li\n",txNew.vout.size()); + // Check the created coinbase pays the correct notaries. + BOOST_FOREACH(const CTxOut& txout, pblock->vtx[0].vout) + { + // skip the coinbase + if ( n == 0 ) { n++; continue; } + // Check the pubkeys match the pubkeys in the notarisation. script = (uint8_t *)&txout.scriptPubKey[0]; scriptlen = (int32_t)txout.scriptPubKey.size(); - if ( txout.nValue == ASSETCHAINS_NOTARY_PAY && scriptlen == 35 && script[0] == 33 && script[34] == OP_CHECKSIG && memcmp(script+1,staked_pubkeys[NotarisationNotaries[n-1]],33) == 0 ) + if ( scriptlen == 35 && script[0] == 33 && script[34] == OP_CHECKSIG && memcmp(script+1,staked_pubkeys[NotarisationNotaries[n-1]],33) == 0 ) { - matches++; - total += txout.nValue; - fprintf(stderr, "matched.%i\n", NotarisationNotaries[n-1]); + // check the value is correct + if ( pblock->vtx[0].vout[n].nValue == AmountToPay ) + { + matches++; + total += txout.nValue; + fprintf(stderr, "matched.%i\n", 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]); } - n++; + n++; } - if ( matches = n && matches != 0 && total == totalsats ) + if ( matches != 0 && matches == NotarisationNotaries.size() && totalsats == total ) { fprintf(stderr, "VALIDATED.\n" ); return(totalsats); } - return(-1); + return(0); } int64_t komodo_checkcommission(CBlock *pblock,int32_t height) @@ -2043,14 +2127,10 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } } - if( failed == 0 && ASSETCHAINS_NOTARY_PAY != 0 && pblock->vtx[0].vout.size() != 1 ) + if ( failed == 0 && ASSETCHAINS_NOTARY_PAY != 0 && pblock->vtx[0].vout.size() > 1 ) { - if ( slowflag != 0 && komodo_checknotarypay(pblock,height) < 0 ) - { - fprintf(stderr, "Komodo notary pay validation failed.%i\n",height); - return(-1); - } - else + // We check the full validation in ConnectBlock directly to get the amount for coinbase. So just approx here. + if ( slowflag == 0 ) { // Check the notarisation tx is to the crypto address. if ( !komodo_is_notarytx(pblock->vtx[1]) == 1 ) diff --git a/src/main.cpp b/src/main.cpp index 99fb44147..ec79fafbc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3574,14 +3574,32 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin fprintf(stderr,"checktoshis %.8f vs %.8f numvouts %d\n",dstr(checktoshis),dstr(block.vtx[0].vout[1].nValue),(int32_t)block.vtx[0].vout.size()); } } - if ( ASSETCHAINS_NOTARY_PAY != 0 && block.vtx[0].vout.size() > 1 ) + bool sleepflag = false; + if ( ASSETCHAINS_NOTARY_PAY != 0 ) { - uint64_t notarypaycheque = komodo_checknotarypay((CBlock *)&block,(int32_t)pindex->GetHeight()); - if ( notarypaycheque > 0 ) - blockReward += notarypaycheque; - else - return state.DoS(100, error("ConnectBlock(): Notary Pay exceeds the amount allowed! (actual=%d vs correct=%d)", block.vtx[0].GetValueOut(), blockReward), - REJECT_INVALID, "bad-cb-amount"); + // do a full block scan to get notarisation position and to enforce 1 notarisation is in block only. + // 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. + 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 + if ( notarisationTx == 1 ) + { + // Check if the notaries have been paid. + if ( block.vtx[0].vout.size() == 1 ) + return state.DoS(100, error("ConnectBlock(): Notary has not been paid!"), + REJECT_INVALID, "bad-cb-amount"); + // calculate the notaries compensation and validate the amounts and pubkeys are correct. + uint64_t notarypaycheque = komodo_checknotarypay((CBlock *)&block,(int32_t)pindex->GetHeight()); + fprintf(stderr, "notarypaycheque.%lu\n", notarypaycheque); + if ( notarypaycheque > 0 ) + blockReward += notarypaycheque; + else + return state.DoS(100, error("ConnectBlock(): Notary pay Validation Failed!"), + REJECT_INVALID, "bad-cb-amount"); + } } if (ASSETCHAINS_SYMBOL[0] != 0 && pindex->GetHeight() == 1 && block.vtx[0].GetValueOut() != blockReward) { @@ -3592,6 +3610,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin { if ( ASSETCHAINS_SYMBOL[0] != 0 || pindex->GetHeight() >= KOMODO_NOTARIES_HEIGHT1 || block.vtx[0].vout[0].nValue > blockReward ) { + //fprintf(stderr, "coinbase pays too much\n"); + //sleepflag = true; return state.DoS(100, error("ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)", block.vtx[0].GetValueOut(), blockReward), @@ -3641,15 +3661,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin ConnectNotarisations(block, pindex->GetHeight()); // MoMoM notarisation DB. - int notarisationTx = komodo_connectblock(pindex,*(CBlock *)&block); // dPoW state update. - if ( ASSETCHAINS_NOTARY_PAY != 0 && notarisationTx > 0 ) - { - printf("VALID NOTARISATION connect block.%i tx.%i\n",pindex->GetHeight(),notarisationTx); - if ( notarisationTx != 1 ) - return state.DoS(100, error("ConnectBlock(): Notarisation is not in TX position 1! Invalid Block!"), - REJECT_INVALID, "bad-notarization-position"); - } - if (fTxIndex) if (!pblocktree->WriteTxIndex(vPos)) return AbortNode(state, "Failed to write transaction index"); @@ -3704,6 +3715,9 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin LogPrint("bench", " - Callbacks: %.2fms [%.2fs]\n", 0.001 * (nTime4 - nTime3), nTimeCallbacks * 0.000001); //FlushStateToDisk(); + komodo_connectblock(false,pindex,*(CBlock *)&block); // dPoW state update. + if (sleepflag) + sleep(30); return true; } diff --git a/src/miner.cpp b/src/miner.cpp index 4ad70912c..6476a7b48 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -153,7 +153,7 @@ int32_t komodo_is_notarytx(const CTransaction& tx); CScript Marmara_scriptPubKey(int32_t height,CPubKey pk); 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); +uint64_t komodo_notarypay(CMutableTransaction &txNew, std::vector &NotarisationNotaries, uint32_t timestamp, int32_t height, uint8_t *script, int32_t len); CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { @@ -672,14 +672,16 @@ 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 ) + else if ( fNotarisationBlock && ASSETCHAINS_NOTARY_PAY != 0 && pblock->vtx[1].vout.size() == 2 && pblock->vtx[1].vout[1].nValue == 0 ) { - // This block contains a valid notarisation as best as we can know. We cant check this 100% until we try to connect block. - // This assumes notaries are not going to collude to create invalid notarisations. - // If they did this, then the block would be invalid, and all kinds of werid things will happen. - // We can test this, and see what happens, if its unreliable, we will need to create a CC contract. - uint64_t totalsats = komodo_notarypay(txNew, NotarisationNotaries, pblock->nTime); - fprintf(stderr, "Created notary payment coinbase totalsat.%lu\n",totalsats); + // Get the OP_RETURN for the notarisation + uint8_t *script = (uint8_t *)&pblock->vtx[1].vout[1].scriptPubKey[0]; + int32_t scriptlen = (int32_t)pblock->vtx[1].vout[1].scriptPubKey.size(); + if ( script[0] == OP_RETURN ) + { + uint64_t totalsats = komodo_notarypay(txNew, NotarisationNotaries, pblock->nTime, nHeight, script, scriptlen); + fprintf(stderr, "Created notary payment coinbase totalsat.%lu\n",totalsats); + } else fprintf(stderr, "vout 2 of notarisation is not OP_RETURN scriptlen.%i\n", scriptlen); } pblock->vtx[0] = txNew;