Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: bitcoinandroid on October 05, 2011, 06:29:19 AM



Title: Questions about Transaction Protocol Rules
Post by: bitcoinandroid on October 05, 2011, 06:29:19 AM
Hi folks,

I'm currently going through the protocol rules coding up a simple example to try and better understand bitcoin.  Specifically, the transaction rules:
https://en.bitcoin.it/wiki/Protocol_rules#.22tx.22_messages

Apologies if some of these are simple questions - I am still somewhat new to this.

> 1. Check syntactic correctness

Is there a formal way to do this or just generally seeing if all the fields can be parsed without an error?

> 3. Size in bytes < MAX_BLOCK_SIZE

I saw in a discussion somewhere this 1,000,000 bytes?  Not sure if this is still the case.  I assume this isn't too important and just to prevent ddos attacks on smaller clients?

> 4. Each output value, as well as the total, must be in legal money range

Does this just mean can't be < 8 decimals places?  I haven't seen any other formal discussion around what a valid range is for an amount.


Thanks for your help!


Title: Re: Questions about Transaction Protocol Rules
Post by: theymos on October 05, 2011, 06:50:36 AM
I saw in a discussion somewhere this 1,000,000 bytes?  Not sure if this is still the case.  I assume this isn't too important and just to prevent ddos attacks on smaller clients?

This is the case. If you fail to apply the restriction, you'll end up on a separate network.

Quote
generally seeing if all the fields can be parsed without an error?

Yes.

Quote
I haven't seen any other formal discussion around what a valid range is for an amount.

0-21 million. 0 is valid.

The precision is part of "syntactic correctness".


Title: Re: Questions about Transaction Protocol Rules
Post by: bitcoinandroid on October 05, 2011, 07:00:42 AM
Awesome!  This is super helpful.  I really appreciate you taking the time to make some of this more clear to newer developers.

I may have a few more questions going forward as I make progress.  Thanks again!


Title: Re: Questions about Transaction Protocol Rules
Post by: bitcoinandroid on October 06, 2011, 07:08:47 AM
Hi, I'm back with a few more!  Slowly making my way through.

> 17. Reject if transaction fee (defined as sum of input values minus sum of output values) would be too low to get into an empty block

Last I saw 0 transaction fees are allowed.  Is this correct as a minimum?

Also, is COINBASE_MATURITY still = 100 ?

What's the best place to find the current value of these magic numbers and get notified when they change?  I've been able to google some of them in the official client code on github, but was just curious.

Thanks for the help!


Title: Re: Questions about Transaction Protocol Rules
Post by: log0s on October 06, 2011, 05:35:48 PM
> 17. Reject if transaction fee (defined as sum of input values minus sum of output values) would be too low to get into an empty block

Last I saw 0 transaction fees are allowed.  Is this correct as a minimum?

There is no network enforced minimum fee (though it must not be negative).  Individual miners can choose their own minimum fees, however.


Also, is COINBASE_MATURITY still = 100 ?

Yes, the network enforced value is 100.


What's the best place to find the current value of these magic numbers and get notified when they change?  I've been able to google some of them in the official client code on github, but was just curious.

Thanks for the help!

A lot of the values you asked about will likely not be changed for a while, if ever, as most of them would be changes that fork the blockchain (something the main bitcoin developers go to great lengths to avoid).  I think the best places to find this information is probably the wiki and the source code, otherwise just asking people in the forum or in irc.


Title: Re: Questions about Transaction Protocol Rules
Post by: bitcoinandroid on October 16, 2011, 01:30:51 AM
Thanks log0s!

So for that rule #17, I think just to prevent DOS I will make a simple rule: if the sum of inputs is < 0.01 and transaction fee is < 0.0005 then reject it.  Hopefully something like that is reasonable as a start.


Title: Re: Questions about Transaction Protocol Rules
Post by: bitcoinandroid on October 16, 2011, 01:43:46 AM
Also, something I was a little confused about.  When receiving a broadcasted transaction, you don't actually know which part is change right?  So can you even tell the net amount of the transaction, or are you really just basing the threshold off the sum of the inputs?

For example
1 input with 50 coins

2 outputs, first for 0.01 second for 49.99

You don't know if the 1 cent or 49.99 goes back to the sender right?

Obviously if the transaction was being generated from within your client, then you could tell.  But for broadcasted transactions I wasn't sure how to make the rejection rule.


Title: Re: Questions about Transaction Protocol Rules
Post by: gmaxwell on October 16, 2011, 06:53:32 PM
Thanks log0s!

So for that rule #17, I think just to prevent DOS I will make a simple rule: if the sum of inputs is < 0.01 and transaction fee is < 0.0005 then reject it.  Hopefully something like that is reasonable as a start.

The anti-DOS rule is:

A 0.0005 fee is required if any output is smaller than 0.01 (not the sum of the inputs)  or if the priority is less than 51,000,000.
You calculate the priority as sum(input value * confirmations)/tx_data_size

If your change would be smaller than the fee 0.0005 the wallet is smart enough to give it up as fee to avoid the 0.0005 fee— but it's not generally smart enough to always pick the mixture of inputs required to avoid a fee and could be improved.  What it currently does is tries to find the smallest set of inputs that sum to at least your transaction value, first using only input txn which have 6+ confirms, then 1+ confirms (and your own zero confirm txn), then using unconfirmed inputs.