The Skeleton of Truth: Exploring `getblockheader`
The Skeleton of Truth: Exploring getblockheader
Sometimes you don't need the whole book; you just need to see the cover. In Bitcoin, the cover of a block is called the Header. It is a tiny, 80-byte piece of data that contains all the cryptographic proof needed to verify the block. The command for this is getblockheader. It is the "Skeleton of Truth," the "Lightweight Protocol of the Bridge."
Analyzing the "Skeleton Retrieval" Code
In the source code (src/rpc/blockchain.cpp), the getblockheader command fast because it only reads from the node's memory-based index.
/**
* This function retrieves ONLY the "Skeleton" (the header) of a block.
*/
static RPCMethod getblockheader()
{
return RPCMethod{
"getblockheader",
"Returns an Object with information about blockheader.\n",
{
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"},
{"verbose", RPCArg::Type::BOOL, RPCArg::Default{true}, "true for JSON, false for hex bytes"},
},
// ... (Example omitted)
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
uint256 hash(ParseHashV(request.params[0], "hash"));
ChainstateManager& chainman = EnsureAnyChainman(request.context);
const CBlockIndex* pblockindex = WITH_LOCK(cs_main, return chainman.m_blockman.LookupBlockIndex(hash));
if (!pblockindex) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
return blockheaderToJSON(*chainman.ActiveChain().Tip(), *pblockindex, chainman.GetConsensus().powLimit);
}
Explaining the Logic to a Non-Coder
blockheaderToJSON: This is the "Translation Table." It takes the binary code and turns it into English: the timestamp, the link to the previous block, and the "Nonce" (the winning number). It is the "Decoding of the Seal."
The Power of the Header
The header is what makes Bitcoin "Scale." Because it is so small, even a mobile phone can download all the headers in history and verify the chain without needing 500GB of space. This is SPV (Simplified Payment Verification). The header is the "Concentrated Essence" of Bitcoin's security. It is the "Unbreakable Link" between the past and the present.
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: