Author

Topic: [Question] Question about how does the bitcoin network prevent double-spending. (Read 211 times)

hv_
legendary
Activity: 2534
Merit: 1055
Clean Code and Scale
Miners are adding blocks to the chain and need to ensure the consensus rules, one of these are exactly to ensure no double spendings. In principal these double spending can happen if such txs come in via different mempools, where miners stack new txs to build blocks from. But if a miner did mine a block causing a double spend, others will reject it and the miner has mined for a loss / he will not get any mining reward.

So miners will not mine double spends since it is not

1 economical honored
2 would make bitcoin useless anyway.
3 sadly with rbf double spends / stealing txs can be done and cannot detected as such
staff
Activity: 3458
Merit: 6793
Just writing some code
Nodes validate transactions. Transactions must adhere to certain rules, and a node will check that it does. Since every node uses the same rules to validate, every node is in agreement as to whether a transaction is valid or invalid.

In particular, one of those nodes is that a transaction only spends Unspent Transaction Outputs. Nodes maintain a database of UTXOs and checks if a transaction's input spends something in that database. If it does, there is no double spend. If it doesn't, there may be a double spend, but it is invalid regardless. Either the output has already been spent (so it is a double spend and is thus invalid), or it spends an output that does not exist. Both are invalid things to do.
legendary
Activity: 3430
Merit: 3080
so, your question is:

"I understand the whole of Bitcoin, but I don't understand it. will someone explain the whole of Bitcoin?"
newbie
Activity: 76
Merit: 0
It is my first time started learning how do bitcoin transactions happen under the hood, and all the technology behind it.
So, I come across this double-spending thing and how does the network prevent it.
Basically, if I send the same 1BTC I have in my wallet to separate bitcoin addresses, one after another, only one transaction get confirmed (the first transaction most likely) , and the other one will be recognized as invalid. So, my question is how the network (or miners) confirm that a particular transaction is invalid(1BTC has already been spent)/valid(1BTC has not been spent), and according to what factors?

I know the technology behind the blockchain, and more specifically how transactions get added inside blocks and the proof-of-work miners do to include blocks into the blockchain.

WHAT I DON'T UNDERSTAND IS HOW THE NETWORK DETERMINE A CERTAIN TRANSACTION IS VALID OR NOT?

It'd be really great if one can explain it to me more clearly, so that I could understand the whole process, without having any doubts about anything.  
Jump to: