Module 6: Blocks and Blockchain State

Learning Objectives

By the end of this module, you will:

Read and interpret block and chain data using Bitcoin Core commands

Understand chain tips and how re-orgs occur in regtest

Track transaction confirmations and understand depth

Inspect the mempool for unconfirmed transactions


1

Reading Block Data

After mining blocks in regtest or syncing a mainnet/testnet node, you can inspect block data using several bitcoin-cli commands.

Get the hash of the most recent block:

Get best block hash

Retrieve full block data using the hash:

Get block data

To get just the header:

Get block header

This includes:

Height

Timestamp

Version

Merkle root

Previous block hash

Nonce

Chainwork

Get block hash by height:

Get block hash by height

Example:

Example: Get block data for block 1

2

Using getchaintips and Understanding Chain Re-orgs

The command getchaintips returns all known tips of the blockchain:

Getchaintips

This is useful in regtest when you're simulating chain reorganizations. For example, if you invalidate a block:

Simulate chain reorganization

Then generate a longer competing chain (replace <miner_address> with your mining address):

Generate chain

Your node will adopt the longer chain tip, causing a re-org. This is how Bitcoin resolves consensus forks.


3

Understanding Confirmations and Depth

A transaction's confirmation count is equal to the number of blocks on top of the block that includes it.

To see how many confirmations a transaction has (replace <txid> with an actual transaction ID):

Inspect Transaction

You’ll see:

confirmations: number of blocks since inclusion

blockhash: which block it was mined in

Alternatively, use :

Inspect Transaction

To simulate confirmations in regtest, simply mine more blocks (replace <miner_address> with your mining address):

Confirm regtest block

This simulates time passing and increases confirmation depth instantly.


4

Inspecting Mempool Transactions

The mempool holds transactions waiting to be mined. In regtest, it’s typically empty unless you send a transaction before mining.

List all mempool transactions:

Get mempool

Get details of a specific mempool transaction (replace <txid> with an actual transaction ID):

Inspect mempool

This shows:

Fee

Size

Ancestor/descendant count

Time in pool

You can clear the mempool by restarting the node or by mining a block that confirms the pending transactions.


Activity

1

Generate five blocks and get the latest block hash

2

Use getblock and getblockheader ti inspect the block

3

Send a transaction and observe it in the mempool before mining.

4

Mine one block and check the transaction’s confirmation count.

5

Invalidate the block using invalidateblock , then, inspect with getchaintips


Share on
Share on FacebookShare on XShare on LinkedIn
Did you find this page useful?