nochowderforyou / clams

Clam Project
MIT License
62 stars 58 forks source link

-mininput fails to ignore some outputs #311

Open dooglus opened 6 years ago

dooglus commented 6 years ago

I used mininput=0.01 in clam.conf to ignore outputs smaller than 0.01 CLAM, then sent myself a transaction paying me multiple outputs, some larger than 0.01 and some smaller.

When I listunspent, I only see the larger outputs, but when I getbalance I see the sum of all outputs, not only the larger ones.

It seems the solution is to move the threshold test up a level:

diff --git a/src/wallet.h b/src/wallet.h
index 6386b1c..1b98045 100644
--- a/src/wallet.h
+++ b/src/wallet.h
@@ -242,7 +242,7 @@ public:
     int64_t GetDebit(const CTxIn& txin) const;
     bool IsMine(const CTxOut& txout) const
     {
-        return ::IsMine(*this, txout.scriptPubKey);
+        return txout.nValue >= nMinimumInputValue && ::IsMine(*this, txout.scriptPubKey);
     }
     int64_t GetCredit(const CTxOut& txout) const
     {
@@ -260,7 +260,7 @@ public:
     bool IsMine(const CTransaction& tx) const
     {
         BOOST_FOREACH(const CTxOut& txout, tx.vout)
-            if (IsMine(txout) && txout.nValue >= nMinimumInputValue)
+            if (IsMine(txout))
                 return true;
         return false;
     }
dooglus commented 6 years ago

I sent myself 0.1, 0.01, 0.001, 0.0001 in 4 separate transactions, and then sent myself the same 4 amounts but in a single transaction. So the total I received is 0.2222, but only 0.22 of it is at or above the 0.01 threshold.

I check the unspent outputs, and only see the four outputs that I should see:

$ echo $(clamd listunspent | grep amount | awk '{print $3}' | sort)
0.01000000, 0.01000000, 0.10000000, 0.10000000,

But when I check the balance, I see the sum of 6 outputs, including 2 of the too-small ones:

$ clamd getbalance
0.22110000

After applying the patch in OP, the getbalance gives 0.22 as expected:

$ clamd getbalance
0.22000000