Skip to content

Instantly share code, notes, and snippets.


John Newbery jnewbery

Block or report user

Report or block jnewbery

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
jnewbery /
Last active Nov 5, 2019
Wallet development

Wallet development

What are a wallet’s functions?

  • Key management
    • Identify owned transactions
    • Generating new addresses
    • Determining how to sign transactions
  • Constructing and sending transactions
    • Parsing addresses and turning them into txOuts
jnewbery /
Last active Jul 17, 2019
P2P peer prioritization logic for tx relay


Bitcoin nodes relay txs to each other over the P2P network. If a node receives a valid tx from a peer, it adds it to the mempool and relays it to its other peers. If it receives an invalid tx from a peer, it must decide what action to take. We distinguish three cases:

  1. a transaction which is valid according to consensus rules, but invalid according to the node's policy rules.
  2. a transaction which is valid according to long-established consensus rules,
#!/usr/bin/env python3
import subprocess
import os
if == 'posix':
RED = "\033[1;31m"
BLUE = "\033[0;34m"
CYAN = "\033[0;36m"
GREEN = "\033[0;32m"
RESET = "\033[0;0m"
jnewbery /
Last active Jan 10, 2019
File Descriptors in Bitcoin Core


  • We use leveldb for multiple databases: block index, chainstate and (optionally) txindex. block index is very small, but chainstate and txindex can grow to many hundreds of files.
  • Each database has a limit on number of 'open files'. This limit includes both mmapped files (which ldb takes the fd for, opens and then closes, returning the fd) and files which ldb opens and holds the fd for. There's a default in the leveldb code here. This is the per-database max_open_files limit.

Bitcoin Core wallet design notes

The Bitcoin Core wallet consists of:

  • An in memory keystore (in /src/keystore.cpp), which contains:
    • private keys stored as mapKeys - a map from the CKeyID to the private key.
    • watchonly public keys, stored as mapWatchKeys - a map from the CKeyID to the public key.
    • scripts, stored as mapScripts - a map from the CScriptID to the secrialized script.
    • watchonly scripts, stored as setWatch - a set of serialized scripts.
  • Additional key metadata such as key birthday, hd derivation path. See CKeyMetadata in /src/wallet/walletdb.h
#!/usr/bin/env python3
"""Search for blocks where the BIP34 indicated coinbase height is > block height.
Uses Bitcoin Core's test framework."""
import time
from authproxy import AuthServiceProxy
from script import CScript
a = AuthServiceProxy("http://<user>:<password>@<ip>:<port>")
You can’t perform that action at this time.