Bitcoin Forum

Bitcoin => Bitcoin Discussion => Topic started by: sr_gi on November 23, 2015, 03:38:35 PM



Title: Transaction dust (or how to calculate transaction fees?)
Post by: sr_gi on November 23, 2015, 03:38:35 PM
Hi there,

I'm trying to figure out how exactly the fees related to the transaction dust work. I'm trying to test some code related to small payments (or maybe even micro-payments) in the testnet and I'm getting a bit stuck.

For what I could find in the source code (https://github.com/bitcoin/bitcoin/blob/v0.10.0rc3/src/primitives/transaction.h#L137):

Quote
 // "Dust" is defined in terms of CTransaction::minRelayTxFee,
  // which has units satoshis-per-kilobyte.
  // If you'd pay more than 1/3 in fees
  // to spend something, then we consider it dust.
  // A typical txout is 34 bytes big, and will
  // need a CTxIn of at least 148 bytes to spend:
  // so dust is a txout less than 546 satoshis
  // with default minRelayTxFee.

I've also read from stackexchange (http://bitcoin.stackexchange.com/questions/10986/what-is-meant-by-bitcoin-dust) that :

Quote
Sending less than 0.01 BTC to any recipient — The network considers these small outputs to be “dust,” and discourages them by requiring a fee.

But I couldn't find how those fees are applied. It mean that for each input smaller than 0.001 BTC a minimum fee should be included? So for example a transaction with 3 inputs (two of them with less than 0.001 BTC) and two outputs will need 3*0.00001 BTC as fee? (One for each input below 0.001 and another one as BTC/kb payment?)


Title: Re: Transaction dust (or how to calculate transaction fees?)
Post by: Pattart on November 23, 2015, 03:54:04 PM
To calculate the dust, consider an the size of the output, and the size of the corresponding input to spend it. In most cases, the output is 34 bytes and the input that spends it will be 148 bytes. Add those together and you get 182 bytes. The minrelaytxfee in the latest version is 0.00005 BTC/kb. So that means it is 0.00000005 BTC/byte. Multiply that by the number of bytes required to spend the output (182). You will get 0.0000091. Multiply that by 3 and you get the current dust threshold of 0.0000273 BTC.

This means that in order to spend 0.0000273 BTC or lower, you will be paying one third or more of that amount in fees.


Title: Re: Transaction dust (or how to calculate transaction fees?)
Post by: Miiike on November 23, 2015, 05:14:15 PM
Glad there is someone talking about transaction dust, I have a question about it but I didn't want to wake an old sleeping thread. My question is, I heard that Xapo gives a free transaction fee services. Does this means I'll be completely free from transaction dust that (they say will always) follows the faucet activity?


Title: Re: Transaction dust (or how to calculate transaction fees?)
Post by: Pattart on November 23, 2015, 05:19:05 PM
Glad there is someone talking about transaction dust, I have a question about it but I didn't want to wake an old sleeping thread. My question is, I heard that Xapo gives a free transaction fee services. Does this means I'll be completely free from transaction dust that (they say will always) follows the faucet activity?
No. Xapo is paying the fee for you. The fee is separate from the dust. The dust is determined by the minimum fee that nodes are willing to relay.


Title: Re: Transaction dust (or how to calculate transaction fees?)
Post by: Miiike on November 23, 2015, 05:32:50 PM
Glad there is someone talking about transaction dust, I have a question about it but I didn't want to wake an old sleeping thread. My question is, I heard that Xapo gives a free transaction fee services. Does this means I'll be completely free from transaction dust that (they say will always) follows the faucet activity?
No. Xapo is paying the fee for you. The fee is separate from the dust. The dust is determined by the minimum fee that nodes are willing to relay.

Oh god, now it's getting even more complicated.. Could you suggest me a thread explaining the difference between fee and the dust? Or better, can you help explain it to me in an easy way?


Title: Re: Transaction dust (or how to calculate transaction fees?)
Post by: Pattart on November 23, 2015, 06:49:26 PM
Glad there is someone talking about transaction dust, I have a question about it but I didn't want to wake an old sleeping thread. My question is, I heard that Xapo gives a free transaction fee services. Does this means I'll be completely free from transaction dust that (they say will always) follows the faucet activity?
No. Xapo is paying the fee for you. The fee is separate from the dust. The dust is determined by the minimum fee that nodes are willing to relay.

Oh god, now it's getting even more complicated.. Could you suggest me a thread explaining the difference between fee and the dust? Or better, can you help explain it to me in an easy way?
Basically the fee is a bribe to miners to include your transaction. Generally the higher your transaction fee is, the more likely your transaction will get confirmed sooner. The fee is typically based on the size of the transaction. Dust is an output that is so small that spending it would require a fee that is 1/3 or more of the output itself. The dust threshold is determined by a minimum fee that nodes are willing to relay. The current default is 0.00005 BTC/kb. This makes the current dust threshold to be 2730 satoshis, the calculation is explained earlier.


Title: Re: Transaction dust (or how to calculate transaction fees?)
Post by: odolvlobo on November 23, 2015, 07:39:36 PM
Hi there,

I'm trying to figure out how exactly the fees related to the transaction dust work. I'm trying to test some code related to small payments (or maybe even micro-payments) in the testnet and I'm getting a bit stuck.

For what I could find in the source code (https://github.com/bitcoin/bitcoin/blob/v0.10.0rc3/src/primitives/transaction.h#L137):

Quote
 // "Dust" is defined in terms of CTransaction::minRelayTxFee,
  // which has units satoshis-per-kilobyte.
  // If you'd pay more than 1/3 in fees
  // to spend something, then we consider it dust.
  // A typical txout is 34 bytes big, and will
  // need a CTxIn of at least 148 bytes to spend:
  // so dust is a txout less than 546 satoshis
  // with default minRelayTxFee.

I've also read from stackexchange (http://bitcoin.stackexchange.com/questions/10986/what-is-meant-by-bitcoin-dust) that :

Quote
Sending less than 0.01 BTC to any recipient — The network considers these small outputs to be “dust,” and discourages them by requiring a fee.

But I couldn't find how those fees are applied. It mean that for each input smaller than 0.001 BTC a minimum fee should be included? So for example a transaction with 3 inputs (two of them with less than 0.001 BTC) and two outputs will need 3*0.00001 BTC as fee? (One for each input below 0.001 and another one as BTC/kb payment?)

You are making it more complicated than it needs to be. The fee is applied to the size of the entire transaction.

The comments in the source about the size of inputs and outputs are referring to determining the minimum size of a transaction.

The "dust" in the stackexchange quote is informally referring to any small amount as "dust". The rule that it is referring to requires any transaction that includes an output of less than 0.01 BTC to pay the minimum fee.

This page might be helpful: https://en.bitcoin.it/wiki/Transaction_fees


Title: Re: Transaction dust (or how to calculate transaction fees?)
Post by: Miiike on November 23, 2015, 08:10:10 PM
Glad there is someone talking about transaction dust, I have a question about it but I didn't want to wake an old sleeping thread. My question is, I heard that Xapo gives a free transaction fee services. Does this means I'll be completely free from transaction dust that (they say will always) follows the faucet activity?
No. Xapo is paying the fee for you. The fee is separate from the dust. The dust is determined by the minimum fee that nodes are willing to relay.

Oh god, now it's getting even more complicated.. Could you suggest me a thread explaining the difference between fee and the dust? Or better, can you help explain it to me in an easy way?
Basically the fee is a bribe to miners to include your transaction. Generally the higher your transaction fee is, the more likely your transaction will get confirmed sooner. The fee is typically based on the size of the transaction. Dust is an output that is so small that spending it would require a fee that is 1/3 or more of the output itself. The dust threshold is determined by a minimum fee that nodes are willing to relay. The current default is 0.00005 BTC/kb. This makes the current dust threshold to be 2730 satoshis, the calculation is explained earlier.

Which means as long as i collect (we're talking from faucet) above 2730 sat, I won't get any dust?


Title: Re: Transaction dust (or how to calculate transaction fees?)
Post by: shorena on November 23, 2015, 08:14:01 PM
To calculate the dust, consider an the size of the output, and the size of the corresponding input to spend it. In most cases, the output is 34 bytes and the input that spends it will be 148 bytes. Add those together and you get 182 bytes. The minrelaytxfee in the latest version is 0.00005 BTC/kb. So that means it is 0.00000005 BTC/byte. Multiply that by the number of bytes required to spend the output (182). You will get 0.0000091. Multiply that by 3 and you get the current dust threshold of 0.0000273 BTC.

This means that in order to spend 0.0000273 BTC or lower, you will be paying one third or more of that amount in fees.

Keep in mind though that each node can modify minrelaytxfee and thus can have a different understanding of dust.

E.g. would a node set the setting to 0.00002 BTC/kb, dust would be 1092 satoshi.


Title: Re: Transaction dust (or how to calculate transaction fees?)
Post by: sr_gi on November 23, 2015, 09:15:51 PM
To calculate the dust, consider an the size of the output, and the size of the corresponding input to spend it. In most cases, the output is 34 bytes and the input that spends it will be 148 bytes. Add those together and you get 182 bytes. The minrelaytxfee in the latest version is 0.00005 BTC/kb. So that means it is 0.00000005 BTC/byte. Multiply that by the number of bytes required to spend the output (182). You will get 0.0000091. Multiply that by 3 and you get the current dust threshold of 0.0000273 BTC.

This means that in order to spend 0.0000273 BTC or lower, you will be paying one third or more of that amount in fees.

So if I get it right:

  • In a transaction with 1 input and 1 output the required fee will be 910 Satoshi.
  • And if it have 2 inputs and 1 output, it will be 1650 Satoshi.
 

But what will happen in both cases if the inputs are below the transaction dust threshold, how big should be the fee in order to ensure that the transaction will be relayed?


Title: Re: Transaction dust (or how to calculate transaction fees?)
Post by: Pattart on November 23, 2015, 10:15:29 PM
Which means as long as i collect (we're talking from faucet) above 2730 sat, I won't get any dust?
No. What you collect from the faucet become inputs for one of your transactions. You create transactions which have outputs. The inputs don't matter, what matters is that your outputs are above the dust threshold.

To calculate the dust, consider an the size of the output, and the size of the corresponding input to spend it. In most cases, the output is 34 bytes and the input that spends it will be 148 bytes. Add those together and you get 182 bytes. The minrelaytxfee in the latest version is 0.00005 BTC/kb. So that means it is 0.00000005 BTC/byte. Multiply that by the number of bytes required to spend the output (182). You will get 0.0000091. Multiply that by 3 and you get the current dust threshold of 0.0000273 BTC.

This means that in order to spend 0.0000273 BTC or lower, you will be paying one third or more of that amount in fees.

So if I get it right:

  • In a transaction with 1 input and 1 output the required fee will be 910 Satoshi.
  • And if it have 2 inputs and 1 output, it will be 1650 Satoshi.
 

But what will happen in both cases if the inputs are below the transaction dust threshold, how big should be the fee in order to ensure that the transaction will be relayed?
No, the transaction has a bunch of other data that also increases its size. The size that we are talking about here are specifically the bytes for an output and its corresponding input in the next transaction. It does not matter what the inputs of a transaction are, just that the size in bytes of the output and the corresponding input that spends it. In most cases this will be 182 bytes.

It does not matter that the inputs are dust, just that the outputs are dust. If the inputs are dust, then you will probably be spending more on fees than you will be getting in outputs.


Title: Re: Transaction dust (or how to calculate transaction fees?)
Post by: sr_gi on November 24, 2015, 11:51:14 AM
Alright. Thank you so much!