Bitcoin Forum
May 25, 2024, 11:53:52 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: What is the tie-breaker between transactions of same fee and size?  (Read 95 times)
markcolls (OP)
Member
**
Offline Offline

Activity: 60
Merit: 21


View Profile
December 04, 2020, 12:10:05 PM
 #1

Suppose 1 last transaction is going to be included in a blocked. Suppose then the two next highest fee transactions have both the exact same size and fee/byte. Then how is it decided which one is included in the block? Is it by which ever transaction was broadcast first? Or is it done randomly?

Additionally, I have a lot of these protocol related questions that I have. Is there some text I could read that answers all these questions that arise in my head?
tranthidung
Legendary
*
Offline Offline

Activity: 2282
Merit: 4020


Farewell o_e_l_e_o


View Profile WWW
December 04, 2020, 12:50:17 PM
 #2

I am not sure my answer is correct (I guess it is inaccurate in some parts) but let's give me this post to discuss. I can learn more from my inaccurate understandings.

I guess if two waiting transactions have same size, same mining fee (not fee rate), the older will be chosen to be confirmed first by miners, according to [1]
Formula
Code:
priority = sum(input_value_in_base_units * input_age)/size_in_bytes
In fact, it can be more complex than such. How many transactions will be confirmed in one block of bitcoin.

You can imagine when fee rates on the network drops to 2 sat/(v)byte, ie. and all waiting transactions with that fee rate are totally fitted in size (and max number of transactions) of one block, they all will be confirmed at the same time. In rare cases, the tip of mempool (1 MB) is cut at exactly transaction A, while transaction B with same fee rate, same size, same mining fee so B will be confirmed in the next one block. Of course, if same fee rate will be used in next one block.

[1] https://en.bitcoin.it/wiki/Miner_fees#Priority_transactions

▄▄███████▄▄
▄██████████████▄
▄██████████████████▄
▄████▀▀▀▀███▀▀▀▀█████▄
▄█████████████▄█▀████▄
███████████▄███████████
██████████▄█▀███████████
██████████▀████████████
▀█████▄█▀█████████████▀
▀████▄▄▄▄███▄▄▄▄████▀
▀██████████████████▀
▀███████████████▀
▀▀███████▀▀
.
 MΞTAWIN  THE FIRST WEB3 CASINO   
.
.. PLAY NOW ..
markcolls (OP)
Member
**
Offline Offline

Activity: 60
Merit: 21


View Profile
December 04, 2020, 01:23:53 PM
 #3

I am not sure my answer is correct (I guess it is inaccurate in some parts) but let's give me this post to discuss. I can learn more from my inaccurate understandings.

I guess if two waiting transactions have same size, same mining fee (not fee rate), the older will be chosen to be confirmed first by miners, according to [1]
Formula
Code:
priority = sum(input_value_in_base_units * input_age)/size_in_bytes
In fact, it can be more complex than such. How many transactions will be confirmed in one block of bitcoin.

You can imagine when fee rates on the network drops to 2 sat/(v)byte, ie. and all waiting transactions with that fee rate are totally fitted in size (and max number of transactions) of one block, they all will be confirmed at the same time. In rare cases, the tip of mempool (1 MB) is cut at exactly transaction A, while transaction B with same fee rate, same size, same mining fee so B will be confirmed in the next one block. Of course, if same fee rate will be used in next one block.

[1] https://en.bitcoin.it/wiki/Miner_fees#Priority_transactions


The first time my transaction is included in the block and hashed by the miners I get a confirmation. What does the second confirmation mean? And the third and so on?
mprep
Global Moderator
Legendary
*
Offline Offline

Activity: 3766
Merit: 2610


In a world of peaches, don't ask for apple sauce


View Profile WWW
December 04, 2020, 01:28:20 PM
Last edit: December 04, 2020, 01:39:55 PM by mprep
 #4

I am not sure my answer is correct (I guess it is inaccurate in some parts) but let's give me this post to discuss. I can learn more from my inaccurate understandings.

I guess if two waiting transactions have same size, same mining fee (not fee rate), the older will be chosen to be confirmed first by miners, according to [1]
Formula
Code:
priority = sum(input_value_in_base_units * input_age)/size_in_bytes
In fact, it can be more complex than such. How many transactions will be confirmed in one block of bitcoin.

You can imagine when fee rates on the network drops to 2 sat/(v)byte, ie. and all waiting transactions with that fee rate are totally fitted in size (and max number of transactions) of one block, they all will be confirmed at the same time. In rare cases, the tip of mempool (1 MB) is cut at exactly transaction A, while transaction B with same fee rate, same size, same mining fee so B will be confirmed in the next one block. Of course, if same fee rate will be used in next one block.

