Bitcoin Forum
July 01, 2024, 06:22:24 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [Whats happen] when~~  (Read 501 times)
|Ocean| (OP)
Full Member
***
Offline Offline

Activity: 126
Merit: 100

Mining Bitcoins Since 2010


View Profile
December 06, 2015, 04:13:05 PM
 #1

I wanna ask what happen to other transactions if the input is still unconfirmed?
Will the other transactions using that unconfirmed input balance will vanish if that input is not confirmed?
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3444
Merit: 6733


Just writing some code


View Profile WWW
December 06, 2015, 04:19:19 PM
 #2

The transaction will continue to be unconfirmed until the all previous transactions in the in the transaction chain are confirmed. If they aren't confirmed after a few days, those transactions will be dropped from the mempool.

DannyHamilton
Legendary
*
Offline Offline

Activity: 3430
Merit: 4681



View Profile
December 06, 2015, 05:07:59 PM
 #3

I wanna ask what happen to other transactions if the input is still unconfirmed?
Will the other transactions using that unconfirmed input balance will vanish if that input is not confirmed?

That depends on what happens with that earlier transaction.

If it continues to be rebroadcast, then both transactions will remain unconfirmed.

If a different transaction is confirmed using the same inputs as the first unconfirmed transaction, then the transactions that were dependent on the first transaction will become invalid.

Lets look at an example:

You have 2 unspent outputs:
  • Confirmed unspent output A valued at 1 BTC
  • Confirmed unspent output B valued at 2 BTC

You create a transaction (Transaction 1) that spends both outputs.  It sends 2.5 BTC to a merchant, and 0.5 BTC back to yourself as change:

  • Output A valued at 1 BTC is spent in Transaction 1 but unconfirmed
  • Output B valued at 2 BTC is spent in Transaction 1 but unconfirmed
  • Unspent output C valued at 2.5 BTC (sent to merchant) is created in Transaction 1 but unconfirmed
  • Unspent output D valued at 0.5 BTC (sent to you) is created in Transaction 1 but unconfirmed

Your wallet now shows a balance of 0.5 BTC unconfirmed, the merchant sees 2.5 BTC unconfirmed.

You create a transaction (Transaction 2) that spends your 0.5 BTC output. It sends the 0.5 BTC to a friend with no change:

  • Output A valued at 1 BTC is spent in Transaction 1 but unconfirmed
  • Output B valued at 2 BTC is spent in Transaction 1 but unconfirmed
  • Unspent output C valued at 2.5 BTC (sent to merchant) is created in Transaction 1 but unconfirmed
  • Output D valued at 0.5 BTC (sent to you) is created in Transaction 1, spent in Transaction 2 but unconfirmed
  • Unspent output E valued at 0.5 BTC (sent to your friend) is created in Transaction 2 but unconfirmed

There is nothing requiring any node or wallet to "forget" about any of these transactions. They can be remembered forever as long as they remain valid.  However, in order to save space in memory and avoid attacks that might try to fill up storage space with billions of transactions that will never confirm, most wallets and most nodes choose to forget about unconfirmed transactions after a while.  Anyone on the network that has seen any of these transactions (including any of the recipients or senders can re-broadcast any of these transactions at any time if they like and they will still be valid.

Lets pretend that some time has passed and that your wallet has chosen to "forget" about these transactions, but the wallet used by the merchant and your friend hasn't forgotten about them yet.

  • Your wallet shows output A valued at 1 BTC as unspent and available to be respent. The merchant and your friend see output A as spent in Transaction 1 but unconfirmed
  • Your wallet shows output B valued at 2 BTC as unspent and available to be respent. The merchant and your friend see output B as spent in Transaction 1 but unconfirmed
  • Your wallet is unaware of output C. The merchant and your friend see output C valued at 2.5 BTC (sent to merchant) created in Transaction 1 but unconfirmed
  • Your wallet is unaware of output D. The merchant and your friend see output D valued at 0.5 BTC (sent to you) created in Transaction 1, spent in Transaction 2 but unconfirmed
  • Your wallet is unaware of output E. The merchant and your friend see output E valued at 0.5 BTC (sent to your friend) created in Transaction 2 but unconfirmed

Ok, now that your your wallet has forgotten about the unconfirmed transactions, you see a balance of 3 BTC confirmed in your wallet and waiting to be spent.  Meanwhile the merchant sees 2.5 BTC unconfirmed in his wallet, and your friend sees 0.5 BTC unconfirmed in his wallet.

Now lets say that most of the network nodes have forgotten about Transaction 1.  They are now willing to accept and relay new transactions that spend output A. You decide to create Output F with Transaction 3 to donate 0.75 BTC from your wallet to a charity. The wallet also creates Output G valued at 0.25 BTC as change sent back to your wallet. Your wallet chooses to fund this Transaction 3 with what it sees as a completely available Output A valued at 1 BTC.

  • Your wallet and the charity see output A valued at 1 BTC as spent in Transaction 3 but unconfirmed. The wallets operated by the merchant and your friend reject transaction 3 as a "double spend" attempt. They see output A as spent in Transaction 1 but unconfirmed
  • Your wallet and the charity see output B valued at 2 BTC as unspent and available to be respent. The wallets operated by the merchant and your friend reject transaction 3 as a "double spend" attempt. They see output B as spent in Transaction 1 but unconfirmed
  • Your wallet and the charity are unaware of output C. The merchant and your friend still see output C valued at 2.5 BTC (sent to merchant) created in Transaction 1 but unconfirmed
  • Your wallet and the charity are unaware of output D. The merchant and your friend still see output D valued at 0.5 BTC (sent to you) created in Transaction 1, spent in Transaction 2 but unconfirmed
  • Your wallet and the charity see output F valued at 0.75 BTC (sent to charity) created in Transaction 3 but unconfirmed. The merchant and your friend do not accept Transaction 3, and therefore do not see output F.
  • Your wallet and the charity see output G valued at 0.25 BTC (sent to you) created in Transaction 3 but unconfirmed. The merchant and your friend do not accept Transaction 3, and therefore do not see output F.
  • Your wallet and the charity are unaware of output E. The merchant and your friend see output E valued at 0.5 BTC (sent to your friend) created in Transaction 2 but unconfirmed

Ok, what a mess now, right?

Your friend thinks he has 0.5 BTC unconfirmed, the merchant thinks he has 2.5 BTC unconfirmed, the charity thinks they have 0.75 BTC unconfirmed, and your wallet thinks that the 2 BTC output B is confirmed and was never spent, and that you have 0.25 BTC in change in unconfirmed output G.

This is why it is important not to accept unconfirmed transactions unless you are very confident that they will confirm soon.  Clearly some of these transactions are going to become invalid soon.

There are two possibilities:

Possibility 1 (A miner somewhere never forgot about Transaction 1, saw things the same way as your friend and the merchant and eventualy confirms Transaction 1):

Ok, in this scenario, as soon as any node (including your own wallet, the charity's wallet, the merchant, and your friend) sees the valid block that includes Transaction 1, Transaction 3 immediately becomes invalid and is thrown away.  Since Output A is already spent (and now confirmed) in Transaction 1, it cannot be spent in Transaction 3.

  • Output A valued at 1 BTC is spent in Transaction 1 and confirmed
  • Output B valued at 2 BTC is spent in Transaction 1 and confirmed
  • Unspent output C valued at 2.5 BTC (sent to merchant) is created in Transaction 1 and confirmed
  • Output D valued at 0.5 BTC (sent to you) is created and confirmed in Transaction 1, spent in Transaction 2 but unconfirmed
  • Unspent output E valued at 0.5 BTC (sent to your friend) is created in Transaction 2 but unconfirmed
  • Output F valued at 0.75 BTC and created in Transaction 3 is invalid and forgotten by the entire network
  • Output G valued at 0.25 BTC and created in Transaction 3 is invalid and forgotten by the entire network

The merchant now sees that he has a confirmed 2.5 BTC. Your friend sees that he has an unconfirmed 0.5 BTC, but that the input is confirmed, so it seems more likely to him that the transaction to him will confirm soon.  Your wallet is reminded about transaction 1, and now sees that it has an unconfirmed balance of 0.5 BTC (your wallet has not yet been reminded about the transaction to your friend and won't remember that transaction unless it is either confirmed or re-broadcast by someone). The charity sees the 0.75 BTC transaction vanish and no longer sees that as an unconfirmed balance. The 0.75 BTC simply disappears out of the charity's wallet.


Possibility 2 (A miner somewhere confirms Transaction 3:

Ok, in this scenario, as soon as any node (including your own wallet, the charity's wallet, the merchant, and your friend) sees the valid block that includes Transaction 3, Transaction 1 and 2 immediately become2 invalid and are thrown away.  Since Output A is already spent (and now confirmed) in Transaction 3, it cannot be spent in Transaction 1.  Since Transaction 1 is invalid, Transaction 2 cannot be valid.

  • Output A valued at 1 BTC is spent in Transaction 3 and confirmed
  • Output B valued at 2 BTC is unspent
  • Output C valued at 2.5 BTC and created in Transaction 1 is invalid and forgotten by the entire network
  • Output D valued at 0.5 BTC and created in Transaction 1 is invalid and forgotten by the entire network
  • Output E valued at 0.5 BTC and created in Transaction 2 is invalid and forgotten by the entire network
  • Output F valued at 0.75 BTC (sent to charity) is created in Transaction 3 and confirmed
  • Output G valued at 0.25 BTC (sent to your) is created in Transaction 3 and confirmed

The merchant now sees the 2.5 BTC vanish from his wallet. The transaction that created it no longer exists. Your friend sees the 0.5 BTC vanish from his wallet. The transaction that created it no longer exists. Your wallet is Sees that the 2 BTC Output B was never spent and is still confirmed and waiting to be spent.  Your wallet also sees the 0.25 BTC of change that was created in Transaction 3 is confirmed and waiting to be spent.  Your wallet balance is 2.25 BTC confirmed.  The charity sees 0.75 BTC confirmed added to their wallet.
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!