Contributing¶
What this repository holds in common with the others of the organization — the toolchain, the lint gate, the tool tables behind it, the workflow set and the branch rules — is stated once in the btclib-org repository standard, each rule with the alternative it was decided against. It binds this repository, so a change departing from it is a divergence, and one filed as an issue in that repository rather than here: a difference between two repositories belongs to neither of them.
This file is the same in every repository of the organization up to its last section. What is true of one tree only — the commands that build its environment, the gates it runs, which of its workflows decide a merge — is under that heading, and the comparison stops there.
How the organization decides, and who holds which role, is
GOVERNANCE.md; what it intends to do, and what it
deliberately does not, is ROADMAP.md. Both are the
organization’s, one copy each beside the standard.
The issue tracker¶
Where an issue is filed, and what an alignment finding has to name, is the standard’s What this repository is: an issue spanning repositories, or whose subject is the standard, goes to btclib-org/.github, and one about this tree alone stays here.
A finding noticed while doing something else goes where REVIEWING.md’s
What is filed, and what is not says, for an author as much as for a
reviewer: a pull request answering two questions cannot be accepted for
either.
An issue labelled good first issue is one set aside for a first
contribution: small and self-contained.
One search lists the open ones across the organization, so
a newcomer need not know in advance which repository to look in.
Documentation and comments¶
Section 9 of the standard is the prose style, and it governs the prose this tree ships — comments, docstrings and markdown. It is not restated here: a second wording is the one that goes stale, which is that section’s own One fact in one place.
A commit message is prose this tree ships too, though section 9 does not
say so: the only merge method the rule accepts puts it on main
as the landing commit’s body, so what is written in one is read there
long after the branch is gone.
Pull requests¶
What main accepts, and what it refuses to everyone, is section 11 of
the standard. Run the gates locally before opening anything —
the last section of this file says which they are — because CI runs
exactly them, so a red run there is a local run that was not done.
Every commit of a pull request carries a Signed-off-by: trailer
naming its author, which certifies the Developer Certificate of
Origin. git commit -s adds it, and git rebase --signoff <base>
adds it to commits already made. The Sign-off check is required, so a
pull request whose commits lack the trailer cannot merge; its failure
prints the command that adds it. The standard’s Signatures
says why a signature does not replace it, and which commits the
Sign-off job skips.
What a pull request’s title and description have to say about the issues it closes, and why a manual link in the Development panel is a trap neither of them shows, is the standard’s What a pull request says it is. Read it before opening one; it is the rule most often found broken after the fact.
Before it is opened, the branch’s own commit subjects and bodies are read against that same rule. The description does not exist yet to disagree with them, and the standard has the command that scans the branch’s own commit text for a verb in front of a reference.
The two spellings are named here as well as there, against section 9’s
One fact in one place, the paragraph above naming the section
and not the forms, which are the half a citation is got wrong in:
(closes #N) cites an issue the change closes, wherever the citation
sits — the title, the commit subject where Merge method makes
that the thing that lands — and (issue #N)
cites, in those same places, an issue the change advances and does not
close. One token holds one meaning whichever file it sits in, so the
pair is chosen by what is true of the change rather than by which file
is being written, and a tree’s own landed subjects are not what to copy
it from: nothing already landed is rewritten, so what a repository wrote
before the rule stays where it is.
REVIEWING.md is the standard a review is written against, and is this
file’s other half. Read before opening a pull request, it is what the
pull request will be answered against.
A pull request adds no entry to CHANGELOG.md or RELEASE_NOTES.md, a
release’s own pull request excepted (section 9, section 12).
One subject, opened as soon as it is written¶
A pull request answers one question. Issues that share a subject are one pull request, closing each of them; issues that do not are one pull request each, however small either of them is.
It is opened the moment it is written and verified — not held for the previous one to be reviewed or to land, and not batched with the next. A batch arrives as one reviewing job with several subjects, which is the shape that costs the most to read; a finished pull request held back is review that could have started and did not.
Working this way stacks branches, which is fine and costs one rule: a child whose base was amended is moved with the old base named,
git rebase --onto <new-base> <old-base-sha> <child>
because a plain rebase replays the base’s old commit inside the child,
and the forge then shows the base’s old text as additions with nothing
red anywhere. Read the child’s diff afterwards rather than trusting the
rebase, and retarget each child onto main as its parent lands.
The review¶
A review is given promptly and on local evidence. It does not wait for CI, does not report a check as a finding, and does not discuss a run at all: whether CI is green is the author’s business, once, at landing time.
The exchange is anchored to a sha rather than to a branch, a branch being free to move under a review:
the author hands off by naming the sha pushed and the evidence run against it, then leaves that head alone;
the reviewer answers with findings — where, what is wrong, how they know it, and whether each is blocking;
the author accepts what is reasonable, declines the rest with a reason in the thread, pushes the answer without waiting for CI, and resolves each thread once answered;
the reviewer reopens a thread whose finding is still blocking, and re-reviews the delta rather than the branch.
What ends the loop is the ack of record, and the author does not
supply their own. A reading that says what it found and delivers no
verdict is a review too and ends nothing; the standard’s Review
has which is which, and REVIEWING.md has how each is written. A
disagreement that survives a second exchange goes to the maintainer
instead of into a third round.
The ack of record is not the approval Landing it asks for: it is a bot’s review of type COMMENT (the standard’s Review says whose).
Landing it¶
CI is read once, and this is where: on the head that lands. main does
not ask that head to be up to date with it, and section 11
says why. So a branch is rebased only where it conflicts with main, or
where its checks ran on a main that has since been repaired, because
re-running its checks would test the same merge commit. A rebase that
moved nothing but the base leaves the ack standing; one that resolved a
conflict does not, that resolution being a change no reviewer has seen.
When main’s CI is red after a merge, its repair lands before any other
pull request, and no --auto below stays armed until then: what lands
meanwhile is merged onto a tree known to be broken, and main’s next run
cannot tell a new failure from the one already there. An armed pull
request whose checks ran before the break merges on them all the same.
Then squash, the only method the rule accepts.
It lands once somebody other than its author has approved that
head, through gh pr merge pinned to it:
gh pr merge <n> --squash --match-head-commit <the head the checks ran on>
With --auto added, GitHub runs the same merge once the approval and
the checks are in.
Where the repository has a bypass, the maintainer may land without
that approval, through it: GOVERNANCE.md’s How a
decision is made says which repositories.
--admin turns off gh’s own refusal, and GitHub applies
the bypass to the merge. enforce_admins is off, so it waits for no
required check either:
gh pr merge <n> --squash --admin \
--match-head-commit <the head the checks ran on>
Without --admin, gh pr merge refuses a head with no approval, saying
it is not mergeable: the base branch policy prohibits the merge.
The pin is not optional, in either command. Reading the ack and
merging are two calls, and the head is free to move between them — the
push that would move it comes out of the same round the verdict does.
Unpinned, the command takes whatever sits at the head when it runs;
pinned, it refuses a head that has moved, and a round lost that way is
cheaper than a tree nobody has read reaching main.
The review above anchors the exchange to a sha and section 11
has an ack name one: the pin is that rule reaching the call that
performs the landing.
Verify what landed rather than trusting the answer, the signature the standard asks for being a valid one rather than a particular signer’s:
gh api repos/{owner}/{repo}/commits/main \
--jq '.commit.verification | {verified, reason}'
What it closed is read again here too, from the landed sha rather than from the pull request: the standard’s What a pull request says it is has the second read, and why the first alone does not reach a squash subject composed after it runs.
The forge deletes the head branch itself, per the setting section 11
names. What is still yours is bringing every checkout sitting on main
up to date,
that being where the next session starts from and a stale one being where
a branch gets built on a base that has moved. REPOSITORY.md carries the
settings and why they are what they are.
This repository in particular¶
Everything above is the same file in every repository of the organization; everything below is this one’s, and the comparison stops at this heading.
The environment and the gates¶
uv is the only thing that has to be installed; it fetches the interpreter
.python-version pins and every dependency group itself. There is a
project here and it is installed, so the gates run through uv run and
not through the uvx a tree with no project needs:
uv sync
uv run pytest
git add -A && uv run pre-commit run --all-files
uv run pre-commit validate-config .pre-commit-config.yaml
uv run --locked --no-default-groups --group docs \
sphinx-build -W -n -b html docs/source docs/build/html
if grep -rn 'href="#\.\.\?/' docs/build/html --include='*.html'; then
echo "::error::the links above resolve to no page (unresolved relative path)"
exit 1
fi
--all-files means every file git tracks, so a file that is new and not
yet staged is not one of them: run it unstaged and the hooks pass over
exactly the files most likely to fail them. Staging first is what makes
the local gate answer the same question pre-commit.ci does.
The documentation build is the one no hook reads reStructuredText for: a
docstring docutils cannot parse fails it with every hook green – a name
ending in an underscore is a reference to a link target, which is what
the double backticks around a literal like NODE_ are for.
Not --only-group docs in place of the documentation build’s own
--no-default-groups --group docs. The two read like the same request
and are not: --only-group excludes the project along with every other
group, so autodoc’s own import of btclib_node raises
ModuleNotFoundError under -W on a .venv that does not already have
it installed. Where the same .venv was synced earlier in the session
by uv sync or uv run pytest, the project is already there and the
build succeeds without --only-group ever having installed it, so the
command’s outcome tracks the .venv’s own history rather than the tree
it is meant to check. docs.yml runs the form above for the same
reason, next to the same warning.
The grep after the build is that gate’s second step. What myst renders
for a target it cannot resolve is an anchor on the page it is already on
– an id nothing defines – and the build fails on it only through the
myst.xref_missing warning docs/source/conf.py suppresses nowhere,
having resolved every link the included root files carry ahead of myst’s
own resolver; the grep asks the same question of the HTML, where a
suppression cannot hide the answer. Two spellings answer for every local
destination, .pre-commit-config.yaml’s local-link-prefix hook holding
each of them to the ./ or ../ prefix.
validate-config is worth running before pushing a change to the hook
config: it catches what a wrong types_or tag or a malformed entry would
otherwise turn into a red lint job.
Check exit codes, not filtered output. pre-commit run ... | grep -v Passed hides a failure, and grep finding nothing exits 1, which is not
the gate’s answer to anything.
The gate is not installed as a git hook. pre-commit install writes
into the common git directory, which every worktree of this repository
shares: git -C <worktree> rev-parse --git-path hooks answers with the
same directory in each. So one session installing it installs it for
every other. Run the gate by hand before committing.
Every statement and every branch is covered, and uv run pytest fails if
any stops being. A run narrowed by a path, -k, -m, --deselect,
--ignore, --ignore-glob or --last-failed is not the run a floor
over the whole suite is a claim about, so it is not held to one —
tests/conftest.py is where that is decided, and where anything else
narrowing a run is added. --cov-fail-under asked for explicitly still
applies.
The tests marked slow are skipped by a run without --run-slow, and
tests/README.md’s Slow tests says why. To run them, and only them:
uv run pytest -m slow --run-slow --no-cov
Every test is bounded, too. A node that stops answering fails the test
that built it, named, with a stack of every thread it left running,
instead of holding the run open until something outside it gives up. The
limit is timeout in pyproject.toml, measured against the slowest test
there is and reasoned about where it is set.
What gates a merge, and what only reports¶
lint.yml runs the hooks .pre-commit-config.yaml declares, so there
is no second list of tools and versions to keep in step; its invocation
differs from the one above only in being --locked and in printing what
a fixing hook would have written. test.yml runs the suite over the
interpreter and platform axes its own header argues, held to the
coverage floor pyproject.toml declares on its ubuntu-latest cells.
A pull request that touches
only the root prose skips the suite and reports the skip as a pass, which
is what keeps an aggregate check from blocking on a run that never
happened. docs.yml runs the same build the environment section above
does, on every pull request the way lint.yml and test.yml do rather
than on a schedule, and is a required check alongside them.
integration-bitcoind.yml starts a real bitcoind and asks it what no
recorded reply under tests/_data can answer, and is required too:
REPOSITORY.md’s Required checks on main names them all.
Whether any of these can refuse a merge is a repository setting and
not a file, and REPOSITORY.md reads it back from the endpoint rather
than restating it here. Read that file before assuming a red run stops
anything.
Everything else reports. api-break.yml labels a pull request that
breaks the public API and gates nothing. slow.yml runs the tests marked
slow weekly and on demand. codeql.yml
follows a value from a peer’s message or an RPC request body to where it
is used, which no hook here does. os-macos.yml runs the suite on the one
platform pyproject.toml classifies that the gate does not run, and its header
says what differs beneath it. os-ubuntu.yml runs it on
ubuntu-24.04-arm beside the gate’s own image, which is where aarch64
Linux is exercised at all. links.yml asks whether somebody else’s
server answered, and
bootstrap-dns.yml asks the same question of the DNS seeds
src/btclib_node/chains.py names. verified-signatures.yml reports after each
push to main whether every commit pushed is verified; the standard’s
Signatures has the rule. claude-review.yml writes the review
and its own header says it must not become a required check.
vendored-vectors.yml re-checks tests/_data/README.md’s and
scripts/seeds/README.md’s pins against upstream, deps-latest.yml
upgrades every dependency and runs the suite,
the lint gate and the packaging checks against the result,
deps-oldest.yml is that sentinel’s mirror and takes the registry
specifiers down to their oldest allowed release instead, its own header
saying which declared floor that leaves out and why, pypi-install.yml
installs btclib-node from the index rather than from a checkout and
runs it past import, sdist-rebuild.yml rebuilds the latest release’s
sdist from its tag and verifies it against the release’s attestation, and
mutation.yml is its own section below. fuzz.yml runs the atheris harnesses
under fuzz/ against octets nobody chose, and its own header says which
parser this tree owns of what a peer reaches and why the harness is a script
rather than the ClusterFuzzLite container the sibling libraries build.
scorecard.yml runs OpenSSF’s third-party audit of the repository’s
supply-chain posture, on push to main and on a weekly schedule. Unlike
every other workflow above, it carries neither a pull_request trigger
nor workflow_dispatch, so there is no way to ask about a branch at
all – its own header says why.
Which day each of the periodic ones runs is one calendar for the whole
organization, in section 10 of btclib-org/.github’s
README, not
repeated here. The trade it makes is worth knowing before relying on it:
a defect only a sweep can see sits on main until that sweep runs, at
most a week.
Mutation testing¶
mutation.yml asks the question coverage cannot: a line the suite
executes is not a line the suite checks. It gates nothing and runs
weekly; the configuration is the single source of the scope and the
test command.
uv run --locked --no-default-groups --group test --group mutation \
cosmic-ray baseline .github/mutation/interpreter.toml
uv run --locked --no-default-groups --group test --group mutation \
cosmic-ray init .github/mutation/interpreter.toml interpreter.sqlite
uv run --locked --no-default-groups --group test --group mutation \
cosmic-ray exec .github/mutation/interpreter.toml interpreter.sqlite
uv run --locked --no-default-groups --group test --group mutation \
cr-report --surviving-only --show-diff interpreter.sqlite
The session writes each mutation into src/btclib_node/interpreter.py
and restores it afterwards, so nothing else may read the file while it
runs. interpreter.py is the consensus entry point ARCHITECTURE.md’s
Validation names as what validates. Each scope is a .toml of its own
in .github/mutation/, the way btclib-org/btclib’s own holds one per
profile, and is run the same way with its own name in place of
interpreter: headers_sync.toml mutates p2p/headers_sync.py.
test-command in .github/mutation/interpreter.toml runs with -n0,
overriding addopts’ own -n auto for the one process that reads the
mutated file: the file-edit form is the one CLAUDE.md’s Non-obvious
facts names as reaching a worker, and cosmic-ray’s own mutation is the
same form, applied to the file rather than to a running process.
Building the distribution and checking it¶
test.yml’s dist job reads the sdist and the wheel with the check
dependency group. A pull request builds its own files there; on a
release the job reads the ones reusable-build.yml built and signed,
which release.yml’s publish jobs download. Running the same commands
here answers before a pull request does.
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
uv build
uv run --no-project --python 3.14 .github/scripts/normalize_sdist.py dist/
uv run --locked --only-group check twine check --strict dist/*
uv run --locked --only-group check check-wheel-contents dist/*.whl
uv run --locked --only-group check pyroma --min 10 dist/*.tar.gz
The epoch and the normalizer come first because they rewrite the sdist’s
member metadata, so what the three checks read is the archive that job
would hand on. --only-group is right here where it is wrong for the
documentation build above: these three read dist/ and none of them
needs btclib_node installed.
check-sdist is not among them: .pre-commit-config.yaml runs it as a
hook, so the lint gate already asks it, and it builds an archive of its
own rather than reading the one above. dist/ is ignored, so building
here does not dirty the tree that gate reads.
A release path, and what it has published¶
.github/workflows/release.yml exists and section 2 of
btclib-org/.github’s
README
measures a repository’s tier from that file and pyproject.toml alone,
so this tree is tier 1 — the decision
ISS btclib-org/btclib-node#286
records, superseding the tier-2 state
PR btclib-org/btclib-node#171
had landed one day before that issue was filed. RELEASING.md and
RELEASE_NOTES.md are the two files section 2 gives a tier-1 repository
that #171 had removed, back under this section’s own heading.
It publishes to PyPI. The pypi and testpypi pair of
RELEASING.md’s One-time setup is what uploads —
REPOSITORY.md’s The two publishing environments reads that pair
back — and between releases project.version is the shape
RELEASING.md’s calendar scheme takes then: the month a cycle is open
on, with no day, which is what version-check refuses on a tag. Which
versions are published, and which tags there are, is read from the
index and the repository rather than from this file:
curl -s https://pypi.org/pypi/btclib-node/json |
python3 -c 'import json,sys; print(sorted(json.load(sys.stdin)["releases"]))'
gh api repos/btclib-org/btclib-node/tags --jq '.[].name'
A lightweight v0.1.0 from 2023, with a release page and no artifact
on it, was deleted with its release on 2026-08-23, on the maintainer’s
decision closing btclib-org/.github#105: a ref with no object of its
own has nothing on it to sign, and a repository that published nothing
had no release the tag was the record of. This section went on
describing it for four days afterwards (btclib-org/btclib-node#553),
which is what a deletion decided in another repository’s issue costs
when nobody carries it into the files that mention it. CHANGELOG.md
starts where the record starts rather than where a tag does, for the
reason its own introduction gives.
A tag is cut with git tag -s. tag-integrity does not check the tag’s
own signature: REPOSITORY.md has what it refuses and the call that
reads it back. Its one rule is required_signatures, with neither
non_fast_forward nor deletion, so nothing refuses a tag’s deletion,
and what follows is kept by hand.
The tag of a published version is never deleted or cut again: the
version stays on PyPI whatever a tag does, an index refusing a version
that has been uploaded once, and deleting its tag takes away the only
thing that says which commit it was built from. A tag nothing has been
published from can be deleted and cut again, and whether anything has
is read from the index — RELEASING.md’s If something goes wrong
has the call that licenses the deletion.
RELEASING.md is the whole of the procedure, from the one-time
publisher registration through the tag command itself — naming the
release commit explicitly, which the argumentless git tag -s v<version>
this paragraph could show instead does not — through what to do if a
release goes wrong; it is not repeated here.
Following Bitcoin Core¶
Where this tree reimplements something Bitcoin Core also does — a constant, an eviction order, the error an RPC answers a refusal with — it matches Core’s behaviour, and the comment beside it names the commit Core was read at. It may differ in two ways. The first is the language: Python-native, fluent or efficient in Python where Core’s own line is shaped by C++, never a design weighed against Core’s on its own merits. The second is a departure the maintainer decided, which SECURITY.md’s Where this node departs from Bitcoin Core lists and argues, and which the code it changes cites. Refusing v1 by default is one (btclib-org/btclib-node#1190). What differs from Core in consensus or in relay is a difference the network sees, so the default is not a matter of taste.
Write the citation as at bitcoin/bitcoin@<sha> with at on the same
physical line as the sha: ruff’s ERA001 reads a comment line at a
time, and at glued to the citation is never valid Python
(btclib-org/btclib-node#471). A citation in a docstring needs none of
this.
src/btclib_node/db.py’s docstring is the worked example of the
Python-native axis: taking LevelDB’s own fork through rocksdict, a
typed wheel on this tree’s interpreter, over Core’s vendored LevelDB is
a packaging choice, and the docstring argues the store against Core’s on
those terms.
Mimicry is of the observed behaviour end to end, not of a local
catch: where a layer below differs, the same behaviour can need
different code above it, and that is still matching. db.py’s store
verifies a per-block checksum on every read
(btclib-org/btclib-node#641), the guarantee LevelDB gives Core’s
CDBWrapper::Read before its deserialize try runs. UtxoIndex’s two
Coin.parse fallbacks answer None for a checksum-clean record that
does not deserialize, as CDBWrapper::Read and
CCoinsViewDB::GetCoin answer “absent” rather than raising
(btclib-org/btclib-node#650); ChainstateInconsistencyError’s docstring
argues that decision.
A capability Core has that this tree lacks is a gap to close, not a
constraint to design around, wherever the reason is a library fact
rather than a decision: the store’s per-block checksum is RocksDB’s own
(btclib-org/btclib-node#641), taken in place of a stdlib sqlite3 that
ships no checksummed VFS (btclib-org/btclib-node#637).
A convention of this tree is not on that axis. Where Core defines the surface — an RPC’s field names and what they mean, a message’s semantics — consistency with the rest of this codebase is no reason to answer differently from Core: the reader on the other side is a client written against Core.
Units are where that bites hardest. A feerate here is satoshis per
kvB wherever one is emitted or read, and Core’s getmempoolinfo answers
mempoolminfee in BTC per kvB. A field of Core’s that this tree answers
takes Core’s unit: the client reading it was written against Core, so
the internally consistent answer is wrong by eight orders of magnitude
with nothing to say so. The rule stops where the encoding is not this
tree’s to pick: BIP133’s feefilter carries satoshis per kvB on the
wire because BIP133 says so.
What is not legitimate is the silent kind. Where the behaviour departs from a source the code cites, the code says so and says what forced it: a reader who finds a citation and an unexplained difference cannot tell a decision from an oversight. Reading Core’s own source is part of writing the divergence, because what gets reproduced is what Core does rather than what a report said it does.
Core is read from a local checkout brought forward with a fetch and a
fast-forward on a clean master, never written to, rather than fetched
a file at a time: a raw fetch can come back truncated with nothing to
say so, missing the function a divergence question is about. The sha the
checkout lands on is what the comment cites.
The other sha a citation may carry is a released Core’s, with the
release’s tag name beside it: a claim about the bitcoind this tree is
tested against, rather than about Core’s tip, is cited at that release’s
tag commit. .github/workflows/integration-bitcoind.yml pins the
release, and a citation reads it there. The tag name is what tells such
a citation from a stale read, because ancestry does not: a sha read from
an out-of-date master is an ancestor of master all the same.
Where that release and Core master behave differently, consensus and
relay follow the release: the network runs released Cores, so a peer on
the wire is never speaking master’s tip. A peer-refusal rule may go
stricter than the release ahead of that behaviour landing in one,
provided the code argues the divergence against the release and cites
master’s sha beside it: refusing a misbehaving peer more readily changes
nothing an honest peer’s messages achieve. sendcmpct’s announce octet
is the case in point: master reads it as a byte and calls Misbehaving
on a value above one, where the release reads a bare bool and refuses
nothing.