Bitcoin Forum
May 25, 2024, 07:54:59 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Hello! My name is Mark Ingle....  (Read 235 times)
MarkIngle (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 0


View Profile
April 03, 2021, 03:06:03 AM
 #1

...I am new to this forum and the bitcoin architecture.  After downloading the source code from Github I am having trouble navigating the structure of the code.  My interest is learning the logic that performs the hashing to create the Proof-of-Work and links the blocks.  My goal is to learn this part as I think it has other uses in the technology field potentially IoT and communications (top four layers).

Is there any documentation that explains the code architecture at a high level?

Thanks in advance.....and thanks to the development team that has kept this solution going!  Really awesome work!
NotATether
Legendary
*
Online Online

Activity: 1610
Merit: 6761


bitcoincleanup.com / bitmixlist.org


View Profile WWW
April 03, 2021, 05:38:27 AM
 #2

I assume that by source code you mean Bitcoin Core's github repo? https://github.com/bitcoin/bitcoin

My interest is learning the logic that performs the hashing to create the Proof-of-Work and links the blocks.  My goal is to learn this part as I think it has other uses in the technology field potentially IoT and communications (top four layers).

If you want to find the RPC call in which full nodes receive submitted blocks to link them on the chain, that section is located in this file: https://github.com/bitcoin/bitcoin/blob/80a699fda9ff1129546cabbf17e955680a1cc705/src/rpc/mining.cpp#L108-L137 . GitHub has an advanced search feature that let's you find usages of functions so that should help you locate the called functions.

To see how the difficulty adjustment is done look inside src/pow.cpp https://github.com/bitcoin/bitcoin/blob/master/src/pow.cpp

If however you want to see the process of hashing to make a valid block then you should look at the source code of a proper miner such as cgminer. Bitcoin Core used to have a built-in miner but that was removed a few versions back as CPU mining became inefficient.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
MarkIngle (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 0


View Profile
April 03, 2021, 01:56:45 PM
 #3

Thank you very much!  Yes the bitcoin source code.

I found pow.cpp last night so thanks for confirming!  Really interesting code...I am not that familiar with hashing but I think I am able figure things out with all of the information available.  I think this will an interesting rabbit hole!

Thank you for the info on cgminer too.  I have Bitcoin Core running on my Mac just to help me understand as I am a hands on learner.  I didnt expect it to work but could see that has inbound/outbound connections with little activity.  With the current demands of processing the long chain it make sense the mining task would be off loaded.

I really appreciate the help!

What is the main purpose of Bitcoin Core?....transactions within the Bitcoin network?

Mark
NotATether
Legendary
*
Online Online

Activity: 1610
Merit: 6761


bitcoincleanup.com / bitmixlist.org


View Profile WWW
April 03, 2021, 04:32:29 PM
 #4

What is the main purpose of Bitcoin Core?....transactions within the Bitcoin network?

It's purpose is to verify all transactions on the blockchain from head to toe, and to facilitate other full nodes' verification process by sending them copies of blocks and transactions it has. Malformed transactions and blocks are dropped, and the nodes sending them are eventually blocked by their receivers from connecting to them. In this way we create a self-reliant network of nodes which collectively guarantee the integrity of the blockchain.

This works because all kinds of payment terminals like exchanges, web wallets and lightweight clients must all eventually relay their transactions to a full node.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Coding Enthusiast
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
April 04, 2021, 02:47:17 AM
Merited by hugeblack (2)
 #5

I am not that familiar with hashing but I think I am able figure things out with all of the information available.  I think this will an interesting rabbit hole!
Maybe this visualization can help understand what's happening in the hashing process:
Just know that headers are 80 bytes and SHA256 breaks data into 64-byte blocks when compressing them.

https://bitcointalk.org/index.php?topic=5158000.0

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
MarkIngle (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 0


View Profile
April 04, 2021, 04:22:04 AM
 #6

Yes thank you!  Diagrams are the best when it comes to iterative logic in code.  Thank you very much!!!
MarkIngle (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 0


View Profile
April 04, 2021, 04:30:23 AM
 #7

I also found this video with links doing a step by step of hashing data and how it works....Im putting it here for others falling down the same rabbit hole!

https://www.youtube.com/watch?v=_160oMzblY8

MarkIngle (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 0


View Profile
April 06, 2021, 12:47:44 AM
 #8

A Block is composed of a block header and transactions(~2000).  The header is composed of the previous block hash, time stamp, nonce, and merkle root.  Two questions :  (1) Where in the process does this information get confirmed once a hash has been determined? (2) When and where is the data decrypted?
pooya87
Legendary
*
Offline Offline

Activity: 3458
Merit: 10588



View Profile
April 06, 2021, 02:57:36 AM
 #9

(1) Where in the process does this information get confirmed once a hash has been determined?
The process of mining is like this:
- Miner selects a bunch of preferred transaction from its node's mempool and creates a new block with them and fills in the header variables (that includes computing the merkle root hash and setting the correct target).
- Then the miner computes the header hash
- Then the miner converts that hash to an integer and compares it with the target. If it is <= target then moves to last step, if not the miner has to change something in the header to perform previous step and this step again. First thing that is changed is the nonce, if they run out of nonces to change they have to change something else, usually an extra nonce in the coinbase transaction that would also change the merkle root hash.
- Last step is to publish the block on the network network to let other peers know that they have found a new block.

Quote
(2) When and where is the data decrypted?
There is no encryption anywhere in bitcoin protocol.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
MarkIngle (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 0


View Profile
April 06, 2021, 11:35:57 PM
 #10

Quote
(2) When and where is the data decrypted?
There is no encryption anywhere in bitcoin protocol.
[/quote]

decrypted - Poor choice of word on my part.  Sorry.  My 2nd question was really about the data used to create the merkle root.  Is the merkle root hash used in some way to breakout the transaction data so that is can be confirmed?
pooya87
Legendary
*
Offline Offline

Activity: 3458
Merit: 10588



View Profile
April 07, 2021, 03:31:06 AM
Merited by DarkStar_ (5), icopress (1)
 #11

My 2nd question was really about the data used to create the merkle root.  Is the merkle root hash used in some way to breakout the transaction data so that is can be confirmed?
Merkle root hash is computed using the transaction hash of all transactions in the block by creating a "merkle tree" then selecting and hashing 2 transaction hashes at a time.

tx1 tx2 tx3 tx4 tx5 tx5duplicate
 └───┘   └───┘   └───┘
  h1&2    h3&4    h5&5  h5&5duplicate
   └───────┘       └──────┘
     h12&34         h55&55
       └──────────────┘
          root hash

Merkle root hash is there to ensure that the transactions in the block can not change in any way (remove, add new, change position,...) because if any of these changes occur the transaction hash is changed and consequently the merkle root hash is changed.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
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!