Skip to content

Instantly share code, notes, and snippets.

View LarryRuane's full-sized avatar

Larry Ruane LarryRuane

View GitHub Profile
@LarryRuane
LarryRuane / pr-notes.md
Last active August 1, 2026 16:00
1-Aug-2026 - compact spent coins

PR description working notes — compact spents (draft, not for commit)

Branch: https://github.com/LarryRuane/bitcoin/tree/2026-07-compact-spents

Scratch material for the eventual PR description / commit messages. Grows as we go.

Larry's (human) description

The next section and beyond was written by Claude Code Fable 5, but this section is by ME, an actual human! The overall design is mine, Claude

@LarryRuane
LarryRuane / claude-conversation.txt
Created July 26, 2026 17:52
claude - opus conversation July 2026
╭─── Claude Code v2.1.218 ─────────────────────────────────────────────────────╮
│ │ Tips for getting │
│ Welcome back Larry Michael! │ started │
│ │ Run /init to create a … │
│ ▐▛███▜▌ │ ─────────────────────── │
│ ▝▜█████▛▘ │ What's new │
│ ▘▘ ▝▝ │ Changed `/code-review`… │
│ Fable 5 · Claude Max · larryruane@gmail.com's │ Added screen-reader an… │
│ Organization │ Fixed Windows paths wi… │
│ /sd/g/w/bitcoin-spentdb │ /release-notes for more │
@LarryRuane
LarryRuane / 10ca73c02cbff5.diff
Created June 17, 2026 23:33
archiving spent coins to leveldb
diff --git a/src/coins.cpp b/src/coins.cpp
index c403e006c8..2eb673910a 100644
--- a/src/coins.cpp
+++ b/src/coins.cpp
@@ -14,16 +14,24 @@ TRACEPOINT_SEMAPHORE(utxocache, add);
TRACEPOINT_SEMAPHORE(utxocache, spent);
TRACEPOINT_SEMAPHORE(utxocache, uncache);
+constexpr bool lmr_debug{false};
+
@LarryRuane
LarryRuane / gist:7a1ea41744a1068e069a91304ca29c4a
Last active May 7, 2026 22:26
allocate Coin separately from CCoinsCacheEntry commit 2d5ab09f0d
diff --git a/src/coins.cpp b/src/coins.cpp
index c403e006c8..d2272406ea 100644
--- a/src/coins.cpp
+++ b/src/coins.cpp
@@ -1,384 +1,415 @@
// Copyright (c) 2012-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <coins.h>
@LarryRuane
LarryRuane / specification-proposal.md
Last active July 8, 2025 14:14
proposal for bitcoin consensus protocol specification written in code

Proposal Summary

I don't have a formal protocol verification background, but I have a proposal related to specification that may aid in creating formal verification, and would be helpful in its own right.

Specifications are usually in the form of a document, but of Bitcoin it's often said that its only protocol (consensus) specification is the Bitcoin Core client software (although it's a de facto, not authoritative specification; the latter doesn't exist). But the difficulty in verifying its correctness, or for readers to understand it, is that it (appropriately) includes so much non-protocol complexity and optimization (both CPU and memory). Also, it's written in C++, which is very efficient, but is not easy to understand.

With that background, my proposal is to write a full consensus protocol specification in the form of working code in its simplest possible form. Human language is amgibuous, but code is precise; it answers all possible question

@LarryRuane
LarryRuane / block-times.py
Created December 31, 2023 20:52
print heights of blocks with out-of-order timestamps
#!/usr/bin/env python3
# When two cosecutive blocks have out of order timestamps (the higher height's time
# is less than the lower height's time), print the height of the lower-height block.
#
# prerequisite;
# $ pip3 install python-bitcoinrpc
# or see https://github.com/jgarzik/python-bitcoinrpc
from bitcoinrpc.authproxy import AuthServiceProxy
api = AuthServiceProxy("http://lmr:lmr@127.0.0.1:8332")
@LarryRuane
LarryRuane / backtrace.txt
Created May 24, 2023 16:31
gdb backtrace (bt, stack trace) of prevector dynamically allocating memory during -reindex-chainstate, master commit 3a93957a5dc97cb2fd0656d1e2451ebef57204df
prevector<28u, unsigned char, unsigned int, int>::change_capacity (this=0x555561065eb8, new_capacity=67) at ./prevector.h:191
prevector<28u, unsigned char, unsigned int, int>::resize_uninitialized (this=0x555561065eb8, new_size=67) at ./prevector.h:392
Unserialize_impl<CAutoFile, 28u, unsigned char> (is=..., v=...) at ./serialize.h:782
Unserialize<CAutoFile, 28u, unsigned char> (is=..., v=...) at ./serialize.h:797
UnserializeMany<CAutoFile, prevector<28u, unsigned char, unsigned int, int>&> (s=..., arg=...) at ./serialize.h:1059
SerReadWriteMany<CAutoFile, prevector<28u, unsigned char, unsigned int, int>&> (s=..., ser_action=...) at ./serialize.h:1072
CScript::SerializationOps<CAutoFile, CScript, CSerActionUnserialize> (obj=..., s=..., ser_action=...) at ./script/script.h:435
CScript::Unser<CAutoFile> (s=..., obj=...) at ./script/script.h:435
CScript::Unserialize<CAutoFile> (this=0x555561065eb8, s=...) at ./script/script.h:435
Unserialize<CAutoFile, CScript&> (is=..., a=...) at ./serialize.h:705
@LarryRuane
LarryRuane / txo-flush-log-to-bin.py
Created May 16, 2023 23:07
temporary script to turn logging lines into binary
#!/bin/env python3
import sys
from struct import pack
if len(sys.argv) != 2:
print("usage:", sys.argv[0], "file")
sys.exit(1)
bitoffset = 0
v = 0
#!/bin/env python3
import sys
import random
if not len(sys.argv) == 4:
print("usage:", sys.argv[0], "reps points a-win-%")
sys.exit(1)
reps = int(sys.argv[1])
points = int(sys.argv[2])
@LarryRuane
LarryRuane / txo-history.py
Last active May 5, 2023 19:09
This prints one line for each tx output: 1) the output's txid, 2) its index, 3) its age in units of txos since genesis before being spent, 9999999999 means a long time or currently unspent
#!/usr/bin/env python3
import time, sys
from bitcoinrpc.authproxy import AuthServiceProxy
api = AuthServiceProxy("http://lmr:lmr@127.0.0.1:8332")
# infinite retry
def api_retry(*args):
global api
while True: