<p>Generally each transaction is validated when it is added to the mempool of the node. This happens when the node first sees the transaction, it doesn't wait til it is added to a candidate block for mining. The candidate block for mining would be formed out of the transactions already in the mempool - those which have already been validated by the node.</p>
<p>If another node receives a block then yes, it will validate the proof of work and other factors such as the timestamp, and it will also validate each transaction in the block that it hasn't seen before. The ones it has seen before will simply be removed from its mempool and do not need to be re-validated.</p>
<p>Re 3., nodes will not accept two conflicting transactions into their mempool. Each node will accept whichever valid transaction they see first. This may not be the one that ends up in the block eventually, but the node will correct this once one of the two conflicting transactions has been mined.</p>

CC BY-SA 4.0
2020-09-18T10:25:30.377Z
1) So, when a transaciton is being made, before it gets added to the mempool, it gets validated first, right ? and if it's correct, then that's when node adds it to mempool. Correct ?

2) how does node check if user has the right balance ? it seems like node has to loop through the whole blockchain's UTXO transactions  , isn't that tiresome ? i remember there is something else to quickly check if user has the valid balance.
Nika Kurashvili
CC BY-SA 4.0
2020-09-19T18:22:30.190Z
@NikaKurashvili Computers are ideally suited to that kind of "tedious" task. It's precisely the kind of thing that is nearly trivial for them to do. This is, for example, exactly what any search engine does. And the process of building indexes to make searches efficient is a solved problem.
David Schwartz
CC BY-SA 4.0
2020-09-21T07:33:15.293Z
@NikaKurashvili That's correct, validating nodes will store the entire set of unspent transaction outputs (UTXOs) in order to check that all inputs to a transaction are valid (not just the balance, also that they fulfill all the other conditions such as checking the script or signature required is present).
meshcollider
CC BY-SA 4.0
2020-09-18T00:53:59.057Z
2020-09-18T00:53:59.057Z
meshcollider
<p>I have a couple of questions and will try to explain them here.</p>
<p>So, let's say we have 4 nodes in the whole network.</p>
<ol>
<li><p>one of the nodes (node A) took transactions from pool. before they put it into a candidate block, they first validate each transaction, right ? if so, i guess they check balance and signature. Anything else ?  and if all good, they put each valid transactions into a candidate block and after that, they start mining this block... I guess unvalid transactions disappear or something..</p>
</li>
<li><p>Let's say node A mined the block the quickest. It put the block into its ledger and also shared this block to other nodes so they can add it to their own ledger too.  I know that other nodes won't just add it to the ledger until they confirm that this new block was really mined(will take the hash of the header and check if it's below current). Is this correct ? if so, Then, question is, will they also conduct a validation for each transaction from this block ? if yes - why ? if no - why ?</p>
</li>
<li><p>If I make 2 transactions one after another, even though I only have balance for only one transaction, those 2 will go to pool first. and I guess, when my node checks validation of transactions before putting it into a candidate block, they will see that whichever they check first is valid, and second one is not valid anymore since they already have checked the first one. Right ?</p>
</li>
</ol>

CC BY-SA 4.0
2021-04-01T04:53:50.453Z
I've been wondering the same. Every tutorial emphasizes how pow hashing works and says little about how tx are actually validated..
GN.
<bitcoin-core><blockchain><proof-of-work>
how and when does block and transaction validations take place?
Nika Kurashvili
# how and when does block and transaction validations take place?

(Asked by: username_0 on 2020-09-17)

I have a couple of questions and will try to explain them here.

So, let's say we have 4 nodes in the whole network.

1. one of the nodes (node A) took transactions from pool. before they put it into a candidate block, they first validate each transaction, right ? if so, i guess they check balance and signature. Anything else ? and if all good, they put each valid transactions into a candidate block and after that, they start mining this block... I guess unvalid transactions disappear or something..
2. Let's say node A mined the block the quickest. It put the block into its ledger and also shared this block to other nodes so they can add it to their own ledger too. I know that other nodes won't just add it to the ledger until they confirm that this new block was really mined(will take the hash of the header and check if it's below current). Is this correct ? if so, Then, question is, will they also conduct a validation for each transaction from this block ? if yes - why ? if no - why ?
3. If I make 2 transactions one after another, even though I only have balance for only one transaction, those 2 will go to pool first. and I guess, when my node checks validation of transactions before putting it into a candidate block, they will see that whichever they check first is valid, and second one is not valid anymore since they already have checked the first one. Right ?

**Tags:** bitcoin-core, blockchain, proof-of-work

> **Comments:**
> **username_1**: I've been wondering the same. Every tutorial emphasizes how pow hashing works and says little about how tx are actually validated..  

---

## 1 answers

### Answer by username_2 on 2020-09-18. Score: 3 | Accepted answer

Generally each transaction is validated when it is added to the mempool of the node. This happens when the node first sees the transaction, it doesn't wait til it is added to a candidate block for mining. The candidate block for mining would be formed out of the transactions already in the mempool - those which have already been validated by the node.

If another node receives a block then yes, it will validate the proof of work and other factors such as the timestamp, and it will also validate each transaction in the block that it hasn't seen before. The ones it has seen before will simply be removed from its mempool and do not need to be re-validated.

Re 3., nodes will not accept two conflicting transactions into their mempool. Each node will accept whichever valid transaction they see first. This may not be the one that ends up in the block eventually, but the node will correct this once one of the two conflicting transactions has been mined.

> **Comments:**
> **username_0**: 1) So, when a transaciton is being made, before it gets added to the mempool, it gets validated first, right ? and if it's correct, then that's when node adds it to mempool. Correct ?  2) how does node check if user has the right balance ? it seems like node has to loop through the whole blockchain's UTXO transactions  , isn't that tiresome ? i remember there is something else to quickly check if user has the valid balance.  
> **username_3**: @username_0 Computers are ideally suited to that kind of "tedious" task. It's precisely the kind of thing that is nearly trivial for them to do. This is, for example, exactly what any search engine does. And the process of building indexes to make searches efficient is a solved problem.  
> **username_2**: @username_0 That's correct, validating nodes will store the entire set of unspent transaction outputs (UTXOs) in order to check that all inputs to a transaction are valid (not just the balance, also that they fulfill all the other conditions such as checking the script or signature required is present).  

---

