0
So I understand how blockchains work[1]. I understand how proof-of-work works[2]. And I understand how they work together. I also understand (or at least I think I do :) how transactions work (A block can contain arbitrary data inside of it, so it can contain a message signed by A that he transfers 5 btc to B).
But where does the bitcoin itself fit in this picture?
Is it a recalculated number every time (so if A gives 1 btc to B, then if I want to confirm, I verify that A has 1 btc to give away by checking who sent him anything, and make sure that he has what to give away, etc. up until the miner's bounty)? If so, this would have to be done whenever a block is mined (if not, I (who have 0 btc in my "wallet") can certify that I give B 100 btc, mine a block, and include that transaction. And while the blockchain on its own would still work (meaning that the hashes work out and solve the proof-of-work), the accounting wouldn't).
Am I making sense or am I totally off?
[1]. It's a linked list, but instead of linking-by-address, it's a link-by-hash.
[2]. Change a part of the Node so that the node's hash would start with 100 zeros, for example.
transaction cannot create more value in its outputs than it spends in its inputs So how does the network verify inputs? – btc – 2018-04-16T23:13:52.303
A transaction creates transaction outputs. These transaction outputs are spent as inputs in other transactions. They have an associated value and a set of conditions required to spend that output. So verification means that a node will look up the transaction output that is being spent from (as it is directly referenced in the input) and makes sure that the transaction spending that output provides the necessary information required to spend that output as well as recording its value for use later in validating the transaction. – Andrew Chow – 2018-04-16T23:22:12.617
So a miner verifies the contract it puts into the blockchain? And what if it cheated and put it in even if it was illegal? Does every miner upstream verify each contract? – btc – 2018-04-17T01:48:04.763
Not just miners, full nodes (which miners are a subset of) verify all blocks and transactions. If a block contains an invalid transaction, then all full nodes (including other miners) will reject that block for violating the consensus rules and continue as if that block did not exist. The miners are not the ones who determine whether a transaction is valid; full nodes determine that for themselves. – Andrew Chow – 2018-04-17T02:28:03.577
Thanks for this answer!! Just one small question, according to this answer, as of six years ago there were almost 10 million transaction recorded in the blockchain. How far back is each transaction verified (in the official software)? And (just curious here) have there been any (in the wild) attempts at double-spending in collusion with a miner that were stopped by others?
– btc – 2018-04-17T06:10:00.643Transactions are verified "all the way back", i.e. every transaction in the chain of transactions is verified. However there are smart ways to do this besides verifying every single transaction for each new transaction. For Bitcoin Core, it maintains a separate database that contains the set of Unspent Transaction Outputs. Any UTXO in this database means that it is unspent and that the transaction it is from was valid. So when verifying a transaction, it can pull up the UTXOs it spends. If they exist, it can safely assume that all of the transactions in the transaction chain are valid. – Andrew Chow – 2018-04-17T15:35:30.633