Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: bigdude71 on May 24, 2017, 06:53:55 AM



Title: Things I still don't understand about the blockchain
Post by: bigdude71 on May 24, 2017, 06:53:55 AM
Hi,

I'm into bitcoin and crypto for a few years. And getting more and more into this space.

However, there are things that I still don't understand about bitcoin and blockchain in general and I think others will also appreciate learning about.
I hope someone can help me understand the following:

1. Bitcoin block size is limited to 1 MB - right?
So what will happen if the amount of transactions in last 10 minutes will not be able to fit in the block?
Or for example if someone malicious will run a loop script that opens millions / billions of addresses and send them 0.0000001 BTC to clog the system...?

2. As I understand - The blockchain's ledger doesn't have my wallets total amount - it's only documenting the transactions.
So to know how much BTC my wallet has - We have to calculate everything from the beginning of the blockchain, or at least from the first block of my wallet's address - right?
If this is true, how come it's not super slow once the blockchain in very big?


Thanks!

 


Title: Re: Things I still don't understand about the blockchain
Post by: Foxpup on May 24, 2017, 08:34:26 AM
1. Bitcoin block size is limited to 1 MB - right?
Right.

So what will happen if the amount of transactions in last 10 minutes will not be able to fit in the block?
Normally, the transactions paying the highest fees get in first, and all others will have to wait for the next block. (Miners don't have to prioritise transactions by fee, but they have a financial incentive to do so.)

Or for example if someone malicious will run a loop script that opens millions / billions of addresses and send them 0.0000001 BTC to clog the system...?
Without fees (making the attack incredibly expensive), such transactions will not be confirmed.



2. As I understand - The blockchain's ledger doesn't have my wallets total amount - it's only documenting the transactions.
So to know how much BTC my wallet has - We have to calculate everything from the beginning of the blockchain, or at least from the first block of my wallet's address - right?
Right.

If this is true, how come it's not super slow once the blockchain in very big?
Because wallet software stores the result, so it only has to calculate it from scratch once, which doesn't take too long in any case as computers are fast.


Title: Re: Things I still don't understand about the blockchain
Post by: bigdude71 on May 24, 2017, 09:22:21 AM
Thanks Foxpup, I really appreciate your help!

I have more questions now.. :P

Fees:
1. How are those set and where? Is the fee set on each transaction? Can I choose to pay as much as I want?
2. Is it percentage or fixed?
3. The miner of the latest block gets all the fees for the transaction in that block? Or is it more complicated?

Thanks again


Title: Re: Things I still don't understand about the blockchain
Post by: Foxpup on May 24, 2017, 10:03:06 AM
1. How are those set and where? Is the fee set on each transaction? Can I choose to pay as much as I want?
The sender of the transaction sets the fee for that transaction, and it can be as much or as little as they choose. Note that competently designed wallet software will automatically choose an appropriate fee based on current conditions; it is not normally necessary to choose a fee manually.

2. Is it percentage or fixed?
It is proportional to the number of bytes of data the transaction requires, since that's the limiting factor in including transactions in a block.

3. The miner of the latest block gets all the fees for the transaction in that block? Or is it more complicated?
Yes, it's that simple.


Title: Re: Things I still don't understand about the blockchain
Post by: bigdude71 on May 25, 2017, 06:52:17 AM
Thanks again Foxpup,

You said about the fee amount:
Quote
It is proportional to the number of bytes of data the transaction requires, since that's the limiting factor in including transactions in a block.
Isn't this a very similar number of bytes for each transaction? I mean, it's simply adding or removing numbers for public addresses - isn't it?


Another question in that path: Once I send something bitcoins, where does my transaction goes to for all the miners to grab it from?
I understand that all the past data is in the blockchain, but where is the data that is still not in the blockchain?

Thanks again!


Title: Re: Things I still don't understand about the blockchain
Post by: HCP on May 25, 2017, 07:13:33 AM
Isn't this a very similar number of bytes for each transaction? I mean, it's simply adding or removing numbers for public addresses - isn't it?
Not necessarily. When you send bitcoins to an address... it creates an "Unspent Transaction Output"... also know as an UTXO. When you want to create a transaction, you need to start adding UTXOs together until you get enough to add up to the total you're trying to spend (+ miners fee).

So... if you have a "big" UTXO, like 1.0 BTC... and you want to send 0.1 BTC someone... that's easy... 1 UTXO in -> 2 UTXOs out (0.1 to the person, 0.8999 back to you as change, + 0.0001 miners fee). A transaction like that (1 in, 2 out) will generally be around 226bytes.

However, if you have a whole bunch on little UTXOs in your wallet... like you have 15x 0.01 BTC payments... and now you want to send 0.1 BTC to someone... you're going to need 11 UTXOs as input (remember, you have to cover the miners fee!) So... 11 UTXO in -> 2 UTXO out (0.1 to person, 0.009 to you as change + 0.001 miners fee).

The "general" formula for transaction size is:

(#Inputs * 148) + (#outputs * 34) + 10 bytes

So, the first one:
(1 * 148) + (2 * 34) + 10 = 226 bytes :D

and the 2nd one:
(11 * 148) + (2 * 34) + 10 = 1706 bytes! :o

This is the reason why you should try as hard as possible to avoid collecting lots of small amounts in your wallet... sooner or later you'll end up needing to use a whole bunch of UTXOs to create a transaction and you'll get slammed on fees :-\

Quote
Another question in that path: Once I send something bitcoins, where does my transaction goes to for all the miners to grab it from?
I understand that all the past data is in the blockchain, but where is the data that is still not in the blockchain?
There is a network of "nodes" who hold and relay unconfirmed transactions... they have what is referred to as a "mempool" or memory pool... your transaction sits in the mempool of various nodes until a miner includes it in a block.

If it sits for too long (used to be around 72 hours, but seems to be getting longer these days) nodes will start to drop it from their mempool. Once all nodes drop it, it is like the transaction never existed and your coins should be respendable by your wallet.