2

I know that it verifies the block hash by calculating each hash of the contiguous blocks in order, but does it verify the balance of each wallet sending the transactions as well? And does it do the block hash calculation every time, or does it just do it when it starts up?

2

When a node receives a transaction, they perform the following steps at a high level.

Inductively, they already have a set of validated transactions; these belong to the blockchain they have adopted as well as their current mempool. From this, the node has extracted a UTXO.

  1. Ensure that the inputs of the new transaction reference valid outpoints in the UTXO. This ensures that the money being spent is real.

  2. Verify the Law of Conservation, i.e., that the sum of value of the outputs does not exceed the sum of the value of the inputs. This ensures that no new money is being created. The one exception to this is when a new coinbase transaction is received with a newly mined block; in that case, new money can really be created.

  3. For each input of the new transaction, ensure that running the scriptPubKey script attached to the outpoint it connects to with the parameters specified in the scriptSig of the input, leaves the Bitcoin Script stack with a non-zero value at the top. Most of the time, this is the step where the digital signature validation happens and ensures the money is being spent by its rightful owner.

The last step above has many subcases and can function in various ways depending on whether the transaction involves a segregated witness or an attached indirect script, for example.

Lastly, once a transaction is validated by the above steps, the UTXO of the node is updated so that they can validate further transactions.

None of the above has anything to do with block validation. Block validation is a separate mechanism from transaction validation. Transactions are validated even when they don't belong to blocks. One of the block validation steps is to validate all block transactions with the above algorithm. Transaction validation does not require calculating any block hashes.

1

When a node receives a transaction, what steps does it do to verify that transaction?

This reference may be a bit obsolete (and even incorrect), but it is a good start: https://en.bitcoin.it/wiki/Protocol_rules#.22tx.22_messages

I know that it verifies the block hash by calculating each hash of the contiguous blocks in order, but does it verify the balance of each wallet sending the transactions as well?

No sense in this question. Verifying transactions has nothing with checking block hash. And there is no such thing as balance of each wallet in bitcoin protocol.

And does it do the block hash calculation every time, or does it just do it when it starts up?

Checking the hash of the header of block performed only one time when the node receives the block. No need to check it more than once, because the header and its hash can not be changed later.

0

I know that it verifies the block hash by calculating each hash of the contiguous blocks in order

This alone just verifies that the chain is unbroken. The node will also hash the block header to verify the that hash meets the difficulty requirements for that block height. It also builds the transaction merkle tree, and verifies that the merkle root in the header matches the merkle root of the transaction data.

does it verify the balance of each wallet sending the transactions as well

A wallet is a collection of addresses. As far as the blockchain is concerned, there is no such thing as a wallet, all addresses are treated individually.

A transaction consumes one or more outputs that were previously created to certain addresses. Each address can be associate with multiple outputs. When spending coins, a transaction must reference specific outputs in the past (identified by a transaction ID + output index). The node will then verify that these outputs have not previously been spent by another transaction. It will also verified that the provided scriptSig in the transaction satisfies the requirements for spending an output (usually a signature by a specific private key).

And does it do the block hash calculation every time, or does it just do it when it starts up?

Block verification is only performed as new blocks are received. If you shutdown a node and start it again, it will only run a complete validation for new blocks.

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.