Bitcoin Forum
November 07, 2024, 04:33:22 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to find the right module in bitcoin core ?  (Read 180 times)
hmrawal (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
November 11, 2020, 04:45:20 PM
 #1

I am trying to learn how the bitcoin core source code functions so that I can test out few ideas I have in my head.
But for that I need to know which functions are used in every module.
The source code is so vast that I am confused now. Can anyone tell me how do I find the right module to start learning the code ?

For example if I want to learn how the code works for signing a message where should I begin with ?
I know one module will lead to another but where should I start from for that particular task (i.e. signing a message)?
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3542
Merit: 6886


Just writing some code


View Profile WWW
November 11, 2020, 04:58:21 PM
Merited by ABCbits (3), NotATether (2), Heisenberg_Hunter (2), mocacinno (1)
 #2

Bitcoin Core interacts with the outside world primarily through 3 ways: the P2P network, RPC interface, and GUI. The RPC and GUI to roughly the same things, and it's easier to understand RPCs, so I will ignore the GUI for now.

When you want to see what happens when a user does some action, find the RPC for that action. Then you can find the function that handles that RPC in the code, and follow what it does from there. All of the RPCs can be find in the files in src/rpc/, in src/wallet/rpcwallet.cpp, or in src/wallet/rpcdump.cpp. The functions are named the same as the RPC itself so they should be easy to find.

For example, if you want to learn how message signing works, you would first look at the list of RPCs using the help RPC. Then you would see a command called signmessage. You can even look at the help text for signmessage by doing help signmessage. This would tell you that this RPC is what you would use to sign a message. Now you can search for a function named signmessage in the code. You can do this with git grep. Because it is a function, you can append a parentheses to filter out other uses of signmessage. So you would do git grep -n "signmessage(" (the -n tells git grep to print out the line numbers too. The result is that you see that there is a function signmessage() in src/wallet/rpcwallet.cpp. Now you can go there, find the function, and trace what it calls.

The other way in which Bitcoin Core receives data is through the P2P network. All of the handling of network messages is done in src/net_processing.cpp in a function named ProcessMessage. This function has several ifs to identify what type of message each message is and apply the appropriate processing. So you can search within this function for the network message that you want and trace from there how that is being handled.

For example, if you wanted to learn how blocks were processed, you would look in ProcessMessage for the block message. You would look for if (msg_type == NetMsgType::BLOCK). Once you find it, you can just trace the code to see how blocks are being handled and processed.

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!