<p>Imagine the blockchain as... a chain of blocks</p>

<p>The situation is:</p>

<pre><code>A -&gt; B -&gt; C
      \-&gt; C'
</code></pre>

<p>But some nodes see it as  <strong>A -> B -> C</strong> and mine over the block <strong>C</strong></p>

<p>and some other see <strong>A -> B -> C'</strong> and mine over the block <strong>C'</strong></p>

<p>If node sees something like this:</p>

<pre><code>A -&gt; B -&gt; C -&gt; D -&gt; E...
      \-&gt; C'-&gt; D'-&gt; E'...
</code></pre>

<p>it should select the chain with larger <code>cumulative difficulty</code> (longest) and forget anything about orphan chain</p>

CC BY-SA 3.0
2017-10-30T16:33:51.790Z
So the immediate two questions that come to mind are: (1) how does a node decide that it's A->B->C rather than A->B->C'?  Is it just whoever was working on C rather than C'? and (2) At what point would a node "select the chain with larger cumulative difficulty"?  If C' is found first, would they immediately switch and forget the block containing the legitimate transaction?
Marcus Johnson
CC BY-SA 3.0
2017-10-30T16:55:53.240Z
(1) if you have C and C' - compare their difficulty and drop one. In fact you can drop any of them because usually C+D > dC' and C'+D' > C
amaclin
CC BY-SA 3.0
2017-10-30T16:56:13.153Z
(2) at any point
amaclin
CC BY-SA 3.0
2017-10-30T17:00:01.050Z
yes, transactions in orphan chain are forgotten and return to state unconfirmed if not included to main chain
amaclin
CC BY-SA 3.0
2017-10-30T14:32:06.247Z
2017-10-30T14:32:06.247Z
amaclin
<blockquote>
  <p>What exactly happens when the remaining 70% see this transaction? Do they stop mining Block 1?</p>
</blockquote>

<p>Let's say they started mining Block1 when the chain was <code>-A-B-C-&gt;</code>. They were mining on-top of block C. When Block2 is mined on top of C the situation becomes <code>-A-B-C-Block2-&gt;</code>. These 70% now stop mining <code>Block1</code> and they move to mine on-top of <code>Block2</code>. The first transaction is not added to the chain and is rejected and the second transaction is confirmed (with confirmation length of 1 block). (After some time when the next block is mined on top of <code>Block2</code> if will be confirmed with length of 2 blocks.)</p>

<blockquote>
  <p>At what point can Block 1 be orphaned?</p>
</blockquote>

<p><code>Block1</code> was never added to the chain so is not orphaned.</p>

CC BY-SA 3.0
2017-10-30T16:35:14.677Z
So you're saying that in my example, the double-spend attack would have been successful and there is no way to prevent this?
Marcus Johnson
CC BY-SA 3.0
2017-10-30T16:40:09.370Z
Coins would not be double spent. Coins were spent only on Block2. First transaction is then rejected and person B did not send the good. Person B would send the goods only if first transaction managed to get mined but it did not in your example.
croraf
CC BY-SA 3.0
2017-10-30T16:43:59.240Z
Assuming Person B released the goods at 0/unconfirmed...
Marcus Johnson
CC BY-SA 3.0
2017-10-30T16:44:56.970Z
He would not do that as it would not be smart, and contrary to bitcoin concept. Don't know what practice is, but I would send the goods only when transaction is confirmed in a block (thus added to the blockchain) and has one more additional block on top of that.
croraf
CC BY-SA 3.0
2017-10-30T16:48:17.953Z
So I guess he waits for 6 confirmations, at which point you're going to tell me there's a low probability that the "illegitimate" miners have been working on a secret chain long enough supersede the legitimate chain?
Marcus Johnson
CC BY-SA 3.0
2017-10-30T16:49:06.370Z
Yes. This is true, with 6 being arguable number.
croraf
CC BY-SA 3.0
2017-10-31T21:21:18.430Z
change "one more additional block" in my comment above, with "several additional blocks". I think number 6 you mention comes from the fact that one mining pool once mined 6 blocks in a row.
croraf
CC BY-SA 3.0
2017-10-30T15:06:06.433Z
2017-10-30T15:21:47.247Z
2017-10-30T15:21:47.247Z
croraf
<p>Apologies if this has been covered, but there's one area of the Bitcoin network that is not clear in my head, and it's intimately linked to the double-spend problem.</p>

<p>Suppose <strong><em>Person A</em></strong> is purchasing an item in a store.  They "pay" <strong><em>Person B</em></strong> 1 BTC for a good and broadcast this transaction to the network, which <strong><em>Person B</em></strong> sees as unconfirmed.  The transaction is included in a block (<strong><em>Block 1</em></strong>) whose Proof of Work is now being found/solved.</p>

<p>Suppose <strong><em>Person A</em></strong> controls 30% of the Bitcoin mining network (arbitrary high proportion), and has <em>his</em> miners instead mine a different block (<strong><em>Block 2</em></strong>) containing a transaction spending the same BTC to a different wallet controlled by <strong><em>Person A</em></strong>.  </p>

<p>Suppose the Proof of Work for <strong><em>Block 2</em></strong> is, against the odds, obtained first, and the "corrupt" miner who finds the requisite hash broadcasts it to the entire bitcoin network.  This is where my understanding breaks down.  What <em>exactly</em> happens when the remaining 70% see this transaction?  Do they stop mining <strong><em>Block 1</em></strong>?  At what point can <strong><em>Block 1</em></strong> be orphaned?  </p>

