<p>If two blocks has the same ancestor, we say we have a fork. If a node sees a fork, it assumes the first block it saw as the best one, but keeps the other. As the time goes on, eventually someone will solve the PoW for the next block, and this block will likely extend one of the two chains (i.e. this block will be right after one of the fork's one). The chain with more work'll always win, so whichever chain gets extended becomes the active one.<br />
If Node-8's block gets extended, then the network'll adopt it as the current best chain, even if they see Node-5's block first. Since Node-8's block got through, A will be sent to B, and the other transaction will be invalidated.<br />
That's why some people wait some confirmations until get a payment as final because there's no risk of reorg (reorg means change the current tip, replacing some blocks we considered part of the best chain, and replacing by others).</p>

CC BY-SA 4.0
2022-07-12T00:12:50.277Z
2022-07-12T00:12:50.277Z
Davidson Souza
<p>I'm going to offer a frame challenge. Your scenario makes no sense to me, because you seem to have a wrong perception of <a href="https://bitcoin.stackexchange.com/q/12427/5406">how the blockchain works</a> and is propagated on the network.</p>
<p>First problem: at 6:02 Node-5 has already heard about transaction A-&gt;B. Transactions are only propagated at best effort but transactions that are candidates for the next block should get to most nodes within 30 seconds. No biggie: we can fix that by making the attacker send at 6:00 in parallel A-&gt;B to Node-8 and A-&gt;C to Node-5. So Node-5 and Node-8 do have different views on the unconfirmed transactions now and each considers their payment valid. If they see the other transaction, they will reject it because it's in conflict with the one they have already.</p>
<p>Now at 6:08 Node-8 finds a new block which includes A-&gt;C. Block propagation has the highest priority and the propagation of blocks is guaranteed. Some nodes might not hear about an unconfirmed transaction, but every node hears about a new block <a href="https://bitcoin.stackexchange.com/a/113506/5406">within seconds</a>. If the block is valid and the new best chain-tip, everyone extends their blockchain with that new block. At this point Node-8 realizes that A-&gt;C has spent the funds and the transaction A-&gt;B is now invalid. Node-8 drops A-&gt;B from their mempool. Every miner, including Node-8, switches to trying to find a new block that follows the block that was published by Node-5. The doublespend has been resolved, because only one of the transactions has survived.</p>
<p>Nodes validate transactions before they add them to their mempool. At that point they can only assess whether a transaction would be eligible to be included in a block, and they only keep the first (or best) conflicting transaction they see. Once a block is published the content of the block always supersedes the content of their mempool. Blocks are the shared ground truth of the network and the blockchain has only one block at every height. When the chaintip progresses, everyone starts working on the new height.</p>
<p>If Node-5 and Node-8 had found their blocks at the same time (within a couple seconds of each other), they would have each broadcast theirs to their peers. Every node would stick to whatever block they had seen first until another block were found. Then everyone would converge on the new best chaintip and the other block would become an extinct chaintip, not part of the best chain.</p>

CC BY-SA 4.0
2022-07-12T17:26:26.000Z
Thanks a lot for your support, it helped me a lot and The time reference that is taken in question is just for representing the sequence of events but not to represent the exact time range that it would take. Thanks a lot again for info :)
Arjun Reddy
CC BY-SA 4.0
2022-07-12T17:48:31.457Z
I've extended my answer to cover the case that the competing blocks were found at the same time.
Murch
CC BY-SA 4.0
2022-07-12T03:34:13.543Z
2022-07-12T17:47:49.303Z
2022-07-12T17:47:49.303Z
Murch
<blockquote>
<p><strong>... Node-8 has lost a lot of computation power, which is very unfair?</strong></p>
</blockquote>
<p>The Bitcoin network protocols do not protect or reimburse a miner for work they honestly carry out mining a valid transaction passed to them by a secretly malicious person attempting a double spend.</p>