[1] https://en.bitcoin.it/wiki/Miner_fees#Priority_transactions


The first time my transaction is included in the block and hashed by the miners I get a confirmation. What does the second confirmation mean? And the third and so on?
From https://en.bitcoin.it/wiki/Confirmation (emphasis added by me):

Quote
After a transaction is broadcast to the Bitcoin network, it may be included in a block that is published to the network. When that happens it is said that the transaction has been mined at a depth of 1 block. With each subsequent block that is found, the number of blocks deep is increased by one. To be secure against double spending, a transaction should not be considered as confirmed until it is a certain number of blocks deep.

tl;dr number of blocks (within the currently dominant chain) the transaction exists in.

EDIT: By "exists", I mean that if you took the entire dominant chain at a certain number of blocks and parsed it (e.g. in Bitcoin wallet app), the transaction would be included in some block within that chain (either the newest or any older one). So if, hypothetically, your transaction was included in block 5 in the dominant chain and the newest block is now 6, your transaction has 2 confirmations since it "exists" in blocks 5 and 6, even though the transaction data has only been directly included in block 5.

markcolls (OP)
Member
**
Offline Offline

Activity: 60
Merit: 21


View Profile
December 04, 2020, 01:37:54 PM
 #5

I am not sure my answer is correct (I guess it is inaccurate in some parts) but let's give me this post to discuss. I can learn more from my inaccurate understandings.

I guess if two waiting transactions have same size, same mining fee (not fee rate), the older will be chosen to be confirmed first by miners, according to [1]
Formula
Code:
priority = sum(input_value_in_base_units * input_age)/size_in_bytes
In fact, it can be more complex than such. How many transactions will be confirmed in one block of bitcoin.

You can imagine when fee rates on the network drops to 2 sat/(v)byte, ie. and all waiting transactions with that fee rate are totally fitted in size (and max number of transactions) of one block, they all will be confirmed at the same time. In rare cases, the tip of mempool (1 MB) is cut at exactly transaction A, while transaction B with same fee rate, same size, same mining fee so B will be confirmed in the next one block. Of course, if same fee rate will be used in next one block.

[1] https://en.bitcoin.it/wiki/Miner_fees#Priority_transactions


The first time my transaction is included in the block and hashed by the miners I get a confirmation. What does the second confirmation mean? And the third and so on?
From https://en.bitcoin.it/wiki/Confirmation (emphasis added by me):

Quote
After a transaction is broadcast to the Bitcoin network, it may be included in a block that is published to the network. When that happens it is said that the transaction has been mined at a depth of 1 block. With each subsequent block that is found, the number of blocks deep is increased by one. To be secure against double spending, a transaction should not be considered as confirmed until it is a certain number of blocks deep.

tl;dr number of blocks (within the currently dominant chain) the transaction exists in.

EDIT: By "exists", I mean that if you took the entire dominant chain at a certain number of blocks and parsed it (e.g. in Bitcoin wallet app), the transaction would be included in some block within that chain (either the newest or any older one). So if, hypothetically, your transaction was included in block 5 in the dominant chain and the newest block is now 6, your transaction has 2 confirmations since it "exists" in blocks 5 and 6.


 Cry I didn't understand what you said.
tranthidung
Legendary
*
Offline Offline

Activity: 2282
Merit: 4020


Farewell o_e_l_e_o


View Profile WWW
December 04, 2020, 01:41:37 PM
Last edit: December 04, 2020, 02:03:17 PM by tranthidung
 #6

Here is the statistics for transaction counts within every block, over years. See the draw results for details. In median -- p50 (can call it as true mean), there are around 2.3k to 2.4k (in last 2 years) of transactions within one bitcoin block. 50% of blocks in each year (look at range from p25 to p75) will have transaction counts from 1711 to 2852 (2019) or 1677 to 2707 (2020 so far).

So yeah if you have a waiting transaction A, I have a waiting transaction B, with same size, same fee rate, same mining fee, and if we are both lucky at the same block, our 2 'waiting' transactions will be confirmed in a same block with total transactions are 2300, ie. It means our 2 transactions will be confirmed together with another 2298 other transactions in that block.

If the cut-off (at 2300 transactions, max cap of that block), your priority ordinal number is 2300, and mine is 2301, I will be out and have to wait for a next one block.

The priority ordinal number is what I did not know. I guess it is calculated with the above formula. If yes, it depends on age of waiting transaction.

Code:
Summary for variables: transaction_count
     by categories of: year

     year |         N      mean        sd       p50       p25       p75       min       max
