This commit is contained in:
jl777
2016-10-22 13:23:25 -03:00
parent 2860f74793
commit 17878015bb
11 changed files with 60 additions and 53 deletions

View File

@@ -383,9 +383,9 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const
return coins->vout[input.prevout.n].scriptPubKey;
}
uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime);
uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime);
CAmount CCoinsViewCache::GetValueIn(int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const
CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const
{
uint32_t timestamp,minutes; int64_t interest;
*interestp = 0;
@@ -396,7 +396,7 @@ CAmount CCoinsViewCache::GetValueIn(int64_t *interestp,const CTransaction& tx,ui
{
value = GetOutputFor(tx.vin[i]).nValue;
nResult += value;
interest = komodo_interest(value,tx.nLockTime,tiptime);
interest = komodo_interest(nHeight,value,tx.nLockTime,tiptime);
#ifdef KOMODO_ENABLE_INTEREST
nResult += interest;
#endif

View File

@@ -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(int64_t *interestp,const CTransaction& tx,uint32_t prevblocktime) const;
CAmount GetValueIn(int32_t nHeight,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;

View File

@@ -83,38 +83,6 @@ const char *Notaries[][2] =
{ "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" },
};
uint64_t komodo_accrued_interest(int32_t height,int64_t paidinterest)
{
static uint64_t *interests; static int32_t maxheight;
int32_t ind,incr = 100000;
if ( height >= maxheight )
{
interests = (uint64_t *)realloc(interests,(maxheight + incr) * sizeof(*interests) * 2);
memset(&interests[maxheight << 1],0,incr * sizeof(*interests) * 2);
maxheight += incr;
}
ind = (height << 1);
if ( paidinterest < 0 ) // request
return(interests[ind]);
else
{
if ( interests[ind + 1] != paidinterest )
{
interests[ind + 1] = paidinterest;
if ( height == 0 )
height++;
for (; height<maxheight; height++,ind+=2)
interests[ind] = interests[ind - 2] + interests[ind + 1];
}
}
}
uint64_t komodo_moneysupply(int32_t height)
{
if ( height <= 1 )
return(0);
else return(COIN * 100000000 + (height-1) * 3 + komodo_accrued_interest(height,-1));
}
int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp)
{

View File

@@ -4,10 +4,49 @@
#define KOMODO_INTEREST ((uint64_t)(0.05 * COIN))
#define dstr(x) ((double)(x)/COIN)
uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime)
uint64_t komodo_accrued_interest(int32_t height,int64_t paidinterest)
{
static uint64_t *interests; static int32_t maxheight;
uint64_t total; int32_t ind,incr = 100000;
if ( height >= maxheight )
{
interests = (uint64_t *)realloc(interests,(maxheight + incr) * sizeof(*interests) * 2);
memset(&interests[maxheight << 1],0,incr * sizeof(*interests) * 2);
maxheight += incr;
}
ind = (height << 1);
if ( paidinterest < 0 ) // request
return(interests[ind]);
else
{
if ( interests[ind + 1] != paidinterest )
{
interests[ind + 1] = paidinterest;
if ( height == 0 )
interests[ind] = interests[ind + 1];
else interests[ind] = interests[ind - 2] + interests[ind + 1];
total = interests[ind];
for (++height; height<maxheight; height++)
{
ind = (height << 1);
interests[ind] = total;
interests[ind + 1] = 0;
}
}
}
}
uint64_t komodo_moneysupply(int32_t height)
{
if ( height <= 1 )
return(0);
else return(COIN * 100000000 + (height-1) * 3 + komodo_accrued_interest(height,-1));
}
uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime)
{
int32_t minutes; uint64_t numerator,denominator,interest = 0;
if ( nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= COIN )
if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= COIN )
{
minutes = (tiptime - nLockTime) / 60;
numerator = (nValue * KOMODO_INTEREST);

View File

@@ -1132,7 +1132,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
// Bring the best block into scope
view.GetBestBlock();
nValueIn = view.GetValueIn(&interest,tx,chainActive.Tip()->nTime);
nValueIn = view.GetValueIn(chainActive.Tip()->nHeight,&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);
@@ -2154,7 +2154,7 @@ 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(&interest,tx,chainActive.Tip()->nTime) - tx.GetValueOut();
nFees += view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime) - tx.GetValueOut();
sum += interest;
std::vector<CScriptCheck> vChecks;
if (!ContextualCheckInputs(tx, state, view, fScriptChecks, flags, false, chainparams.GetConsensus(), nScriptCheckThreads ? &vChecks : NULL))

View File

@@ -276,7 +276,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
if (!view.HaveInputs(tx))
continue;
CAmount nTxFees = view.GetValueIn(&interest,tx,chainActive.Tip()->nTime)-tx.GetValueOut();
CAmount nTxFees = view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime)-tx.GetValueOut();
nTxSigOps += GetP2SHSigOpCount(tx, view);
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS)

