The Self-Audit: Ensuring Integrity with `verifychain`
13. The Self-Audit: Ensuring Integrity with verifychain
Trust is the enemy of security. Even though your node verifies every block as it arrives, what if your hard drive fails? What if a stray cosmic ray flips a single bit in your database? To be "Absolutely Certain," you must perform a "Self-Audit." The command for this is verifychain. It is the "Deep Scan of the Vault," the "Price of Certainty."
Analyzing the "Auditor" Code
In the source code (src/rpc/blockchain.cpp), this command calls the VerifyDB class, which performs a hierarchical set of checks, from simple header links to full script verification.
/**
* This function triggers a "Manual Audit" of the local database.
*/
static RPCMethod verifychain()
{
// ... (Arguments omitted)
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
int check_level = request.params[0].isNull() ? 3 : request.params[0].getInt<int>();
int check_depth = request.params[1].isNull() ? 6 : request.params[1].getInt<int>();
ChainstateManager& chainman = EnsureAnyChainman(request.context);
LOCK(cs_main);
// We run the 'VerifyDB' engine.
CVerifyDB vdb;
return vdb.VerifyDB(chainman.ActiveChainstate(), chainman.GetParams().GetConsensus(), chainman.ActiveChainstate().CoinsTip(), check_level, check_depth);
}
Explaining the Audit Levels to a Non-Coder
-
check_level: This is the "Intensity of the Search."- Level 0: Just check the files exist.
- Level 3: Check the "Merkle Tree" (ensure no transactions were changed).
- Level 4: Re-verify every "Signature" (the most intense check). It is the choice between a "Quick Glance" and a "Forensic Examination."
-
check_depth: This is "How Far Back" you want to look. If you set it to 100, the node will audit the last 100 blocks. If you set it to 0, it will audit the entire history of the world. It is the "Length of the Memory."
The Vigilance of the Vault
verifychain is a slow and heavy process. It uses a lot of CPU power. But it is the only way to be "Sovereign." By running this command, you are telling the universe: "I don't even trust my own hard drive. I only trust the Math." It is the "Ultimate Act of Verification."
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: