Any idea why this might be happening?
Watch the debug.log - it probably tells you something like:
2015-05-13 07:00:58 ERROR: AcceptToMemoryPool : not enough fees 22f5cf1835d3f2135d10e460af30eb7ccd6329f0cf9f40a730b0726fe76964e2, 10000 < 20000
or:
2015-04-30 16:19:31 CWallet::CreateTransaction failed: transaction too big (104430 >= 100000)
Thanks!
ERROR: AcceptToMemoryPool : not enough fees 02ce86ccb2dcce0841410b4e243363aa80c7aa5978572f9529074eade0040f75, 0 < 10000
I usually use the following to determine fees:
Calculating Fee:
Vout_Count = 50
Debug: estimated transaction size: 9042 bytes (fee required at 10000 bytes or more)
tx_size_ok = 1
Debug: transaction priority: 238.31M (fee required at 57.6M or less)
sugg_fee = 0
I even tried forcing a small fee but the transaction still failed.
So how can I calculate the required fee?
I use this in a shell script I wrote once:
fee=$((($(eval $sign | wc -c) / 2 + 999) / 1000))
ie. sign the transaction, count the characters in the hex string, halve it to get the size in bytes, and round up to a multiple of 1000. Then I use 0.0001*$fee as the fee.
Of course, changing the fee requires you to re-sign the transaction, which can cause the length to change a little (since each input is signed separately, and the length of each signature can increase or decrease by one byte). So to by on the safe side you might want to add 999 + number_of_inputs in there, not just 999. Or just iterate on failure, recalculating the fee from the signed tx length until it succeeds.
Edit: CLAM doesn't have fee-free transactions, I don't think. Every transaction has to include a fee of 0.0001 per 1000 bytes or part thereof. So that's where you're going wrong. I'm not sure whether this is a hard rule (enforced on received transactions and/or blocks) or simply enforced by the client before it will transmit a transaction. Maybe you could modify your local client code to have it send zero-fee transactions and have the network accept them. I never looked into that.
Edit2: I decided to experiment with a zero-fee transaction.
First off, AcceptToMemoryPool() does this check:
int64_t txMinFee = GetMinFee(tx, 1000, GMF_RELAY, nSize);
if ((fLimitFree && nFees < txMinFee) || (!fLimitFree && nFees < MIN_TX_FEE))
return error("AcceptToMemoryPool : not enough fees %s, %d < %d",
hash.ToString(),
nFees, txMinFee);
That's where the error you saw came from.
Removing that check isn't enough. You just get a different error:
2015-05-13 16:37:44 ERROR: AcceptToMemoryPool : ConnectInputs failed c2287daabc7a7b86b723a6c791932fe89371c7c1e8d0cabeb1f4078dcbcda131
That's coming from ConnectInputs() which does this check:
// enforce transaction fees for every block
int64_t nRequiredFee = GetMinFee(*this);
if (nTxFee < nRequiredFee)
return fBlock? DoS(100, error("ConnectInputs() : %s not paying required fee=%s, paid=%s", GetHash().ToString(), FormatMoney(nRequiredFee), FormatMoney(nTxFee))) : false;
Removing that check too allows me to send a transaction with no fees:
$ cc sendrawtransaction $(cc signrawtransaction $(cc createrawtransaction '[{"txid":"951c5cebf8b04a8251f8617331e797a003e52daebdde9670381979e418b8e5cd","vout":1}]' '{"xW42Nau4hpdSu5931gaRHgx6B2ah3WpEvX":{"count":1,"amount":0.25}}') | grep hex | cut -d'"' -f4)
e812bf578bbc0157ac3fd0ed90e0634537d846b50ea71223391739a9ed55f54d
But checking on other nodes in the network, the transaction was either never seen, or seen and rejected with this error message:
2015-05-13 16:42:55 ERROR: AcceptToMemoryPool : not enough fees e812bf578bbc0157ac3fd0ed90e0634537d846b50ea71223391739a9ed55f54d, 0 < 10000
So maybe if I staked the block myself it would be accepted? To do that I need to run with -mintxfee=0 otherwise my node won't try to include the zero-fee transaction in the blocks it stakes:
// Skip free transactions if we're past the minimum block size:
if (fSortedByFee && (dFeePerKb < nMinTxFee) && (nBlockSize + nTxSize >= nBlockMinSize))
continue;
Then there was another check for fee size in the miner code, so I commented that out too:
int64_t nTxFees = tx.GetValueIn(mapInputs)-tx.GetValueOut();
if (nTxFees < nMinFee)
continue;
Finally I managed to stake my zero-fee transaction into a block. When the block was sent to a standard node, it rejected it:
2015-05-13 18:12:13 ERROR: ConnectInputs() : e812bf578bbc0157ac3fd0ed90e0634537d846b50ea71223391739a9ed55f54d not paying required fee=0.0001, paid=0.00
2015-05-13 18:12:13 InvalidChainFound: invalid block=0c4d66dc6fb8ff9bec6c9e26f12feddec1e3adb6a6f041b309b4947b02bfbc52 height=465778 trust=35361372754116997652 blocktrust=188138013378102 date=05/13/15 18:12:16
2015-05-13 18:12:13 InvalidChainFound: current best=85b33a65171b31060c66516d5c51c04149e39434eca3a8389e39eb60bd8ab779 height=465777 trust=35361184616103619550 blocktrust=188715424952782 date=05/13/15 18:09:52
2015-05-13 18:12:13 ERROR: SetBestChain() : SetBestChainInner failed
2015-05-13 18:12:13 ERROR: AcceptBlock() : AddToBlockIndex failed
2015-05-13 18:12:13 ERROR: ProcessBlock() : AcceptBlock FAILED
So I guess that answers that question. ConnectInputs() is called both when creating a transaction and when checking the transactions in received blocks, and it rejects transactions which don't have enough fees.
I was worried I would have to reindex my blockchain on the node that staked the invalid block to get it to continue staking from a valid block, but it turned out I didn't need to. The rest of the network carried on staking from the last valid block, generated a longer chain than my invalid chain, and my node switched to that longer chain, orphaning the invalid block containing the zero-fee transaction.