CC BY-SA 3.0
2017-10-30T15:00:08.537Z
I would change the wordings: "...to a different wallet controlled by Person A" with "...to pay Person C for yet another good".
croraf
CC BY-SA 3.0
2017-10-30T15:27:10.323Z
In my understanding, the 70% of miners aren't working all on identical blocks Block1, but each on his own block, which might or might not include the first or the second transaction, depending on their transaction priority scheme, the transactions available and so on. No miner will include both contradicting transactions in his block. There's no guarantee which transaction wins, but guarantee that only one will persist.
Ralf Kleberhoff
CC BY-SA 3.0
2017-10-30T16:31:40.137Z
Yes, that was an oversimplification for the example.  Block 1 was just supposed to represent any block that contained the legitimate transaction but did not contain the illegitimate transaction
Marcus Johnson
<unconfirmed-transactions><doublespend><proof-of-work>
How does the network know the legitimate chain in a double-spend attempt?
Marcus Johnson
# How does the network know the legitimate chain in a double-spend attempt?

(Asked by: username_0 on 2017-10-30)

Apologies if this has been covered, but there's one area of the Bitcoin network that is not clear in my head, and it's intimately linked to the double-spend problem.

Suppose ***Person A*** is purchasing an item in a store. They "pay" ***Person B*** 1 BTC for a good and broadcast this transaction to the network, which ***Person B*** sees as unconfirmed. The transaction is included in a block (***Block 1***) whose Proof of Work is now being found/solved.

Suppose ***Person A*** controls 30% of the Bitcoin mining network (arbitrary high proportion), and has *his* miners instead mine a different block (***Block 2***) containing a transaction spending the same BTC to a different wallet controlled by ***Person A***.

Suppose the Proof of Work for ***Block 2*** is, against the odds, obtained first, and the "corrupt" miner who finds the requisite hash broadcasts it to the entire bitcoin network. This is where my understanding breaks down. What *exactly* happens when the remaining 70% see this transaction? Do they stop mining ***Block 1***? At what point can ***Block 1*** be orphaned?

**Tags:** unconfirmed-transactions, doublespend, proof-of-work

> **Comments:**
> **username_1**: I would change the wordings: "...to a different wallet controlled by Person A" with "...to pay Person C for yet another good".  
> **username_2**: In my understanding, the 70% of miners aren't working all on identical blocks Block1, but each on his own block, which might or might not include the first or the second transaction, depending on their transaction priority scheme, the transactions available and so on. No miner will include both contradicting transactions in his block. There's no guarantee which transaction wins, but guarantee that only one will persist.  
> **username_0**: Yes, that was an oversimplification for the example.  Block 1 was just supposed to represent any block that contained the legitimate transaction but did not contain the illegitimate transaction  

---

## 2 answers

### Answer by username_3 on 2017-10-30. Score: 1

Imagine the blockchain as... a chain of blocks
The situation is:
A -> B -> C
      \-> C'

But some nodes see it as  A -> B -> C and mine over the block C
and some other see A -> B -> C' and mine over the block C'
If node sees something like this:
A -> B -> C -> D -> E...
      \-> C'-> D'-> E'...

it should select the chain with larger cumulative difficulty (longest) and forget anything about orphan chain

> **Comments:**
> **username_0**: So the immediate two questions that come to mind are: (1) how does a node decide that it's A->B->C rather than A->B->C'?  Is it just whoever was working on C rather than C'? and (2) At what point would a node "select the chain with larger cumulative difficulty"?  If C' is found first, would they immediately switch and forget the block containing the legitimate transaction?  
> **username_3**: (1) if you have C and C' - compare their difficulty and drop one. In fact you can drop any of them because usually C+D > dC' and C'+D' > C  
> **username_3**: (2) at any point  
> **username_3**: yes, transactions in orphan chain are forgotten and return to state unconfirmed if not included to main chain  

---

### Answer by username_1 on 2017-10-30. Score: 0

> What exactly happens when the remaining 70% see this transaction? Do they stop mining Block 1?

Let's say they started mining Block1 when the chain was `-A-B-C->`. They were mining on-top of block C. When Block2 is mined on top of C the situation becomes `-A-B-C-Block2->`. These 70% now stop mining `Block1` and they move to mine on-top of `Block2`. The first transaction is not added to the chain and is rejected and the second transaction is confirmed (with confirmation length of 1 block). (After some time when the next block is mined on top of `Block2` if will be confirmed with length of 2 blocks.)

> At what point can Block 1 be orphaned?

`Block1` was never added to the chain so is not orphaned.

> **Comments:**
> **username_0**: So you're saying that in my example, the double-spend attack would have been successful and there is no way to prevent this?  
> **username_1**: Coins would not be double spent. Coins were spent only on Block2. First transaction is then rejected and person B did not send the good. Person B would send the goods only if first transaction managed to get mined but it did not in your example.  
> **username_0**: Assuming Person B released the goods at 0/unconfirmed...  
> **username_1**: He would not do that as it would not be smart, and contrary to bitcoin concept. Don't know what practice is, but I would send the goods only when transaction is confirmed in a block (thus added to the blockchain) and has one more additional block on top of that.  
> **username_0**: So I guess he waits for 6 confirmations, at which point you're going to tell me there's a low probability that the "illegitimate" miners have been working on a secret chain long enough supersede the legitimate chain?  
> **username_1**: Yes. This is true, with 6 being arguable number.  
> **username_1**: change "one more additional block" in my comment above, with "several additional blocks". I think number 6 you mention comes from the fact that one mining pool once mined 6 blocks in a row.  

---

