From 093487f6f0242a850f955493e6d75f839bf89f58 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 04:09:51 -1100 Subject: [PATCH 01/39] Fix not enough rewards case --- 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 efb47fdb3..3674ac42b 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -631,7 +631,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 { if ( reward > txfee ) { - if ( (inputs= AddRewardsInputs(ignore,0,cp,mtx,rewardspk,reward+txfee,30,sbits,fundingtxid)) > 0 ) + if ( (inputs= AddRewardsInputs(ignore,0,cp,mtx,rewardspk,reward+txfee,30,sbits,fundingtxid)) >= reward+txfee ) { if ( inputs >= (reward + 2*txfee) ) CCchange = (inputs - (reward + txfee)); From 8b10fb48e0fd8b03ce35dcbb1983a7f59d573c3e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 04:32:42 -1100 Subject: [PATCH 02/39] Handle partial but not enough rewards funding --- src/cc/rewards.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 3674ac42b..696867596 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -262,9 +262,9 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t else return(true); } if ( vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("lock tx vout.0 is normal output"); - else if ( tx.vout.size() < 3 ) - return eval->Invalid("unlock tx not enough vouts"); + return eval->Invalid("unlock tx vout.0 is normal output"); + else if ( numvouts != 3 ) + return eval->Invalid("unlock tx wrong number of vouts"); else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("unlock tx vout.0 is normal output"); else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -277,6 +277,8 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return false; else if ( tx.vout[1].nValue > amount+reward ) return eval->Invalid("unlock tx vout.1 isnt amount+reward"); + else if ( tx.vout[2].nValue > 0 ) + return eval->Invalid("unlock tx vout.2 isnt 0"); preventCCvouts = 1; break; } @@ -587,7 +589,7 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 locktxid) { - CMutableTransaction mtx; CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript opret,scriptPubKey,ignore; uint256 hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; int64_t funding,reward=0,amount=0,inputs,CCchange=0; struct CCcontract_info *cp,C; + CMutableTransaction mtx,firstmtx; CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript opret,scriptPubKey,ignore; uint256 hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; int64_t funding,reward=0,amount=0,inputs,CCchange=0; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_REWARDS); if ( txfee == 0 ) txfee = 10000; @@ -631,6 +633,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 { if ( reward > txfee ) { + firstmtx = mtx; if ( (inputs= AddRewardsInputs(ignore,0,cp,mtx,rewardspk,reward+txfee,30,sbits,fundingtxid)) >= reward+txfee ) { if ( inputs >= (reward + 2*txfee) ) @@ -642,10 +645,10 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 } else { - mtx.vout.push_back(CTxOut(amount-txfee,scriptPubKey)); + firstmtx.vout.push_back(CTxOut(amount-txfee,scriptPubKey)); //CCerror = "cant find enough rewards inputs"; fprintf(stderr,"not enough rewards funds to payout %.8f, recover mode tx\n",(double)(reward+txfee)/COIN); - return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,opret)); + return(FinalizeCCTx(-1LL,cp,firstmtx,mypk,txfee,opret)); } } else From de70190c2a310584fabeec4136e418c13c363265 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 04:40:23 -1100 Subject: [PATCH 03/39] Add opret --- src/cc/rewards.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 696867596..e34b8908f 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -589,7 +589,7 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 locktxid) { - CMutableTransaction mtx,firstmtx; CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript opret,scriptPubKey,ignore; uint256 hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; int64_t funding,reward=0,amount=0,inputs,CCchange=0; struct CCcontract_info *cp,C; + CMutableTransaction mtx,firstmtx; CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript scriptPubKey,ignore; uint256 hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; int64_t funding,reward=0,amount=0,inputs,CCchange=0; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_REWARDS); if ( txfee == 0 ) txfee = 10000; @@ -648,7 +648,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 firstmtx.vout.push_back(CTxOut(amount-txfee,scriptPubKey)); //CCerror = "cant find enough rewards inputs"; fprintf(stderr,"not enough rewards funds to payout %.8f, recover mode tx\n",(double)(reward+txfee)/COIN); - return(FinalizeCCTx(-1LL,cp,firstmtx,mypk,txfee,opret)); + return(FinalizeCCTx(-1LL,cp,firstmtx,mypk,txfee,EncodeRewardsOpRet('U',sbits,fundingtxid))); } } else From eb69e5cee62fe65e3dd32996f6a0c554d8e4fea2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 04:54:03 -1100 Subject: [PATCH 04/39] Windows rag --- src/cryptoconditions/src/secp256k1.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cryptoconditions/src/secp256k1.c b/src/cryptoconditions/src/secp256k1.c index c1eb82765..6b616705b 100644 --- a/src/cryptoconditions/src/secp256k1.c +++ b/src/cryptoconditions/src/secp256k1.c @@ -46,6 +46,12 @@ void lockSign() { fclose(fp); #endif if (read != 32) { +#ifdef _WIN32 + int32_t i; + for (i=0; i<32; i++) + ((uint8_t *)ent)[i] = rand(); + fprintf(stderr,"@libscott plz make this a high entropy for windows\n"); +#endif fprintf(stderr, "Could not read 32 bytes entropy from system\n"); exit(1); } From 9f545d8eb3febdbdb5595415f2a82635ca4fd301 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 04:55:02 -1100 Subject: [PATCH 05/39] Fix --- src/cryptoconditions/src/secp256k1.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cryptoconditions/src/secp256k1.c b/src/cryptoconditions/src/secp256k1.c index 6b616705b..b3e198945 100644 --- a/src/cryptoconditions/src/secp256k1.c +++ b/src/cryptoconditions/src/secp256k1.c @@ -51,9 +51,10 @@ void lockSign() { for (i=0; i<32; i++) ((uint8_t *)ent)[i] = rand(); fprintf(stderr,"@libscott plz make this a high entropy for windows\n"); -#endif +#else fprintf(stderr, "Could not read 32 bytes entropy from system\n"); exit(1); +#endif } if (!secp256k1_context_randomize(ec_ctx_sign, ent)) { fprintf(stderr, "Could not randomize secp256k1 context\n"); From 96e1505ec8737bb501b946af2d3cc7648e4a4a38 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 05:00:51 -1100 Subject: [PATCH 06/39] Allow weaker rand() for in memory values --- src/cryptoconditions/src/secp256k1.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/cryptoconditions/src/secp256k1.c b/src/cryptoconditions/src/secp256k1.c index b3e198945..a95895fa4 100644 --- a/src/cryptoconditions/src/secp256k1.c +++ b/src/cryptoconditions/src/secp256k1.c @@ -45,16 +45,11 @@ void lockSign() { int read = (int) fread(&ent, 1, 32, fp); fclose(fp); #endif - if (read != 32) { -#ifdef _WIN32 + if (read != 32) + { int32_t i; for (i=0; i<32; i++) ((uint8_t *)ent)[i] = rand(); - fprintf(stderr,"@libscott plz make this a high entropy for windows\n"); -#else - fprintf(stderr, "Could not read 32 bytes entropy from system\n"); - exit(1); -#endif } if (!secp256k1_context_randomize(ec_ctx_sign, ent)) { fprintf(stderr, "Could not randomize secp256k1 context\n"); From 799f664f5f2a6b68d9a4ced0a3bfdc27a6b6240a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 05:05:47 -1100 Subject: [PATCH 07/39] Fix --- src/cc/rewards.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index e34b8908f..61bcf5ca3 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -251,7 +251,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t if ( (*cp->ismyvin)(tx.vin[i].scriptSig) == 0 ) return eval->Invalid("unexpected normal vin for unlock"); } - if ( numvouts == 1 && numvins == 1 ) + if ( numvouts == 2 && numvins == 1 ) { if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0 ) return eval->Invalid("unlock recover tx vout.0 is not normal output"); @@ -259,6 +259,8 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("unlock recover tx vout.0 mismatched scriptPubKey"); else if ( tx.vout[0].nValue > vinTx.vout[0].nValue ) return eval->Invalid("unlock recover tx vout.0 mismatched amounts"); + else if ( tx.vout[1].nValue > 0 ) + return eval->Invalid("unlock recover tx vout.1 nonz amount"); else return(true); } if ( vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) From 8b26f1169c439e76ae4511cd3fcd90610b1fdfbe Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 04:28:41 -1100 Subject: [PATCH 08/39] KOMODO_CONNECTING --- src/cc/CCinclude.h | 1 + src/cc/CCutils.cpp | 1 + src/komodo_globals.h | 2 +- src/main.cpp | 4 +++- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 3954068e1..761e64bcd 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -28,6 +28,7 @@ #include #include +extern int32_t KOMODO_CONNECTING; #define SMALLVAL 0.000000000000001 union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 8cb06ab25..073c2b508 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -256,6 +256,7 @@ CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv) bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) { CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t i,n; int64_t amount; std::vector origpubkey; + fprintf(stderr,"KOMODO_CONNECTING.%d\n",KOMODO_CONNECTING); // there is a chance CC tx is valid in mempool, but invalid when in block, so we cant filter duplicate requests. if any of the vins are spent, for example //txid = ctx.GetHash(); //if ( txid == cp->prevtxid ) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 86c168a85..5971e31cc 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -45,7 +45,7 @@ struct komodo_state KOMODO_STATES[34]; #define _COINBASE_MATURITY 100 int COINBASE_MATURITY = _COINBASE_MATURITY;//100; -int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND; +int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; diff --git a/src/main.cpp b/src/main.cpp index 6dcd6b13b..7a0b0a250 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,7 +56,7 @@ using namespace std; CCriticalSection cs_main; extern uint8_t NOTARY_PUBKEY33[33]; -extern int32_t KOMODO_LOADINGBLOCKS,KOMODO_LONGESTCHAIN,KOMODO_INSYNC; +extern int32_t KOMODO_LOADINGBLOCKS,KOMODO_LONGESTCHAIN,KOMODO_INSYNC,KOMODO_CONNECTING; int32_t KOMODO_NEWBLOCKS; int32_t komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block); void komodo_broadcast(CBlock *pblock,int32_t limit); @@ -3448,6 +3448,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * return AbortNode(state, "Failed to read block"); pblock = █ } + KOMODO_CONNECTING = (int32_t)pindexNew->nHeight; // Get the current commitment tree ZCIncrementalMerkleTree oldTree; assert(pcoinsTip->GetAnchorAt(pcoinsTip->GetBestAnchor(), oldTree)); @@ -3458,6 +3459,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * { CCoinsViewCache view(pcoinsTip); bool rv = ConnectBlock(*pblock, state, pindexNew, view, false, true); + KOMODO_CONNECTING = -1; GetMainSignals().BlockChecked(*pblock, state); if (!rv) { if (state.IsInvalid()) From 0bfdfaef027b56abf4d7c74d55bedd9fa480a1f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 04:34:46 -1100 Subject: [PATCH 09/39] Set KOMODO_CONNECTING from accepttomempool --- src/main.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7a0b0a250..b36e5ad82 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1263,7 +1263,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (pfMissingInputs) *pfMissingInputs = false; - int nextBlockHeight = chainActive.Height() + 1; + int flag=0,nextBlockHeight = chainActive.Height() + 1; auto consensusBranchId = CurrentEpochBranchId(nextBlockHeight, Params().GetConsensus()); // Node operator can choose to reject tx by number of transparent inputs @@ -1283,11 +1283,19 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa //fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n"); return error("AcceptToMemoryPool: komodo_validate_interest failed"); } + if ( KOMODO_CONNECTING <= 0 && chainActive.LastTip() != 0 ) + { + flag = 1; + KOMODO_CONNECTING = (int32_t)chainActive.LastTip()->nHeight + 1; + } if (!CheckTransaction(tx, state, verifier)) { - + if ( flag != 0 ) + KOMODO_CONNECTING = -1; return error("AcceptToMemoryPool: CheckTransaction failed"); } + if ( flag != 0 ) + KOMODO_CONNECTING = -1; // DoS level set to 10 to be more forgiving. // Check transaction contextually against the set of consensus rules which apply in the next block to be mined. if (!ContextualCheckTransaction(tx, state, nextBlockHeight, 10)) From ad274d5be87bc4a5f1b1ca28d00e095cdf25e96e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 04:40:37 -1100 Subject: [PATCH 10/39] Test --- src/cc/CCutils.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 073c2b508..bdeb93481 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -256,6 +256,8 @@ CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv) bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) { CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t i,n; int64_t amount; std::vector origpubkey; + if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation + return(true); fprintf(stderr,"KOMODO_CONNECTING.%d\n",KOMODO_CONNECTING); // there is a chance CC tx is valid in mempool, but invalid when in block, so we cant filter duplicate requests. if any of the vins are spent, for example //txid = ctx.GetHash(); From cd88cde2da53696542ae9e5d41899f6acb2aeae0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 06:37:46 -1100 Subject: [PATCH 11/39] test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index b36e5ad82..74037b65b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1286,7 +1286,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if ( KOMODO_CONNECTING <= 0 && chainActive.LastTip() != 0 ) { flag = 1; - KOMODO_CONNECTING = (int32_t)chainActive.LastTip()->nHeight + 1; + KOMODO_CONNECTING = 100000000 + (int32_t)chainActive.LastTip()->nHeight + 1; } if (!CheckTransaction(tx, state, verifier)) { From cb5763f0096a84ae26c759772f7d361ff5cf0052 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 06:53:50 -1100 Subject: [PATCH 12/39] Test --- src/cc/CCutils.cpp | 2 +- src/main.cpp | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index bdeb93481..61bebab40 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -256,9 +256,9 @@ CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv) bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) { CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t i,n; int64_t amount; std::vector origpubkey; + fprintf(stderr,"KOMODO_CONNECTING.%d\n",KOMODO_CONNECTING); if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation return(true); - fprintf(stderr,"KOMODO_CONNECTING.%d\n",KOMODO_CONNECTING); // there is a chance CC tx is valid in mempool, but invalid when in block, so we cant filter duplicate requests. if any of the vins are spent, for example //txid = ctx.GetHash(); //if ( txid == cp->prevtxid ) diff --git a/src/main.cpp b/src/main.cpp index 74037b65b..299906a9a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1283,26 +1283,17 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa //fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n"); return error("AcceptToMemoryPool: komodo_validate_interest failed"); } - if ( KOMODO_CONNECTING <= 0 && chainActive.LastTip() != 0 ) - { - flag = 1; - KOMODO_CONNECTING = 100000000 + (int32_t)chainActive.LastTip()->nHeight + 1; - } if (!CheckTransaction(tx, state, verifier)) { - if ( flag != 0 ) - KOMODO_CONNECTING = -1; return error("AcceptToMemoryPool: CheckTransaction failed"); } - if ( flag != 0 ) - KOMODO_CONNECTING = -1; // DoS level set to 10 to be more forgiving. // Check transaction contextually against the set of consensus rules which apply in the next block to be mined. if (!ContextualCheckTransaction(tx, state, nextBlockHeight, 10)) { return error("AcceptToMemoryPool: ContextualCheckTransaction failed"); } - + // Coinbase is only valid in a block, not as a loose transaction if (tx.IsCoinBase()) { @@ -1535,12 +1526,21 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // invalid blocks, however allowing such transactions into the mempool // can be exploited as a DoS attack. // XXX: is this neccesary for CryptoConditions? + if ( KOMODO_CONNECTING <= 0 && chainActive.LastTip() != 0 ) + { + flag = 1; + KOMODO_CONNECTING = 100000000 + (int32_t)chainActive.LastTip()->nHeight + 1; + } if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) { + if ( flag != 0 ) + KOMODO_CONNECTING = -1; fprintf(stderr,"accept failure.10\n"); return error("AcceptToMemoryPool: BUG! PLEASE REPORT THIS! ConnectInputs failed against MANDATORY but not STANDARD flags %s", hash.ToString()); } - + if ( flag != 0 ) + KOMODO_CONNECTING = -1; + // Store transaction in memory if ( komodo_is_notarytx(tx) == 0 ) KOMODO_ON_DEMAND++; From a409a6e419652bc09e9c0a48261bf7874b0903d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 07:02:12 -1100 Subject: [PATCH 13/39] Test --- src/komodo_globals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 5971e31cc..2d64bc8fc 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -45,7 +45,7 @@ struct komodo_state KOMODO_STATES[34]; #define _COINBASE_MATURITY 100 int COINBASE_MATURITY = _COINBASE_MATURITY;//100; -int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING; +int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; From 1f5025d995902cbced16844c12b25bfb928c85f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 07:16:14 -1100 Subject: [PATCH 14/39] Handle out of order confirmed CC --- src/main.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 299906a9a..87e79eafc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4168,17 +4168,27 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C // Check transactions if ( ASSETCHAINS_CC != 0 ) // CC contracts might refer to transactions in the current block, from a CC spend within the same block and out of order { - CValidationState stateDummy; + CValidationState stateDummy; int32_t i,j,rejects=0,lastrejects=0; //fprintf(stderr,"put block's tx into mempool\n"); - for (int i = 0; i < block.vtx.size(); i++) + while ( 1 ) { - const CTransaction &tx = block.vtx[i]; - if (tx.IsCoinBase() != 0 ) - continue; - else if ( ASSETCHAINS_STAKED != 0 && (i == (block.vtx.size() - 1)) && komodo_isPoS((CBlock *)&block) != 0 ) - continue; - AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL); - } + for (i=0; i Date: Sun, 19 Aug 2018 07:19:25 -1100 Subject: [PATCH 15/39] Test --- src/cc/CCinclude.h | 2 +- src/cc/dice.cpp | 2 +- src/main.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 761e64bcd..c12389275 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -60,7 +60,7 @@ bool GetAddressUnspent(uint160 addressHash, int type,std::vector 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { if ( DecodeHexTx(tx,res) != 0 ) diff --git a/src/main.cpp b/src/main.cpp index 87e79eafc..2b239dcf3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1623,7 +1623,7 @@ bool GetAddressUnspent(uint160 addressHash, int type, else return(coins.vout[n].nValue); }*/ -bool myAddtomempool(CTransaction &tx) +bool myAddtomempool(const CTransaction &tx) { CValidationState state; CTransaction Ltx; bool fMissingInputs,fOverrideFees = false; if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) From 9a813a0441d30e1084fb3569b727caaf28eaaf5f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 07:21:20 -1100 Subject: [PATCH 16/39] Test --- src/cc/CCinclude.h | 2 +- src/cc/dice.cpp | 2 +- src/main.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index c12389275..761e64bcd 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -60,7 +60,7 @@ bool GetAddressUnspent(uint160 addressHash, int type,std::vector 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { if ( DecodeHexTx(tx,res) != 0 ) diff --git a/src/main.cpp b/src/main.cpp index 2b239dcf3..a2ec5cdb4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1623,7 +1623,7 @@ bool GetAddressUnspent(uint160 addressHash, int type, else return(coins.vout[n].nValue); }*/ -bool myAddtomempool(const CTransaction &tx) +bool myAddtomempool(CTransaction &tx) { CValidationState state; CTransaction Ltx; bool fMissingInputs,fOverrideFees = false; if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) @@ -4174,7 +4174,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { for (i=0; i Date: Sun, 19 Aug 2018 07:56:44 -1100 Subject: [PATCH 17/39] Fix --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a2ec5cdb4..8bf4f269b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4174,7 +4174,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { for (i=0; i Date: Sun, 19 Aug 2018 07:58:02 -1100 Subject: [PATCH 18/39] Syntax --- src/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8bf4f269b..fba7193d0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4174,12 +4174,13 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { for (i=0; i Date: Sun, 19 Aug 2018 08:42:57 -1100 Subject: [PATCH 19/39] Change mempool print --- src/cc/CCutils.cpp | 10 ++++++++-- src/main.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 61bebab40..54a9a0225 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -255,10 +255,16 @@ CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv) bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) { - CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t i,n; int64_t amount; std::vector origpubkey; - fprintf(stderr,"KOMODO_CONNECTING.%d\n",KOMODO_CONNECTING); + CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t height,i,n,from_mempool = 0; int64_t amount; std::vector origpubkey; if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation return(true); + height = KOMODO_CONNECTING; + if ( (KOMODO_CONNECTING & (1<<30)) != 0 ) + { + from_mempool = 1; + height &= ((1<<30) - 1); + } + fprintf(stderr,"KOMODO_CONNECTING.%d mempool.%d\n",height,from_mempool); // there is a chance CC tx is valid in mempool, but invalid when in block, so we cant filter duplicate requests. if any of the vins are spent, for example //txid = ctx.GetHash(); //if ( txid == cp->prevtxid ) diff --git a/src/main.cpp b/src/main.cpp index fba7193d0..5c2e02e54 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1529,7 +1529,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if ( KOMODO_CONNECTING <= 0 && chainActive.LastTip() != 0 ) { flag = 1; - KOMODO_CONNECTING = 100000000 + (int32_t)chainActive.LastTip()->nHeight + 1; + KOMODO_CONNECTING = (1<<30) + (int32_t)chainActive.LastTip()->nHeight + 1; } if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) { From 60a91e3bd4fc885d800b44cec8248c5f0539d11d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 23:04:01 -1100 Subject: [PATCH 20/39] Change dice odds > 1 to match industry method Get the first 5 nibbles < 1 million, mod it by 10000 and compare against 1000/(odds+1) --- src/cc/dice.cpp | 47 ++++++++++++++++++++++++++++++++++++-------- src/komodo_gateway.h | 1 + 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c2f055d8d..2616bd536 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -225,9 +225,14 @@ uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv) // max 1 vout per tx return(hentropy); } +int32_t dice_5nibbles(uint8_t *fivevals) +{ + return(((int32_t)fivevals[0]<<16) + ((int32_t)fivevals[1]<<12) + ((int32_t)fivevals[2]<<8) + ((int32_t)fivevals[3]<<4) + ((int32_t)fivevals[4])); +} + uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks,uint256 houseentropy,uint256 bettorentropy) { - uint8_t buf[64],_house[32],_bettor[32]; uint64_t winnings; arith_uint256 house,bettor; char str[65],str2[65]; + uint8_t buf[64],_house[32],_bettor[32],_hash[32],hash[32],hash16[64]; uint64_t winnings; arith_uint256 hash,house,bettor; char str[65],str2[65]; int32_t i,modval; if ( odds < 10000 ) return(0); else odds -= 10000; @@ -247,11 +252,35 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t endiancpy(&buf[32],(uint8_t *)&houseentropy,32); vcalc_sha256(0,(uint8_t *)&_bettor,buf,64); endiancpy((uint8_t *)&bettor,_bettor,32); + winnings = 0; if ( odds > 1 ) - bettor = (bettor / arith_uint256(odds)); - if ( bettor >= house ) + { + //bettor = (bettor / arith_uint256(odds)); + endiancpy(buf,(uint8_t *)&house,32); + endiancpy(&buf[32],(uint8_t *)&bettor,32); + vcalc_sha256(0,(uint8_t *)&_hash,buf,64); + endiancpy(hash,_hash,32); + for (i=0; i<32; i++) + { + hash16[i<<1] = ((hash[i] >> 4) & 0x0f); + hash16[(i<<1) + 1] = (hash[i] & 0x0f); + } + modval = 0; + for (i=0; i<12; i++) + { + modval = dice_5nibbles(&hash16[i*5]); + if ( modval < 1000000 ) + { + modval %= 10000; + break; + } + } + fprintf(stderr,"modval %d vs %d\n",modval,10000/(odds+1)) + if ( modval < 10000/(odds+1) ) + winnings = bet * (odds+1); + } + else if ( bettor >= house ) winnings = bet * (odds+1); - else winnings = 0; return(winnings); } @@ -424,6 +453,8 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("cant find fundingtxid"); else if ( fundingTx.vout.size() > 0 && DecodeDiceFundingOpRet(fundingTx.vout[fundingTx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) != 'F' ) return eval->Invalid("fundingTx not valid"); + if ( maxodds > 9999 ) + return eval->Invalid("maxodds too big"); fundingPubKey = fundingTx.vout[1].scriptPubKey; switch ( funcid ) { @@ -838,9 +869,9 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx; CScript fundingPubKey,scriptPubKey; uint256 entropy,hentropy; CPubKey mypk,dicepk; uint64_t sbits; struct CCcontract_info *cp,C; int64_t minbet,maxbet,maxodds,timeoutblocks; - if ( amount < 0 ) + if ( amount < 0 || maxodds < 1 || maxodds > 9999 ) { - fprintf(stderr,"negative parameter error\n"); + fprintf(stderr,"negative parameter or invalid maxodds error (limit 9999)\n"); return(""); } if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) @@ -874,9 +905,9 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds) { CMutableTransaction mtx; CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropy,hentropy; struct CCcontract_info *cp,C; - if ( bet < 0 || odds < 1 ) + if ( bet < 0 || odds < 1 || odds > 9999 ) { - fprintf(stderr,"negative parameter error\n"); + fprintf(stderr,"negative parameter or odds too big error\n"); return(""); } if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6a8ef310b..20ece62d2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -755,6 +755,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim if ( height > 1 && checktoshis == 0 ) { checktoshis = ((uint64_t)GetBlockSubsidy(height, Params().GetConsensus()) - block.vtx[0].vout[0].nValue); + //checktoshis += txn_count * 0.001; // rely on higher level validations to prevent emitting more coins than actual txfees } if ( height >= 2 && (overflow != 0 || total > checktoshis || strangeout != 0) ) { From cd98443d65ebc2d09a17b8a6ad0dc95e61b7082a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 23:06:59 -1100 Subject: [PATCH 21/39] Syntax --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 2616bd536..0d7e168c3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -232,7 +232,7 @@ int32_t dice_5nibbles(uint8_t *fivevals) uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks,uint256 houseentropy,uint256 bettorentropy) { - uint8_t buf[64],_house[32],_bettor[32],_hash[32],hash[32],hash16[64]; uint64_t winnings; arith_uint256 hash,house,bettor; char str[65],str2[65]; int32_t i,modval; + uint8_t buf[64],_house[32],_bettor[32],_hash[32],hash[32],hash16[64]; uint64_t winnings; arith_uint256 house,bettor; char str[65],str2[65]; int32_t i,modval; if ( odds < 10000 ) return(0); else odds -= 10000; @@ -275,7 +275,7 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t break; } } - fprintf(stderr,"modval %d vs %d\n",modval,10000/(odds+1)) + fprintf(stderr,"modval %d vs %d\n",modval,10000/(odds+1)); if ( modval < 10000/(odds+1) ) winnings = bet * (odds+1); } From 76b729d24639c0cd6c9ff26d023a5801053433a6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 23:08:11 -1100 Subject: [PATCH 22/39] Fix --- src/cc/dice.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0d7e168c3..e8d0678ce 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -255,6 +255,8 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t winnings = 0; if ( odds > 1 ) { + if ( odds > 9999 ) // shouldnt happen + return(0); //bettor = (bettor / arith_uint256(odds)); endiancpy(buf,(uint8_t *)&house,32); endiancpy(&buf[32],(uint8_t *)&bettor,32); @@ -275,7 +277,7 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t break; } } - fprintf(stderr,"modval %d vs %d\n",modval,10000/(odds+1)); + fprintf(stderr,"modval %d vs %d\n",modval,(int32_t)(10000/(odds+1))); if ( modval < 10000/(odds+1) ) winnings = bet * (odds+1); } From d2b767f71df0310161439e8ec4ebc11e33891021 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 23:10:22 -1100 Subject: [PATCH 23/39] Test --- src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 5c2e02e54..51e53a742 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1535,7 +1535,6 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa { if ( flag != 0 ) KOMODO_CONNECTING = -1; - fprintf(stderr,"accept failure.10\n"); return error("AcceptToMemoryPool: BUG! PLEASE REPORT THIS! ConnectInputs failed against MANDATORY but not STANDARD flags %s", hash.ToString()); } if ( flag != 0 ) From bc3419f06d1ef275149940031b900f2c54d9c2be Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 20 Aug 2018 02:26:42 -1100 Subject: [PATCH 24/39] Revert --- src/cc/dice.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e8d0678ce..263b644ad 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -255,9 +255,14 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t winnings = 0; if ( odds > 1 ) { + { // old way + bettor = (bettor / arith_uint256(odds)); + if ( bettor >= house ) + winnings = bet * (odds+1); + return(winnings); + } if ( odds > 9999 ) // shouldnt happen return(0); - //bettor = (bettor / arith_uint256(odds)); endiancpy(buf,(uint8_t *)&house,32); endiancpy(&buf[32],(uint8_t *)&bettor,32); vcalc_sha256(0,(uint8_t *)&_hash,buf,64); From d930ed4f2e17faf5404051738e053c7bb3fdfc13 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 20 Aug 2018 02:27:11 -1100 Subject: [PATCH 25/39] Unrevert --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 263b644ad..b3115ab8f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -255,6 +255,7 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t winnings = 0; if ( odds > 1 ) { + if ( 0 ) { // old way bettor = (bettor / arith_uint256(odds)); if ( bettor >= house ) From 33f4e4925cdf9d048fc92c4748a94552af940dac Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 20 Aug 2018 08:32:00 -1100 Subject: [PATCH 26/39] Fix maxodds check --- src/cc/dice.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index b3115ab8f..03529b0ed 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -855,7 +855,7 @@ UniValue DiceList() std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks) { CMutableTransaction mtx; uint256 zero; CScript fundingPubKey; CPubKey mypk,dicepk; int64_t a,b,c,d; uint64_t sbits; struct CCcontract_info *cp,C; - if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 1 || timeoutblocks < 0 || timeoutblocks > 1440 ) + if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 1 || maxodds > 9999 || timeoutblocks < 0 || timeoutblocks > 1440 ) { fprintf(stderr,"negative parameter error\n"); return(""); @@ -877,13 +877,18 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx; CScript fundingPubKey,scriptPubKey; uint256 entropy,hentropy; CPubKey mypk,dicepk; uint64_t sbits; struct CCcontract_info *cp,C; int64_t minbet,maxbet,maxodds,timeoutblocks; - if ( amount < 0 || maxodds < 1 || maxodds > 9999 ) + if ( amount < 0 || maxodds < 1 ) { - fprintf(stderr,"negative parameter or invalid maxodds error (limit 9999)\n"); + fprintf(stderr,"negative parameter\n"); return(""); } if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) return(""); + if ( maxodds > 9999 ) + { + fprintf(stderr,"maxodds.%llu error (limit 9999)\n",(long long)maxodds); + return(""); + } scriptPubKey = CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG; if ( 0 ) { From e222a19d4b9bb42a3cd0df7875b69c5fd968e003 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 20 Aug 2018 08:46:12 -1100 Subject: [PATCH 27/39] Fix maxodds check --- src/cc/dice.cpp | 7 +------ src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 03529b0ed..8da052c86 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -877,18 +877,13 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx; CScript fundingPubKey,scriptPubKey; uint256 entropy,hentropy; CPubKey mypk,dicepk; uint64_t sbits; struct CCcontract_info *cp,C; int64_t minbet,maxbet,maxodds,timeoutblocks; - if ( amount < 0 || maxodds < 1 ) + if ( amount < 0 ) { fprintf(stderr,"negative parameter\n"); return(""); } if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) return(""); - if ( maxodds > 9999 ) - { - fprintf(stderr,"maxodds.%llu error (limit 9999)\n",(long long)maxodds); - return(""); - } scriptPubKey = CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG; if ( 0 ) { diff --git a/src/main.cpp b/src/main.cpp index 51e53a742..47d5fb017 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4185,7 +4185,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C } if ( rejects == 0 || rejects == lastrejects ) break; - fprintf(stderr,"addtomempool for CC checking: n.%d rejects.%d last.%d\n",(int32_t)block.vtx.size(),rejects,lastrejects); + fprintf(stderr,"addtomempool ht.%d for CC checking: n.%d rejects.%d last.%d\n",height,(int32_t)block.vtx.size(),rejects,lastrejects); lastrejects = rejects; rejects = 0; } From 38b5d53f015a320b23853afc1d1f378495b20b36 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 20 Aug 2018 21:41:20 -1100 Subject: [PATCH 28/39] +print --- src/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 47d5fb017..548ce2011 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4184,7 +4184,11 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C rejects++; } if ( rejects == 0 || rejects == lastrejects ) + { + if ( lastrejects != 0 ) + fprintf(stderr,"lastrejects.%d -> all tx in mempool\n",lastrejects); break; + } fprintf(stderr,"addtomempool ht.%d for CC checking: n.%d rejects.%d last.%d\n",height,(int32_t)block.vtx.size(),rejects,lastrejects); lastrejects = rejects; rejects = 0; From a03146b340d61add1191364656f099fb5f5b7efb Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 22 Aug 2018 09:26:37 +0200 Subject: [PATCH 29/39] Lots more error checking in rewards and dice --- qa/rpc-tests/cryptoconditions.py | 4 +- src/cc/dice.cpp | 14 +++++-- src/cc/rewards.cpp | 25 +++++++---- src/wallet/rpcwallet.cpp | 72 ++++++++++++++++++++++++++------ 4 files changed, 89 insertions(+), 26 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 68b381272..519a34182 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -6,7 +6,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.authproxy import JSONRPCException from test_framework.util import assert_equal, assert_greater_than, \ - initialize_chain_clean, start_nodes, start_node, connect_nodes_bi, \ + initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \ stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds, rpc_port import time @@ -327,10 +327,10 @@ class CryptoConditionsTest (BitcoinTestFramework): print("Importing privkey") rpc.importprivkey(self.privkey) - self.run_faucet_tests() self.run_rewards_tests() self.run_dice_tests() self.run_token_tests() + self.run_faucet_tests() if __name__ == '__main__': diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e8d0678ce..2cc18de39 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -15,6 +15,8 @@ #include "CCdice.h" +extern std::string CCerror; + // timeout /* @@ -949,7 +951,8 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 //char str[65]; fprintf(stderr,"DiceBetFinish.%s %s\n",planstr,uint256_str(str,bettxid)); if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { - fprintf(stderr,"Diceinit error\n"); + CCerror = "Diceinit error"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } fundingpk = DiceFundingPk(fundingPubKey); @@ -964,7 +967,8 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } if ( AddNormalinputs(mtx,mypk,txfee,1) == 0 ) { - fprintf(stderr,"no txfee inputs for win/lose\n"); + CCerror = "no txfee inputs for win/lose"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) @@ -978,7 +982,8 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 { if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { - fprintf(stderr,"bettxid already spent\n"); + CCerror = "bettxid already spent"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } //fprintf(stderr,"iswin.%d matches\n",iswin); @@ -1056,7 +1061,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { - fprintf(stderr,"Diceinit error\n"); + CCerror = "Diceinit error"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(0.); } fundingpk = DiceFundingPk(fundingPubKey); diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 61bcf5ca3..d3d374613 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -539,7 +539,8 @@ std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,i sbits = stringbits(planstr); if ( RewardsPlanExists(cp,sbits,rewardspk,a,b,c,d) == 0 ) { - fprintf(stderr,"Rewards plan %s doesnt exist\n",planstr); + CCerror = strprintf("Rewards plan %s doesnt exist\n",planstr); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } sbits = stringbits(planstr); @@ -547,8 +548,12 @@ std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,i { mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,rewardspk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeRewardsOpRet('A',sbits,fundingtxid))); - } else fprintf(stderr,"cant find enough inputs\n"); - fprintf(stderr,"cant find fundingtxid\n"); + } else { + CCerror = "cant find enough inputs"; + fprintf(stderr,"%s\n", CCerror.c_str()); + } + CCerror = "cant find fundingtxid"; + fprintf(stderr,"%s\n", CCerror.c_str()); return(""); } @@ -557,7 +562,8 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t lockedfunds,sbits,funding,APR,minseconds,maxseconds,mindeposit; struct CCcontract_info *cp,C; if ( deposit < txfee ) { - fprintf(stderr,"deposit amount less than txfee\n"); + CCerror = "deposit amount less than txfee"; + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } cp = CCinit(&C,EVAL_REWARDS); @@ -568,12 +574,14 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t sbits = stringbits(planstr); if ( RewardsPlanExists(cp,sbits,rewardspk,APR,minseconds,maxseconds,mindeposit) == 0 ) { - fprintf(stderr,"Rewards plan %s doesnt exist\n",planstr); + CCerror = strprintf("Rewards plan %s doesnt exist\n",planstr); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } if ( deposit < mindeposit ) { - fprintf(stderr,"Rewards plan %s deposit %.8f < mindeposit %.8f\n",planstr,(double)deposit/COIN,(double)mindeposit/COIN); + CCerror = strprintf("Rewards plan %s deposit %.8f < mindeposit %.8f\n",planstr,(double)deposit/COIN,(double)mindeposit/COIN); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } if ( (funding= RewardsPlanFunds(lockedfunds,sbits,cp,rewardspk,fundingtxid)) >= deposit ) // arbitrary cmpval @@ -583,7 +591,10 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t mtx.vout.push_back(MakeCC1vout(cp->evalcode,deposit,rewardspk)); mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeRewardsOpRet('L',sbits,fundingtxid))); - } else fprintf(stderr,"cant find enough inputs %.8f not enough for %.8f, make sure you imported privkey for the -pubkey address\n",(double)funding/COIN,(double)deposit/COIN); + } else { + CCerror = strprintf("cant find enough inputs %.8f not enough for %.8f, make sure you imported privkey for the -pubkey address\n",(double)funding/COIN,(double)deposit/COIN); + fprintf(stderr,"%s\n",CCerror.c_str()); + } } fprintf(stderr,"cant find rewards inputs funding %.8f locked %.8f vs deposit %.8f\n",(double)funding/COIN,(double)lockedfunds/COIN,(double)deposit/COIN); return(""); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 05faaeeb1..fa93bf3a7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4968,7 +4968,7 @@ UniValue tokenaddress(const UniValue& params, bool fHelp) UniValue rewardscreatefunding(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char *name; uint64_t funds,APR,minseconds,maxseconds,mindeposit; std::string hex; + UniValue result(UniValue::VOBJ); char *name; int64_t funds,APR,minseconds,maxseconds,mindeposit; std::string hex; if ( fHelp || params.size() > 6 || params.size() < 2 ) throw runtime_error("rewardscreatefunding name amount APR mindays maxdays mindeposit\n"); if ( ensure_CCrequirements() < 0 ) @@ -4981,17 +4981,43 @@ UniValue rewardscreatefunding(const UniValue& params, bool fHelp) mindeposit = 100 * COIN; name = (char *)params[0].get_str().c_str(); funds = atof(params[1].get_str().c_str()) * COIN; + + if ( funds <= 0 ) { + ERR_RESULT("funds must be positive"); + return result; + } if ( params.size() > 2 ) { APR = atof(params[2].get_str().c_str()) * COIN; + if ( APR > REWARDSCC_MAXAPR ) + { + ERR_RESULT("25% APR is maximum"); + return result; + } if ( params.size() > 3 ) { minseconds = atol(params[3].get_str().c_str()) * 3600 * 24; + if ( minseconds < 0 ) { + ERR_RESULT("mindays must be non-negative"); + return result; + } if ( params.size() > 4 ) { maxseconds = atol(params[4].get_str().c_str()) * 3600 * 24; + if ( maxseconds <= 0 ) { + ERR_RESULT("maxdays must be positive"); + return result; + } + if ( maxseconds < minseconds ) { + ERR_RESULT("maxdays must be greater than mindays"); + return result; + } if ( params.size() > 5 ) mindeposit = atof(params[5].get_str().c_str()) * COIN; + if ( mindeposit <= 0 ) { + ERR_RESULT("mindeposit must be positive"); + return result; + } } } } @@ -5017,7 +5043,9 @@ UniValue rewardslock(const UniValue& params, bool fHelp) fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); amount = atof(params[2].get_str().c_str()) * COIN; hex = RewardsLock(0,name,fundingtxid,amount); - if ( amount > 0 ) { + if ( CCerror != "" ){ + ERR_RESULT(CCerror); + } else if ( amount > 0 ) { if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); @@ -5040,7 +5068,9 @@ UniValue rewardsaddfunding(const UniValue& params, bool fHelp) fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); amount = atof(params[2].get_str().c_str()) * COIN; hex = RewardsAddfunding(0,name,fundingtxid,amount); - if (amount > 0) { + if (CCerror != "") { + ERR_RESULT(CCerror); + } else if (amount > 0) { if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); @@ -5050,8 +5080,7 @@ UniValue rewardsaddfunding(const UniValue& params, bool fHelp) result.push_back(Pair("error", "couldnt create rewards addfunding transaction")); } } else { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "funding amount must be positive")); + ERR_RESULT("funding amount must be positive"); } return(result); } @@ -5260,7 +5289,7 @@ UniValue dicebet(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt create faucet get transaction"); + } else ERR_RESULT("couldnt create dice bet transaction"); } else { ERR_RESULT("amount and odds must be positive"); } @@ -5280,7 +5309,10 @@ UniValue dicefinish(const UniValue& params, bool fHelp) fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); bettxid = Parseuint256((char *)params[2].get_str().c_str()); hex = DiceBetFinish(&r,0,name,fundingtxid,bettxid,1); - if ( hex.size() > 0 ) + if ( CCerror != "" ) + { + ERR_RESULT(CCerror); + } else if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); @@ -5303,6 +5335,10 @@ UniValue dicestatus(const UniValue& params, bool fHelp) if ( params.size() == 3 ) bettxid = Parseuint256((char *)params[2].get_str().c_str()); winnings = DiceStatus(0,name,fundingtxid,bettxid); + if (CCerror != "") { + ERR_RESULT(CCerror); + return result; + } result.push_back(Pair("result", "success")); if ( winnings >= 0. ) { @@ -5528,7 +5564,7 @@ UniValue tokencancelbid(const UniValue& params, bool fHelp) UniValue tokenfillbid(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint64_t fillamount; std::string hex; uint256 tokenid,bidtxid; + UniValue result(UniValue::VOBJ); int64_t fillamount; std::string hex; uint256 tokenid,bidtxid; if ( fHelp || params.size() != 3 ) throw runtime_error("tokenfillbid tokenid bidtxid fillamount\n"); if ( ensure_CCrequirements() < 0 ) @@ -5538,9 +5574,14 @@ UniValue tokenfillbid(const UniValue& params, bool fHelp) tokenid = Parseuint256((char *)params[0].get_str().c_str()); bidtxid = Parseuint256((char *)params[1].get_str().c_str()); fillamount = atol(params[2].get_str().c_str()); - if ( tokenid == zeroid || bidtxid == zeroid || fillamount <= 0 ) + if ( fillamount <= 0 ) { - result.push_back(Pair("error", "invalid parameter")); + ERR_RESULT("fillamount must be positive"); + return(result); + } + if ( tokenid == zeroid || bidtxid == zeroid ) + { + ERR_RESULT("must provide tokenid and bidtxid"); return(result); } hex = FillBuyOffer(0,tokenid,bidtxid,fillamount); @@ -5567,7 +5608,7 @@ UniValue tokenask(const UniValue& params, bool fHelp) askamount = (price * numtokens) * COIN + 0.0000000049999; if ( tokenid == zeroid || numtokens <= 0 || price <= 0 || askamount <= 0 ) { - result.push_back(Pair("error", "invalid parameter")); + ERR_RESULT("invalid parameter"); return(result); } hex = CreateSell(0,numtokens,tokenid,askamount); @@ -5638,7 +5679,7 @@ UniValue tokencancelask(const UniValue& params, bool fHelp) UniValue tokenfillask(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint64_t fillunits; std::string hex; uint256 tokenid,asktxid; + UniValue result(UniValue::VOBJ); int64_t fillunits; std::string hex; uint256 tokenid,asktxid; if ( fHelp || params.size() != 3 ) throw runtime_error("tokenfillask tokenid asktxid fillunits\n"); if ( ensure_CCrequirements() < 0 ) @@ -5648,7 +5689,12 @@ UniValue tokenfillask(const UniValue& params, bool fHelp) tokenid = Parseuint256((char *)params[0].get_str().c_str()); asktxid = Parseuint256((char *)params[1].get_str().c_str()); fillunits = atol(params[2].get_str().c_str()); - if ( tokenid == zeroid || asktxid == zeroid || fillunits <= 0 ) + if ( fillunits <= 0 ) + { + ERR_RESULT("fillunits must be positive"); + return(result); + } + if ( tokenid == zeroid || asktxid == zeroid ) { result.push_back(Pair("error", "invalid parameter")); return(result); From 47a5268bd48a3630271b3a6ab3e5762d725cb9eb Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 22 Aug 2018 09:49:55 +0200 Subject: [PATCH 30/39] Prevent useless prints in regtest --- src/pow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pow.cpp b/src/pow.cpp index 6d218ef13..1291e445e 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -203,6 +203,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int if ( ASSETCHAINS_SYMBOL[0] != 0 || height > 792000 ) { //if ( 0 && height > 792000 ) + if ( Params().NetworkIDString() != "regtest" ) { for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); From df09c378ca82d8d2c4db814711f5a8d1f5e42e54 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 22 Aug 2018 09:50:06 +0200 Subject: [PATCH 31/39] Fix a test --- qa/rpc-tests/cryptoconditions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 519a34182..4474a8084 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -68,7 +68,7 @@ class CryptoConditionsTest (BitcoinTestFramework): # basic sanity tests result = rpc.getwalletinfo() - assert_equal(result['txcount'], 101) + assert_greater_than(result['txcount'], 100) assert_greater_than(result['balance'], 0.0) balance = result['balance'] From b8245a93971e7a6954cd60113749880641ff5325 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 22 Aug 2018 10:11:05 +0200 Subject: [PATCH 32/39] enable cross chain CC stuff in tests --- qa/rpc-tests/cryptoconditions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 4474a8084..3b4700858 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -43,7 +43,7 @@ class CryptoConditionsTest (BitcoinTestFramework): '-ac_supply=5555555', '-ac_reward=10000000', '-pubkey=' + self.pubkey, - '-ac_cc=1', + '-ac_cc=2', '-whitelist=127.0.0.1', '-debug', '-daemon', From 505634eeae86276d14d39711856e4264f9b19076 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 22 Aug 2018 17:07:04 +0200 Subject: [PATCH 33/39] Pass various internal dice errors back in JSON response --- src/cc/dice.cpp | 55 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a9d957f75..6c21dd8dc 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -859,12 +859,17 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t CMutableTransaction mtx; uint256 zero; CScript fundingPubKey; CPubKey mypk,dicepk; int64_t a,b,c,d; uint64_t sbits; struct CCcontract_info *cp,C; if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 1 || maxodds > 9999 || timeoutblocks < 0 || timeoutblocks > 1440 ) { - fprintf(stderr,"negative parameter error\n"); + CCerror = "invalid parameter error"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } memset(&zero,0,sizeof(zero)); if ( (cp= Diceinit(fundingPubKey,zero,&C,planstr,txfee,mypk,dicepk,sbits,a,b,c,d)) == 0 ) + { + CCerror = "Diceinit error"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); + } if ( AddNormalinputs(mtx,mypk,funds+3*txfee,60) > 0 ) { mtx.vout.push_back(MakeCC1vout(cp->evalcode,funds,dicepk)); @@ -872,7 +877,8 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(dicepk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceFundingOpRet('F',sbits,minbet,maxbet,maxodds,timeoutblocks))); } - fprintf(stderr,"cant find enough inputs\n"); + CCerror = "cant find enough inputs"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } @@ -881,7 +887,8 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 CMutableTransaction mtx; CScript fundingPubKey,scriptPubKey; uint256 entropy,hentropy; CPubKey mypk,dicepk; uint64_t sbits; struct CCcontract_info *cp,C; int64_t minbet,maxbet,maxodds,timeoutblocks; if ( amount < 0 ) { - fprintf(stderr,"negative parameter\n"); + CCerror = "amount must be positive"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) @@ -907,31 +914,46 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,dicepk)); mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet('E',sbits,fundingtxid,hentropy,zeroid))); - } else fprintf(stderr,"cant find enough inputs\n"); - } else fprintf(stderr,"only fund creator can add more funds (entropy)\n"); + } else { + CCerror = "cant find enough inputs"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + } + } else { + CCerror = "only fund creator can add more funds (entropy)"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + } return(""); } std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds) { CMutableTransaction mtx; CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropy,hentropy; struct CCcontract_info *cp,C; - if ( bet < 0 || odds < 1 || odds > 9999 ) + if ( bet < 0 ) { - fprintf(stderr,"negative parameter or odds too big error\n"); + CCerror = "bet must be positive"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } + if ( odds < 1 || odds > 9999 ) + { + CCerror = "odds must be between 1 and 9999"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) return(""); if ( bet < minbet || bet > maxbet || odds > maxodds ) { - fprintf(stderr,"Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds); + CCerror = strprintf("Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds); + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } if ( (funding= DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid)) >= 2*bet*odds+txfee && entropyval != 0 ) { if ( myIsutxo_spentinmempool(entropytxid,0) != 0 ) { - fprintf(stderr,"entropy txid is spent\n"); + CCerror = "entropy txid is spent"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } mtx.vin.push_back(CTxIn(entropytxid,0,CScript())); @@ -945,8 +967,10 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet } else fprintf(stderr,"cant find enough inputs %.8f note enough for %.8f\n",(double)funding/COIN,(double)bet/COIN); } if ( entropyval == 0 && funding != 0 ) - fprintf(stderr,"cant find dice entropy inputs\n"); - else fprintf(stderr,"cant find dice inputs\n"); + CCerror = "cant find dice entropy inputs"; + else + CCerror = "cant find dice input"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } @@ -1015,7 +1039,8 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 odds = (betTx.vout[2].nValue - txfee); if ( odds < 1 || odds > maxodds ) { - fprintf(stderr,"illegal odds.%d vs maxodds.%d\n",(int32_t)odds,(int32_t)maxodds); + CCerror = strprintf("illegal odds.%d vs maxodds.%d\n",(int32_t)odds,(int32_t)maxodds); + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } CCchange = betTx.vout[0].nValue + betTx.vout[1].nValue; @@ -1029,7 +1054,8 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } else { - fprintf(stderr,"not enough inputs for %.8f\n",(double)fundsneeded/COIN); + CCerror = strprintf("not enough inputs for %.8f\n",(double)fundsneeded/COIN); + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,dicepk)); @@ -1058,7 +1084,8 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } } *resultp = -1; - fprintf(stderr,"couldnt find bettx or entropytx\n"); + CCerror = "couldnt find bettx or entropytx"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } From 6843837cdab55dcaea4e73ed901e3672b6820f8b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 22 Aug 2018 07:18:22 -1100 Subject: [PATCH 34/39] +prints --- src/cc/dice.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 6c21dd8dc..8d793d7c9 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -665,6 +665,8 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0; uint8_t funcid; std::vector > unspentOutputs; + entropyval = 0; + entropytxid = zeroid; if ( GetTransaction(reffundingtxid,tx,hashBlock,false) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) != 0 ) { fundingPubKey = tx.vout[1].scriptPubKey; @@ -745,6 +747,7 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontrac { char CCaddr[64]; uint64_t sbits; uint256 txid,hashBlock; CTransaction tx; std::vector > txids; + fundingtxid = zeroid; GetCCaddress(cp,CCaddr,dicepk); SetCCtxids(txids,cp->normaladdr); if ( fundingtxid != zeroid ) // avoid scan unless creating new funding plan @@ -755,8 +758,8 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontrac { fundingPubKey = tx.vout[1].scriptPubKey; return(true); - } - } + } else fprintf(stderr,"error decoding opret or sbits mismatch %llx vs %llx\n",(long long)sbits,(long long)refsbits); + } else fprintf(stderr,"couldnt get funding tx\n"); return(false); } for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) @@ -866,7 +869,7 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t memset(&zero,0,sizeof(zero)); if ( (cp= Diceinit(fundingPubKey,zero,&C,planstr,txfee,mypk,dicepk,sbits,a,b,c,d)) == 0 ) { - CCerror = "Diceinit error"; + CCerror = "Diceinit error in create funding"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } @@ -981,7 +984,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 //char str[65]; fprintf(stderr,"DiceBetFinish.%s %s\n",planstr,uint256_str(str,bettxid)); if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { - CCerror = "Diceinit error"; + CCerror = "Diceinit error in finish"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } @@ -1094,7 +1097,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { - CCerror = "Diceinit error"; + CCerror = "Diceinit error in status"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(0.); } From 692b653d797a94056aa122a6f74213396cc65564 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 22 Aug 2018 07:30:16 -1100 Subject: [PATCH 35/39] Fix --- src/cc/dice.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8d793d7c9..0ed434e83 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -745,13 +745,13 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontract_info *cp,uint64_t refsbits,CPubKey dicepk,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) { - char CCaddr[64]; uint64_t sbits; uint256 txid,hashBlock; CTransaction tx; + char CCaddr[64]; uint64_t sbits=0; uint256 txid,hashBlock; CTransaction tx; std::vector > txids; - fundingtxid = zeroid; GetCCaddress(cp,CCaddr,dicepk); SetCCtxids(txids,cp->normaladdr); if ( fundingtxid != zeroid ) // avoid scan unless creating new funding plan { + fprintf(stderr,"check fundingtxid\n"); if ( GetTransaction(fundingtxid,tx,hashBlock,false) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,CCaddr,0) != 0 ) { if ( DecodeDiceFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 'F' && sbits == refsbits ) @@ -798,7 +798,7 @@ struct CCcontract_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,s else cmpflag = 1; if ( DicePlanExists(fundingPubKey,reffundingtxid,cp,sbits,dicepk,minbet,maxbet,maxodds,timeoutblocks) != cmpflag ) { - fprintf(stderr,"Dice plan (%s) already exists cmpflag.%d\n",planstr,cmpflag); + fprintf(stderr,"Dice plan (%s) exists.%d vs cmpflag.%d\n",planstr,!cmpflag,cmpflag); return(0); } return(cp); From eafcb941409f86d425de7f3615b0254a9236c9b2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 22 Aug 2018 07:57:48 -1100 Subject: [PATCH 36/39] CCerror = ""; --- src/cc/dice.cpp | 2 +- src/wallet/rpcwallet.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0ed434e83..7cabbe804 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -751,7 +751,7 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontrac SetCCtxids(txids,cp->normaladdr); if ( fundingtxid != zeroid ) // avoid scan unless creating new funding plan { - fprintf(stderr,"check fundingtxid\n"); + //fprintf(stderr,"check fundingtxid\n"); if ( GetTransaction(fundingtxid,tx,hashBlock,false) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,CCaddr,0) != 0 ) { if ( DecodeDiceFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 'F' && sbits == refsbits ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fa93bf3a7..3332cd8c3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4836,6 +4836,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt int32_t ensure_CCrequirements() { extern uint8_t NOTARY_PUBKEY33[]; + CCerror = ""; if ( NOTARY_PUBKEY33[0] == 0 ) return(-1); else if ( GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX) == 0 ) From eb4cf14d400a88e1a294ac42eeb724da6189aab5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 22 Aug 2018 08:07:52 -1100 Subject: [PATCH 37/39] Tweak message --- src/cc/dice.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7cabbe804..506a61cd0 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -967,7 +967,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet mtx.vout.push_back(MakeCC1vout(cp->evalcode,bet,dicepk)); mtx.vout.push_back(CTxOut(txfee+odds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet('B',sbits,fundingtxid,entropy,zeroid))); - } else fprintf(stderr,"cant find enough inputs %.8f note enough for %.8f\n",(double)funding/COIN,(double)bet/COIN); + } else fprintf(stderr,"cant find enough normal inputs for %.8f, plan funding %.8f\n",(double)bet/COIN,(double)funding/COIN); } if ( entropyval == 0 && funding != 0 ) CCerror = "cant find dice entropy inputs"; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3332cd8c3..ffb75983a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5290,7 +5290,7 @@ UniValue dicebet(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt create dice bet transaction"); + } else ERR_RESULT("couldnt create dice bet transaction. make sure your address has funds"); } else { ERR_RESULT("amount and odds must be positive"); } From 1c75341741b95835e7568dd44d327f545c53cc14 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 22 Aug 2018 08:17:20 -1100 Subject: [PATCH 38/39] -ac_ccactivate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allows a chain to “dynamically” update to CC enabled --- src/cc/CCinclude.h | 2 +- src/cc/CCutils.cpp | 4 +++- src/komodo_globals.h | 2 +- src/komodo_utils.h | 6 ++++++ src/main.h | 4 ++-- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 761e64bcd..4795ead3c 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -28,7 +28,7 @@ #include #include -extern int32_t KOMODO_CONNECTING; +extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE; #define SMALLVAL 0.000000000000001 union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 54a9a0225..a57197537 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -256,9 +256,11 @@ CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv) bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) { CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t height,i,n,from_mempool = 0; int64_t amount; std::vector origpubkey; + height = KOMODO_CONNECTING; if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation return(true); - height = KOMODO_CONNECTING; + if ( ASSETCHAINS_CC == 0 || height < KOMODO_CCACTIVATE ) + return eval->Invalid("CC are disabled or not active yet"); if ( (KOMODO_CONNECTING & (1<<30)) != 0 ) { from_mempool = 1; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 2d64bc8fc..918e7c4f6 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -46,7 +46,7 @@ struct komodo_state KOMODO_STATES[34]; int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1; -int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE = 1; +int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 616f7ecaa..23e6b280e 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1544,6 +1544,7 @@ void komodo_args(char *argv0) } KOMODO_STOPAT = GetArg("-stopat",0); ASSETCHAINS_CC = GetArg("-ac_cc",0); + KOMODO_CCACTIVATE = GetArg("-ac_ccactivate",0); ASSETCHAINS_PUBLIC = GetArg("-ac_public",0); ASSETCHAINS_PRIVATE = GetArg("-ac_private",0); if ( (KOMODO_REWIND= GetArg("-rewind",0)) != 0 ) @@ -1650,6 +1651,11 @@ void komodo_args(char *argv0) //printf("created (%s)\n",fname); } else printf("error creating (%s)\n",fname); #endif + if ( KOMODO_CCACTIVATE != 0 && ASSETCHAINS_CC == 0 ) + { + ASSETCHAINS_CC = 2; + fprintf(stderr,"smart utxo CC contracts will activate at height.%d\n",KOMODO_CCACTIVATE); + } } else { diff --git a/src/main.h b/src/main.h index dfea318cb..fd418502a 100644 --- a/src/main.h +++ b/src/main.h @@ -104,8 +104,8 @@ 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) +#define DEFAULT_ADDRESSINDEX (GetArg("-ac_cc",0) != 0 || GetArg("-ac_ccactivate",0) != 0) +#define DEFAULT_SPENTINDEX (GetArg("-ac_cc",0) != 0 || GetArg("-ac_ccactivate",0) != 0) static const bool DEFAULT_TIMESTAMPINDEX = false; static const unsigned int DEFAULT_DB_MAX_OPEN_FILES = 1000; static const bool DEFAULT_DB_COMPRESSION = true; From dcdb45372d855182842d3748671d7f2e1f97518a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Aug 2018 05:22:21 -1100 Subject: [PATCH 39/39] Require 100 coins to create a dice plan --- src/cc/dice.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 506a61cd0..dd9322eeb 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -866,6 +866,12 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } + if ( funds < 100*COIN ) + { + CCerror = "dice plan needs at least 100 coins"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } memset(&zero,0,sizeof(zero)); if ( (cp= Diceinit(fundingPubKey,zero,&C,planstr,txfee,mypk,dicepk,sbits,a,b,c,d)) == 0 ) {