----------+--------------------------------------------------------------------------------
     2009 |   32490.0       1.0       0.1       1.0       1.0       1.0       1.0       6.0
     2010 |   67920.0       2.7      16.5       1.0       1.0       2.0       1.0     850.0
     2011 |   59627.0      31.9      39.4      14.0       8.0      42.0       1.0     912.0
     2012 |   54526.0     155.0     187.4      87.0      28.0     194.0       1.0    1871.0
     2013 |   63433.0     309.7     238.6     256.0     122.0     459.0       1.0    3861.0
     2014 |   58865.0     429.2     380.4     322.0     143.0     606.0       1.0    3417.0
     2015 |   54321.0     840.8     684.1     671.0     307.0    1226.0       1.0   12239.0
     2016 |   54851.0    1506.4     857.6    1543.0     774.0    2221.0       1.0    4077.0
     2017 |   55928.0    1860.7     708.8    2013.0    1494.0    2348.0       1.0    4667.0
     2018 |   54498.0    1493.6     901.8    1499.0     685.0    2273.0       1.0    4109.0
     2019 |   54232.0    2208.7     861.2    2459.0    1711.0    2852.0       1.0    4402.0
     2020 |   49148.0    2113.5     802.1    2324.0    1677.0    2707.0       1.0    4377.0
----------+--------------------------------------------------------------------------------
    Total |  659839.0     898.5    1009.1     415.0      28.0    1762.0       1.0   12239.0
-------------------------------------------------------------------------------------------

Interestingly, when I run data, I found that block (you can see the max value in 2015, at 12239). It happens at block #367853
Code:
        +------------------------------------+
        | blockid   year   transaction_count |
        |------------------------------------|
367854. |  367853   2015               12239 |
        +------------------------------------+
Double check with blockchair.com and even with blockchain.com, my finding is correct. It seems to be a dust attack I heard of but never dig to get it.

▄▄███████▄▄
▄██████████████▄
▄██████████████████▄
▄████▀▀▀▀███▀▀▀▀█████▄
▄█████████████▄█▀████▄
███████████▄███████████
██████████▄█▀███████████
██████████▀████████████
▀█████▄█▀█████████████▀
▀████▄▄▄▄███▄▄▄▄████▀
▀██████████████████▀
▀███████████████▀
▀▀███████▀▀
.
 MΞTAWIN  THE FIRST WEB3 CASINO   
.
.. PLAY NOW ..
mprep
Global Moderator
Legendary
*
Offline Offline

Activity: 3766
Merit: 2610


In a world of peaches, don't ask for apple sauce


View Profile WWW
December 04, 2020, 02:05:54 PM
Last edit: December 04, 2020, 02:32:32 PM by mprep
Merited by DdmrDdmr (2), markcolls (1)
 #7

The first time my transaction is included in the block and hashed by the miners I get a confirmation. What does the second confirmation mean? And the third and so on?
From https://en.bitcoin.it/wiki/Confirmation (emphasis added by me):

Quote
After a transaction is broadcast to the Bitcoin network, it may be included in a block that is published to the network. When that happens it is said that the transaction has been mined at a depth of 1 block. With each subsequent block that is found, the number of blocks deep is increased by one. To be secure against double spending, a transaction should not be considered as confirmed until it is a certain number of blocks deep.

tl;dr number of blocks (within the currently dominant chain) the transaction exists in.

EDIT: By "exists", I mean that if you took the entire dominant chain at a certain number of blocks and parsed it (e.g. in Bitcoin wallet app), the transaction would be included in some block within that chain (either the newest or any older one). So if, hypothetically, your transaction was included in block 5 in the dominant chain and the newest block is now 6, your transaction has 2 confirmations since it "exists" in blocks 5 and 6.


 Cry I didn't understand what you said.
Completely understandable. As you've mentioned, you understand that when a miner includes your transaction in a block, it has 1 confirmation. Well, these blocks aren't free floating. Each block references (points to) a different block in the past essentially saying "I'm building on top of this block". So if you took some sort of recently mined block and started going backwards (block X points to older block Y which points to an even older Block U) you'd get a blockchain. However, since the entire system is decentralized (there is no definitive be-all-end-all authority), as long as a blockchain matches the rules of the Bitcoin protocol, it's considered valid. As such, whenever I'm talking about the "dominant chain", I'm talking about on blockchain that matches the rules and is the longest one publicly available.

