From c3a9d0fa0cd5fd7939b68162db8b50a8505471d7 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Apr 2019 12:28:27 +0800 Subject: [PATCH 1/9] test --- src/rpc/rawtransaction.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 6e90c4db5..41ed8ff66 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -721,7 +721,7 @@ UniValue verifytxoutproof(const UniValue& params, bool fHelp) UniValue createrawtransaction(const UniValue& params, bool fHelp) { - if (fHelp || params.size() < 2 || params.size() > 4) + if (fHelp ) || //params.size() < 2 || params.size() > 4) throw runtime_error( "createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,...} ( locktime ) ( expiryheight )\n" "\nCreate a transaction spending the given inputs and sending to the given addresses.\n" @@ -754,6 +754,32 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) + HelpExampleRpc("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"address\\\":0.01}\"") ); + int nextBlockHeight = chainActive.Height() + 1; + CMutableTransaction rawTx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextBlockHeight); + CCcontract_info *cp, C; + + cp = CCinit(&C,EVAL_ORACLES); + CPubKey ccAddress = CPubKey(ParseHex(cp->CChexstr)); + CPubKey mypk = Mypubkey(); + + CTxOut vout = MakeCC1of2vout(EVAL_ORACLES, 1000000, mypk, ccAddress); + + std::vector vPubKeys = std::vector(); + vPubKeys.push_back(mypk); + vPubKeys.push_back(ccAddress); + + std::vector> vData = std::vector>(); + std::string test = "thisisatest"; + vData.push_back(std::vector(test.begin(), test.end())); + test = "anothertest"; + vData.push_back(std::vector(test.begin(), test.end())); + COptCCParams ccp = COptCCParams(COptCCParams::VERSION, EVAL_ORACLES, 1, 2, vPubKeys, vData); + + vout.scriptPubKey << ccp.AsVector() << OP_DROP; + rawTx.vout.push_back(vout); + + return EncodeHexTx(rawTx); + LOCK(cs_main); RPCTypeCheck(params, boost::assign::list_of(UniValue::VARR)(UniValue::VOBJ)(UniValue::VNUM)(UniValue::VNUM), true); if (params[0].isNull() || params[1].isNull()) From 0bb8c5be229521d584ac40900ee5a9a853a4f1a1 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Apr 2019 13:14:04 +0800 Subject: [PATCH 2/9] fix wallet code. Force daemon close and reccomend zapwallettxns for non staking chains. --- src/wallet/walletdb.cpp | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index eab041d94..5631fb79e 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -30,6 +30,7 @@ #include "utiltime.h" #include "wallet/wallet.h" #include "zcash/Proof.hpp" +#include "komodo_defs.h" #include #include @@ -486,7 +487,6 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, auto verifier = libzcash::ProofVerifier::Strict(); if (!(CheckTransaction(0,wtx, state, verifier) && (wtx.GetHash() == hash) && state.IsValid())) { - fprintf(stderr, "Removing corrupt tx from wallet.%s\n", hash.ToString().c_str()); deadTxns.push_back(hash); return false; } @@ -951,23 +951,35 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) result = DB_CORRUPT; } - if (!deadTxns.empty()) + if ( !deadTxns.empty() ) { - int32_t reAdded = 0; - CWalletDB walletdb(pwallet->strWalletFile, "r+", false); - BOOST_FOREACH (uint256& hash, deadTxns) { - if (!EraseTx(hash)) - fprintf(stderr, "could not delete tx.%s\n",hash.ToString().c_str()); - uint256 blockhash; CTransaction tx; - if (GetTransaction(hash,tx,blockhash,true)) + if ( ASSETCHAINS_STAKED != 0 ) + { + int32_t reAdded = 0; + CWalletDB walletdb(pwallet->strWalletFile, "r+", false); + BOOST_FOREACH (uint256& hash, deadTxns) { - CWalletTx wtx(pwallet,tx); - pwallet->AddToWallet(wtx, false, &walletdb); - reAdded++; + fprintf(stderr, "Removing corrupt tx from wallet.%s\n", hash.ToString().c_str()); + if (!EraseTx(hash)) + fprintf(stderr, "could not delete tx.%s\n",hash.ToString().c_str()); + uint256 blockhash; CTransaction tx; + if (GetTransaction(hash,tx,blockhash,true)) + { + CWalletTx wtx(pwallet,tx); + pwallet->AddToWallet(wtx, false, &walletdb); + reAdded++; + } } + fprintf(stderr, "Cleared %lu corrupted transactions from wallet. Readded %i known transactions.\n",(long)deadTxns.size(),reAdded); + fNoncriticalErrors = false; + deadTxns.clear(); + } + else if ( (GetBoolArg("-zapwallettxes", false)) ) + { + LogPrintf("Transactions are corrupted. Please restart daemon with -zapwallettxes=2\n"); + fprintf(stderr,"Transactions are corrupted. Please restart daemon with -zapwallettxes=2\n"); + return DB_CORRUPT; } - fprintf(stderr, "Cleared %lu corrupted transactions from wallet. Readded %i known transactions.\n",(long)deadTxns.size(),reAdded); - deadTxns.clear(); } if (fNoncriticalErrors && result == DB_LOAD_OK) From ece9e468bc2de19eeb7a0aca9f63c4000887c866 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Apr 2019 23:14:46 -1100 Subject: [PATCH 3/9] #define PRICES_MAXDATAPOINTS 8 --- src/komodo_defs.h | 1 + src/komodo_gateway.h | 1 - src/rpc/blockchain.cpp | 9 ++++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 4db390494..23a689154 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -85,6 +85,7 @@ void komodo_netevent(std::vector payload); #define KOMODO_KVDURATION 1440 #define KOMODO_KVBINARY 2 #define PRICES_SMOOTHWIDTH 1 +#define PRICES_MAXDATAPOINTS 8 uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume); int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel); int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a6b5b4566..ed80c2a4a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1555,7 +1555,6 @@ extern std::vector Mineropret; // opreturn data set by the data gatheri #define KOMODO_LOCALPRICE_CACHESIZE 13 #define KOMODO_MAXPRICES 2048 #define PRICES_SMOOTHWIDTH 1 -#define PRICES_MAXDATAPOINTS 8 #define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"CBCOINBASE",cmdstr,0,0,0) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 18f7b0fc0..ab6bd7fb9 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1255,7 +1255,14 @@ UniValue prices(const UniValue& params, bool fHelp) rngval = (rngval*11109 + 13849); if ( (correlated[i]= komodo_pricecorrelated(rngval,j,&prices[offset],1,0,PRICES_SMOOTHWIDTH)) < 0 ) throw JSONRPCError(RPC_INVALID_PARAMETER, "null correlated price"); - + { + int64_t checkprices[PRICES_MAXDATAPOINTS]; + if ( komodo_priceget(checkprices,j,nextheight-1-i,1) >= 0 ) + { + if ( checkprices[1] != correlated[i] ) + fprintf(stderr,"ind.%d ht.%d %.8f != %.8f\n",j,nextheight-1-i,(double)checkprices[1]/COIN,(double)correlated[i]/COIN); + } + } } tmpbuf = (int64_t *)calloc(sizeof(int64_t),2*PRICES_DAYWINDOW); for (i=0; i Date: Mon, 15 Apr 2019 23:27:20 -1100 Subject: [PATCH 4/9] Smoothed --- src/rpc/blockchain.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index ab6bd7fb9..c0a45e292 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1195,7 +1195,7 @@ UniValue prices(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("prices maxsamples\n"); LOCK(cs_main); - UniValue ret(UniValue::VOBJ); uint64_t seed,rngval; int64_t *tmpbuf,smoothed,*correlated; char name[64],*str; uint32_t rawprices[1440*6],*prices; uint32_t i,width,j,numpricefeeds=-1,n,numsamples,nextheight,offset,ht; + UniValue ret(UniValue::VOBJ); uint64_t seed,rngval; int64_t *tmpbuf,smoothed,*correlated,checkprices[PRICES_MAXDATAPOINTS]; char name[64],*str; uint32_t rawprices[1440*6],*prices; uint32_t i,width,j,numpricefeeds=-1,n,numsamples,nextheight,offset,ht; if ( ASSETCHAINS_CBOPRET == 0 ) throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices"); @@ -1256,11 +1256,13 @@ UniValue prices(const UniValue& params, bool fHelp) if ( (correlated[i]= komodo_pricecorrelated(rngval,j,&prices[offset],1,0,PRICES_SMOOTHWIDTH)) < 0 ) throw JSONRPCError(RPC_INVALID_PARAMETER, "null correlated price"); { - int64_t checkprices[PRICES_MAXDATAPOINTS]; if ( komodo_priceget(checkprices,j,nextheight-1-i,1) >= 0 ) { if ( checkprices[1] != correlated[i] ) - fprintf(stderr,"ind.%d ht.%d %.8f != %.8f\n",j,nextheight-1-i,(double)checkprices[1]/COIN,(double)correlated[i]/COIN); + { + //fprintf(stderr,"ind.%d ht.%d %.8f != %.8f\n",j,nextheight-1-i,(double)checkprices[1]/COIN,(double)correlated[i]/COIN); + correlated[i] = checkprices[1]; + } } } } @@ -1269,6 +1271,14 @@ UniValue prices(const UniValue& params, bool fHelp) { offset = j*width + i; smoothed = komodo_priceave(tmpbuf,&correlated[i],1); + if ( komodo_priceget(checkprices,j,nextheight-1-i,1) >= 0 ) + { + if ( checkprices[2] != smoothed ) + { + fprintf(stderr,"ind.%d ht.%d %.8f != %.8f\n",j,nextheight-1-i,(double)checkprices[2]/COIN,(double)smoothed/COIN); + smoothed = checkprices[2]; + } + } UniValue parr(UniValue::VARR); parr.push_back(ValueFromAmount((int64_t)prices[offset] * komodo_pricemult(j))); parr.push_back(ValueFromAmount(correlated[i])); From 81aa1908d9b4bafaa307863eca616079a442c73c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Apr 2019 23:31:59 -1100 Subject: [PATCH 5/9] Deprecate prices_extract --- src/cc/CCPrices.h | 1 - src/cc/prices.cpp | 6 ++---- src/rpc/blockchain.cpp | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 633cc32e2..3dbe6a87c 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -18,7 +18,6 @@ #define CC_PRICES_H #include "CCinclude.h" -int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks,int32_t ind); int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblocks); #define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 5d164d97e..407cd81fa 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -320,8 +320,7 @@ int32_t prices_syntheticvec(std::vector &vec,std::vector int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t minmax,int16_t leverage) { - int32_t i,ind,errcode,depth,retval = -1; uint16_t opcode; int64_t *pricedata,pricestack[4],price,den,a,b,c; - pricedata = (int64_t *)calloc(sizeof(*pricedata)*3,1 + PRICES_DAYWINDOW*2 + PRICES_SMOOTHWIDTH); + int32_t i,ind,errcode,depth,retval = -1; uint16_t opcode; int64_t pricedata[PRICES_MAXDATAPOINTS],pricestack[4],price,den,a,b,c; price = den = depth = errcode = 0; for (i=0; i vec,int32_t height,int32_t m { case 0: pricestack[depth] = 0; - if ( prices_extract(pricedata,height,1,ind) == 0 ) + if ( komodo_priceget(pricedata,ind,height,1) > 0 ) { if ( minmax == 0 ) pricestack[depth] = pricedata[2]; @@ -420,7 +419,6 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m if ( errcode != 0 ) break; } - free(pricedata); if ( den == 0 ) return(-11); else if ( depth != 0 ) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index c0a45e292..035d44662 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1156,7 +1156,7 @@ UniValue paxprice(const UniValue& params, bool fHelp) return ret; } -int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks,int32_t ind) +/*int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks,int32_t ind) { int32_t height,i,n,width,numpricefeeds = -1; uint64_t seed,ignore,rngval; uint32_t rawprices[1440*6],*ptr; int64_t *tmpbuf; width = numblocks+PRICES_DAYWINDOW*2+PRICES_SMOOTHWIDTH; @@ -1188,7 +1188,7 @@ int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks, pricedata[i*3+2] = komodo_priceave(tmpbuf,&pricedata[i*3+1],3); free(tmpbuf); return(0); -} +}*/ UniValue prices(const UniValue& params, bool fHelp) { From 997f9ce5fcfb600cc6832a431c11912c8b94b65e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Apr 2019 20:59:15 +0800 Subject: [PATCH 6/9] initial commit to use CCopt for custom CC --- src/cc/CCinclude.h | 4 ++-- src/cc/CCutils.cpp | 21 +++++++++++++++++++-- src/cc/customcc.cpp | 45 +++++++++++++++++++++++++++++++++++++-------- src/main.cpp | 2 +- 4 files changed, 59 insertions(+), 13 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 5b6d575f3..6ca6fa3bc 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -226,8 +226,8 @@ bool priv2addr(char *coinaddr,uint8_t buf33[33],uint8_t priv32[32]); CPubKey buf2pk(uint8_t *buf33); void endiancpy(uint8_t *dest,uint8_t *src,int32_t len); uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv,int32_t entropyvout,int32_t usevout); -CTxOut MakeCC1vout(uint8_t evalcode,CAmount nValue,CPubKey pk); -CTxOut MakeCC1of2vout(uint8_t evalcode,CAmount nValue,CPubKey pk,CPubKey pk2); +CTxOut MakeCC1vout(uint8_t evalcode,CAmount nValue,CPubKey pk, const std::vector>* vData = NULL); +CTxOut MakeCC1of2vout(uint8_t evalcode,CAmount nValue,CPubKey pk,CPubKey pk2, const std::vector>* vData = NULL); CC *MakeCCcond1(uint8_t evalcode,CPubKey pk); CC *MakeCCcond1of2(uint8_t evalcode,CPubKey pk1,CPubKey pk2); CC* GetCryptoCondition(CScript const& scriptSig); diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 55c93d7b3..a34bf1a81 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -58,20 +58,37 @@ CC *MakeCCcond1(uint8_t evalcode,CPubKey pk) return CCNewThreshold(2, {condCC, Sig}); } -CTxOut MakeCC1vout(uint8_t evalcode,CAmount nValue,CPubKey pk) +CTxOut MakeCC1vout(uint8_t evalcode,CAmount nValue, CPubKey pk, const std::vector>* vData) { CTxOut vout; CC *payoutCond = MakeCCcond1(evalcode,pk); vout = CTxOut(nValue,CCPubKey(payoutCond)); + if ( vData ) + { + std::vector> vtmpData = std::vector>(vData->begin(), vData->end()); + std::vector vPubKeys = std::vector(); + vPubKeys.push_back(pk); + COptCCParams ccp = COptCCParams(COptCCParams::VERSION, evalcode, 1, 1, vPubKeys, vtmpData); + vout.scriptPubKey << ccp.AsVector() << OP_DROP; + } cc_free(payoutCond); return(vout); } -CTxOut MakeCC1of2vout(uint8_t evalcode,CAmount nValue,CPubKey pk1,CPubKey pk2) +CTxOut MakeCC1of2vout(uint8_t evalcode,CAmount nValue,CPubKey pk1,CPubKey pk2, const std::vector>* vData) { CTxOut vout; CC *payoutCond = MakeCCcond1of2(evalcode,pk1,pk2); vout = CTxOut(nValue,CCPubKey(payoutCond)); + if ( vData ) + { + std::vector> vtmpData = std::vector>(vData->begin(), vData->end()); + std::vector vPubKeys = std::vector(); + vPubKeys.push_back(pk1); + vPubKeys.push_back(pk2); + COptCCParams ccp = COptCCParams(COptCCParams::VERSION, evalcode, 1, 2, vPubKeys, vtmpData); + vout.scriptPubKey << ccp.AsVector() << OP_DROP; + } cc_free(payoutCond); return(vout); } diff --git a/src/cc/customcc.cpp b/src/cc/customcc.cpp index 9f58c5c8b..34144fedc 100644 --- a/src/cc/customcc.cpp +++ b/src/cc/customcc.cpp @@ -11,7 +11,7 @@ */ CScript custom_opret(uint8_t funcid,CPubKey pk) -{ +{ CScript opret; uint8_t evalcode = EVAL_CUSTOM; opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << pk); return(opret); @@ -64,25 +64,54 @@ UniValue custom_func1(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) mypk = pubkey2pk(Mypubkey()); if ( AddNormalinputs(mtx,mypk,COIN+txfee,64) >= COIN+txfee ) // add utxo to mtx { - mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,mypk)); // make vout0 - // add opreturn, change is automatically added and tx is properly signed - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,custom_opret('1',mypk)); + // make op_return payload as normal. + CScript opret = custom_opret('1',mypk); + std::vector> vData = std::vector>(); + vData.push_back(std::vector(opret.begin(), opret.end())); + // make vout0 with op_return included as payload. + mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,mypk,&vData)); + fprintf(stderr, "vout size2.%li\n", mtx.vout.size()); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,CScript()); return(custom_rawtxresult(result,rawtx,broadcastflag)); } return(result); } +bool has_opret(const CTransaction &tx, uint8_t evalcode) +{ + for ( auto vout : tx.vout ) + { + if ( vout.scriptPubKey[1] == evalcode ) + return true; + } + return false; +} + bool custom_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { char expectedaddress[64]; CPubKey pk; - if ( tx.vout.size() != 2 ) // make sure the tx only has 2 outputs + CScript opret; int32_t numvout; + if ( !has_opret(tx, EVAL_CUSTOM) ) + { + std::vector> vParams = std::vector>(); + CScript dummy; + if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition(&dummy, vParams) && vParams.size() == 1 ) + { + opret << E_MARSHAL(ss << vParams[0]); + } + numvout = 1; + } + else + { + opret = tx.vout[1].scriptPubKey; + numvout = 2; + } + if ( tx.vout.size() != numvout ) // make sure the tx only has appropriate outputs return eval->Invalid("invalid number of vouts"); - else if ( custom_opretdecode(pk,tx.vout[1].scriptPubKey) != '1' ) // verify has opreturn + else if ( custom_opretdecode(pk,opret) != '1' ) // verify opreturn payload return eval->Invalid("invalid opreturn"); GetCCaddress(cp,expectedaddress,pk); if ( IsCClibvout(cp,tx,0,expectedaddress) == COIN ) // make sure amount and destination matches return(true); else return eval->Invalid("invalid vout0 amount"); } - - diff --git a/src/main.cpp b/src/main.cpp index e0e40c9a5..304ff52a5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -796,7 +796,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason, const int nHeight) else if ((whichType == TX_MULTISIG) && (!fIsBareMultisigStd)) { reason = "bare-multisig"; return false; - } else if (txout.scriptPubKey.IsPayToCryptoCondition() == 0 && txout.IsDust(::minRelayTxFee)) { + } else if (whichType != TX_CRYPTOCONDITION && txout.IsDust(::minRelayTxFee)) { reason = "dust"; return false; } From 660c8dc26c92c39e1077f072f56ba936acafc0ce Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Apr 2019 21:08:39 +0800 Subject: [PATCH 7/9] fix has_opret function --- src/cc/customcc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/customcc.cpp b/src/cc/customcc.cpp index 34144fedc..2e174f510 100644 --- a/src/cc/customcc.cpp +++ b/src/cc/customcc.cpp @@ -81,7 +81,7 @@ bool has_opret(const CTransaction &tx, uint8_t evalcode) { for ( auto vout : tx.vout ) { - if ( vout.scriptPubKey[1] == evalcode ) + if ( vout.scriptPubKey[0] == OP_RETURN && vout.scriptPubKey[1] == evalcode ) return true; } return false; From 87ebcc3b2b21998761a101851bb8fab16081980f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Apr 2019 21:11:06 +0800 Subject: [PATCH 8/9] revert createrawtransaction --- src/rpc/rawtransaction.cpp | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 41ed8ff66..6e90c4db5 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -721,7 +721,7 @@ UniValue verifytxoutproof(const UniValue& params, bool fHelp) UniValue createrawtransaction(const UniValue& params, bool fHelp) { - if (fHelp ) || //params.size() < 2 || params.size() > 4) + if (fHelp || params.size() < 2 || params.size() > 4) throw runtime_error( "createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,...} ( locktime ) ( expiryheight )\n" "\nCreate a transaction spending the given inputs and sending to the given addresses.\n" @@ -754,32 +754,6 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) + HelpExampleRpc("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"address\\\":0.01}\"") ); - int nextBlockHeight = chainActive.Height() + 1; - CMutableTransaction rawTx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextBlockHeight); - CCcontract_info *cp, C; - - cp = CCinit(&C,EVAL_ORACLES); - CPubKey ccAddress = CPubKey(ParseHex(cp->CChexstr)); - CPubKey mypk = Mypubkey(); - - CTxOut vout = MakeCC1of2vout(EVAL_ORACLES, 1000000, mypk, ccAddress); - - std::vector vPubKeys = std::vector(); - vPubKeys.push_back(mypk); - vPubKeys.push_back(ccAddress); - - std::vector> vData = std::vector>(); - std::string test = "thisisatest"; - vData.push_back(std::vector(test.begin(), test.end())); - test = "anothertest"; - vData.push_back(std::vector(test.begin(), test.end())); - COptCCParams ccp = COptCCParams(COptCCParams::VERSION, EVAL_ORACLES, 1, 2, vPubKeys, vData); - - vout.scriptPubKey << ccp.AsVector() << OP_DROP; - rawTx.vout.push_back(vout); - - return EncodeHexTx(rawTx); - LOCK(cs_main); RPCTypeCheck(params, boost::assign::list_of(UniValue::VARR)(UniValue::VOBJ)(UniValue::VNUM)(UniValue::VNUM), true); if (params[0].isNull() || params[1].isNull()) From 18854e2af787893dfd5b82284c960220a03bf3e7 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 17 Apr 2019 13:42:02 +0800 Subject: [PATCH 9/9] ac_nk params --- src/chainparams.cpp | 7 ++ src/chainparams.h | 2 + src/crypto/equihash.cpp | 262 ++++++++++++++++++++++++++-------------- src/crypto/equihash.h | 100 ++++++++++----- src/komodo_defs.h | 3 +- src/komodo_nk.h | 7 ++ src/komodo_utils.h | 38 +++++- src/miner.cpp | 21 ++-- src/pow.cpp | 3 + 9 files changed, 308 insertions(+), 135 deletions(-) create mode 100644 src/komodo_nk.h diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 26e29d9de..b09ccf7c3 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -92,6 +92,7 @@ static CBlock CreateGenesisBlock(uint32_t nTime, const uint256& nNonce, const st void *chainparams_commandline(void *ptr); #include "komodo_defs.h" int32_t ASSETCHAINS_BLOCKTIME = 60; +uint64_t ASSETCHAINS_NK[2]; const arith_uint256 maxUint = UintToArith256(uint256S("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); @@ -282,6 +283,12 @@ void *chainparams_commandline(void *ptr) mainParams.consensus.nPowTargetSpacing = ASSETCHAINS_BLOCKTIME; } mainParams.SetDefaultPort(ASSETCHAINS_P2PPORT); + if ( ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0 ) + { + //BOOST_STATIC_ASSERT(equihash_parameters_acceptable(ASSETCHAINS_NK[0], ASSETCHAINS_NK[1])); + mainParams.SetNValue(ASSETCHAINS_NK[0]); + mainParams.SetKValue(ASSETCHAINS_NK[1]); + } if ( ASSETCHAINS_RPCPORT == 0 ) ASSETCHAINS_RPCPORT = ASSETCHAINS_P2PPORT + 1; mainParams.pchMessageStart[0] = ASSETCHAINS_MAGIC & 0xff; diff --git a/src/chainparams.h b/src/chainparams.h index ea700c6ca..3b1ad1f72 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -119,6 +119,8 @@ public: void SetDefaultPort(uint16_t port) { nDefaultPort = port; } void SetCheckpointData(CCheckpointData checkpointData); + void SetNValue(uint64_t n) { nEquihashN = n; } + void SetKValue(uint64_t k) { nEquihashK = k; } //void setnonce(uint32_t nonce) { memcpy(&genesis.nNonce,&nonce,sizeof(nonce)); } //void settimestamp(uint32_t timestamp) { genesis.nTime = timestamp; } diff --git a/src/crypto/equihash.cpp b/src/crypto/equihash.cpp index fdb907d35..9a16fc085 100644 --- a/src/crypto/equihash.cpp +++ b/src/crypto/equihash.cpp @@ -54,33 +54,84 @@ #define __BYTE_ORDER BYTE_ORDER #endif */ + static EhSolverCancelledException solver_cancelled; +int8_t ZeroizeUnusedBits(size_t N, unsigned char* hash, size_t hLen) +{ + uint8_t rem = N % 8; + if (rem) + { + // clear lowest 8-rem bits + const size_t step = GetSizeInBytes(N); + for (size_t i = step - 1; i < hLen; i += step) + { + uint8_t b = 0xff << (8-rem); + hash[i] &= b; + } + } + return(0); +} + + template int Equihash::InitialiseState(eh_HashState& base_state) { uint32_t le_N = htole32(N); uint32_t le_K = htole32(K); + unsigned char personalization[crypto_generichash_blake2b_PERSONALBYTES] = {}; - memcpy(personalization, "ZcashPoW", 8); + if ( ASSETCHAINS_NK[0] == 0 && ASSETCHAINS_NK[1] == 0 ) + memcpy(personalization, "ZcashPoW", 8); + else + memcpy(personalization, "NandKPoW", 8); memcpy(personalization+8, &le_N, 4); memcpy(personalization+12, &le_K, 4); + + const uint8_t outlen = (512 / N) * GetSizeInBytes(N); + + BOOST_STATIC_ASSERT(!((!outlen) || (outlen > BLAKE2B_OUTBYTES))); return crypto_generichash_blake2b_init_salt_personal(&base_state, NULL, 0, // No key. - (512/N)*N/8, + outlen, NULL, // No salt. personalization); } void GenerateHash(const eh_HashState& base_state, eh_index g, - unsigned char* hash, size_t hLen) + unsigned char* hash, size_t hLen, size_t N) { - eh_HashState state; - state = base_state; - eh_index lei = htole32(g); - crypto_generichash_blake2b_update(&state, (const unsigned char*) &lei, - sizeof(eh_index)); - crypto_generichash_blake2b_final(&state, hash, hLen); + if ( ASSETCHAINS_NK[0] == 0 && ASSETCHAINS_NK[1] == 0 ) + { + eh_HashState state; + state = base_state; + eh_index lei = htole32(g); + crypto_generichash_blake2b_update(&state, (const unsigned char*) &lei, + sizeof(eh_index)); + crypto_generichash_blake2b_final(&state, hash, hLen); + } + else + { + uint32_t myHash[16] = {0}; + uint32_t startIndex = g & 0xFFFFFFF0; + + for (uint32_t g2 = startIndex; g2 <= g; g2++) { + uint32_t tmpHash[16] = {0}; + + eh_HashState state; + state = base_state; + eh_index lei = htole32(g2); + crypto_generichash_blake2b_update(&state, (const unsigned char*) &lei, + sizeof(eh_index)); + + crypto_generichash_blake2b_final(&state, (unsigned char*)&tmpHash[0], static_cast(hLen)); + + for (uint32_t idx = 0; idx < 16; idx++) myHash[idx] += tmpHash[idx]; + } + + memcpy(hash, &myHash[0], hLen); + ZeroizeUnusedBits(N, hash, hLen); + } } void ExpandArray(const unsigned char* in, size_t in_len, @@ -88,7 +139,7 @@ void ExpandArray(const unsigned char* in, size_t in_len, size_t bit_len, size_t byte_pad) { assert(bit_len >= 8); - assert(8*sizeof(uint32_t) >= 7+bit_len); + assert(8*sizeof(uint32_t) >= bit_len); size_t out_width { (bit_len+7)/8 + byte_pad }; assert(out_len == 8*out_width*in_len/bit_len); @@ -131,10 +182,10 @@ void CompressArray(const unsigned char* in, size_t in_len, size_t bit_len, size_t byte_pad) { assert(bit_len >= 8); - assert(8*sizeof(uint32_t) >= 7+bit_len); + assert(8*sizeof(uint32_t) >= bit_len); size_t in_width { (bit_len+7)/8 + byte_pad }; - assert(out_len == bit_len*in_len/(8*in_width)); + assert(out_len == (bit_len*in_len/in_width + 7)/8); uint32_t bit_len_mask { ((uint32_t)1 << bit_len) - 1 }; @@ -148,17 +199,23 @@ void CompressArray(const unsigned char* in, size_t in_len, // When we have fewer than 8 bits left in the accumulator, read the next // input element. if (acc_bits < 8) { + if (j < in_len) { acc_value = acc_value << bit_len; for (size_t x = byte_pad; x < in_width; x++) { acc_value = acc_value | ( ( // Apply bit_len_mask across byte boundaries - in[j+x] & ((bit_len_mask >> (8*(in_width-x-1))) & 0xFF) - ) << (8*(in_width-x-1))); // Big-endian + in[j + x] & ((bit_len_mask >> (8 * (in_width - x - 1))) & 0xFF) + ) << (8 * (in_width - x - 1))); // Big-endian } j += in_width; acc_bits += bit_len; } + else { + acc_value <<= 8 - acc_bits; + acc_bits += 8 - acc_bits;; + } + } acc_bits -= 8; out[i] = (acc_value >> acc_bits) & 0xFF; @@ -207,7 +264,7 @@ std::vector GetIndicesFromMinimal(std::vector minimal, ExpandArray(minimal.data(), minimal.size(), array.data(), lenIndices, cBitLen+1, bytePad); std::vector ret; - for (int i = 0; i < lenIndices; i += sizeof(eh_index)) { + for (size_t i = 0; i < lenIndices; i += sizeof(eh_index)) { ret.push_back(ArrayToEhIndex(array.data()+i)); } return ret; @@ -221,7 +278,7 @@ std::vector GetMinimalFromIndices(std::vector indices, size_t minLen { (cBitLen+1)*lenIndices/(8*sizeof(eh_index)) }; size_t bytePad { sizeof(eh_index) - ((cBitLen+1)+7)/8 }; std::vector array(lenIndices); - for (int i = 0; i < indices.size(); i++) { + for (size_t i = 0; i < indices.size(); i++) { EhIndexToArray(indices[i], array.data()+(i*sizeof(eh_index))); } std::vector ret(minLen); @@ -254,12 +311,12 @@ FullStepRow::FullStepRow(const unsigned char* hashIn, size_t hInLen, } template template -FullStepRow::FullStepRow(const FullStepRow& a, const FullStepRow& b, size_t len, size_t lenIndices, int trim) : +FullStepRow::FullStepRow(const FullStepRow& a, const FullStepRow& b, size_t len, size_t lenIndices, size_t trim) : StepRow {a} { assert(len+lenIndices <= W); assert(len-trim+(2*lenIndices) <= WIDTH); - for (int i = trim; i < len; i++) + for (size_t i = trim; i < len; i++) hash[i-trim] = a.hash[i] ^ b.hash[i]; if (a.IndicesBefore(b, len, lenIndices)) { std::copy(a.hash+len, a.hash+len+lenIndices, hash+len-trim); @@ -281,7 +338,7 @@ template bool StepRow::IsZero(size_t len) { // This doesn't need to be constant time. - for (int i = 0; i < len; i++) { + for (size_t i = 0; i < len; i++) { if (hash[i] != 0) return false; } @@ -301,10 +358,10 @@ std::vector FullStepRow::GetIndices(size_t len, size_t len } template -bool HasCollision(StepRow& a, StepRow& b, int l) +bool HasCollision(StepRow& a, StepRow& b, size_t l) { // This doesn't need to be constant time. - for (int j = 0; j < l; j++) { + for (size_t j = 0; j < l; j++) { if (a.hash[j] != b.hash[j]) return false; } @@ -326,7 +383,7 @@ TruncatedStepRow::TruncatedStepRow(const TruncatedStepRow& a, const Tr { assert(len+lenIndices <= W); assert(len-trim+(2*lenIndices) <= WIDTH); - for (int i = trim; i < len; i++) + for (size_t i = static_cast(trim); i < len; i++) hash[i-trim] = a.hash[i] ^ b.hash[i]; if (a.IndicesBefore(b, len, lenIndices)) { std::copy(a.hash+len, a.hash+len+lenIndices, hash+len-trim); @@ -355,10 +412,10 @@ std::shared_ptr TruncatedStepRow::GetTruncatedIndices(size_t le #ifdef ENABLE_MINING template bool Equihash::BasicSolve(const eh_HashState& base_state, - const std::function)> validBlock, + const std::function&)> validBlock, const std::function cancelled) { - eh_index init_size { 1 << (CollisionBitLength + 1) }; + eh_index init_size { 1U << (CollisionBitLength + 1) }; // 1) Generate first list LogPrint("pow", "Generating first list\n"); @@ -368,16 +425,16 @@ bool Equihash::BasicSolve(const eh_HashState& base_state, X.reserve(init_size); unsigned char tmpHash[HashOutput]; for (eh_index g = 0; X.size() < init_size; g++) { - GenerateHash(base_state, g, tmpHash, HashOutput); + GenerateHash(base_state, g, tmpHash, HashOutput, N); for (eh_index i = 0; i < IndicesPerHashOutput && X.size() < init_size; i++) { - X.emplace_back(tmpHash+(i*N/8), N/8, HashLength, - CollisionBitLength, (g*IndicesPerHashOutput)+i); + X.emplace_back(tmpHash+(i*GetSizeInBytes(N)), GetSizeInBytes(N), HashLength, + CollisionBitLength, static_cast(g*IndicesPerHashOutput)+i); } if (cancelled(ListGeneration)) throw solver_cancelled; } // 3) Repeat step 2 until 2n/(k+1) bits remain - for (int r = 1; r < K && X.size() > 0; r++) { + for (unsigned int r = 1; r < K && X.size() > 0; r++) { LogPrint("pow", "Round %d:\n", r); // 2a) Sort the list LogPrint("pow", "- Sorting list\n"); @@ -385,20 +442,20 @@ bool Equihash::BasicSolve(const eh_HashState& base_state, if (cancelled(ListSorting)) throw solver_cancelled; LogPrint("pow", "- Finding collisions\n"); - int i = 0; - int posFree = 0; + size_t i = 0; + size_t posFree = 0; std::vector> Xc; while (i < X.size() - 1) { // 2b) Find next set of unordered pairs with collisions on the next n/(k+1) bits - int j = 1; + size_t j = 1; while (i+j < X.size() && HasCollision(X[i], X[i+j], CollisionByteLength)) { j++; } // 2c) Calculate tuples (X_i ^ X_j, (i, j)) - for (int l = 0; l < j - 1; l++) { - for (int m = l + 1; m < j; m++) { + for (size_t l = 0; l < j - 1; l++) { + for (size_t m = l + 1; m < j; m++) { if (DistinctIndices(X[i+l], X[i+m], hashLen, lenIndices)) { Xc.emplace_back(X[i+l], X[i+m], hashLen, lenIndices, CollisionByteLength); } @@ -442,16 +499,16 @@ bool Equihash::BasicSolve(const eh_HashState& base_state, std::sort(X.begin(), X.end(), CompareSR(hashLen)); if (cancelled(FinalSorting)) throw solver_cancelled; LogPrint("pow", "- Finding collisions\n"); - int i = 0; + size_t i = 0; while (i < X.size() - 1) { - int j = 1; + size_t j = 1; while (i+j < X.size() && HasCollision(X[i], X[i+j], hashLen)) { j++; } - for (int l = 0; l < j - 1; l++) { - for (int m = l + 1; m < j; m++) { + for (size_t l = 0; l < j - 1; l++) { + for (size_t m = l + 1; m < j; m++) { FullStepRow res(X[i+l], X[i+m], hashLen, lenIndices, 0); if (DistinctIndices(X[i+l], X[i+m], hashLen, lenIndices)) { auto soln = res.GetIndices(hashLen, 2*lenIndices, CollisionBitLength); @@ -475,20 +532,21 @@ bool Equihash::BasicSolve(const eh_HashState& base_state, template void CollideBranches(std::vector>& X, const size_t hlen, const size_t lenIndices, const unsigned int clen, const unsigned int ilen, const eh_trunc lt, const eh_trunc rt) { - int i = 0; - int posFree = 0; + size_t i = 0; + size_t posFree = 0; + assert(X.size() > 0); std::vector> Xc; while (i < X.size() - 1) { // 2b) Find next set of unordered pairs with collisions on the next n/(k+1) bits - int j = 1; + size_t j = 1; while (i+j < X.size() && HasCollision(X[i], X[i+j], clen)) { j++; } // 2c) Calculate tuples (X_i ^ X_j, (i, j)) - for (int l = 0; l < j - 1; l++) { - for (int m = l + 1; m < j; m++) { + for (size_t l = 0; l < j - 1; l++) { + for (size_t m = l + 1; m < j; m++) { if (DistinctIndices(X[i+l], X[i+m], hlen, lenIndices)) { if (IsValidBranch(X[i+l], hlen, ilen, lt) && IsValidBranch(X[i+m], hlen, ilen, rt)) { Xc.emplace_back(X[i+l], X[i+m], hlen, lenIndices, clen); @@ -526,10 +584,10 @@ void CollideBranches(std::vector>& X, const size_t hlen, cons template bool Equihash::OptimisedSolve(const eh_HashState& base_state, - const std::function)> validBlock, + const std::function&)> validBlock, const std::function cancelled) { - eh_index init_size { 1 << (CollisionBitLength + 1) }; + eh_index init_size { 1U << (CollisionBitLength + 1) }; eh_index recreate_size { UntruncateIndex(1, 0, CollisionBitLength + 1) }; // First run the algorithm with truncated indices @@ -547,16 +605,16 @@ bool Equihash::OptimisedSolve(const eh_HashState& base_state, Xt.reserve(init_size); unsigned char tmpHash[HashOutput]; for (eh_index g = 0; Xt.size() < init_size; g++) { - GenerateHash(base_state, g, tmpHash, HashOutput); + GenerateHash(base_state, g, tmpHash, HashOutput, N); for (eh_index i = 0; i < IndicesPerHashOutput && Xt.size() < init_size; i++) { - Xt.emplace_back(tmpHash+(i*N/8), N/8, HashLength, CollisionBitLength, - (g*IndicesPerHashOutput)+i, CollisionBitLength + 1); + Xt.emplace_back(tmpHash+(i*GetSizeInBytes(N)), GetSizeInBytes(N), HashLength, CollisionBitLength, + static_cast(g*IndicesPerHashOutput)+i, static_cast(CollisionBitLength + 1)); } if (cancelled(ListGeneration)) throw solver_cancelled; } // 3) Repeat step 2 until 2n/(k+1) bits remain - for (int r = 1; r < K && Xt.size() > 0; r++) { + for (unsigned int r = 1; r < K && Xt.size() > 0; r++) { LogPrint("pow", "Round %d:\n", r); // 2a) Sort the list LogPrint("pow", "- Sorting list\n"); @@ -564,21 +622,21 @@ bool Equihash::OptimisedSolve(const eh_HashState& base_state, if (cancelled(ListSorting)) throw solver_cancelled; LogPrint("pow", "- Finding collisions\n"); - int i = 0; - int posFree = 0; + size_t i = 0; + size_t posFree = 0; std::vector> Xc; while (i < Xt.size() - 1) { // 2b) Find next set of unordered pairs with collisions on the next n/(k+1) bits - int j = 1; + size_t j = 1; while (i+j < Xt.size() && HasCollision(Xt[i], Xt[i+j], CollisionByteLength)) { j++; } // 2c) Calculate tuples (X_i ^ X_j, (i, j)) - bool checking_for_zero = (i == 0 && Xt[0].IsZero(hashLen)); - for (int l = 0; l < j - 1; l++) { - for (int m = l + 1; m < j; m++) { + //bool checking_for_zero = (i == 0 && Xt[0].IsZero(hashLen)); + for (size_t l = 0; l < j - 1; l++) { + for (size_t m = l + 1; m < j; m++) { // We truncated, so don't check for distinct indices here TruncatedStepRow Xi {Xt[i+l], Xt[i+m], hashLen, lenIndices, @@ -628,16 +686,16 @@ bool Equihash::OptimisedSolve(const eh_HashState& base_state, std::sort(Xt.begin(), Xt.end(), CompareSR(hashLen)); if (cancelled(FinalSorting)) throw solver_cancelled; LogPrint("pow", "- Finding collisions\n"); - int i = 0; + size_t i = 0; while (i < Xt.size() - 1) { - int j = 1; + size_t j = 1; while (i+j < Xt.size() && HasCollision(Xt[i], Xt[i+j], hashLen)) { j++; } - for (int l = 0; l < j - 1; l++) { - for (int m = l + 1; m < j; m++) { + for (size_t l = 0; l < j - 1; l++) { + for (size_t m = l + 1; m < j; m++) { TruncatedStepRow res(Xt[i+l], Xt[i+m], hashLen, lenIndices, 0); auto soln = res.GetTruncatedIndices(hashLen, 2*lenIndices); @@ -676,10 +734,10 @@ bool Equihash::OptimisedSolve(const eh_HashState& base_state, eh_index newIndex { UntruncateIndex(partialSoln.get()[i], j, CollisionBitLength + 1) }; if (j == 0 || newIndex % IndicesPerHashOutput == 0) { GenerateHash(base_state, newIndex/IndicesPerHashOutput, - tmpHash, HashOutput); + tmpHash, HashOutput, N); } - icv.emplace_back(tmpHash+((newIndex % IndicesPerHashOutput) * N/8), - N/8, HashLength, CollisionBitLength, newIndex); + icv.emplace_back(tmpHash+((newIndex % IndicesPerHashOutput) * GetSizeInBytes(N)), + GetSizeInBytes(N), HashLength, CollisionBitLength, newIndex); if (cancelled(PartialGeneration)) throw solver_cancelled; } boost::optional>> ic = icv; @@ -697,7 +755,7 @@ bool Equihash::OptimisedSolve(const eh_HashState& base_state, ic->insert(ic->end(), X[r]->begin(), X[r]->end()); std::sort(ic->begin(), ic->end(), CompareSR(hashLen)); if (cancelled(PartialSorting)) throw solver_cancelled; - size_t lti = rti-(1<(1)<::IsValidSolution(const eh_HashState& base_state, std::vector< X.reserve(1 << K); unsigned char tmpHash[HashOutput]; for (eh_index i : GetIndicesFromMinimal(soln, CollisionBitLength)) { - GenerateHash(base_state, i/IndicesPerHashOutput, tmpHash, HashOutput); - X.emplace_back(tmpHash+((i % IndicesPerHashOutput) * N/8), - N/8, HashLength, CollisionBitLength, i); + GenerateHash(base_state, i/IndicesPerHashOutput, tmpHash, HashOutput, N); + X.emplace_back(tmpHash+((i % IndicesPerHashOutput) * GetSizeInBytes(N)), + GetSizeInBytes(N), HashLength, CollisionBitLength, i); } size_t hashLen = HashLength; size_t lenIndices = sizeof(eh_index); while (X.size() > 1) { std::vector> Xc; - for (int i = 0; i < X.size(); i += 2) { + for (size_t i = 0; i < X.size(); i += 2) { if (!HasCollision(X[i], X[i+1], CollisionByteLength)) { LogPrint("pow", "Invalid solution: invalid collision length between StepRows\n"); LogPrint("pow", "X[i] = %s\n", X[i].GetHex(hashLen)); @@ -795,50 +853,74 @@ bool Equihash::IsValidSolution(const eh_HashState& base_state, std::vector< return X[0].IsZero(hashLen); } -// Explicit instantiations for Equihash<96,3> -template int Equihash<96,3>::InitialiseState(eh_HashState& base_state); -#ifdef ENABLE_MINING -template bool Equihash<96,3>::BasicSolve(const eh_HashState& base_state, - const std::function)> validBlock, - const std::function cancelled); -template bool Equihash<96,3>::OptimisedSolve(const eh_HashState& base_state, - const std::function)> validBlock, - const std::function cancelled); -#endif -template bool Equihash<96,3>::IsValidSolution(const eh_HashState& base_state, std::vector soln); - // Explicit instantiations for Equihash<200,9> template int Equihash<200,9>::InitialiseState(eh_HashState& base_state); #ifdef ENABLE_MINING template bool Equihash<200,9>::BasicSolve(const eh_HashState& base_state, - const std::function)> validBlock, + const std::function&)> validBlock, const std::function cancelled); template bool Equihash<200,9>::OptimisedSolve(const eh_HashState& base_state, - const std::function)> validBlock, + const std::function&)> validBlock, const std::function cancelled); #endif template bool Equihash<200,9>::IsValidSolution(const eh_HashState& base_state, std::vector soln); - -// Explicit instantiations for Equihash<96,5> -template int Equihash<96,5>::InitialiseState(eh_HashState& base_state); + +// Explicit instantiations for Equihash<96,3> +template int Equihash<150,5>::InitialiseState(eh_HashState& base_state); #ifdef ENABLE_MINING -template bool Equihash<96,5>::BasicSolve(const eh_HashState& base_state, - const std::function)> validBlock, +template bool Equihash<150,5>::BasicSolve(const eh_HashState& base_state, + const std::function&)> validBlock, const std::function cancelled); -template bool Equihash<96,5>::OptimisedSolve(const eh_HashState& base_state, - const std::function)> validBlock, +template bool Equihash<150,5>::OptimisedSolve(const eh_HashState& base_state, + const std::function&)> validBlock, const std::function cancelled); #endif -template bool Equihash<96,5>::IsValidSolution(const eh_HashState& base_state, std::vector soln); +template bool Equihash<150,5>::IsValidSolution(const eh_HashState& base_state, std::vector soln); // Explicit instantiations for Equihash<48,5> +template int Equihash<144,5>::InitialiseState(eh_HashState& base_state); +#ifdef ENABLE_MINING +template bool Equihash<144,5>::BasicSolve(const eh_HashState& base_state, + const std::function&)> validBlock, + const std::function cancelled); +template bool Equihash<144,5>::OptimisedSolve(const eh_HashState& base_state, + const std::function&)> validBlock, + const std::function cancelled); +#endif +template bool Equihash<144,5>::IsValidSolution(const eh_HashState& base_state, std::vector soln); + +// Explicit instantiations for Equihash<96,5> +template int Equihash::InitialiseState(eh_HashState& base_state); +#ifdef ENABLE_MINING +template bool Equihash::BasicSolve(const eh_HashState& base_state, + const std::function&)> validBlock, + const std::function cancelled); +template bool Equihash::OptimisedSolve(const eh_HashState& base_state, + const std::function&)> validBlock, + const std::function cancelled); +#endif +template bool Equihash::IsValidSolution(const eh_HashState& base_state, std::vector soln); + +// Explicit instantiations for Equihash<96,5> template int Equihash<48,5>::InitialiseState(eh_HashState& base_state); #ifdef ENABLE_MINING template bool Equihash<48,5>::BasicSolve(const eh_HashState& base_state, - const std::function)> validBlock, + const std::function&)> validBlock, const std::function cancelled); template bool Equihash<48,5>::OptimisedSolve(const eh_HashState& base_state, - const std::function)> validBlock, + const std::function&)> validBlock, const std::function cancelled); #endif template bool Equihash<48,5>::IsValidSolution(const eh_HashState& base_state, std::vector soln); + +// Explicit instantiations for Equihash<48,5> +template int Equihash<210,9>::InitialiseState(eh_HashState& base_state); +#ifdef ENABLE_MINING +template bool Equihash<210,9>::BasicSolve(const eh_HashState& base_state, + const std::function&)> validBlock, + const std::function cancelled); +template bool Equihash<210,9>::OptimisedSolve(const eh_HashState& base_state, + const std::function&)> validBlock, + const std::function cancelled); +#endif +template bool Equihash<210,9>::IsValidSolution(const eh_HashState& base_state, std::vector soln); diff --git a/src/crypto/equihash.h b/src/crypto/equihash.h index 6691844ba..57c434dae 100644 --- a/src/crypto/equihash.h +++ b/src/crypto/equihash.h @@ -10,6 +10,7 @@ #include "utilstrencodings.h" #include "sodium.h" +#include "komodo_nk.h" #include #include @@ -24,6 +25,9 @@ typedef crypto_generichash_blake2b_state eh_HashState; typedef uint32_t eh_index; typedef uint8_t eh_trunc; +#define BLAKE2B_OUTBYTES 64 +extern uint64_t ASSETCHAINS_NK[2]; + void ExpandArray(const unsigned char* in, size_t in_len, unsigned char* out, size_t out_len, size_t bit_len, size_t byte_pad=0); @@ -61,7 +65,7 @@ public: std::string GetHex(size_t len) { return HexStr(hash, hash+len); } template - friend bool HasCollision(StepRow& a, StepRow& b, int l); + friend bool HasCollision(StepRow& a, StepRow& b, size_t l); }; class CompareSR @@ -77,7 +81,7 @@ public: }; template -bool HasCollision(StepRow& a, StepRow& b, int l); +bool HasCollision(StepRow& a, StepRow& b, size_t l); template class FullStepRow : public StepRow @@ -94,7 +98,7 @@ public: FullStepRow(const FullStepRow& a) : StepRow {a} { } template - FullStepRow(const FullStepRow& a, const FullStepRow& b, size_t len, size_t lenIndices, int trim); + FullStepRow(const FullStepRow& a, const FullStepRow& b, size_t len, size_t lenIndices, size_t trim); FullStepRow& operator=(const FullStepRow& a); inline bool IndicesBefore(const FullStepRow& a, size_t len, size_t lenIndices) const { return memcmp(hash+len, a.hash+len, lenIndices) < 0; } @@ -159,17 +163,22 @@ inline constexpr size_t equihash_solution_size(unsigned int N, unsigned int K) { return (1 << K)*(N/(K+1)+1)/8; } +constexpr uint8_t GetSizeInBytes(size_t N) +{ + return static_cast((N + 7) / 8); +} + template class Equihash { private: BOOST_STATIC_ASSERT(K < N); - BOOST_STATIC_ASSERT(N % 8 == 0); + //BOOST_STATIC_ASSERT(N % 8 == 0); BOOST_STATIC_ASSERT((N/(K+1)) + 1 < 8*sizeof(eh_index)); public: enum : size_t { IndicesPerHashOutput=512/N }; - enum : size_t { HashOutput=IndicesPerHashOutput*N/8 }; + enum : size_t { HashOutput = IndicesPerHashOutput * GetSizeInBytes(N) }; enum : size_t { CollisionBitLength=N/(K+1) }; enum : size_t { CollisionByteLength=(CollisionBitLength+7)/8 }; enum : size_t { HashLength=(K+1)*CollisionByteLength }; @@ -184,79 +193,100 @@ public: int InitialiseState(eh_HashState& base_state); #ifdef ENABLE_MINING bool BasicSolve(const eh_HashState& base_state, - const std::function)> validBlock, + const std::function&)> validBlock, const std::function cancelled); bool OptimisedSolve(const eh_HashState& base_state, - const std::function)> validBlock, + const std::function&)> validBlock, const std::function cancelled); #endif bool IsValidSolution(const eh_HashState& base_state, std::vector soln); }; #include "equihash.tcc" +/* +* Equihash 200,9 (KMD/Zcash) +* Equihash 150,5 (beam) +* Equihash 144,5 (SnowGem) +* Equihash 96,5 (Minex) +* Equihash 48,5 (regtest) +* Equihash 210,9 (Aion) */ -static Equihash<96,3> Eh96_3; static Equihash<200,9> Eh200_9; -static Equihash<96,5> Eh96_5; +static Equihash<150,5> Eh150_5; +static Equihash<144,5> Eh144_5; +static Equihash Eh96_5; static Equihash<48,5> Eh48_5; +static Equihash<210,9> Eh210_9; #define EhInitialiseState(n, k, base_state) \ - if (n == 96 && k == 3) { \ - Eh96_3.InitialiseState(base_state); \ - } else if (n == 200 && k == 9) { \ - Eh200_9.InitialiseState(base_state); \ - } else if (n == 96 && k == 5) { \ + if (n == 200 && k == 9) { \ + Eh200_9.InitialiseState(base_state); \ + } else if (n == 150 && k == 5) { \ + Eh150_5.InitialiseState(base_state); \ + } else if (n == 144 && k == 5) { \ + Eh144_5.InitialiseState(base_state); \ + } else if (n == ASSETCHAINS_N && k == ASSETCHAINS_K) { \ Eh96_5.InitialiseState(base_state); \ } else if (n == 48 && k == 5) { \ Eh48_5.InitialiseState(base_state); \ + } else if (n == 210 && k == 9) { \ + Eh210_9.InitialiseState(base_state); \ } else { \ throw std::invalid_argument("Unsupported Equihash parameters"); \ } #ifdef ENABLE_MINING inline bool EhBasicSolve(unsigned int n, unsigned int k, const eh_HashState& base_state, - const std::function)> validBlock, + const std::function&)> validBlock, const std::function cancelled) { - if (n == 96 && k == 3) { - return Eh96_3.BasicSolve(base_state, validBlock, cancelled); - } else if (n == 200 && k == 9) { + if (n == 200 && k == 9) { return Eh200_9.BasicSolve(base_state, validBlock, cancelled); - } else if (n == 96 && k == 5) { + } else if (n == 150 && k == 5) { + return Eh150_5.BasicSolve(base_state, validBlock, cancelled); + } else if (n == 144 && k == 5) { + return Eh144_5.BasicSolve(base_state, validBlock, cancelled); + } else if (n == ASSETCHAINS_N && k == ASSETCHAINS_K) { return Eh96_5.BasicSolve(base_state, validBlock, cancelled); - } else if (n == 48 && k == 5) { + } else if (n == 48 && k == 5) { return Eh48_5.BasicSolve(base_state, validBlock, cancelled); + } else if (n == 210 && k == 9) { + return Eh210_9.BasicSolve(base_state, validBlock, cancelled); } else { throw std::invalid_argument("Unsupported Equihash parameters"); } } inline bool EhBasicSolveUncancellable(unsigned int n, unsigned int k, const eh_HashState& base_state, - const std::function)> validBlock) + const std::function&)> validBlock) { return EhBasicSolve(n, k, base_state, validBlock, [](EhSolverCancelCheck pos) { return false; }); } inline bool EhOptimisedSolve(unsigned int n, unsigned int k, const eh_HashState& base_state, - const std::function)> validBlock, + const std::function&)> validBlock, const std::function cancelled) { - if (n == 96 && k == 3) { - return Eh96_3.OptimisedSolve(base_state, validBlock, cancelled); - } else if (n == 200 && k == 9) { + if (n == 200 && k == 9) { return Eh200_9.OptimisedSolve(base_state, validBlock, cancelled); - } else if (n == 96 && k == 5) { + } else if (n == 150 && k == 5) { + return Eh150_5.OptimisedSolve(base_state, validBlock, cancelled); + } else if (n == 144 && k == 5) { + return Eh144_5.OptimisedSolve(base_state, validBlock, cancelled); + } else if (n == ASSETCHAINS_N && k == ASSETCHAINS_K) { return Eh96_5.OptimisedSolve(base_state, validBlock, cancelled); - } else if (n == 48 && k == 5) { + } else if (n == 48 && k == 5) { return Eh48_5.OptimisedSolve(base_state, validBlock, cancelled); + } else if (n == 210 && k == 9) { + return Eh210_9.OptimisedSolve(base_state, validBlock, cancelled); } else { throw std::invalid_argument("Unsupported Equihash parameters"); } } inline bool EhOptimisedSolveUncancellable(unsigned int n, unsigned int k, const eh_HashState& base_state, - const std::function)> validBlock) + const std::function&)> validBlock) { return EhOptimisedSolve(n, k, base_state, validBlock, [](EhSolverCancelCheck pos) { return false; }); @@ -264,14 +294,18 @@ inline bool EhOptimisedSolveUncancellable(unsigned int n, unsigned int k, const #endif // ENABLE_MINING #define EhIsValidSolution(n, k, base_state, soln, ret) \ - if (n == 96 && k == 3) { \ - ret = Eh96_3.IsValidSolution(base_state, soln); \ - } else if (n == 200 && k == 9) { \ - ret = Eh200_9.IsValidSolution(base_state, soln); \ - } else if (n == 96 && k == 5) { \ + if (n == 200 && k == 9) { \ + ret = Eh200_9.IsValidSolution(base_state, soln); \ + } else if (n == 150 && k == 5) { \ + ret = Eh150_5.IsValidSolution(base_state, soln); \ + } else if (n == 144 && k == 5) { \ + ret = Eh144_5.IsValidSolution(base_state, soln); \ + } else if (n == ASSETCHAINS_N && k == ASSETCHAINS_K) { \ ret = Eh96_5.IsValidSolution(base_state, soln); \ } else if (n == 48 && k == 5) { \ ret = Eh48_5.IsValidSolution(base_state, soln); \ + } else if (n == 210 && k == 9) { \ + ret = Eh210_9.IsValidSolution(base_state, soln); \ } else { \ throw std::invalid_argument("Unsupported Equihash parameters"); \ } diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 23a689154..964ec852d 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -15,6 +15,7 @@ #ifndef KOMODO_DEFS_H #define KOMODO_DEFS_H +#include "komodo_nk.h" #define ASSETCHAINS_MINHEIGHT 128 #define ASSETCHAINS_MAX_ERAS 3 @@ -53,7 +54,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,ASSETCHAINS_CBOPRET; extern bool VERUS_MINTBLOCKS; -extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_NOTARY_PAY[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[],ASSETCHAINS_NK[2]; extern const char *ASSETCHAINS_ALGORITHMS[]; extern int32_t VERUS_MIN_STAKEAGE; extern uint32_t ASSETCHAINS_VERUSHASH, ASSETCHAINS_VERUSHASHV1_1, ASSETCHAINS_NONCESHIFT[], ASSETCHAINS_HASHESPERROUND[]; diff --git a/src/komodo_nk.h b/src/komodo_nk.h new file mode 100644 index 000000000..3c9034dde --- /dev/null +++ b/src/komodo_nk.h @@ -0,0 +1,7 @@ +#ifndef KOMODO_NK_H +#define KOMODO_NK_H + +#define ASSETCHAINS_N 96 +#define ASSETCHAINS_K 5 + +#endif diff --git a/src/komodo_utils.h b/src/komodo_utils.h index bbd68ae30..d87b50716 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1667,6 +1667,28 @@ extern int64_t MAX_MONEY; void komodo_cbopretupdate(int32_t forceflag); void SplitStr(const std::string& strVal, std::vector &outVals); +int8_t equihash_params_possible(uint64_t n, uint64_t k) +{ + /* To add more of these you also need to edit: + * equihash.cpp very end of file with the tempate to point to the new param numbers + * equihash.h + * line 210/217 (declaration of equihash class) + * Add this object to the following functions: + * EhInitialiseState + * EhBasicSolve + * EhOptimisedSolve + * EhIsValidSolution + * Alternatively change ASSETCHAINS_N and ASSETCHAINS_K in komodo_nk.h for fast testing. + */ + if ( k == 9 && (n == 200 || n == 210) ) + return(0); + if ( k == 5 && (n == 150 || n == 144 || n == 96 || n == 48) ) + return(0); + if ( k == ASSETCHAINS_K && n == ASSETCHAINS_N) + return(0); + return(-1); +} + void komodo_args(char *argv0) { extern const char *Notaries_elected1[][2]; @@ -1729,6 +1751,7 @@ void komodo_args(char *argv0) ASSETCHAINS_BLOCKTIME = GetArg("-ac_blocktime",60); ASSETCHAINS_PUBLIC = GetArg("-ac_public",0); ASSETCHAINS_PRIVATE = GetArg("-ac_private",0); + Split(GetArg("-ac_nk",""), ASSETCHAINS_NK, 0); if ( (KOMODO_REWIND= GetArg("-rewind",0)) != 0 ) { printf("KOMODO_REWIND %d\n",KOMODO_REWIND); @@ -1749,6 +1772,14 @@ void komodo_args(char *argv0) break; } } + if ( ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH && ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0 ) + { + if ( equihash_params_possible(ASSETCHAINS_NK[0], ASSETCHAINS_NK[1]) == -1 ) + { + printf("equihash values N.%li and K.%li are not currently available\n", ASSETCHAINS_NK[0], ASSETCHAINS_NK[1]); + exit(0); + } else printf("ASSETCHAINS_ALGO, algorithm set to equihash with N.%li and K.%li\n", ASSETCHAINS_NK[0], ASSETCHAINS_NK[1]); + } if (i == ASSETCHAINS_NUMALGOS) { printf("ASSETCHAINS_ALGO, %s not supported. using equihash\n", selectedAlgo.c_str()); @@ -1974,7 +2005,7 @@ void komodo_args(char *argv0) fprintf(stderr,"-ac_script and -ac_marmara are mutually exclusive\n"); StartShutdown(); } - if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 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 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 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; @@ -2104,6 +2135,11 @@ void komodo_args(char *argv0) komodo_cbopretupdate(1); // will set Mineropret fprintf(stderr,"This blockchain uses data produced from CoinDesk Bitcoin Price Index\n"); } + if ( ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0 ) + { + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_NK[0]),(void *)&ASSETCHAINS_NK[0]); + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_NK[1]),(void *)&ASSETCHAINS_NK[1]); + } } addn = GetArg("-seednode",""); diff --git a/src/miner.cpp b/src/miner.cpp index f131bc90e..295fcb803 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1608,9 +1608,10 @@ void static BitcoinMiner() if ( notaryid != My_notaryid ) My_notaryid = notaryid; std::string solver; - //if ( notaryid >= 0 || ASSETCHAINS_SYMBOL[0] != 0 ) - solver = "tromp"; - //else solver = "default"; + if ( ASSETCHAINS_NK[0] == 0 && ASSETCHAINS_NK[1] == 0 ) + solver = "tromp"; + else + solver = "default"; assert(solver == "tromp" || solver == "default"); LogPrint("pow", "Using Equihash solver \"%s\" with n = %u, k = %u\n", solver, n, k); if ( ASSETCHAINS_SYMBOL[0] != 0 ) @@ -1951,11 +1952,11 @@ void static BitcoinMiner() ehSolverRuns.increment(); if (found) { int32_t i; uint256 hash = pblock->GetHash(); - for (i=0; i<32; i++) - fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); - fprintf(stderr," <- %s Block found %d\n",ASSETCHAINS_SYMBOL,Mining_height); - FOUND_BLOCK = 1; - KOMODO_MAYBEMINED = Mining_height; + //for (i=0; i<32; i++) + // fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); + //fprintf(stderr," <- %s Block found %d\n",ASSETCHAINS_SYMBOL,Mining_height); + //FOUND_BLOCK = 1; + //KOMODO_MAYBEMINED = Mining_height; break; } } catch (EhSolverCancelledException&) { @@ -1968,12 +1969,12 @@ void static BitcoinMiner() // Check for stop or if block needs to be rebuilt boost::this_thread::interruption_point(); // Regtest mode doesn't require peers - if ( FOUND_BLOCK != 0 ) + /*if ( FOUND_BLOCK != 0 ) { FOUND_BLOCK = 0; fprintf(stderr,"FOUND_BLOCK!\n"); //sleep(2000); - } + } */ if (vNodes.empty() && chainparams.MiningRequiresPeers()) { if ( ASSETCHAINS_SYMBOL[0] == 0 || Mining_height > ASSETCHAINS_MINHEIGHT ) diff --git a/src/pow.cpp b/src/pow.cpp index 1716099ee..6f5476abe 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -344,6 +344,9 @@ bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams& param { if (ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH) return true; + + if ( ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0 && pblock->GetHash().ToString() == "027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71" ) + return true; unsigned int n = params.EquihashN(); unsigned int k = params.EquihashK();