I am trying to set transaction fees using method settxfee over JSON RPC. I know that txFee (feerate) is entered in BTC/kilobyte. The problem is, that somehow roughly about 3 of 20 transactions have higher feerate (from 1% to tens of %) than set. Even if feerate is reasonable (not extreme minimum).
For example, I have made a couple of transactions with feerate = 0.000075 to the same wallet. That means same address, same fee, same amount. But the one of transactions have significantly higher feerate, which corresponds to 0.00008745 BTC/kB. (Notice feerate, not fee, which is not the matter of this question)
You can inspect that transaction here: https://www.blocktrail.com/tBTC/tx/223ca54c7554a3025c64e4b3c2cd1d087d3234dac0f4479ab4fbc955fd66a629
and getInfo returns following:
{ "result": { "deprecation-warning": "WARNING: getinfo is deprecated and will be fully removed in 0.16. Projects should transition to using getblockchaininfo, getnetworkinfo, and getwalletinfo before upgrading to 0.16", "version": 150001, "protocolversion": 70015, "walletversion": 139900, "balance": 4.97794018, "blocks": 1260652, "timeoffset": 0, "connections": 8, "proxy": "", "difficulty": 2108481.043832448, "testnet": true, "keypoololdest": 1516698441, "keypoolsize": 1999, "unlocked_until": 0, "paytxfee": 0.000075, "relayfee": 0.00001, "errors": "Warning: unknown new rules activated (versionbit 28)" }, "error": null, "id": "getinfo" }
where you can find "paytxfee": 0.000075.
Wallet command getTransaction of this transaction returns:
{ "result": { "amount": 0, "fee": -0.0000425, "confirmations": 9, "blockhash": "000000000000074ccf2706f67b0e14d41332a802506ff20ec6f8ca2b5617d3de", "blockindex": 39, "blocktime": 1516966703, "txid": "223ca54c7554a3025c64e4b3c2cd1d087d3234dac0f4479ab4fbc955fd66a629", "walletconflicts": [], "time": 1516966389, "timereceived": 1516966389, "bip125-replaceable": "no", "comment": "testSetTxFee", "details": [ { "account": "", "address": "mfX97PgpBN3FfcqtCbGQEVhTqfTgkhq2oY", "category": "send", "amount": -0.0001, "label": "", "vout": 0, "fee": -0.0000425, "abandoned": false }, { "account": "", "address": "mfX97PgpBN3FfcqtCbGQEVhTqfTgkhq2oY", "category": "receive", "amount": 0.0001, "label": "", "vout": 0 } ], "hex": "020000000311e435e566c8be4bc464864a0feb5b2ecf0e6b27d991ff495b1fa08e0ae2e8fc010000006a47304402203d6f61c6e00116471ff1040b10ae7e663e85d9cf123fe156173a6aa4da09ed1f02200dd871b8795450d49d490ed18e0986191ffb71463ea2fddafa4f1a780a1bc9b601210376c77248c7babc3ebaa829f7e84d962bf594fa3cd43cb993acafd318e0664867feffffff4276ce1b9f5a239f80141374b09673936ab5c62d308efb065a4f57cae9686e19000000006b483045022100e0e288ae95d09c7a9c1332acf87225a0438eca9464e488b05deb91a7b8598b910220442c5dc30a5e0488d15ae5a2204c7be4c908081d67e12ca1eb5e40013128ad490121025e642cbf02c9c5d910cdc4aa675c9f5cdbf29126ef20a211a1f71a9c7fb07678feffffffa6ebff34c02e28b3c54325ae741fbde0b25cf6d8a82e65518ec272182a59dfd6010000006a4730440220324a6d325b01bc763f8c8bcd8c068de6480b282af5b4cfc1d64a164f0328b16a02203082a6327c5b0204b7f02912f390e1a6c239b310bed2653b0be8bcea3e49addf012103d12d4776820b676697e50e452beda155fc91748c9fb4877cc243fa513f410febfeffffff0110270000000000001976a91400090765051b6fff0183085b2bf3b6506744329288ac653c1300" }, "error": null, "id": "getbalance" }
Where HEX size is 486 bytes. Therefore, fee should be 486/1000 * 0.000075 = 0.00003645, not 0.00004250.
EDIT: when sending the same transactions manytimes, it worked. But when my unit test does:
setTxFee(0.00001)
sendTransaction()
...
setTxFee(0.000075)
sendTransaction()
...
setTxFee(0.000035)
sendTransaction()
Then it sends transaction with bad fees (sometimes). Is it possible that bitcoind does not apply feerate imediatelly?
Do you know, why is that so?
Thank you for your answers and sorry for my english.