changeset 30:95cf64d958cb draft

fix transaction fee bug in CreateTransaction, higher size cutoff for free transactions in GetMinFee git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@42 1a98c847-1fd6-4fd8-948a-caf3550aa51b
author s_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
date Sun, 06 Dec 2009 00:29:09 +0000
parents 1488d70ef072
children 4209f0c9d172
files main.cpp main.h serialize.h
diffstat 3 files changed, 17 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/main.cpp
+++ b/main.cpp
@@ -2479,10 +2479,8 @@
                     if (tx.IsCoinBase() || !tx.IsFinal())
                         continue;
 
-                    // Transaction fee requirements, mainly only needed for flood control
-                    // Under 10K (about 80 inputs) is free for first 100 transactions
-                    // Base rate is 0.01 per KB
-                    int64 nMinFee = tx.GetMinFee(pblock->vtx.size() < 100);
+                    // Transaction fee based on block size
+                    int64 nMinFee = tx.GetMinFee(nBlockSize);
 
                     map<uint256, CTxIndex> mapTestPoolTmp(mapTestPool);
                     if (!tx.ConnectInputs(txdb, mapTestPoolTmp, CDiskTxPos(1,1,1), 0, nFees, false, true, nMinFee))
@@ -2768,11 +2766,11 @@
                 if (nValue < 0)
                     return false;
                 int64 nValueOut = nValue;
-                nValue += nFee;
+                int64 nTotalValue = nValue + nFee;
 
                 // Choose coins to use
                 set<CWalletTx*> setCoins;
-                if (!SelectCoins(nValue, setCoins))
+                if (!SelectCoins(nTotalValue, setCoins))
                     return false;
                 int64 nValueIn = 0;
                 foreach(CWalletTx* pcoin, setCoins)
@@ -2784,7 +2782,7 @@
                     wtxNew.vout.push_back(CTxOut(nValueOut, scriptPubKey));
 
                 // Fill a vout back to self with any change
-                if (nValueIn > nValue)
+                if (nValueIn > nTotalValue)
                 {
                     // New private key
                     if (keyRet.IsNull())
@@ -2793,7 +2791,7 @@
                     // Fill a vout to ourself
                     CScript scriptPubKey;
                     scriptPubKey << keyRet.GetPubKey() << OP_CHECKSIG;
-                    wtxNew.vout.push_back(CTxOut(nValueIn - nValue, scriptPubKey));
+                    wtxNew.vout.push_back(CTxOut(nValueIn - nTotalValue, scriptPubKey));
                 }
 
                 // Fill a vout to the payee
@@ -2814,9 +2812,9 @@
                             SignSignature(*pcoin, wtxNew, nIn++);
 
                 // Check that enough fee is included
-                if (nFee < wtxNew.GetMinFee(true))
+                if (nFee < wtxNew.GetMinFee())
                 {
-                    nFee = nFeeRequiredRet = wtxNew.GetMinFee(true);
+                    nFee = nFeeRequiredRet = wtxNew.GetMinFee();
                     continue;
                 }
 
--- a/main.h
+++ b/main.h
@@ -512,14 +512,19 @@
         return nValueOut;
     }
 
-    int64 GetMinFee(bool fDiscount=false) const
+    int64 GetMinFee(unsigned int nBlockSize=1) const
     {
         // Base fee is 1 cent per kilobyte
         unsigned int nBytes = ::GetSerializeSize(*this, SER_NETWORK);
         int64 nMinFee = (1 + (int64)nBytes / 1000) * CENT;
 
-        // First 100 transactions in a block are free
-        if (fDiscount && nBytes < 10000)
+        // Transactions under 60K are free as long as block size is under 80K
+        // (about 27,000bc if made of 50bc inputs)
+        if (nBytes < 60000 && nBlockSize < 80000)
+            nMinFee = 0;
+
+        // Transactions under 3K are free as long as block size is under 200K
+        if (nBytes < 3000 && nBlockSize < 200000)
             nMinFee = 0;
 
         // To limit dust spam, require a 0.01 fee if any output is less than 0.01
--- a/serialize.h
+++ b/serialize.h
@@ -20,7 +20,7 @@
 class CAutoFile;
 
 static const int VERSION = 106;
-static const char* pszSubVer = " linux-test9";
+static const char* pszSubVer = " test10";