Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: cvramen on February 14, 2014, 01:32:05 AM



Title: Spending At The Same Time?
Post by: cvramen on February 14, 2014, 01:32:05 AM
  • There is a Bitcoin wallet containing 10 Bitcoin.
  • Two people on two separate computers open the Bitcoin wallet simultaneously.
  • They spend 6 Bitcoin from the wallet.
  • They hit the Send button simultaneously
  • They have set up the timing and positioning so that they are the same time/distance from the nearest Bitcoin node (I know this is silly, but this was the hypothetical presented to me)

What would happen?

My friend asked me what would happen in this situation and I think I know what the answer is, but I thought I'd confirm with the community, so I can say that I heard the answer from other people as well. Gotta be able to answer newcomer questions, if we want Bitcoin to be successful, even silly or weird ones. :P


Title: Re: Spending At The Same Time?
Post by: spin on February 14, 2014, 10:40:17 AM
One of the two transactions will arrive before the other at each node.  Each node will reject the second one to arrive.
Eventually one of the transactions (you can't predict which I guess) will arrive at a miner and be included in the blockchain.  Once that happens the other will be ignored by nodes.


Title: Re: Spending At The Same Time?
Post by: DannyHamilton on February 14, 2014, 03:42:44 PM
One of the two transactions will arrive before the other at each node.  Each node will reject the second one to arrive.
Eventually one of the transactions (you can't predict which I guess) will arrive at a miner and be included in the blockchain.  Once that happens the other will be ignored by nodes.

Very good answer.

Here is one where the answer isn't quite as obvious.

Same exact question, except instead of sending 6 BTC, the two people both send 4 BTC?

(I'm aware of the answer to this question.  I'm just posting it to provoke some thought in people who might think they know what will happen.  The true experts will get it right, but many people who think they know the answer will be surprised when they read the actual answer)


Title: Re: Spending At The Same Time?
Post by: uminatsu on February 14, 2014, 06:57:18 PM
One of the two transactions will arrive before the other at each node.  Each node will reject the second one to arrive.
Eventually one of the transactions (you can't predict which I guess) will arrive at a miner and be included in the blockchain.  Once that happens the other will be ignored by nodes.

Very good answer.

Here is one where the answer isn't quite as obvious.

Same exact question, except instead of sending 6 BTC, the two people both send 4 BTC?

(I'm aware of the answer to this question.  I'm just posting it to provoke some thought in people who might think they know what will happen.  The true experts will get it right, but many people who think they know the answer will be surprised when they read the actual answer)

That depends on how the initial 10BTC was distributed among the unspent outputs. If the whole 10BTC is just one unspent output then only one transaction can be confirmed no matter how little they send. But suppose there's 2 unspent outputs of 5BTC each and the two people each send 4BTC from a different unspent output then both can be confirmed.


Title: Re: Spending At The Same Time?
Post by: Rannasha on February 14, 2014, 07:03:46 PM
One of the two transactions will arrive before the other at each node.  Each node will reject the second one to arrive.
Eventually one of the transactions (you can't predict which I guess) will arrive at a miner and be included in the blockchain.  Once that happens the other will be ignored by nodes.

Very good answer.

Here is one where the answer isn't quite as obvious.

Same exact question, except instead of sending 6 BTC, the two people both send 4 BTC?

(I'm aware of the answer to this question.  I'm just posting it to provoke some thought in people who might think they know what will happen.  The true experts will get it right, but many people who think they know the answer will be surprised when they read the actual answer)

That depends on how the initial 10BTC was distributed among the unspent outputs. If the whole 10BTC is just one unspent output then only one transaction can be confirmed no matter how little they send. But suppose there's 2 unspent outputs of 5BTC each and the two people each send 4BTC from a different unspent output then both can be confirmed.

But if both people use the same wallet-software and create their transaction at the same time (or at least before their wallet-software becomes aware of the transaction created by the other), both copies of the software will select the same unspent output(s) to create the transaction and it will still double-spend.


Title: Re: Spending At The Same Time?
Post by: uminatsu on February 14, 2014, 07:07:42 PM
One of the two transactions will arrive before the other at each node.  Each node will reject the second one to arrive.
Eventually one of the transactions (you can't predict which I guess) will arrive at a miner and be included in the blockchain.  Once that happens the other will be ignored by nodes.

Very good answer.

Here is one where the answer isn't quite as obvious.

Same exact question, except instead of sending 6 BTC, the two people both send 4 BTC?

(I'm aware of the answer to this question.  I'm just posting it to provoke some thought in people who might think they know what will happen.  The true experts will get it right, but many people who think they know the answer will be surprised when they read the actual answer)

That depends on how the initial 10BTC was distributed among the unspent outputs. If the whole 10BTC is just one unspent output then only one transaction can be confirmed no matter how little they send. But suppose there's 2 unspent outputs of 5BTC each and the two people each send 4BTC from a different unspent output then both can be confirmed.

But if both people use the same wallet-software and create their transaction at the same time (or at least before their wallet-software becomes aware of the transaction created by the other), both copies of the software will select the same unspent output(s) to create the transaction and it will still double-spend.

That's correct. The only way both transactions can go through is if the two people coordinate ahead of time to select disjoint unspent output(s) and push Tx manually.