CC BY-SA 4.0
2022-07-12T09:40:32.923Z
2022-07-12T09:40:32.923Z
RedGrittyBrick
<p><strong>In the network nodes below as shown in picture:</strong>
<a href="https://i.sstatic.net/Eiotz.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Eiotz.jpg" alt="Nodes" /></a></p>
<p>Let's say <strong>A</strong> is trying to double spend by sending bitcoins to <strong>B,C</strong> (<strong>A</strong>-&gt;<strong>B</strong>) and <strong>(A-&gt;C)</strong> and let's say A tried to relay <strong>(A-&gt;B)</strong> transaction to honest Node - 8 and at this point let's assume that current time is <strong>6'o clock(might be any time zone)</strong>. So at <strong>6:00</strong> <strong>A</strong> relayed its transaction (<strong>A</strong>-&gt;<strong>B</strong>) to honest Node-8. let's say at <strong>6:02</strong> (exactly after 2 mins) <strong>A</strong> tries to double spend that bitcoin and sends that bitcoin (<strong>A-&gt;C</strong>) to honest Node - 5 and at <strong>6:04</strong> let's say honest Node-5 validates all transaction to be valid since <strong>A's</strong> Input UTXOs are not broadcasted to network until now.</p>
<p>At the same time let Node-8 also validates all transaction in its block to be valid, since <strong>A's</strong> Input UTXOs still exist. let's say at <strong>6:05</strong> Node-5 and Node-8 are trying to solve hash puzzle to mine a their block and at <strong>6:08</strong> lets say Node-5 solved the puzzle and broadcasted it's block to network. While Node-8 is trying to solve the puzzle with the transactions it has**(A-&gt;B)**. Let's say at <strong>6:14</strong> Node-8 solved the puzzle and tried to broadcast its block <strong>which contains (A-&gt;B which is double spending).</strong> Then the peer-nodes will reject the block that Node-8 has broadcasted because it has an invalid transaction(Double spent transaction).</p>
<p><strong>- Here the fault is not Node-8, Node-8 is honest doing its work by following protocol. Even though peer-nodes in this case has rejected honest Node-8's Block and Node-8 has lost a lot of computation power, which is very unfair?</strong></p>
<p><strong>- How Bitcoin protocol solves/help this issue for Node-8?</strong></p>
<p><strong>Correct me if I am wrong...</strong></p>

<blockchain><mining-theory><blockchain-fork><doublespend><block-validity>
How does Bitcoin prevent double-spending without penalizing miners?
Arjun Reddy
# How does Bitcoin prevent double-spending without penalizing miners?

(Asked by: username_0 on 2022-07-11)

