The Vigilance of the Vault: Auditing with `verifychain`
17. The Vigilance of the Vault: Auditing with verifychain
In the world of Bitcoin, "Don't Trust, Verify" is not just a slogan; it's a "Lifestyle." Even if your node has been running for years, you might want to perform a "Deep Audit" of your own local records. This is the job of verifychain. it is the "Vigilance of the Vault," the "Self-Audit" of the Librarian.
It scans the local block files and re-verifies the math, the signatures, and the links. It is the "Price of Certainty" in a world of digital entropy.
Analyzing the "Auditor" Code
In the source code (src/rpc/blockchain.cpp), verifychain allows you to set the "Intensity" of the audit.
/**
* This function triggers a manual re-verification of the local data.
* It is the "Audit of the Librarian."
*/
static RPCMethod verifychain()
{
return RPCMethod{"verifychain",
"Verifies blockchain database.\n",
{
{"checklevel", RPCArg::Type::NUM, RPCArg::Default{3}, "0=minimal, 4=full signature check"},
{"nblocks", RPCArg::Type::NUM, RPCArg::Default{6}, "Number of blocks to check back"},
},
// ... (Example omitted)
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
int level = request.params[0].isNull() ? 3 : request.params[0].getInt<int>();
int depth = request.params[1].isNull() ? 6 : request.params[1].getInt<int>();
ChainstateManager& chainman = EnsureAnyChainman(request.context);
LOCK(cs_main);
CVerifyDB vdb;
return vdb.VerifyDB(chainman.ActiveChainstate(), chainman.GetConsensus(), chainman.ActiveChainstate().CoinsTip(), level, depth);
}
Explaining the Audit Levels to a Non-Coder
level 4: This is the "Forensic Examination." The node doesn't just check if the blocks are linked; it re-executes every single digital signature in those blocks. It is the "Total Re-Verification" of history. It is the most "Honest" command in the bridge.
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: