Bitcoin Forum
May 11, 2024, 12:23:26 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Transaction sequence  (Read 238 times)
CTracker (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 4


View Profile
May 14, 2020, 06:30:35 AM
Merited by DdmrDdmr (2)
 #1

When I press 'send', what exactly happens after? What I know is 1the transaction is broadcasted into the network, 2a miner will collect it and add it to a block, 3it will be confirmed, 4then the recipient will receive the btc I sent.

Please add more in-betweens and correct my misunderstanding (if there's any). I don't mind if you get technical about the processes. I simply want to see the whole picture. Thank you.
1715387006
Hero Member
*
Offline Offline

Posts: 1715387006

View Profile Personal Message (Offline)

Ignore
1715387006
Reply with quote  #2

1715387006
Report to moderator
Bitcoin addresses contain a checksum, so it is very unlikely that mistyping an address will cause you to lose money.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715387006
Hero Member
*
Offline Offline

Posts: 1715387006

View Profile Personal Message (Offline)

Ignore
1715387006
Reply with quote  #2

1715387006
Report to moderator
cryptoaddictchie
Legendary
*
Offline Offline

Activity: 2072
Merit: 1315



View Profile
May 14, 2020, 06:46:41 AM
 #2

To visualize it better this a good infographics

Source: Transaction cycle

Also some good explanation on this blog.


https://itnext.io/pulling-the-blockchain-apart-the-transaction-life-cycle-381b76842c6


.BEST..CHANGE.███████████████
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
██
███████████████
..BUY/ SELL CRYPTO..
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10558



View Profile
May 14, 2020, 07:08:43 AM
Merited by DdmrDdmr (2), mocacinno (1), LeGaulois (1), mk4 (1)
 #3

when you create and broadcast a transaction it goes to the node(s) that you send it to, then those nodes send it to other nodes until nearly all the network finds out about your transaction (assuming it is a valid transaction and it doesn't violate any of the preference rules set by any of the nodes like the standard rules including but not limited to fee per byte).

one of these nodes belongs to the recipient (or they are connected to a node through different ways such as an SPV client), so you can say that they "receive" the coins you sent them as soon as the transaction reaches their node.

similarly miners are connected to the same nodes and choose a transaction from the mempool of that node. if they choose your tx and put it in the block they are mining and then they successfully mine that block, your transaction becomes "confirmed" which means the cost of reversing it is big enough to be considered "final".

in other words the recipient receives the transaction (the money) right away since it takes a second or two for a tx to propagate through the entire bitcoin network. but it will be final (irreversible) after it is confirmed.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
mocacinno
Legendary
*
Offline Offline

Activity: 3388
Merit: 4922


https://merel.mobi => buy facemasks with BTC/LTC


View Profile WWW
May 14, 2020, 07:11:56 AM
Merited by DdmrDdmr (2), LeGaulois (1)
 #4

Well, your wallet holds private keys, the public keys of those private keys are hashed. These hashes are your addresses.
In the past, somebody funded your addresses: somebody else created a transaction, and one or more of the outputs of said transaction were funding an address whose private key belonged to your wallet. You have one or more unspent outputs funding one or more addresses, the sum of the value of these unspent outputs is seen as the balance of your wallet.

When you click "send", you wallet will combine one or more of those unspent outputs with a total value equal or greater to the amount you want to transfer PLUS the mining fee. If the sum of the values of the used unspent outputs is bigger than the amount you want to transfer plus the fee, a change address is used. This change addres also belongs to your wallet, and it's funded with the leftover value.
In the meantime, while selecting unspent outputs to use, and finding out wether a change address is needed, your wallet also calculates the optimal fee. Sometimes you can pick your own fee, sometimes a slider is used, sometimes the fee calculation is hidden altogether, but your wallet calculates the weight of your transaction and adjusts the fee accordingly.

After the unsigned transaction is created (unspent outputs are used as an input, new unspent outputs are created as output), the transaction is signed with the private key(s) belonging to the addresses whose unspent outputs are being used as an input.

The signed transaction is now broadcasted to the nodes. Each node checks if all unspent outputs used as input are available in their utxo db (db with all valid unspent outputs), they also check the signatures. Invalid transactions get rejected, valid ones get broadcasted to other nodes.

In the end, the transaction ends up in the mempool of about all the nodes of the network. Some of these nodes belong to miners. Miners sort the transactions from highest fee/Wu to lowest fee/Wu. They take the top tx's (untill the block is full), calculate a merkle tree, put the merkle root in the block header they're trying to solve (together with the sha256d hash of the previous block header) and try to find a nonce for which the sha256d of the new header is under the current target.

If they succeed, they found a valid block, and they can broadcast it to the network.

As soon as a signed transaction is broadcasted, the receiver usually sees an incoming, unconfirmed transaction. Once a transaction ended up in a valid block, the receiver will see the transaction is confirmed.
When new blocks get mined on top of the block containing a transaction, the receiver will see +1 confirmation...

As long as a transaction remains unconfirmed, it'll stay in the node's mempool. Each node can truncate their mempool, so if a transaction remains unconfirmed for to long, most nodes will have dropped it from their mempool. This is one of the reasons why it's a bad idear to accept 0 conf transaction.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
CTracker (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 4


View Profile
May 14, 2020, 07:46:14 AM
 #5

It will take time before I can fully understand what really goes on in the network but I appreciate all the data provided here so far. I realized how much of a newbie I am from reading your responses. If anybody want to add more to the discussion, please do so. I will be offline soon but I will read them when I get back.
tranthidung
Legendary
*
Offline Offline

Activity: 2268
Merit: 4013


Farewell o_e_l_e_o


View Profile WWW
May 14, 2020, 10:24:47 AM
 #6

in other words the recipient receives the transaction (the money) right away since it takes a second or two for a tx to propagate through the entire bitcoin network. but it will be final (irreversible) after it is confirmed.
The thread reminds that I read this part in the book "Mastering Bitcoin". There are some exchanges and casinos accept and make deposits visible in balance after 1 confirmation, but most of the have a number at 3 confirmations. I remember this part because if OP want to make deal with a person, he should wait the transaction has at least 1 confirmation on the network or even better, with 3 confirmations.
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 ..
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10558



View Profile
May 15, 2020, 03:08:13 AM
 #7

The thread reminds that I read this part in the book "Mastering Bitcoin". There are some exchanges and casinos accept and make deposits visible in balance after 1 confirmation, but most of the have a number at 3 confirmations. I remember this part because if OP want to make deal with a person, he should wait the transaction has at least 1 confirmation on the network or even better, with 3 confirmations.

the thing about number of confirmations is that the value people should look for depends on a bunch of factors.

for starters it depends on how the user is connecting to the bitcoin network and he they perceive each block. for example someone running a full verification node can be certain about validity of a block and the fact that there has not been any chain splits or blockchain reorganization so they can accept 1 confirmation with a much higher certainty. in comparison someone using a SPV client doesn't have the same confidence since SPV clients can't detect reorgs as well as a full node does so they have to require a higher number of confirmations. and things are worse for those using other types of wallets like those that rely on a centralized server (usually phone wallets are like this).

there is also network status (what is going on with bitcoin). 99.9% of the times bitcoin is working fine but there are times that we have an upgrade (a soft/hard fork) that can increase the chances of a split and during such times (like the 2017 SegWit soft fork) specially if there is a high chance of chain split (like the 2017 UASF) a higher number of confirmation should be required.

last but not least, the amount of bitcoin being received can be another deciding factor. for instance receiving $100 worth of bitcoin doesn't require the same precautions as receiving $1 million worth of bitcoin.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
CTracker (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 4


View Profile
May 16, 2020, 04:10:02 PM
Merited by mocacinno (1), The Cryptovator (1)
 #8

Hello again. I have a few more questions and I apologize in advance if they appear stupid  Sad

Well, your wallet holds private keys, the public keys of those private keys are hashed. These hashes are your addresses.
In the past, somebody funded your addresses: somebody else created a transaction, and one or more of the outputs of said transaction were funding an address whose private key belonged to your wallet. You have one or more unspent outputs funding one or more addresses, the sum of the value of these unspent outputs is seen as the balance of your wallet.

When you click "send", you wallet will combine one or more of those unspent outputs with a total value equal or greater to the amount you want to transfer PLUS the mining fee. If the sum of the values of the used unspent outputs is bigger than the amount you want to transfer plus the fee, a change address is used. This change addres also belongs to your wallet, and it's funded with the leftover value.
In the meantime, while selecting unspent outputs to use, and finding out wether a change address is needed, your wallet also calculates the optimal fee. Sometimes you can pick your own fee, sometimes a slider is used, sometimes the fee calculation is hidden altogether, but your wallet calculates the weight of your transaction and adjusts the fee accordingly.
Can we use numbers so I can better understand this?

Let's say someone sent me 0.10, 0.20, 0.30, and 0.40 btc in the past [total unspent output = 1 btc] and I want to send 0.55 to someone else. Assuming my wallet will combine the first three transactions 0.10 + 0.20 + 0.30 = 0.60. The excess balance of 0.05 less the mining fee will go to the change address generated by my wallet. Is this correct?

When selecting unspent outputs to combine, does the wallet follow a method like first in first out? Or is this random?
Why is there a change address?

Quote
After the unsigned transaction is created (unspent outputs are used as an input, new unspent outputs are created as output), the transaction is signed with the private key(s) belonging to the addresses whose unspent outputs are being used as an input.
I'm lost here.

Using the example above
"unspent outputs are used as an input" = 0.55 + mining fees?
"new unspent outputs are created as output" = 0.05 less mining fees + 0.40?

Quote
The signed transaction is now broadcasted to the nodes. Each node checks if all unspent outputs used as input are available in their utxo db (db with all valid unspent outputs), they also check the signatures. Invalid transactions get rejected, valid ones get broadcasted to other nodes.
How many nodes is 1 signed transaction broadcasted to?

Quote
In the end, the transaction ends up in the mempool of about all the nodes of the network. Some of these nodes belong to miners. Miners sort the transactions from highest fee/Wu to lowest fee/Wu. They take the top tx's (untill the block is full), calculate a merkle tree, put the merkle root in the block header they're trying to solve (together with the sha256d hash of the previous block header) and try to find a nonce for which the sha256d of the new header is under the current target.

If they succeed, they found a valid block, and they can broadcast it to the network.

As soon as a signed transaction is broadcasted, the receiver usually sees an incoming, unconfirmed transaction. Once a transaction ended up in a valid block, the receiver will see the transaction is confirmed.
When new blocks get mined on top of the block containing a transaction, the receiver will see +1 confirmation...
I understand most parts here. I will need to read about the merkle tree and root.

Quote
As long as a transaction remains unconfirmed, it'll stay in the node's mempool. Each node can truncate their mempool, so if a transaction remains unconfirmed for to long, most nodes will have dropped it from their mempool. This is one of the reasons why it's a bad idear to accept 0 conf transaction.
Does this mean that each node have their own mempool? I was under the impression that there is only one mempool.


when you create and broadcast a transaction it goes to the node(s) that you send it to, then those nodes send it to other nodes until nearly all the network finds out about your transaction (assuming it is a valid transaction and it doesn't violate any of the preference rules set by any of the nodes like the standard rules including but not limited to fee per byte).
Do I get to pick which node to send to? Or do you mean to say the node(s) connected to the wallet I am using?
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10558



View Profile
May 17, 2020, 02:45:56 AM
 #9

Let's say someone sent me 0.10, 0.20, 0.30, and 0.40 btc in the past [total unspent output = 1 btc] and I want to send 0.55 to someone else. Assuming my wallet will combine the first three transactions 0.10 + 0.20 + 0.30 = 0.60. The excess balance of 0.05 less the mining fee will go to the change address generated by my wallet. Is this correct?

When selecting unspent outputs to combine, does the wallet follow a method like first in first out? Or is this random?
Why is there a change address?
that is correct but how your wallet chooses outputs depends on the wallet itself. there really is no rule to follow. in the past age of an output could make a difference in some miner's decision of picking up the transaction with low (zero) fee. but this not not true anymore but some wallets still use the age to  select them and some others randomly select outputs.
change address isn't anything special, it is an address like anything else. some wallets use it to split the "change" and other funds to improve privacy a little bit.

Quote
How many nodes is 1 signed transaction broadcasted to?
again it depends on the wallet you are using. a full node client adds your transaction to its own mempool and each time it connects to a new node it relays its transactions to that other node. an SPV node may only connect to a single full node and broadcast the tx to that node only. and so on.

Quote
Does this mean that each node have their own mempool?
precisely.

Quote
Do I get to pick which node to send to? Or do you mean to say the node(s) connected to the wallet I am using?
again it depends on the wallet client you are using. usually they should have an option to let you choose which node you want to connect to, ban a node, add a node,... for example Electrum (which is SPV client) lets you manually select an Electrum node to connect to.
but most of the times the client should do the selection under the hood without you noticing. since technically it doesn't matter which node you connect to and broadcast a new transaction to.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
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!