2

I understand that transactions go into mempool and a miner "verifies" the transactions such as ensuring the user has the appropriate funds and correct signature. Specifically, how are available funds verified? It seems like you would have to iterate through every relevant transaction in every block to determine whether the funds have already been spent or not. This seems quite time consuming so surely there is a shortcut to verifying a user has available funds to spend.

How does a miner verify that the funds are available and not already spent without iterating through the entire Blockchain?

6

How does a miner verify that the funds are available and not already spent without iterating through the entire Blockchain?

Full nodes do iterate through the entire blockchain, but only once. As they work through the chain's history, they create and continuously update a 'UTXO set', which is just basically a list of all valid coins. With each new block, the full nodes on the network will verify the block's contents, and update their UTXO set as they do. This makes verifying new transactions easy: the node just checks their UTXO set to ensure the new transaction is spending valid inputs.

3

How does a miner verify that the funds are available and not already spent without iterating through the entire Blockchain?

In order to know all the unspent transaction output you need the entire blockchain. This is what "full nodes" do. Full nodes look at the entire blockchain all the way back to the genesis block.

"Simplified payment verification" (SPV) nodes are lightweight nodes that don't download the entire block chain, but they need to rely on full node peers for verification.

3

Tl;dr: Bitcoin is cash, not a bank account.

Mints don't keep track of which people hold each of their coins or how much of their cash each person holds.

Mints provide users of their coins with some ways of distinguishing genuine coins from forged coins.


How are funds verified?

They aren't. The Bitcoin network doesn't know about or care about funds. It mainly knows about transactions. From knowledge about transactions comes knowledge about "coins".

I understand that transactions go into mempool

Yes, unconfirmed transactions go into the individual mempool of each node. As answers to other questions have stated, there is no coordination of mempool contents across nodes.

and a miner "verifies" the transactions

Well, all nodes verify transactions and not just miners. It isn't one miner. You may be conflating verification with confirmation. These are two very different things.

such as ensuring the user has the appropriate funds.

No nodes care about whether users have appropriate funds, the network doesn't really know anything about users.

and correct signature.

Yes, any signatures in the transaction are verified by every node separately. The system was designed so that no-one has to rely on some stranger doing verification for them. Signatures don't really identify actual people though.

Specifically, how are available funds verified?

Each node separately keeps track of its own list of all the unspent "coins" that exist globally. By "coins" we usually mean unspent transaction outputs (UTXOs).

It seems like you would have to iterate through every relevant transaction in every block to determine whether the funds have already been spent or not.

True.

This seems quite time consuming so surely there is a shortcut to verifying a user has available funds to spend.

No one care whether users have funds. We only care that coins are real (unspent). Its like cash. It is cash. When you buy something with cash, no one cares how much money you have, only that the cash you give them is not a forgery.

There is no real shortcut. Every nodes keeps track of a list of all genuine (unspent) coins.

lightweight nodes (SPV nodes) do rely on strangers to do some things for them - and consequently they are less secure.

How does a miner verify ...

The same way every other type of node verifies.

... that the funds are available and not already spent without iterating through the entire Blockchain?

By iterating through the entire blockchain once and creating useful, but much smaller, lists from it. Also by indexing those lists for faster retrieval. So this would include an indexed list of known good verified UTXOs that are acceptable to this node as inputs to future transactions it receives data about.

2

Spendable funds in Bitcoin are tracked in the form of Unspent Transaction Outputs (UTXOs). Each transaction consumes some existing UTXOs in the inputs, and creates new transaction outputs to assign recipients funds. Every full node keeps track of the entire set of spendable balances in a datastructure we call the UTXO set. While you can think of the blockchain as Bitcoin's journal of transactions, the UTXO set is the ledger of balances.

Every full node recreates the UTXO set independently by starting with an empty UTXO set and applying every single transaction recorded in the blockchain up to the current block. Once they're caught up to the present, they have the validated the entire history of the Bitcoin network and end up with the complete set of all existing funds. The UTXO set suffices to verify whether a transaction is valid, because it explicitly contains the information which UTXOs are available for spending, they do not need to go back and "iterate through every relevant transaction" again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.