View File

@@ -380,7 +380,7 @@ Value gettxoutsetinfo(const Array& params, bool fHelp)
return ret;
}
uint64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime);
uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime);
uint32_t komodo_txtime(uint256 hash);
Value gettxout(const Array& params, bool fHelp)
@@ -455,12 +455,11 @@ Value gettxout(const Array& params, bool fHelp)
ret.push_back(Pair("value", ValueFromAmount(coins.vout[n].nValue)));
CBlockIndex *pblockindex = chainActive[coins.nHeight];
uint64_t interest; uint32_t timestamp=0;
if ( pblockindex != 0 )
timestamp = pblockindex->nTime;
interest = komodo_interest(coins.vout[n].nValue,timestamp,pindex->nTime);
fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest);
timestamp = pblockindex->nTime; // this is approx, but cant figure out how to get tx here
interest = komodo_interest(coins.nHeight,coins.vout[n].nValue,timestamp,pindex->nTime);
//fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest);
ret.push_back(Pair("interest", ValueFromAmount(interest)));
Object o;

View File

@@ -96,7 +96,7 @@ Array TxJoinSplitToJSON(const CTransaction& tx) {
return vjoinsplit;
}
uint64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime);
uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime);
void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
{
@@ -130,7 +130,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
out.push_back(Pair("value", ValueFromAmount(txout.nValue)));
if ( pindex != 0 && tx.nLockTime != 0 )
{
interest = komodo_interest(txout.nValue,tx.nLockTime,pindex->nTime);
interest = komodo_interest(pindex->nHeight,txout.nValue,tx.nLockTime,pindex->nTime);
fprintf(stderr,"TxtoJSON interest %llu %.8f\n",(long long)interest,(double)interest/COIN);
out.push_back(Pair("interest", ValueFromAmount(interest)));
}

View File

@@ -522,7 +522,7 @@ BOOST_AUTO_TEST_CASE(test_Get)
t1.vout[0].scriptPubKey << OP_1;
int64_t interest;
BOOST_CHECK(AreInputsStandard(t1, coins));
BOOST_CHECK_EQUAL(coins.GetValueIn(&interest,t1,0), (50+21+22)*CENT);
BOOST_CHECK_EQUAL(coins.GetValueIn(0,&interest,t1,0), (50+21+22)*CENT);
// Adding extra junk to the scriptSig should make it non-standard:
t1.vin[0].scriptSig << OP_11;

View File

@@ -2259,7 +2259,8 @@ Value resendwallettransactions(const Array& params, bool fHelp)
return result;
}
uint64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime);
uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime);
Value listunspent(const Array& params, bool fHelp)
{
if (!EnsureWalletIsAvailable(fHelp))
@@ -2371,7 +2372,7 @@ Value listunspent(const Array& params, bool fHelp)
uint64_t interest;
if ( pindex != 0 )
{
interest = komodo_interest(nValue,out.tx->nLockTime,pindex->nTime);
interest = komodo_interest(out.tx->nHeight,nValue,out.tx->nLockTime,pindex->nTime);
entry.push_back(Pair("interest",ValueFromAmount(interest)));
}
}

View File

@@ -2333,7 +2333,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int
return true;
}
uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime);
uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime);
bool CWallet::SelectCoins(const CAmount& nTargetValue, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl* coinControl) const
{
@@ -2377,7 +2377,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set<pair<const CWalletTx*
if(!out.fSpendable)
continue;
nValueRet += out.tx->vout[out.i].nValue;
interest = komodo_interest(out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime);
interest = komodo_interest(out.tx->nHeight,out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime);
#ifdef KOMODO_ENABLE_INTEREST
nValueRet += interest;
#endif