However, nobody is stopping someone from taking an existing blockchain, taking not the newest block in it and starting to secretly mine blocks on top of it (essentially making his own private branch, like in a tree). If he manages to produce a longer branch than the currently "dominant" one and then reveals it by broadcasting it to the public, most clients (wallet apps, miners, explorer websites, etc.) will switch to that branch. Meaning that if your transaction was mined / included into a block that only exists in the old branch, it will suddenly become unconfirmed again. This is why most vendors wait for 6 or so confirmations before they consider the payment as received. Beating the rest of the network mining on top of an already public chain with your own private branch requires tons of resources and keeping it up for several blocks increases that resource requirement immensely. Meaning the more confirmations there are, the smaller the chance your "confirmed" transaction becomes unconfirmed again.

Here's a crude ASCII illustration of the situation:

                                      ____(public blockchain branch)_________
                                     /
-----(main blockchain)-----
                                     \_____(secret private blockchain branch)___

Before the private chain is revealed, the public only knows of the (main blockchain) + (public blockchain branch). To them there are no branches, just a single blockchain. However, someone else has secretly started mining blocks from a certain block in the (main blockchain). To them, there are 2 branches, one that the public continues to mine on and then his / her own secret private branch. These 2 go at it until either the private branch miner gives up or till (like seen in the illustration) he manages to beat the public branch in the number of blocks and (usually) decides to reveal it. Once that happens, most clients will switch to the (secret private blockchain branch), abandoning all blocks within (public blockchain branch).

If, within this illustration, your transaction was mined in a block that is within the (main blockchain) part, your transaction is still confirmed. However, if it is only mined in the (public blockchain branch) and wasn't also included within a single block in the (secret private blockchain branch), once the network switches over, your transaction will yet again be unconfirmed.

Going back to the question, your transaction's data / information isn't included in every single block - it's included in a single block (1 confirmation). A new block is mined that points to that block (2 confirmations). An even newer block is mined and points to the new block that points to the block your transaction is in (3 confirmations). Repeat ad nauseam. When you're paying a transaction fee, that fee gets received only by the block that included your transaction. So when estimating what fee you should pay, the wallet application uses historical (previous blocks, confirmed transactions, their fees, etc.) and current (unconfirmed transactions known to the wallet app, etc.) data to, for example, estimate a probability that your transaction gets included in the next block or in one of the next N number of blocks. Different wallet applications and websites use different algorithms to calculate these numbers so their predictions differ.

Do note that I'm severely oversimplifying, using a lot of non-standard terms, skipping over a lot of small (yet important) details and that I'm not an expert in the exact low level details of how it all works.

tranthidung
Legendary
*
Offline Offline

Activity: 2282
Merit: 4020


Farewell o_e_l_e_o


View Profile WWW
December 04, 2020, 02:39:30 PM
 #8

I thought @mprep misunderstood the question in OP (but he did answered OP later question).

For it, I can simplify it by visualizing a bitcoin blockhain as a soil with many layer, begins with layer 0 (genesis block) and continue to be loaded up by later blocks.
  • Assumes OP transaction is confirmed at block #10. I meant at the layer #10, OP transaction get its first confirmation.
  • The next block (block #11) will be the next layer to cover above layer #10 to help OP transaction has its second transaction and so on
  • The more blocks (layers) are covered above block #10, that transaction will be more difficult to reverse.
  • It is as same as when we dig over soil layers, we can dig over the organic layer, then top-soil, but almost can not dig through sub-soil, parent material or bed-rock layers


Andreas M. Antonopoulos explains it in Mastering bitcoin, chapter 9.
Quote
One way to think about the blockchain is like layers in a geological formation, or glacier core sample. The surface layers might change with the seasons, or even be blown away before they have time to settle. But once you go a few inches deep, geological layers become more and more stable. By the time you look a few hundred feet down, you are looking at a snapshot of the past that has remained undisturbed for millions of years. In the blockchain, the most recent few blocks might be revised if there is a chain recalculation due to a fork. The top six blocks are like a few inches of topsoil. But once you go more deeply into the blockchain, beyond six blocks, blocks are less and less likely to change. After 100 blocks back, there is so much stability that the coinbase transaction—the transaction containing newly mined bitcoin—can be spent. A few thousand blocks back (a month) and the blockchain is settled history, for all practical purposes. While the protocol always allows a chain to be undone by a longer chain and while the possibility of any block being reversed always exists, the probability of such an event decreases as time passes until it becomes infinitesimal.

▄▄███████▄▄
▄██████████████▄
▄██████████████████▄
▄████▀▀▀▀███▀▀▀▀█████▄
▄█████████████▄█▀████▄
███████████▄███████████
██████████▄█▀███████████
██████████▀████████████
▀█████▄█▀█████████████▀
▀████▄▄▄▄███▄▄▄▄████▀
▀██████████████████▀
▀███████████████▀
▀▀███████▀▀
.
 MΞTAWIN  THE FIRST WEB3 CASINO   
.
.. PLAY NOW ..
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!