fix transaction fee bug in CreateTransaction, higher size cutoff for free transaction...
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Sun, 6 Dec 2009 00:29:09 +0000 (00:29 +0000)
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Sun, 6 Dec 2009 00:29:09 +0000 (00:29 +0000)
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@42 1a98c847-1fd6-4fd8-948a-caf3550aa51b

main.cpp
main.h
serialize.h

index ae20e08..6575099 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -2479,10 +2479,8 @@ void BitcoinMiner()
                     if (tx.IsCoinBase() || !tx.IsFinal())\r
                         continue;\r
 \r
-                    // Transaction fee requirements, mainly only needed for flood control\r
-                    // Under 10K (about 80 inputs) is free for first 100 transactions\r
-                    // Base rate is 0.01 per KB\r
-                    int64 nMinFee = tx.GetMinFee(pblock->vtx.size() < 100);\r
+                    // Transaction fee based on block size\r
+                    int64 nMinFee = tx.GetMinFee(nBlockSize);\r
 \r
                     map<uint256, CTxIndex> mapTestPoolTmp(mapTestPool);\r
                     if (!tx.ConnectInputs(txdb, mapTestPoolTmp, CDiskTxPos(1,1,1), 0, nFees, false, true, nMinFee))\r
@@ -2768,11 +2766,11 @@ bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CK
                 if (nValue < 0)\r
                     return false;\r
                 int64 nValueOut = nValue;\r
-                nValue += nFee;\r
+                int64 nTotalValue = nValue + nFee;\r
 \r
                 // Choose coins to use\r
                 set<CWalletTx*> setCoins;\r
-                if (!SelectCoins(nValue, setCoins))\r
+                if (!SelectCoins(nTotalValue, setCoins))\r
                     return false;\r
                 int64 nValueIn = 0;\r
                 foreach(CWalletTx* pcoin, setCoins)\r
@@ -2784,7 +2782,7 @@ bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CK
                     wtxNew.vout.push_back(CTxOut(nValueOut, scriptPubKey));\r
 \r
                 // Fill a vout back to self with any change\r
-                if (nValueIn > nValue)\r
+                if (nValueIn > nTotalValue)\r
                 {\r
                     // New private key\r
                     if (keyRet.IsNull())\r
@@ -2793,7 +2791,7 @@ bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CK
                     // Fill a vout to ourself\r
                     CScript scriptPubKey;\r
                     scriptPubKey << keyRet.GetPubKey() << OP_CHECKSIG;\r
-                    wtxNew.vout.push_back(CTxOut(nValueIn - nValue, scriptPubKey));\r
+                    wtxNew.vout.push_back(CTxOut(nValueIn - nTotalValue, scriptPubKey));\r
                 }\r
 \r
                 // Fill a vout to the payee\r
@@ -2814,9 +2812,9 @@ bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CK
                             SignSignature(*pcoin, wtxNew, nIn++);\r
 \r
                 // Check that enough fee is included\r
-                if (nFee < wtxNew.GetMinFee(true))\r
+                if (nFee < wtxNew.GetMinFee())\r
                 {\r
-                    nFee = nFeeRequiredRet = wtxNew.GetMinFee(true);\r
+                    nFee = nFeeRequiredRet = wtxNew.GetMinFee();\r
                     continue;\r
                 }\r
 \r
diff --git a/main.h b/main.h
index 822045a..716485e 100644 (file)
--- a/main.h
+++ b/main.h
@@ -512,14 +512,19 @@ public:
         return nValueOut;\r
     }\r
 \r
-    int64 GetMinFee(bool fDiscount=false) const\r
+    int64 GetMinFee(unsigned int nBlockSize=1) const\r
     {\r
         // Base fee is 1 cent per kilobyte\r
         unsigned int nBytes = ::GetSerializeSize(*this, SER_NETWORK);\r
         int64 nMinFee = (1 + (int64)nBytes / 1000) * CENT;\r
 \r
-        // First 100 transactions in a block are free\r
-        if (fDiscount && nBytes < 10000)\r
+        // Transactions under 60K are free as long as block size is under 80K\r
+        // (about 27,000bc if made of 50bc inputs)\r
+        if (nBytes < 60000 && nBlockSize < 80000)\r
+            nMinFee = 0;\r
+\r
+        // Transactions under 3K are free as long as block size is under 200K\r
+        if (nBytes < 3000 && nBlockSize < 200000)\r
             nMinFee = 0;\r
 \r
         // To limit dust spam, require a 0.01 fee if any output is less than 0.01\r
index b2d948d..14a2bed 100644 (file)
@@ -20,7 +20,7 @@ class CDataStream;
 class CAutoFile;\r
 \r
 static const int VERSION = 106;\r
-static const char* pszSubVer = " linux-test9";\r
+static const char* pszSubVer = " test10";\r
 \r
 \r
 \r