**In the network nodes below as shown in picture:**
[![Nodes](https://i.sstatic.net/Eiotz.jpg)](https://i.sstatic.net/Eiotz.jpg)

Let's say **A** is trying to double spend by sending bitcoins to **B,C** (**A**->**B**) and **(A->C)** and let's say A tried to relay **(A->B)** transaction to honest Node - 8 and at this point let's assume that current time is **6'o clock(might be any time zone)**. So at **6:00** **A** relayed its transaction (**A**->**B**) to honest Node-8. let's say at **6:02** (exactly after 2 mins) **A** tries to double spend that bitcoin and sends that bitcoin (**A->C**) to honest Node - 5 and at **6:04** let's say honest Node-5 validates all transaction to be valid since **A's** Input UTXOs are not broadcasted to network until now.

At the same time let Node-8 also validates all transaction in its block to be valid, since **A's** Input UTXOs still exist. let's say at **6:05** Node-5 and Node-8 are trying to solve hash puzzle to mine a their block and at **6:08** lets say Node-5 solved the puzzle and broadcasted it's block to network. While Node-8 is trying to solve the puzzle with the transactions it has\*\*(A->B)\*\*. Let's say at **6:14** Node-8 solved the puzzle and tried to broadcast its block **which contains (A->B which is double spending).** Then the peer-nodes will reject the block that Node-8 has broadcasted because it has an invalid transaction(Double spent transaction).

**- Here the fault is not Node-8, Node-8 is honest doing its work by following protocol. Even though peer-nodes in this case has rejected honest Node-8's Block and Node-8 has lost a lot of computation power, which is very unfair?**

**- How Bitcoin protocol solves/help this issue for Node-8?**

**Correct me if I am wrong...**

**Tags:** blockchain, mining-theory, blockchain-fork, doublespend, block-validity


---

## 3 answers

### Answer by username_1 on 2022-07-12. Score: 2

If two blocks has the same ancestor, we say we have a fork. If a node sees a fork, it assumes the first block it saw as the best one, but keeps the other. As the time goes on, eventually someone will solve the PoW for the next block, and this block will likely extend one of the two chains (i.e. this block will be right after one of the fork's one). The chain with more work'll always win, so whichever chain gets extended becomes the active one.  
If Node-8's block gets extended, then the network'll adopt it as the current best chain, even if they see Node-5's block first. Since Node-8's block got through, A will be sent to B, and the other transaction will be invalidated.  
That's why some people wait some confirmations until get a payment as final because there's no risk of reorg (reorg means change the current tip, replacing some blocks we considered part of the best chain, and replacing by others).


---

### Answer by username_2 on 2022-07-12. Score: 2

I'm going to offer a frame challenge. Your scenario makes no sense to me, because you seem to have a wrong perception of [how the blockchain works](https://bitcoin.stackexchange.com/q/12427/5406) and is propagated on the network.

First problem: at 6:02 Node-5 has already heard about transaction A->B. Transactions are only propagated at best effort but transactions that are candidates for the next block should get to most nodes within 30 seconds. No biggie: we can fix that by making the attacker send at 6:00 in parallel A->B to Node-8 and A->C to Node-5. So Node-5 and Node-8 do have different views on the unconfirmed transactions now and each considers their payment valid. If they see the other transaction, they will reject it because it's in conflict with the one they have already.

Now at 6:08 Node-8 finds a new block which includes A->C. Block propagation has the highest priority and the propagation of blocks is guaranteed. Some nodes might not hear about an unconfirmed transaction, but every node hears about a new block [within seconds](https://bitcoin.stackexchange.com/a/113506/5406). If the block is valid and the new best chain-tip, everyone extends their blockchain with that new block. At this point Node-8 realizes that A->C has spent the funds and the transaction A->B is now invalid. Node-8 drops A->B from their mempool. Every miner, including Node-8, switches to trying to find a new block that follows the block that was published by Node-5. The doublespend has been resolved, because only one of the transactions has survived.

Nodes validate transactions before they add them to their mempool. At that point they can only assess whether a transaction would be eligible to be included in a block, and they only keep the first (or best) conflicting transaction they see. Once a block is published the content of the block always supersedes the content of their mempool. Blocks are the shared ground truth of the network and the blockchain has only one block at every height. When the chaintip progresses, everyone starts working on the new height.

If Node-5 and Node-8 had found their blocks at the same time (within a couple seconds of each other), they would have each broadcast theirs to their peers. Every node would stick to whatever block they had seen first until another block were found. Then everyone would converge on the new best chaintip and the other block would become an extinct chaintip, not part of the best chain.

> **Comments:**
> **username_0**: Thanks a lot for your support, it helped me a lot and The time reference that is taken in question is just for representing the sequence of events but not to represent the exact time range that it would take. Thanks a lot again for info :)  
> **username_2**: I've extended my answer to cover the case that the competing blocks were found at the same time.  

---

### Answer by username_3 on 2022-07-12. Score: 0

> **... Node-8 has lost a lot of computation power, which is very unfair?**

The Bitcoin network protocols do not protect or reimburse a miner for work they honestly carry out mining a valid transaction passed to them by a secretly malicious person attempting a double spend.


---

