Bitcoin Forum
November 13, 2024, 06:04:51 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Question on How Transaction Verification Works  (Read 264 times)
BlockchainNoob (OP)
Newbie
*
Offline Offline

Activity: 1
Merit: 1


View Profile
December 27, 2017, 12:11:03 AM
Last edit: December 27, 2017, 12:23:39 AM by BlockchainNoob
Merited by ABCbits (1)
 #1

So I have been trying to understand the process on how transactions get verified but have a few questions that I was hoping you guys could answer. My current understanding of a transaction is like this:

I send 1 bitcoin from my public key (signed with my private key) to another public key. This is then sent to the mempool of the nearest node and then if it meets the requirements of a valid transaction this is broadcast to all other nodes on the network. If I add a high fee to my transaction it will be picked up by a miner and added to a block quickly, if I select a low fee or no fee it risks staying in the mempool. If it is not picked up by a miner after a certain amount of time it will be returned to my wallet.

Question 1: How does the miner verify my transaction in the mem pool? Does the miner's software automatically reference all the existing transactions on the blockchain to ensure that my account has 1 bitcoin to send?

Questions 2: Are only valid transactions added to a block to be verified?

Question 3: It is my understanding that a block needs an even number of transactions in a block in order to hash down to a merkle root. If transactions are in fact verified in a block and not in the mempool, is an additional transaction added to the block when one is discarded so that there are an even number of transactions to hash down to a merkle root?

Question 4: Do miners create their own custom software or are all miners running the exact same software?

If anyone could help me understand the exact path a transaction goes through from start to finish I would really appreciate it. I looked around for answers, but most didn't go into enough detail.

EDIT: Please move this to the newbie forum. Sorry for posting in the wrong section  Undecided
DannyHamilton
Legendary
*
Offline Offline

Activity: 3486
Merit: 4847



View Profile
December 27, 2017, 02:23:59 AM
Merited by ABCbits (3)
 #2

So I have been trying to understand the process on how transactions get verified but have a few questions that I was hoping you guys could answer. My current understanding of a transaction is like this:

I send 1 bitcoin from my public key (signed with my private key) to another public key. This is then sent to the mempool of the nearest node and then if it meets the requirements of a valid transaction this is broadcast to all other nodes on the network. If I add a high fee to my transaction it will be picked up by a miner and added to a block quickly, if I select a low fee or no fee it risks staying in the mempool. If it is not picked up by a miner after a certain amount of time it will be returned to my wallet.

While that is a reasonable high-level understanding of transactions, it gets some of the details incorrect.

Try this:

You create and sign a transaction that is funded with bitcoins that you received in earlier transactions. The public key that was indicated in those earlier transactions indicate which private key must be used to generate the signature. Your transaction indicates a public key that must be used when verifying a signature that spends those bitcoins.

This transaction is shared with ALL the nodes that your wallet is connected to.

Each node verifies for itself that the transaction is valid. If it is, then the transaction is added to the node's own mempool and is shared with all the nodes that are connected to that node. Each of those nodes verifies for itself that the transaction is valid. If it is, then the transaction is added to the node's own mempool and is shared with all the nodes that are connected to that node. And so on until nearly all nodes on the network (including mining nodes) have heard about the transaction.

If you add a high enough fee to your transaction it will be added to one of the next few blocks that are solved worldwide.

If you select a low fee or no fee it risks staying in the mempool (or perhaps even never being added to the mempool of some nodes at all). If it is not included in a block after a whilemany nodes may drop it from their mempool and forget that the transaction ever existed.

Depending on the wallet software that you are using, your wallet might choose to also forget about the transaction after a while (in whice case it will once again show those bitcoins as being available for you to try spending again) or it may re-broadcast the transaction (to remind all the nodes and miners about it), or it may choose to just continue to remember the transaction without re-broadcasting it until you take some action to drop the transaction from your wallet or re-broadcast it.

Any other node that has ever seen the transaction can re-broadcast the transaction if they want to so long as it is valid.

Question 1: How does the miner verify my transaction in the mem pool?

The solo-miner (or mining pool operator) runs node software.  That node software will verify the transaction BEFORE adding it to it's own mempool.

Does the miner's software automatically reference all the existing transactions on the blockchain to ensure that my account has 1 bitcoin to send?

Node software generally keeps a list of unspent transaction outputs (often referred to as the UTXO).  Your transaction is funded by listing (as inputs) unspent transaction outputs. Any transaction outputs that are listed as inputs are then considered to be "spent" and are removed from the UTXO.  So, if your transaction lists any inputs that are not in the UTXO, then your transaction is invalid.  If any signatures in your transaction do not validate properly, then your transaction is invalid.  If any of the structure of your transaction does not line up with the required structure, then your transaction is invalid.

Questions 2: Are only valid transactions added to a block to be verified?

Correct.  Nodes will not add invalid transactions to their mempool.  Nodes will not relay invalid transactions to other nodes. Miners will not accept invalid transactions into the blocks they are building. Nodes will not accept into their blockchain any blocks with invalid transactions. Nodes will not relay blocks with invalid transactions to other nodes.

Question 3: It is my understanding that a block needs an even number of transactions in a block in order to hash down to a merkle root.

This would appear to be untrue.  The merkle algorithm has processes for dealing with odd numbers of transactions.

If transactions are in fact verified in a block and not in the mempool,

Transactions are verified before being added to a mempool.  They are again verified before adding a block to a blockchain.

is an additional transaction added to the block when one is discarded

The protocol rules allow the miner to add as many or as few transaction to their block as they like so long as they include AT LEAST the block reward transaction, AND the block does not exceed the maximum allowed block size (or block weight).  The only other requirement is that the transactions in the block are valid.  The miner can use any criteria they like to choose which transactions to include in the block they are working on and which to leave out.  Since most miners and mining pools are profit motivated, they will generally choose the transactions that pay the highest fee per byte (or per block weight).

Question 4: Do miners create their own custom software or are all miners running the exact same software?

I'm sure there are some solo-miners and some mining pools that have created their own custom software.  I'm sure there are also some solo-miners and some mining pools that are using publicly available open source software.

hopeAo
Jr. Member
*
Offline Offline

Activity: 42
Merit: 2


View Profile
December 27, 2017, 02:56:35 AM
 #3

So I have been trying to understand the process on how transactions get verified but have a few questions that I was hoping you guys could answer. My current understanding of a transaction is like this:

I send 1 bitcoin from my public key (signed with my private key) to another public key. This is then sent to the mempool of the nearest node and then if it meets the requirements of a valid transaction this is broadcast to all other nodes on the network. If I add a high fee to my transaction it will be picked up by a miner and added to a block quickly, if I select a low fee or no fee it risks staying in the mempool. If it is not picked up by a miner after a certain amount of time it will be returned to my wallet.

Question 1: How does the miner verify my transaction in the mem pool? Does the miner's software automatically reference all the existing transactions on the blockchain to ensure that my account has 1 bitcoin to send?

Questions 2: Are only valid transactions added to a block to be verified?

Question 3: It is my understanding that a block needs an even number of transactions in a block in order to hash down to a merkle root. If transactions are in fact verified in a block and not in the mempool, is an additional transaction added to the block when one is discarded so that there are an even number of transactions to hash down to a merkle root?

Question 4: Do miners create their own custom software or are all miners running the exact same software?

If anyone could help me understand the exact path a transaction goes through from start to finish I would really appreciate it. I looked around for answers, but most didn't go into enough detail.

EDIT: Please move this to the newbie forum. Sorry for posting in the wrong section  Undecided


The node will look at a transaction as it arrives and then run many of checks to verify it. Each node builds its own transaction pool, which are mostly the same. The conditions can change and evolve over time and a present list can be checked through the AcceptToMemoryPool, CheckTransaction and CheckInputs functions in the bitcoin client.
john139
Newbie
*
Offline Offline

Activity: 32
Merit: 0


View Profile
April 29, 2019, 12:29:15 PM
 #4



Transactions are verified before being added to a mempool.  They are again verified before adding a block to a blockchain.





Can somebody explain me if in this step double-spending is checked or not ?

definitely it should be checked before being added to the candidate block otherwise after all hashing process that miners make to reach target difficulty the block will be invalid and all the efforts will be nothing .
bob123
Legendary
*
Offline Offline

Activity: 1624
Merit: 2481



View Profile WWW
April 29, 2019, 01:44:49 PM
 #5

Transactions are verified before being added to a mempool.  They are again verified before adding a block to a blockchain.

Can somebody explain me if in this step double-spending is checked or not ?


Yes.

If the transaction is valid -> add to mempool. If the transaction is invalid -> discard it.
If a transaction is recognized as a double spending transaction -> TX is not valid. Therefore it won't get added to the mempool.

For the future:
Please create a new thread if you have a question which is unrelated the OP or when the thread you want to post in is very old (1.5 years definitely is).
Necroposting in such a thread will just attract spammer.

bob123
Legendary
*
Offline Offline

Activity: 1624
Merit: 2481



View Profile WWW
April 30, 2019, 06:21:40 AM
 #6

If a transaction is recognized as a double spending transaction -> TX is not valid.
That depends on what code the miner who submits a block has.
Most likely most miners do not allow a double spend attempt, basically being defined as sending another tx from the same coin balance; but there may be a small % of miners who may allow the second tx to be valid, so if one comes in around the time one of those miners submits a block, it could in theory occur.

I meant a double spending of an already confirmed transaction, not a double spend attempt on an unconfirmed transaction. I should have made this more clear.

A double spending of an already confirmed transaction won't be included by any miner (or else they would simply lose the block reward because the block won't be accepted as a valid one from the network).
However, a double spending of an unconfirmed transaction can definitely happen (and especially if the RBF-flag is set. A RBF-transaction basically is a double spending transaction with an increased fee).

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!