From 1008b2b48ca3f9724c73149e24db374d88a3bd1b Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 5 Aug 2018 22:08:10 -0700 Subject: [PATCH 01/31] Update Github issue template --- .github/ISSUE_TEMPLATE.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index a025e66ac..d73d84b67 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,10 +1,8 @@ -This issue tracker is only for technical issues related to zcashd. +This issue tracker is only for technical issues related to komodod -General Zcash questions and/or support requests and are best directed to the [Zcash Forums](https://forum.z.cash) or [Community Rocket.Chat](https://chat.zcashcommunity.com). - -For reporting security vulnerabilities or for sensitive discussions with our security team, please contact [security@z.cash](mailto:security@z.cash). You can use the [GPG key](https://z.cash/gpg-pubkeys/security.asc) (fingerprint: `AF85 0445 546C 18B7 86F9 2C62 88FB 8B86 D8B5 A68C`) to send an encrypted message. The key and fingerprint are duplicated on our [Public Keys page](https://z.cash/support/pubkeys.html). +General Komodo questions and/or support requests and are best directed to [Discord](https://komodoplatform.com/discord) ### Describe the issue Please provide a general summary of the issue you're experiencing @@ -21,8 +19,8 @@ Tell us what should happen ### Actual behaviour + errors Tell us what happens instead including any noticable error output (any messages displayed on-screen when e.g. a crash occurred) -### The version of Zcash you were using: -Run `zcashd --version` to find out +### The version of Komodo you were using: +Run `komodod --version` to find out ### Machine specs: - OS name + version: @@ -34,9 +32,9 @@ Run `zcashd --version` to find out - Compiler version (gcc -version): ### Any extra information that might be useful in the debugging process. -This includes the relevant contents of `~/.zcash/debug.log`. You can paste raw text, attach the file directly in the issue or link to the text via a pastebin type site. +This includes the relevant contents of `~/.komodo/debug.log`. You can paste raw text, attach the file directly in the issue or link to the text via a pastebin type site. Please also include any non-standard things you did during compilation (extra flags, dependency version changes etc.) if applicable. -### Do you have a backup of `~/.zcash` directory and/or take a VM snapshot? -- Backing up / making a copy of the `~/.zcash` directory might help make the problem reproducible. Please redact appropriately. +### Do you have a backup of `~/.komodo` directory and/or take a VM snapshot? +- Backing up / making a copy of the `~/.komodo` directory might help make the problem reproducible. Please redact appropriately. - Taking a VM snapshot is really helpful for interactively testing fixes From 6deb8c09eb42c1f626edcf68cf20d9e58c87d792 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Aug 2018 20:43:35 -1100 Subject: [PATCH 02/31] Disable FSM, auction, lotto and add some error checks --- src/cc/CCassetstx.cpp | 5 +---- src/cc/auction.cpp | 1 + src/cc/faucet.cpp | 9 +++++---- src/cc/fsm.cpp | 1 + src/cc/lotto.cpp | 1 + src/cc/rewards.cpp | 2 +- src/main.h | 3 ++- src/wallet/rpcwallet.cpp | 2 ++ 8 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 51668eda8..7d55b85ff 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -15,9 +15,6 @@ #include "CCassets.h" -// need allassets -// find asset - int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) { char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t j,vout,n = 0; @@ -35,7 +32,7 @@ int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK continue; if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( (nValue= IsAssetvout(price,origpubkey,vintx,vout,assetid)) > 0 ) + if ( (nValue= IsAssetvout(price,origpubkey,vintx,vout,assetid)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index cf3ae601a..7d8512ede 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -73,6 +73,7 @@ bool AuctionExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransactio bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; + return(false); // reject any auction CC for now numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 51d7f2f6f..570f1539a 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -126,20 +126,21 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx uint64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs) { - char coinaddr[64]; uint64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; + char coinaddr[64]; uint64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; - // prevent dup + vout = (int32_t)it->first.index); + // no need to prevent dup if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( (nValue= IsFaucetvout(cp,vintx,(int32_t)it->first.index)) > 1000000 ) + if ( (nValue= IsFaucetvout(cp,vintx,vout) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) - mtx.vin.push_back(CTxIn(txid,(int32_t)it->first.index,CScript())); + mtx.vin.push_back(CTxIn(txid,vout,CScript())); nValue = it->second.satoshis; totalinputs += nValue; n++; diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index 201535992..e3e112bf6 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -73,6 +73,7 @@ bool FSMExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &t bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; + return(false); // reject any FSM CC for now numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index 43367ab70..0ed223c25 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -73,6 +73,7 @@ bool LottoExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction bool LottoValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; + return(false); // reject any lotto CC for now numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index a0f07aba1..afa025851 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -282,7 +282,7 @@ uint64_t AddRewardsInputs(CScript &scriptPubKey,int32_t fundsflag,struct CCcontr break; if ( j != mtx.vin.size() ) continue; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( (funcid= DecodeRewardsOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid)) != 0 ) { diff --git a/src/main.h b/src/main.h index 56b439fc0..dfea318cb 100644 --- a/src/main.h +++ b/src/main.h @@ -103,9 +103,10 @@ static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60; static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111; //static const bool DEFAULT_ADDRESSINDEX = false; +//static const bool DEFAULT_SPENTINDEX = false; #define DEFAULT_ADDRESSINDEX (GetArg("-ac_cc",0) != 0) +#define DEFAULT_SPENTINDEX (GetArg("-ac_cc",0) != 0) static const bool DEFAULT_TIMESTAMPINDEX = false; -static const bool DEFAULT_SPENTINDEX = false; static const unsigned int DEFAULT_DB_MAX_OPEN_FILES = 1000; static const bool DEFAULT_DB_COMPRESSION = true; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 295460618..c2e486a05 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4837,6 +4837,8 @@ int32_t ensure_CCrequirements() return(-1); else if ( GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX) == 0 ) return(-1); + else if ( GetBoolArg("-spentindex", DEFAULT_SPENTINDEX) == 0 ) + return(-1); else return(0); } From 8a78bd9d8c9dde5b1c8d0d9be904107b894e77c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Aug 2018 20:47:51 -1100 Subject: [PATCH 03/31] Test --- src/cc/faucet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 570f1539a..a786edd2e 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -133,7 +133,7 @@ uint64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPu for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; - vout = (int32_t)it->first.index); + vout = (int32_t)it->first.index; // no need to prevent dup if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { From b24e0ff44ef43c39462498a2ee51c43a7a59e906 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Aug 2018 20:49:12 -1100 Subject: [PATCH 04/31] ) --- src/cc/faucet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index a786edd2e..b8b3b62cb 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -137,7 +137,7 @@ uint64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPu // no need to prevent dup if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( (nValue= IsFaucetvout(cp,vintx,vout) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( (nValue= IsFaucetvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); From 718255b3fdf835774de32a41decea1eb555b0bae Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Aug 2018 23:36:00 -1100 Subject: [PATCH 05/31] smart utxo selection without press release to coin telegraph --- src/cc/CCinclude.h | 7 ++++ src/cc/CCtx.cpp | 98 +++++++++++++++++++++++++++++++++++++++++++--- src/komodo_kv.h | 4 +- 3 files changed, 102 insertions(+), 7 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 0ab0bf874..a59a2325c 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -33,6 +33,13 @@ union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; typedef union _bits256 bits256; +struct CC_utxo +{ + uint256 txid; + int64_t nValue; + int32_t vout; +}; + struct CCcontract_info { uint256 prevtxid; diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index bea26e4a2..171ebf132 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -201,36 +201,124 @@ uint64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout) return(0); } +int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,struct CC_utxo utxos[],int32_t numunspents,uint64_t value) +{ + int32_t i,abovei,belowi; int64_t above,below,gap,atx_value; + abovei = belowi = -1; + for (above=below=i=0; i value ) + { + gap = (atx_value - value); + if ( above == 0 || gap < above ) + { + above = gap; + abovei = i; + } + } + else + { + gap = (value - atx_value); + if ( below == 0 || gap < below ) + { + below = gap; + belowi = i; + } + } + //printf("value %.8f gap %.8f abovei.%d %.8f belowi.%d %.8f\n",dstr(value),dstr(gap),abovei,dstr(above),belowi,dstr(below)); + } + *aboveip = abovei; + *abovep = above; + *belowip = belowi; + *belowp = below; + //printf("above.%d below.%d\n",abovei,belowi); + if ( abovei >= 0 && belowi >= 0 ) + { + if ( above < (below >> 1) ) + return(abovei); + else return(belowi); + } + else if ( abovei >= 0 ) + return(abovei); + else return(belowi); + //return(abovei >= 0 && above < (below>>1) ? abovei : belowi); +} + uint64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,uint64_t total,int32_t maxinputs) { - int32_t vout,j,n = 0; uint64_t nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; + int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=1024; int64_t above,below; uint64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; #ifdef ENABLE_WALLET const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); + utxos = calloc(maxutxos,sizeof(*utxos)); BOOST_FOREACH(const COutput& out, vecOutputs) { if ( out.fSpendable != 0 ) { txid = out.tx->GetHash(); vout = out.i; - for (j=0; jtxid = txid; + up->nValue = out.tx->vout[out.i].nValue; + up->vout = vout; + /*mtx.vin.push_back(CTxIn(txid,vout,CScript())); nValue = out.tx->vout[out.i].nValue; totalinputs += nValue; n++; if ( totalinputs >= total || n >= maxinputs ) + break;*/ + if ( n >= maxutxos ) break; } } } + remains = total; + for (i=0; i= 0 ) + ind = abovei; + else ind = belowi; + if ( ind < 0 ) + { + printf("error finding unspent i.%d of %d, %.8f vs %.8f, abovei.%d belowi.%d ind.%d\n",i,numunspents,dstr(remains),dstr(amount),abovei,belowi,ind); + free(utxos); + return(0); + } + up = utxos[ind]; + utxos[ind] = utxos[--n]; + memset(&utxos[n],0,sizeof(utxos[n])); + mtx.vin.push_back(CTxIn(up->txid,up->vout,CScript())); + totalinputs += up->nValue; + remains -= up->nValue; + if ( totalinputs >= total || (i+1) >= maxinputs ) + break; + } + free(utxos); if ( totalinputs >= total ) return(totalinputs); #endif diff --git a/src/komodo_kv.h b/src/komodo_kv.h index ee0496aae..2f4eadea4 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -88,7 +88,7 @@ int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp if ( (retval= ptr->valuesize) > 0 ) memcpy(value,ptr->value,retval); } - } else fprintf(stderr,"couldnt find (%s)\n",(char *)key); + } //else fprintf(stderr,"couldnt find (%s)\n",(char *)key); portable_mutex_unlock(&KOMODO_KV_mutex); if ( retval < 0 ) { @@ -172,7 +172,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) memcpy(ptr->key,key,keylen); newflag = 1; HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr); - fprintf(stderr,"KV add.(%s) (%s)\n",ptr->key,valueptr); + //fprintf(stderr,"KV add.(%s) (%s)\n",ptr->key,valueptr); } if ( newflag != 0 || (ptr->flags & KOMODO_KVPROTECTED) == 0 ) { From 6facc0ea0631f1bad87f68b01a5f2fd2fe4e0803 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Aug 2018 23:39:16 -1100 Subject: [PATCH 06/31] Syntax --- src/cc/CCtx.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 171ebf132..b3cbfda88 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -260,7 +260,7 @@ uint64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,uint64_t total,in assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); - utxos = calloc(maxutxos,sizeof(*utxos)); + utxos = (struct CC_utxo *)calloc(maxutxos,sizeof(*utxos)); BOOST_FOREACH(const COutput& out, vecOutputs) { if ( out.fSpendable != 0 ) @@ -296,7 +296,7 @@ uint64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,uint64_t total,in abovei = belowi = -1; if ( CC_vinselect(&abovei,&above,&belowi,&below,utxos,n,remains) < 0 ) { - printf("error finding unspent i.%d of %d, %.8f vs %.8f\n",i,numunspents,dstr(remains),dstr(amount)); + printf("error finding unspent i.%d of %d, %.8f vs %.8f\n",i,n,(double)remains/COIN,(double)total/COIN); free(utxos); return(0); } @@ -305,11 +305,11 @@ uint64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,uint64_t total,in else ind = belowi; if ( ind < 0 ) { - printf("error finding unspent i.%d of %d, %.8f vs %.8f, abovei.%d belowi.%d ind.%d\n",i,numunspents,dstr(remains),dstr(amount),abovei,belowi,ind); + printf("error finding unspent i.%d of %d, %.8f vs %.8f, abovei.%d belowi.%d ind.%d\n",i,numunspents,(double)remains/COIN,(double)total/COIN,abovei,belowi,ind); free(utxos); return(0); } - up = utxos[ind]; + up = &utxos[ind]; utxos[ind] = utxos[--n]; memset(&utxos[n],0,sizeof(utxos[n])); mtx.vin.push_back(CTxIn(up->txid,up->vout,CScript())); From eea3a3cdb15bca18866ec0d009e8d921b1376458 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Aug 2018 23:39:57 -1100 Subject: [PATCH 07/31] N --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index b3cbfda88..666132590 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -305,7 +305,7 @@ uint64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,uint64_t total,in else ind = belowi; if ( ind < 0 ) { - printf("error finding unspent i.%d of %d, %.8f vs %.8f, abovei.%d belowi.%d ind.%d\n",i,numunspents,(double)remains/COIN,(double)total/COIN,abovei,belowi,ind); + printf("error finding unspent i.%d of %d, %.8f vs %.8f, abovei.%d belowi.%d ind.%d\n",i,n,(double)remains/COIN,(double)total/COIN,abovei,belowi,ind); free(utxos); return(0); } From d587c96cfc9aaf92c853ffda2c31b8ad509340f2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 7 Aug 2018 04:46:54 -1100 Subject: [PATCH 08/31] Minimum rewardsfunding --- src/cc/rewards.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index afa025851..d9de1ebdb 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -412,7 +412,7 @@ UniValue RewardsList() std::string RewardsCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t APR,int64_t minseconds,int64_t maxseconds,int64_t mindeposit) { CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,a,b,c,d; struct CCcontract_info *cp,C; - if ( funds < 0 || mindeposit < 0 || minseconds < 0 || maxseconds < 0 ) + if ( funds < COIN || mindeposit < 0 || minseconds < 0 || maxseconds < 0 ) { fprintf(stderr,"negative parameter error\n"); return(0); From 112803d8e12488edc9f7b3fc59b0843c1487b66b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 7 Aug 2018 21:25:51 -1100 Subject: [PATCH 09/31] Require sbits/fundingtxid matches for rewards vins --- src/cc/rewards.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index d9de1ebdb..6c5975e51 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -137,18 +137,23 @@ uint8_t DecodeRewardsOpRet(uint256 txid,const CScript &scriptPubKey,uint64_t &sb return(0); } -uint64_t IsRewardsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +uint64_t IsRewardsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) { - char destaddr[64]; - if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) + char destaddr[64]; uint64_t sbits; uint256 fundingtxid,txid; uint8_t funcid; int32_t numvouts; + if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 && (numvouts= (int32_t)tx.vout.size()) > 0 ) { - if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,cp->unspendableCCaddr) == 0 ) - return(tx.vout[v].nValue); + txid = tx.GetHash(); + if ( (funcid= DecodeRewardsOpRet(txid,tx.vout[numvouts-1].scriptPubKey,sbits,fundingtxid)) != 0 && sbits == refsbits && (fundingtxid == reffundingtxid || txid == reffundingtxid) ) + { + + if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,cp->unspendableCCaddr) == 0 ) + return(tx.vout[v].nValue); + } } return(0); } -bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx,uint64_t txfee) +bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx,uint64_t txfee,uint64_t refsbits,uint256 reffundingtxid) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; uint64_t inputs=0,outputs=0,assetoshis; @@ -164,7 +169,7 @@ bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransactio { if ( hashBlock == zerohash ) return eval->Invalid("cant rewards from mempool"); - if ( (assetoshis= IsRewardsvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) + if ( (assetoshis= IsRewardsvout(cp,vinTx,tx.vin[i].prevout.n,refsbits,reffundingtxid)) != 0 ) inputs += assetoshis; } } @@ -172,7 +177,7 @@ bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransactio for (i=0; iismyvin)(tx.vin[i].scriptSig) == 0 ) return eval->Invalid("unexpected normal vin for unlock"); } - if ( RewardsExactAmounts(cp,eval,tx,txfee+tx.vout[1].nValue) == 0 ) + if ( RewardsExactAmounts(cp,eval,tx,txfee+tx.vout[1].nValue,sbits,fundingtxid) == 0 ) return false; else if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) return eval->Invalid("always should find vin.0, but didnt"); @@ -264,7 +269,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t } // 'L' vs 'F' and 'A' -uint64_t AddRewardsInputs(CScript &scriptPubKey,int32_t fundsflag,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs) +uint64_t AddRewardsInputs(CScript &scriptPubKey,int32_t fundsflag,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { char coinaddr[64],str[65]; uint64_t sbits,nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t j,vout,n = 0; uint8_t funcid; std::vector > unspentOutputs; @@ -286,6 +291,8 @@ uint64_t AddRewardsInputs(CScript &scriptPubKey,int32_t fundsflag,struct CCcontr { if ( (funcid= DecodeRewardsOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid)) != 0 ) { + if ( sbits != refsbits || fundingtxid != reffundingtxid ) + continue; fprintf(stderr,"fundsflag.%d (%c) %.8f %.8f\n",fundsflag,funcid,(double)tx.vout[vout].nValue/COIN,(double)it->second.satoshis/COIN); if ( fundsflag != 0 && funcid != 'F' && funcid != 'A' && funcid != 'U' ) continue; @@ -323,7 +330,7 @@ uint64_t RewardsPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey p { if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { - if ( refsbits == sbits && (nValue= IsRewardsvout(cp,tx,vout)) > 0 ) + if ( refsbits == sbits && (nValue= IsRewardsvout(cp,tx,vout,sbits,fundingtxid)) > 0 ) totalinputs += nValue; else fprintf(stderr,"refsbits.%llx sbits.%llx nValue %.8f\n",(long long)refsbits,(long long)sbits,(double)nValue/COIN); } //else fprintf(stderr,"else case\n"); @@ -520,7 +527,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 } fprintf(stderr,"APR %.8f minseconds.%llu maxseconds.%llu mindeposit %.8f\n",(double)APR/COIN,(long long)minseconds,(long long)maxseconds,(double)mindeposit/COIN); if ( locktxid == zeroid ) - amount = AddRewardsInputs(scriptPubKey,0,cp,mtx,rewardspk,(1LL << 30),1); + amount = AddRewardsInputs(scriptPubKey,0,cp,mtx,rewardspk,(1LL << 30),1,sbits,fundingtxid); else { GetCCaddress(cp,coinaddr,rewardspk); @@ -542,7 +549,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 } if ( amount > 0 && (reward= RewardsCalc(amount,mtx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit)) > txfee && scriptPubKey.size() > 0 ) { - if ( (inputs= AddRewardsInputs(ignore,1,cp,mtx,rewardspk,reward+txfee,30)) > 0 ) + if ( (inputs= AddRewardsInputs(ignore,1,cp,mtx,rewardspk,reward+txfee,30,sbits,fundingtxid)) > 0 ) { if ( inputs >= (reward + 2*txfee) ) CCchange = (inputs - (reward + txfee)); From aca80695b1aee53138edd62e5db438838b5d687c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Aug 2018 00:10:51 -1100 Subject: [PATCH 10/31] -print --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index e89dea2e4..dff8b5ab6 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -427,7 +427,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; if ( fwrite(opretbuf,1,olen,fp) != olen ) errs++; -printf("create ht.%d R opret[%d] sp.%p\n",height,olen,sp); +//printf("create ht.%d R opret[%d] sp.%p\n",height,olen,sp); //komodo_opreturn(height,opretvalue,opretbuf,olen,txhash,vout); komodo_eventadd_opreturn(sp,symbol,height,txhash,opretvalue,vout,opretbuf,olen); } From 84b0bd5230705641c292d740a5ca46726f4129fc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Aug 2018 10:40:25 -1100 Subject: [PATCH 11/31] Dont count PoW diff blocks for isPoS count --- src/komodo_bitcoind.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 89e79ccbd..372317050 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1411,7 +1411,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he return(bnTarget); } -int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget) +int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget,arith_uint256 bhash) { CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible=0,isPoS = 0; uint64_t value; CTxDestination voutaddress; if ( ASSETCHAINS_STAKED == 100 && height <= 10 ) @@ -1448,7 +1448,17 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ isPoS = 1; // close enough for a pre-filter //else fprintf(stderr,"komodo_is_PoSblock ht.%d (%s) != (%s) or %.8f != %.8f\n",height,destaddr,voutaddr,dstr(value),dstr(pblock->vtx[txn_count-1].vout[0].nValue)); } else fprintf(stderr,"komodo_is_PoSblock ht.%d couldnt extract voutaddress\n",height);*/ - } //else return(-1); + } + if ( slowflag != 0 && isPoS != 0 ) + { + bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); + if ( bhash < bnTarget ) + { + fprintf(stderr,"ht.%d isPoS but meets PoW diff!\n",height); + isPoS = 0; + } + } + //else return(-1); } //fprintf(stderr,"slow.%d ht.%d isPoS.%d\n",slowflag,height,isPoS); return(isPoS); @@ -1528,7 +1538,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) // must PoS or have at least 16x better PoW { - if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget)) == 0 ) + if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget,bhash)) == 0 ) { if ( ASSETCHAINS_STAKED == 100 && height > 100 ) // only PoS allowed! POSTEST64 return(-1); From 83f41bb0f9db920487167bd6401eb512114b5273 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Aug 2018 10:41:26 -1100 Subject: [PATCH 12/31] PoSperc --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 372317050..fc405d432 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1413,7 +1413,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget,arith_uint256 bhash) { - CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible=0,isPoS = 0; uint64_t value; CTxDestination voutaddress; + CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,PoSperc,txn_count,eligible=0,isPoS = 0; uint64_t value; CTxDestination voutaddress; if ( ASSETCHAINS_STAKED == 100 && height <= 10 ) return(1); txn_count = pblock->vtx.size(); From 11b390d86cb51b03a20daf987f626aac82459245 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Aug 2018 22:59:21 -1100 Subject: [PATCH 13/31] Catch mined PoS lookalike blocks --- src/komodo_bitcoind.h | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fc405d432..87bb19807 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1434,25 +1434,17 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ { if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)pblock->nTime,(int32_t)(eligible - pblock->nTime)); - } else isPoS = 1; + } else isPoS = 2; } - if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx + if ( slowflag == 0 && isPoS == 0 ) // maybe previous block is not seen yet, do the best approx { if ( komodo_isPoS(pblock) != 0 ) isPoS = 1; - /*txtime = komodo_txtime(&value,txid,vout,destaddr); - if ( ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey,voutaddress) ) - { - strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); - if ( strcmp(destaddr,voutaddr) == 0 && pblock->vtx[txn_count-1].vout[0].nValue == value ) - isPoS = 1; // close enough for a pre-filter - //else fprintf(stderr,"komodo_is_PoSblock ht.%d (%s) != (%s) or %.8f != %.8f\n",height,destaddr,voutaddr,dstr(value),dstr(pblock->vtx[txn_count-1].vout[0].nValue)); - } else fprintf(stderr,"komodo_is_PoSblock ht.%d couldnt extract voutaddress\n",height);*/ } if ( slowflag != 0 && isPoS != 0 ) { bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); - if ( bhash < bnTarget ) + if ( bhash < bnTarget || isPoS != 2 ) { fprintf(stderr,"ht.%d isPoS but meets PoW diff!\n",height); isPoS = 0; @@ -1461,7 +1453,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ //else return(-1); } //fprintf(stderr,"slow.%d ht.%d isPoS.%d\n",slowflag,height,isPoS); - return(isPoS); + return(isPoS != 0); } int64_t komodo_checkcommission(CBlock *pblock,int32_t height) From efb8981cb9d9ff63e3aa499ae4bc26652af319ef Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Aug 2018 23:41:59 -1100 Subject: [PATCH 14/31] Segid cache --- src/chain.h | 3 ++- src/komodo_bitcoind.h | 44 ++++++++++++++++++++++++++++++++++++++----- src/main.cpp | 4 ++++ 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/chain.h b/src/chain.h index d882083e6..394b4a6bd 100644 --- a/src/chain.h +++ b/src/chain.h @@ -121,7 +121,7 @@ public: //! height of the entry in the chain. The genesis block has height 0 int nHeight; - int64_t newcoins,zfunds; + int64_t newcoins,zfunds; int8_t segid; // jl777 fields //! Which # file this block is stored in (blk?????.dat) int nFile; @@ -182,6 +182,7 @@ public: { phashBlock = NULL; newcoins = zfunds = 0; + segid = -2; pprev = NULL; pskip = NULL; nHeight = 0; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 87bb19807..96c76245f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1140,6 +1140,8 @@ int8_t komodo_segid(int32_t height) CTxDestination voutaddress; CBlock block; CBlockIndex *pindex; uint64_t value; uint32_t txtime; char voutaddr[64],destaddr[64]; int32_t txn_count,vout; uint256 txid; int8_t segid = -1; if ( height > 0 && (pindex= komodo_chainactive(height)) != 0 ) { + if ( pindex->segid >= -1 ) + return(pindex->segid); if ( komodo_blockload(block,pindex) == 0 ) { txn_count = block.vtx.size(); @@ -1413,9 +1415,15 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget,arith_uint256 bhash) { - CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,PoSperc,txn_count,eligible=0,isPoS = 0; uint64_t value; CTxDestination voutaddress; + CBlockIndex *previndex,*pindex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,PoSperc,txn_count,eligible=0,isPoS = 0; uint64_t value; CTxDestination voutaddress; if ( ASSETCHAINS_STAKED == 100 && height <= 10 ) return(1); + if ( (pindex= mapBlockIndex[pblock->GetHash()]) != 0 && pindex->segid >= -1 ) + { + if ( pindex->segid == -1 ) + return(0); + else return(1); + } txn_count = pblock->vtx.size(); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) { @@ -1429,12 +1437,28 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( prevtime != 0 ) { if ( komodo_isPoS(pblock) != 0 ) + { eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime+27,(char *)""); + } if ( eligible == 0 || eligible > pblock->nTime ) { if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)pblock->nTime,(int32_t)(eligible - pblock->nTime)); - } else isPoS = 2; + if ( slowflag != 0 && pindex != 0 ) + pindex->segid = -1; + } + else + { + isPoS = 2; // 2 means staking utxo validated + if ( slowflag != 0 ) + { + if ( pindex != 0 && height > 100 ) + { + if ( pindex->segid == -2 ) + pindex->segid = komodo_segid(height); + } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d\n",height); + } + } } if ( slowflag == 0 && isPoS == 0 ) // maybe previous block is not seen yet, do the best approx { @@ -1443,12 +1467,20 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ } if ( slowflag != 0 && isPoS != 0 ) { - bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); - if ( bhash < bnTarget || isPoS != 2 ) + if ( isPoS != 2 ) { - fprintf(stderr,"ht.%d isPoS but meets PoW diff!\n",height); + fprintf(stderr,"ht.%d isPoS.%d utxo not validated -> must be PoW fake\n",height,isPoS); isPoS = 0; } + else + { + bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); + if ( bhash < bnTarget ) + { + fprintf(stderr,"ht.%d isPoS but meets PoW diff!\n",height); + isPoS = 0; + } + } } //else return(-1); } @@ -1484,6 +1516,8 @@ bool KOMODO_TEST_ASSETCHAIN_SKIP_POW = 0; int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { uint256 hash; arith_uint256 bnTarget,bhash; bool fNegative,fOverflow; uint8_t *script,pubkey33[33],pubkeys[64][33]; int32_t i,possible,PoSperc,is_PoSblock=0,n,failed = 0,notaryid = -1; int64_t checktoshis,value; CBlockIndex *pprev; + if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW == 0 && Params().NetworkIDString() == "regtest" ) + KOMODO_TEST_ASSETCHAIN_SKIP_POW = 1; if ( !CheckEquihashSolution(pblock, Params()) ) { fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d CheckEquihashSolution failed\n",slowflag,height); diff --git a/src/main.cpp b/src/main.cpp index b42f85ce7..6dcd6b13b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3368,6 +3368,10 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { assert(view.Flush()); DisconnectNotarisations(block); } + pindexDelete->segid = -2; + pindexDelete->newcoins = 0; + pindexDelete->zfunds = 0; + LogPrint("bench", "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * 0.001); uint256 anchorAfterDisconnect = pcoinsTip->GetBestAnchor(); // Write the chain state to disk, if necessary. From b70126d400c0967d4bd1ab315006ea176d52c13b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Aug 2018 23:48:23 -1100 Subject: [PATCH 15/31] Add no cache flag and calculate entropy based on raw segued --- src/komodo_bitcoind.h | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 96c76245f..eee9a5067 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1135,12 +1135,12 @@ uint32_t komodo_segid32(char *coinaddr) return(addrhash.uints[0]); } -int8_t komodo_segid(int32_t height) +int8_t komodo_segid(int32_t nocache,int32_t height) { CTxDestination voutaddress; CBlock block; CBlockIndex *pindex; uint64_t value; uint32_t txtime; char voutaddr[64],destaddr[64]; int32_t txn_count,vout; uint256 txid; int8_t segid = -1; if ( height > 0 && (pindex= komodo_chainactive(height)) != 0 ) { - if ( pindex->segid >= -1 ) + if ( nocache == 0 && pindex->segid >= -1 ) return(pindex->segid); if ( komodo_blockload(block,pindex) == 0 ) { @@ -1175,7 +1175,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) memset(hashbuf,0xff,n); for (i=0; i prevtime+480 ) coinage *= ((blocktime+iter+segid*2) - (prevtime+400)); - //if ( nHeight >= 2500 && blocktime+iter+segid*2 > prevtime+180 ) - // coinage *= ((blocktime+iter+segid*2) - (prevtime+60)); coinage256 = arith_uint256(coinage+1); hashval = ratio * (UintToArith256(hash) / coinage256); - //if ( nHeight >= 900 && nHeight < 916 ) - // hashval = (hashval / coinage256); if ( hashval <= bnTarget ) { winner = 1; @@ -1310,7 +1299,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he continue; if ( (pindex= komodo_chainactive(ht)) != 0 ) { - if ( komodo_segid(ht) >= 0 ) + if ( komodo_segid(0,ht) >= 0 ) { n++; percPoS++; @@ -1455,7 +1444,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( pindex != 0 && height > 100 ) { if ( pindex->segid == -2 ) - pindex->segid = komodo_segid(height); + pindex->segid = komodo_segid(1,height); } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d\n",height); } } From a3b5f801ca81f19eec04b4f3a58a8c695a28f9ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 00:14:35 -1100 Subject: [PATCH 16/31] Update comments --- src/komodo_bitcoind.h | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index eee9a5067..3e3257f08 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1105,7 +1105,6 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ commission must be in coinbase.vout[1] and must be >= 10000 sats PoS stake must be without txfee and in the last tx in the block at vout[0] */ -//#define KOMODO_POWMINMULT 16 uint64_t komodo_commission(const CBlock *pblock) { @@ -1299,7 +1298,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he continue; if ( (pindex= komodo_chainactive(ht)) != 0 ) { - if ( komodo_segid(0,ht) >= 0 ) + if ( komodo_segid(0,ht) >= 0 ) // if using segid cache is unstable consensus, need to directly call komodo_stake() here { n++; percPoS++; @@ -1314,26 +1313,6 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he m++; } } - /*if ( (pindex= komodo_chainactive(ht)) != 0 ) - { - bnTarget.SetCompact(pindex->nBits,&fNegative,&fOverflow); - bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); - hashval = UintToArith256(pindex->GetBlockHash()); - if ( hashval <= bnTarget ) // PoW is never as easy as PoS/16, some PoS will be counted as PoW - { - if ( ASSETCHAINS_STAKED < 100 ) - fprintf(stderr,"1"); - sum += hashval; - n++; - } - else - { - n++; - percPoS++; - if ( ASSETCHAINS_STAKED < 100 ) - fprintf(stderr,"0"); - } - }*/ if ( ASSETCHAINS_STAKED < 100 && (i % 10) == 9 ) fprintf(stderr," %d, ",percPoS); } @@ -1342,7 +1321,6 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height); *percPoSp = percPoS; - //target = (target / arith_uint256(KOMODO_POWMINMULT)); if ( m > 0 ) { ave = (sum / arith_uint256(m)); @@ -1547,7 +1525,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW ) return(0); - if ( ASSETCHAINS_STAKED == 0 ) // komodo_is_PoSblock will check bnTarget + if ( ASSETCHAINS_STAKED == 0 ) // komodo_is_PoSblock will check bnTarget for staked chains return(-1); } } From c6d212db1c1cc67d800591e45f81de6b29524e65 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 02:31:27 -1100 Subject: [PATCH 17/31] Test --- src/komodo_bitcoind.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 3e3257f08..eba33c301 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1298,7 +1298,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he continue; if ( (pindex= komodo_chainactive(ht)) != 0 ) { - if ( komodo_segid(0,ht) >= 0 ) // if using segid cache is unstable consensus, need to directly call komodo_stake() here + if ( komodo_segid(0,ht) >= 0 ) { n++; percPoS++; @@ -1422,7 +1422,10 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( pindex != 0 && height > 100 ) { if ( pindex->segid == -2 ) + { pindex->segid = komodo_segid(1,height); + fprintf(stderr,"set segid.%d <- %d\n",pindex->segid); + } } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d\n",height); } } From 5d3f12159d351366fa2a991653534405d2b27260 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 02:32:34 -1100 Subject: [PATCH 18/31] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index eba33c301..de1b3352e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1424,7 +1424,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( pindex->segid == -2 ) { pindex->segid = komodo_segid(1,height); - fprintf(stderr,"set segid.%d <- %d\n",pindex->segid); + fprintf(stderr,"set segid.%d <- %d\n",height,pindex->segid); } } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d\n",height); } From 549ca5a62592b85797d952ca77375838f58fb4d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 02:38:16 -1100 Subject: [PATCH 19/31] Test --- src/komodo_bitcoind.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index de1b3352e..4b7f15190 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1155,6 +1155,7 @@ int8_t komodo_segid(int32_t nocache,int32_t height) if ( strcmp(destaddr,voutaddr) == 0 && block.vtx[txn_count-1].vout[0].nValue == value ) { segid = komodo_segid32(voutaddr) & 0x3f; + fprintf(stderr,"komodo_segid.(%s) -> %02x\n",segid); } } else fprintf(stderr,"komodo_segid ht.%d couldnt extract voutaddress\n",height); } @@ -1412,7 +1413,10 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)pblock->nTime,(int32_t)(eligible - pblock->nTime)); if ( slowflag != 0 && pindex != 0 ) + { pindex->segid = -1; + fprintf(stderr,"A set segid.%d <- %d\n",height,pindex->segid); + } } else { @@ -1424,7 +1428,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( pindex->segid == -2 ) { pindex->segid = komodo_segid(1,height); - fprintf(stderr,"set segid.%d <- %d\n",height,pindex->segid); + fprintf(stderr,"B set segid.%d <- %d\n",height,pindex->segid); } } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d\n",height); } From a03223780511abfb48c0b83487bd404ee54c8a41 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 02:43:42 -1100 Subject: [PATCH 20/31] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4b7f15190..ceddcee50 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1155,7 +1155,7 @@ int8_t komodo_segid(int32_t nocache,int32_t height) if ( strcmp(destaddr,voutaddr) == 0 && block.vtx[txn_count-1].vout[0].nValue == value ) { segid = komodo_segid32(voutaddr) & 0x3f; - fprintf(stderr,"komodo_segid.(%s) -> %02x\n",segid); + fprintf(stderr,"komodo_segid.(%d) -> %02x\n",height,segid); } } else fprintf(stderr,"komodo_segid ht.%d couldnt extract voutaddress\n",height); } From e77d279f0c60bd80fb9905fe26be11906af95901 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 02:49:15 -1100 Subject: [PATCH 21/31] Test --- src/komodo_bitcoind.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ceddcee50..767b3f4ce 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1155,7 +1155,7 @@ int8_t komodo_segid(int32_t nocache,int32_t height) if ( strcmp(destaddr,voutaddr) == 0 && block.vtx[txn_count-1].vout[0].nValue == value ) { segid = komodo_segid32(voutaddr) & 0x3f; - fprintf(stderr,"komodo_segid.(%d) -> %02x\n",height,segid); + //fprintf(stderr,"komodo_segid.(%d) -> %02x\n",height,segid); } } else fprintf(stderr,"komodo_segid ht.%d couldnt extract voutaddress\n",height); } @@ -1383,7 +1383,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget,arith_uint256 bhash) { - CBlockIndex *previndex,*pindex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,PoSperc,txn_count,eligible=0,isPoS = 0; uint64_t value; CTxDestination voutaddress; + CBlockIndex *previndex,*pindex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,PoSperc,txn_count,eligible=0,isPoS = 0,segid; uint64_t value; CTxDestination voutaddress; if ( ASSETCHAINS_STAKED == 100 && height <= 10 ) return(1); if ( (pindex= mapBlockIndex[pblock->GetHash()]) != 0 && pindex->segid >= -1 ) @@ -1425,9 +1425,9 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ { if ( pindex != 0 && height > 100 ) { - if ( pindex->segid == -2 ) + if ( pindex->segid == -2 && (segid= komodo_segid(1,height)) >= 0 ) { - pindex->segid = komodo_segid(1,height); + pindex->segid = segid; fprintf(stderr,"B set segid.%d <- %d\n",height,pindex->segid); } } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d\n",height); From 8f97da8ea443c95723bbc6e03a550f63f577334c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 02:52:14 -1100 Subject: [PATCH 22/31] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 767b3f4ce..501d14da5 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1439,7 +1439,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( komodo_isPoS(pblock) != 0 ) isPoS = 1; } - if ( slowflag != 0 && isPoS != 0 ) + if ( slowflag != 0 && isPoS != 0 && height > 12500 ) { if ( isPoS != 2 ) { From 435ef4fde25e36e044d1555959e8f741ca03c70b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 02:59:45 -1100 Subject: [PATCH 23/31] Test --- src/komodo_bitcoind.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 501d14da5..02d24fbd7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1386,12 +1386,13 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ CBlockIndex *previndex,*pindex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,PoSperc,txn_count,eligible=0,isPoS = 0,segid; uint64_t value; CTxDestination voutaddress; if ( ASSETCHAINS_STAKED == 100 && height <= 10 ) return(1); - if ( (pindex= mapBlockIndex[pblock->GetHash()]) != 0 && pindex->segid >= -1 ) + pindex = mapBlockIndex[pblock->GetHash()]; + /*if ( pindex != 0 && pindex->segid >= -1 ) { if ( pindex->segid == -1 ) return(0); else return(1); - } + }*/ txn_count = pblock->vtx.size(); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) { From 15bec8194bec86cb7378e4d589a2fa531790e017 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 03:07:53 -1100 Subject: [PATCH 24/31] Test --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 02d24fbd7..561174be7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1387,12 +1387,12 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( ASSETCHAINS_STAKED == 100 && height <= 10 ) return(1); pindex = mapBlockIndex[pblock->GetHash()]; - /*if ( pindex != 0 && pindex->segid >= -1 ) + if ( pindex != 0 && pindex->segid >= -1 ) { if ( pindex->segid == -1 ) return(0); else return(1); - }*/ + } txn_count = pblock->vtx.size(); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) { @@ -1531,7 +1531,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } else if ( possible == 0 || ASSETCHAINS_SYMBOL[0] != 0 ) { - if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW ) + if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW || (strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 12500) ) return(0); if ( ASSETCHAINS_STAKED == 0 ) // komodo_is_PoSblock will check bnTarget for staked chains return(-1); From ad0f453e27545685af52fcd262620c2f11603fb3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 03:10:53 -1100 Subject: [PATCH 25/31] Test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 561174be7..9b9bc7c4d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1531,7 +1531,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } else if ( possible == 0 || ASSETCHAINS_SYMBOL[0] != 0 ) { - if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW || (strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 12500) ) + if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW ) return(0); if ( ASSETCHAINS_STAKED == 0 ) // komodo_is_PoSblock will check bnTarget for staked chains return(-1); @@ -1545,7 +1545,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); else { - if ( slowflag == 0 ) // need all past 100 blocks to calculate PoW target + if ( slowflag == 0 || (strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 12500) ) // need all past 100 blocks to calculate PoW target return(0); if ( slowflag != 0 ) bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); From 703faba6690b390eaebb1dcd9378b8cece67ea21 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 03:16:38 -1100 Subject: [PATCH 26/31] Remove MGNX exemption --- src/komodo_bitcoind.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9b9bc7c4d..483f29d71 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1411,12 +1411,12 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ } if ( eligible == 0 || eligible > pblock->nTime ) { - if ( ASSETCHAINS_STAKED < 100 ) + if ( 0 && ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)pblock->nTime,(int32_t)(eligible - pblock->nTime)); if ( slowflag != 0 && pindex != 0 ) { pindex->segid = -1; - fprintf(stderr,"A set segid.%d <- %d\n",height,pindex->segid); + fprintf(stderr,"PoW block detected set segid.%d <- %d\n",height,pindex->segid); } } else @@ -1440,7 +1440,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( komodo_isPoS(pblock) != 0 ) isPoS = 1; } - if ( slowflag != 0 && isPoS != 0 && height > 12500 ) + if ( slowflag != 0 && isPoS != 0 ) { if ( isPoS != 2 ) { @@ -1545,7 +1545,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); else { - if ( slowflag == 0 || (strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 12500) ) // need all past 100 blocks to calculate PoW target + if ( slowflag == 0 )//|| (strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 13000) ) // need all past 100 blocks to calculate PoW target return(0); if ( slowflag != 0 ) bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); From 6a8820f597a13839bc588ea19da395d03a6fa1c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 03:19:18 -1100 Subject: [PATCH 27/31] Test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 483f29d71..5e3913b23 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1424,9 +1424,9 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ isPoS = 2; // 2 means staking utxo validated if ( slowflag != 0 ) { - if ( pindex != 0 && height > 100 ) + if ( height > 100 ) { - if ( pindex->segid == -2 && (segid= komodo_segid(1,height)) >= 0 ) + if ( pindex != 0 && pindex->segid == -2 && (segid= komodo_segid(1,height)) >= 0 ) { pindex->segid = segid; fprintf(stderr,"B set segid.%d <- %d\n",height,pindex->segid); From eea0a57b3c366b922feebc2811f45bbcd34aabbf Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 03:20:05 -1100 Subject: [PATCH 28/31] Test --- src/komodo_bitcoind.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5e3913b23..3285f2616 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1422,15 +1422,12 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ else { isPoS = 2; // 2 means staking utxo validated - if ( slowflag != 0 ) + if ( slowflag != 0 && height > 100 ) { - if ( height > 100 ) + if ( pindex != 0 && pindex->segid == -2 && (segid= komodo_segid(1,height)) >= 0 ) { - if ( pindex != 0 && pindex->segid == -2 && (segid= komodo_segid(1,height)) >= 0 ) - { - pindex->segid = segid; - fprintf(stderr,"B set segid.%d <- %d\n",height,pindex->segid); - } + pindex->segid = segid; + fprintf(stderr,"B set segid.%d <- %d\n",height,pindex->segid); } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d\n",height); } } From e4ec9bab3edeee439298da02dd5606208723760e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 03:23:21 -1100 Subject: [PATCH 29/31] 13000 MGNX height exemption --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 3285f2616..19c9b15bd 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1542,7 +1542,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); else { - if ( slowflag == 0 )//|| (strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 13000) ) // need all past 100 blocks to calculate PoW target + if ( slowflag == 0 || (strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 13000) ) // need all past 100 blocks to calculate PoW target return(0); if ( slowflag != 0 ) bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); From efceba00d9acef94a022e591dc922b4dd4272300 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 03:26:04 -1100 Subject: [PATCH 30/31] Test --- src/komodo_bitcoind.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 19c9b15bd..463901570 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1534,6 +1534,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } } + if ( strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 13000 ) + return(0); if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) // must PoS or have at least 16x better PoW { if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget,bhash)) == 0 ) @@ -1542,7 +1544,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); else { - if ( slowflag == 0 || (strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 13000) ) // need all past 100 blocks to calculate PoW target + if ( slowflag == 0 ) // need all past 100 blocks to calculate PoW target return(0); if ( slowflag != 0 ) bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); From 81915d9fce766617846073d2337e20720cdca84a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 06:47:24 -1100 Subject: [PATCH 31/31] Fix rewards unlock help trigger --- 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 c2e486a05..d522ba536 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5044,7 +5044,7 @@ UniValue rewardsaddfunding(const UniValue& params, bool fHelp) UniValue rewardsunlock(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); std::string hex; char *name; uint256 fundingtxid,txid; - if ( fHelp || params.size() > 3 ) + if ( fHelp || params.size() > 3 || params.size() < 2 ) throw runtime_error("rewardsunlock name fundingtxid [txid]\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");