This assignment consists of hands-on labs exploring Bitcoin's network architecture, transaction propagation, and block validation mechanisms. You'll work with Bitcoin Core in regtest mode to safely experiment with blockchain operations.
Complete the following labs using Bitcoin Core in regtest mode.
Step 1: Initialize Regtest Environment
bitcoind -regtest -daemonLaunches a local Bitcoin node in regression test mode.
Step 2: Create a Wallet
bitcoin-cli -regtest createwallet devwalletCreates a wallet named devwallet for testing.
Step 3: Generate Some Coins
ADDRESS=$(bitcoin-cli -regtest getnewaddress)
bitcoin-cli -regtest generatetoaddress 101 $ADDRESSMines 101 blocks to your address — gives you spendable test BTC.
Expected output: Block hashes printed in terminal.
Step 4: Verify Blockchain Info
bitcoin-cli -regtest getblockchaininfoConfirms height, difficulty, and network details.
Simulate transaction propagation by running multiple nodes on different ports.
Step 1: Start Second Node
mkdir -p ~/bitcoin-node2
bitcoind -regtest -datadir=~/bitcoin-node2 -port=18445 -rpcport=18446 -daemonStep 2: Connect Nodes
bitcoin-cli -regtest addnode 127.0.0.1:18445 onetryStep 3: Verify Connection
bitcoin-cli -regtest getpeerinfo | jq '.[].addr'You should see 127.0.0.1:18445 listed.
Step 1: Send a Transaction
RECV_ADDR=$(bitcoin-cli -regtest getnewaddress)
bitcoin-cli -regtest sendtoaddress $RECV_ADDR 5.0Step 2: Check Mempool
bitcoin-cli -regtest getmempoolinfo
bitcoin-cli -regtest getrawmempool | jq '.'Displays current transactions waiting to be mined.
Step 3: Mine the Transaction
bitcoin-cli -regtest generatetoaddress 1 $ADDRESSConfirms the transaction in a new block.
Step 4: Verify Confirmation
TXID=<your_txid>
bitcoin-cli -regtest gettransaction $TXIDExpected: confirmations: 1
Objective: Observe reduced bandwidth during block propagation.
Note: For demonstration, run bitcoind with -printtoconsole and enable -debug=net.
Step 1: Enable Compact Blocks
Compact blocks are automatically supported in Bitcoin Core since 0.13.0. To view negotiation:
tail -f ~/.bitcoin/regtest/debug.log | grep compactYou'll see messages like sendcmpct and cmpctblock.
Step 2: Mine a Block and Observe
bitcoin-cli -regtest generatetoaddress 1 $ADDRESSWatch for compact block announcements in debug logs.
Step 1: Run a Node with Compact Filter Index
bitcoind -regtest -daemon -blockfilterindex=1Step 2: Query Block Filter
BLOCK_HASH=$(bitcoin-cli -regtest getblockhash 1)
bitcoin-cli -regtest getblockfilter $BLOCK_HASHReturns filter header and filter data (Golomb-Rice encoded bitstream).
Step 3: Decode Filter (Optional)
Install neutrino or btcd client to test SPV-like behavior locally.
Step 1: Get Block Hash
BLOCK_HASH=$(bitcoin-cli -regtest getbestblockhash)Step 2: Inspect Block Details
bitcoin-cli -regtest getblock $BLOCK_HASH trueNote the merkleroot field.
Step 3: Verify Merkle Root Manually (Python example)
import hashlib
def double_sha256(b):
return hashlib.sha256(hashlib.sha256(b).digest()).digest()
txids = [bytes.fromhex(txid)[::-1] for txid in ["<txid1>", "<txid2>"]]
root = double_sha256(txids[0] + txids[1])[::-1].hex()
print(root)Matches the block's merkleroot.
Step 1: Use bitcoin-cli RPC (legacy)
bitcoin-cli -regtest setnetworkactive falseAdd peers manually with support for BIP37 (use bitcoinj or older btcd client).
Step 2: Generate a Bloom Filter
from pybloom_live import BloomFilter
bf = BloomFilter(capacity=1000, error_rate=0.001)
bf.add('my_txid')
print(bf.bitarray)Demonstrate how probabilistic matching works.
Discussion: Emphasize deprecation due to privacy leaks (clients revealed interests).
Step 1: Corrupt a Block (for demo only)
cp ~/.bitcoin/regtest/blocks/blk00000.dat ~/tmp/
# Manually edit a byte — breaks validationStep 2: Restart Node
bitcoind -regtest -daemonNode rejects the corrupted block → error: bad-blk in logs.
Lesson: Consensus rules are strict; invalid data is rejected network-wide.
Step 1: View Network Graph
bitcoin-cli -regtest getpeerinfo | jq '[.[] | {addr, subver, inbound}]'Step 2: Use bitcoin-cli getnetworkinfo
bitcoin-cli -regtest getnetworkinfoDisplays peer count, local services, relay fees, and protocol version.
Tip: Each peer connection is a TCP link exchanging compact messages — similar to sockets in general networking.
Stop all nodes:
bitcoin-cli -regtest stop
bitcoin-cli -datadir=~/bitcoin-node2 -regtest stopRemove temporary files (optional):
rm -rf ~/bitcoin-node2 ~/.bitcoin/regtestYour submission should include:
📁 assignment-5-submission/
├── README.md (your main report)
├── lab-screenshots or output.txt file/
│ ├── lab1-setup.png/lab1.txt
│ ├── lab3-mempool.png
│ ├── lab6-merkle.png
│ └── ...
├── code/ (any scripts you created)
│ ├── merkle_verification.py
│ └── bloom_filter_demo.py
└── lab-notes.md (observations and findings from each lab)
For each lab, document:
- Commands you executed
- Output/results observed
- Any errors encountered and how you resolved them
- Key insights or learnings
By completing this assignment, you will:
- Experience transaction propagation and mempool behavior
- Observe how BIPs (152, 157, 158) optimize bandwidth and privacy
- Understand how consensus ensures integrity and immutability
- Gain hands-on experience with Bitcoin Core RPC commands
- Mempool.space - Clean UI, detailed information
- Blockchain.com - Classic explorer
- Blockstream.info - Technical details
- Bitcoin Core RPC Documentation
- Bitcoin Developer Guide
- BIP152 - Compact Block Relay
- BIP157/158 - Compact Block Filters
- Start with Lab 1 to ensure your environment is properly set up
- Take screenshots at each step for your submission
- Keep notes as you work through the labs
- If you encounter errors, check the debug logs:
~/.bitcoin/regtest/debug.log - Don't forget to stop your nodes when finished to free up resources
Node won't start:
- Check if another instance is already running
- Verify you have enough disk space
- Check permissions on the Bitcoin data directory
Can't connect to RPC:
- Ensure the node is running (
ps aux | grep bitcoind) - Verify you're using the correct port and datadir parameters
Transaction not appearing in mempool:
- Ensure you have sufficient funds
- Check the transaction fee is adequate
- Verify the receiving address is valid
If you have questions about the assignment:
- Open an issue in this repository
- Ask during office hours
By completing these labs, you'll gain practical understanding of:
- How Bitcoin nodes communicate and propagate data
- How mempool, blocks, and filters interact
- How consensus ensures network integrity
- Real-world Bitcoin Core operations
Next step: Integrate these insights into Bitcoin Core RPC automation or monitoring scripts to extend your infrastructure-level understanding.
Good luck! 🚀