diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index b563bd09a..3c4c6c67c 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -149,8 +149,12 @@ bool IsCCInput(CScript const& scriptSig) bool CheckTxFee(const CTransaction &tx, uint64_t txfee, uint32_t height, uint64_t blocktime) { + LOCK(mempool.cs); + CCoinsView dummy; + CCoinsViewCache view(&dummy); int64_t interest; uint64_t valuein; - CCoinsViewCache &view = *pcoinsTip; + CCoinsViewMemPool viewMemPool(pcoinsTip, mempool); + view.SetBackend(viewMemPool); valuein = view.GetValueIn(height,&interest,tx,blocktime); if ( valuein-tx.GetValueOut() > txfee ) { diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 3e4666f47..526fea52f 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -199,11 +199,10 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & { if ( lockedblocks < 0 || minrelease < 0 || totalallocations <= 0 || txidoprets.size() < 2 ) return(eval->Invalid("negative values")); - if ( !CheckTxFee(tx, PAYMENTS_TXFEE, chainActive.LastTip()->GetHeight(), chainActive.LastTip()->nTime) ) - return eval->Invalid("txfee is too high"); Paymentspk = GetUnspendable(cp,0); //fprintf(stderr, "lockedblocks.%i minrelease.%i totalallocations.%i txidopret1.%s txidopret2.%s\n",lockedblocks, minrelease, totalallocations, txidoprets[0].ToString().c_str(), txidoprets[1].ToString().c_str() ); - + if ( !CheckTxFee(tx, PAYMENTS_TXFEE+1, chainActive.LastTip()->GetHeight(), chainActive.LastTip()->nTime) ) + return eval->Invalid("txfee is too high"); // Get all the script pubkeys and allocations std::vector allocations; std::vector scriptPubKeys; @@ -267,7 +266,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & int64_t test = allocations[n]; test *= checkamount; test /= totalallocations; - if ( test != tx.vout[i].nValue ) + if ( test != tx.vout[i].nValue && test != tx.vout[i].nValue-1 ) { fprintf(stderr, "vout.%i test.%li vs nVlaue.%li\n",i, test, tx.vout[i].nValue); return(eval->Invalid("amounts do not match")); @@ -564,7 +563,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) newamount += (PAYMENTS_TXFEE - mtx.vout[i+1].nValue); mtx.vout[i+1].nValue = PAYMENTS_TXFEE; } - } + } if ( (inputsum= AddPaymentsInputs(cp,mtx,txidpk,newamount+2*PAYMENTS_TXFEE,CC_MAXVINS/2,createtxid,latestheight)) >= newamount+2*PAYMENTS_TXFEE ) { std::string rawtx; diff --git a/src/chainparams.cpp b/src/chainparams.cpp index b09ccf7c3..b8b2998b7 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -289,6 +289,8 @@ void *chainparams_commandline(void *ptr) mainParams.SetNValue(ASSETCHAINS_NK[0]); mainParams.SetKValue(ASSETCHAINS_NK[1]); } + if ( KOMODO_TESTNODE != 0 ) + mainParams.SetMiningRequiresPeers(false); if ( ASSETCHAINS_RPCPORT == 0 ) ASSETCHAINS_RPCPORT = ASSETCHAINS_P2PPORT + 1; mainParams.pchMessageStart[0] = ASSETCHAINS_MAGIC & 0xff; diff --git a/src/chainparams.h b/src/chainparams.h index 3b1ad1f72..daa16af8c 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -121,6 +121,7 @@ public: void SetCheckpointData(CCheckpointData checkpointData); void SetNValue(uint64_t n) { nEquihashN = n; } void SetKValue(uint64_t k) { nEquihashK = k; } + void SetMiningRequiresPeers(bool flag) { fMiningRequiresPeers = flag; } //void setnonce(uint32_t nonce) { memcpy(&genesis.nNonce,&nonce,sizeof(nonce)); } //void settimestamp(uint32_t timestamp) { genesis.nTime = timestamp; } diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 964ec852d..ecaf7339a 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -78,6 +78,7 @@ extern std::string DONATION_PUBKEY; extern uint8_t ASSETCHAINS_PRIVATE; extern int32_t USE_EXTERNAL_PUBKEY; extern char NOTARYADDRS[64][64]; +extern int32_t KOMODO_TESTNODE; int tx_height( const uint256 &hash ); extern std::vector vWhiteListAddress; void komodo_netevent(std::vector payload); diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 6070e9326..dc8cbda35 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -109,6 +109,8 @@ uint64_t PENDING_KOMODO_TX; extern int32_t KOMODO_LOADINGBLOCKS; unsigned int MAX_BLOCK_SIGOPS = 20000; +int32_t KOMODO_TESTNODE; + struct komodo_kv *KOMODO_KV; pthread_mutex_t KOMODO_KV_mutex,KOMODO_CC_mutex; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 4a1080cc1..88efb0264 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1710,6 +1710,7 @@ void komodo_args(char *argv0) DONATION_PUBKEY = GetArg("-donation", ""); NOTARY_PUBKEY = GetArg("-pubkey", ""); KOMODO_DEALERNODE = GetArg("-dealer",0); + KOMODO_TESTNODE = GetArg("-testnode",0); if ( strlen(NOTARY_PUBKEY.c_str()) == 66 ) { decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); diff --git a/src/wallet-utility.cpp b/src/wallet-utility.cpp index 655a3cab4..0b664ecb3 100644 --- a/src/wallet-utility.cpp +++ b/src/wallet-utility.cpp @@ -24,6 +24,7 @@ int32_t ASSETCHAINS_LWMAPOS = 0; int32_t VERUS_BLOCK_POSUNITS = 1000; int32_t ASSETCHAINS_OVERWINTER = 227520; int32_t ASSETCHAINS_SAPLING = 227520; +int32_t KOMODO_TESTNODE = 0; unsigned int MAX_BLOCK_SIGOPS = 20000;