|
November 11, 2020, 04:58:21 PM |
|
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.
|