From 355ca56547184d90a0909c9677fa8618553028ae Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 19:09:24 -0300 Subject: [PATCH] test --- src/coins.cpp | 9 ++++++--- src/coins.h | 2 +- src/komodo.h | 3 +-- src/main.cpp | 11 ++++++----- src/miner.cpp | 3 ++- src/test/transaction_tests.cpp | 4 ++-- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 2e4f23042..505430e87 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -386,9 +386,10 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const uint32_t komodo_txtime(uint256 hash); uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); -CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx,uint32_t tiptime) const +CAmount CCoinsViewCache::GetValueIn(int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const { - uint32_t timestamp,minutes; + uint32_t timestamp,minutes; int64_t interest; + *interestp = 0; if ( tx.IsCoinBase() != 0 ) return 0; CAmount value,nResult = 0; @@ -396,7 +397,9 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx,uint32_t tiptime) con { value = GetOutputFor(tx.vin[i]).nValue; nResult += value; - nResult += komodo_interest(value,komodo_txtime(tx.vin[i].prevout.hash),tiptime); + interest = komodo_interest(value,komodo_txtime(tx.vin[i].prevout.hash),tiptime); + nResult += interest; + (*interestp) += interest; } nResult += tx.GetJoinSplitValueIn(); diff --git a/src/coins.h b/src/coins.h index 920a17f0c..bf4bc7af3 100644 --- a/src/coins.h +++ b/src/coins.h @@ -512,7 +512,7 @@ public: * @param[in] tx transaction for which we are checking input total * @return Sum of value of all inputs (scriptSigs) */ - CAmount GetValueIn(const CTransaction& tx,uint32_t prevblocktime) const; + CAmount GetValueIn(int64_t *interestp,const CTransaction& tx,uint32_t prevblocktime) const; //! Check whether all prevouts of the transaction are present in the UTXO set represented by this view bool HaveInputs(const CTransaction& tx) const; diff --git a/src/komodo.h b/src/komodo.h index 1cacb95de..6c243e6f8 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -278,8 +278,7 @@ uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { minutes = (tiptime - nLockTime) / 60; days = minutes / (24 * 60); - if ( days > 0 ) - interest = (nValue * 5000000) / (365 * 1000000 / days); + interest = (nValue * 5000000) / ((365 * 1000000 * 24 * 60) / minutes); fprintf(stderr,"komodo_interest %lld %.8f nLockTime.%u tiptime.%u minutes.%d days.%d interest %lld %.8f\n",(long long)nValue,(double)nValue/100000000.,nLockTime,tiptime,minutes,days,(long long)interest,(double)interest/100000000); } return(interest * 0); diff --git a/src/main.cpp b/src/main.cpp index f0f59b21c..fc20e557a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1097,7 +1097,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa { CCoinsView dummy; CCoinsViewCache view(&dummy); - + int64_t interest; CAmount nValueIn = 0; { LOCK(pool.cs); @@ -1132,7 +1132,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // Bring the best block into scope view.GetBestBlock(); - nValueIn = view.GetValueIn(tx,chainActive.Tip()->nTime); + nValueIn = view.GetValueIn(&interest,tx,chainActive.Tip()->nTime); // we have all inputs cached now, so switch back to dummy, so we don't need to keep lock on mempool view.SetBackend(dummy); @@ -2100,6 +2100,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin int64_t nTimeStart = GetTimeMicros(); CAmount nFees = 0; int nInputs = 0; + int64_t interest,sum = 0; unsigned int nSigOps = 0; CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size())); std::vector > vPos; @@ -2153,14 +2154,14 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return state.DoS(100, error("ConnectBlock(): too many sigops"), REJECT_INVALID, "bad-blk-sigops"); - nFees += view.GetValueIn(tx,chainActive.Tip()->nTime)-tx.GetValueOut(); - + nFees += view.GetValueIn(&interest,tx,chainActive.Tip()->nTime) - tx.GetValueOut(); + sum += interest; std::vector vChecks; if (!ContextualCheckInputs(tx, state, view, fScriptChecks, flags, false, chainparams.GetConsensus(), nScriptCheckThreads ? &vChecks : NULL)) return false; control.Add(vChecks); } - + komodo_accrued_interest(pindex->nHeight,sum); CTxUndo undoDummy; if (i > 0) { blockundo.vtxundo.push_back(CTxUndo()); diff --git a/src/miner.cpp b/src/miner.cpp index e34e05904..611facea6 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -228,6 +228,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) // Collect transactions into block uint64_t nBlockSize = 1000; uint64_t nBlockTx = 0; + int64_t interest; int nBlockSigOps = 100; bool fSortedByFee = (nBlockPrioritySize <= 0); @@ -275,7 +276,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if (!view.HaveInputs(tx)) continue; - CAmount nTxFees = view.GetValueIn(tx,chainActive.Tip()->nTime)-tx.GetValueOut(); + CAmount nTxFees = view.GetValueIn(&interest,tx,chainActive.Tip()->nTime)-tx.GetValueOut(); nTxSigOps += GetP2SHSigOpCount(tx, view); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS) diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index e9df46152..3de71ca14 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -520,9 +520,9 @@ BOOST_AUTO_TEST_CASE(test_Get) t1.vout.resize(2); t1.vout[0].nValue = 90*CENT; t1.vout[0].scriptPubKey << OP_1; - + int64_t interest; BOOST_CHECK(AreInputsStandard(t1, coins)); - BOOST_CHECK_EQUAL(coins.GetValueIn(t1,0), (50+21+22)*CENT); + BOOST_CHECK_EQUAL(coins.GetValueIn(&interest,t1,0), (50+21+22)*CENT); // Adding extra junk to the scriptSig should make it non-standard: t1.vin[0].scriptSig << OP_11;