feat(holdings): holdings are DECLARED, not inferred from transport

Until now every receive path recorded the SENDER in `file_holders`, and
those rows went straight back out on the wire to third parties as
`cdn_redirect_peers`, as worm holder answers, and as HTTP 302 targets.
Exchanging bytes with a peer enrolled its node id -- and its addresses --
into a list we republished to anyone who asked.

Two things follow, and both matter. The concealment model the erasure
work depends on ("hold k shards quietly, announce exactly one slot") is
impossible on an inferred foundation: acquiring a shard registers you as
its holder whether you consented or not. And an enumerator never had to
hold anything -- it just asked holders who else holds.

`file_holders` rows now split two ways:

  * local hint (`declared = 0`) -- "we exchanged bytes about this file
    with that peer". Drives fetch retry, diff-propagation targets and
    manifest refresh. Never published as a holder of a specific file.
  * declaration (`declared = 1`) -- the peer told us "I hold this and you
    may advertise me for it" (0xD3). The only holder list that may leave
    the node.

All 12 inference sites were triaged into hints with a per-site reason
rather than deleted. 0xD3 became the declaration handler and is validated
hard, since it is now the only unauthenticated input reaching an outbound
holder surface: 16 KB read ceiling (was MAX_PAYLOAD, 64 MB), reject rather
than truncate oversized batches, a `tracks_file` gate so a stranger cannot
mint rows for arbitrary 32-byte ids, a per-peer token bucket and row
budget, and normalised publicly-routable addresses capped at 4. An
introducer nominee must be a known anchor -- otherwise a peer could make
us publish an arbitrary victim's address.

Declarations are soft state: a rotating per-peer sweep rides each
content-sync cycle and `DECLARATION_TTL_MS` (30d) ages out a holder that
goes quiet, so a peer that wipes its database re-learns them.

Durability decisions count EVIDENCE, never claims. A new `witnessed`
column records transport events we handled ourselves, independent of
`declared` because a peer can be both; keying the count on `declared = 0`
instead dropped every honest custodian that declared out of its author's
durability count, making the post look less durable and provoking
replication it did not need. Gating replication on claims would also let
five Sybil identities declare a post and silently stop its author
replicating it -- the data-availability attack the erasure study rules
against.

Alpha policy defaults are deliberately generous (both classes declare,
per-author cap off) because a tight cap makes content unfindable and
there is no spare holder population yet. Own-authored content is never
declared by default: it publishes device <-> posting identity, the
binding the manifest address strip exists to prevent. Non-public content
is never declared at all, at a single chokepoint. Policy changes are
retroactive, so the open alpha shape is transitional.

Known limit, documented in `holdings.rs` and design.html: this hides
WHICH and HOW MANY of an author's posts you hold, not THAT you hold some
of that author's content -- `build_own_uniques` still announces every
distinct author, deliberately interest-blind-but-complete so discovery
works. The one-shard-announcement property holds at file granularity
only; closing the author-level surface is a discovery trade Round 10 has
not ruled on.

Wire format (clean break, zero users): drops
`BlobRequestPayload.requester_addresses`, `BlobResponsePayload`'s
`cdn_registered`, and `CdnManifest.host` -- the last rode every blob
response and was relayed verbatim, so a third party learned "node A holds
this CID" with no declaration from A. ALPN is NOT bumped here; see the PR.

301 core tests (was 267), a3 23/23 (12 pre-existing + 11 new behavioural
assertions), c_topology 33/33 unchanged. Policy knobs reachable from the
desktop app, not CLI-only.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGiPD2cF75mnvneSCjdDC5
This commit is contained in:
Scott Reimers 2026-10-31 15:09:08 -04:00
parent eebf0d86f0
commit 3430a9d4c9
17 changed files with 3560 additions and 157 deletions

View file

@ -175,6 +175,111 @@ done
check "no stored comment claims a TTL past the 366d holder ceiling" \
bash -c "[ $over_cap -eq 0 ]"
# v0.8.1 PHASE 2 — holdings are DECLARED, not inferred from transport.
#
# The scenario above is already a holder-discovery exercise: node2 and node3
# each pull the other's bio to greet it, and node1 serves the registry post to
# both. Declarations ride the content-sync cycle, so drive one explicitly
# rather than waiting for the 60s tick to land inside the run.
echo "== step 7: declared holdings =="
for fd in 13 14 15; do echo "sync" >&$fd; done
sleep 10
# Second pass: the first sweep teaches each peer our declarations; the second
# proves the sweep RECURS rather than firing only at acquisition.
for fd in 13 14 15; do echo "sync" >&$fd; done
sleep 10
# Transport events (serving posts, receiving diffs, greeting exchanges) still
# record LOCAL HINTS, which stay usable for fetch retry and diff propagation.
# Under the old inference rule every one of them wrote a PUBLISHABLE row
# instead. (node1 ends the run with publishable rows only, because serving
# content no longer writes a holder row for the requester at all - which is
# itself the property under test.)
hint_rows=0
for i in 1 2 3; do
hint_rows=$((hint_rows + $(sq $i "SELECT count(*) FROM file_holders WHERE declared=0")))
done
check "transport still records local hints (usable, never published)" \
bash -c "[ $hint_rows -gt 0 ]"
# The declaring side: nodes declare what they hold, through the policy.
d2=$(sq 2 "SELECT count(*) FROM declared_holdings")
d3=$(sq 3 "SELECT count(*) FROM declared_holdings")
check "node2 and node3 each declared a holding (explicit declaration works)" \
bash -c "[ $d2 -ge 1 ] && [ $d3 -ge 1 ]"
# Every publishable row must be attributable to a peer that actually sent us a
# 0xD3 - which, since a declaration only arrives over a live connection, means
# every declared row's peer is a peer we know.
orphan_declared=0
for i in 1 2 3; do
orphan_declared=$((orphan_declared + $(sq $i "SELECT count(*) FROM file_holders f
WHERE f.declared=1 AND f.peer_id NOT IN (SELECT node_id FROM peers)")))
done
check "every publishable holder row came from a peer that declared to us" \
bash -c "[ $orphan_declared -eq 0 ]"
# HUNT ITEM 3 - the point of the whole change: a node that wants content it
# does not hold must be able to find somebody who does. Every node declares the
# registry post (it is not its own authored content), the sweep carries that to
# its peers, so each node must be able to NAME a declared holder for it.
reg=$(grep shipped_constant /tmp/itsgoin-genesis.log | awk '{print $2}')
reg_declared=$(sq 1 "SELECT count(*) FROM file_holders WHERE declared=1 AND lower(hex(file_id))='$reg'")
check "a serving node can name a declared holder for the registry post" \
bash -c "[ $reg_declared -ge 1 ]"
# SELF-HEAL - the mechanism the migration ruling rests on. Clear a declaration
# from node1's view and show the sweep puts it back, so a peer that wipes its
# database (or evicts the row) re-learns our holdings.
victim=$(sq 1 "SELECT lower(hex(peer_id)) FROM file_holders WHERE declared=1 LIMIT 1")
sq 1 "DELETE FROM file_holders WHERE lower(hex(peer_id))='$victim' AND declared=1"
gone=$(sq 1 "SELECT count(*) FROM file_holders WHERE lower(hex(peer_id))='$victim' AND declared=1")
check "the deleted declarations are really gone before the sweep" \
bash -c "[ $gone -eq 0 ]"
for fd in 13 14 15; do echo "sync" >&$fd; done
sleep 12
healed=$(sq 1 "SELECT count(*) FROM file_holders WHERE lower(hex(peer_id))='$victim' AND declared=1")
check "a declaration self-heals after a sync cycle (re-declaration works)" \
bash -c "[ $healed -ge 1 ]"
# Round 10: addresses ride only for anchors. These are loopback test nodes with
# no anchor role, so every declaration must be a bare id.
addr_bearing=0
for i in 1 2 3; do
addr_bearing=$((addr_bearing + $(sq $i "SELECT count(*) FROM file_holders
WHERE declared=1 AND peer_addresses NOT IN ('"''"',\"[]\")")))
done
check "no non-anchor declaration carries an address (bare ids only)" \
bash -c "[ $addr_bearing -eq 0 ]"
# A declaration for a post we authored would publish device <-> persona, which
# is exactly what Iteration A's manifest address strip removed. Checked against
# the never-pruned ledger, so a rotated-out persona counts too.
own_authored=0
for i in 1 2 3; do
own_authored=$((own_authored + $(sq $i "SELECT count(*) FROM declared_holdings d
JOIN own_authored_identities p ON p.node_id = d.author")))
done
check "nobody declared content authored by one of its own personas" \
bash -c "[ $own_authored -eq 0 ]"
# Non-public content is never declared: a declaration announces audience
# membership. Greeting/DM traffic in this run gives the gate something to bite.
nonpublic=0
for i in 1 2 3; do
nonpublic=$((nonpublic + $(sq $i 'SELECT count(*) FROM declared_holdings d JOIN posts p ON p.id = d.post_id WHERE p.visibility != '\''"Public"'\''')))
done
check "no declaration covers non-public content" \
bash -c "[ $nonpublic -eq 0 ]"
# Standing assertions: the wire fields that reported/implied silent enrolment
# are gone. `cdn_registered` said "the host registered you"; `CdnManifest.host`
# said "node A holds this cid" and was relayed verbatim to third parties.
check "the cdn_registered silent-enrolment flag is gone from the tree" \
bash -c '! grep -rq "cdn_registered" --include=*.rs "$(dirname "$0")/../crates"'
check "CdnManifest no longer carries a serving-host id" \
bash -c '! grep -rq "pub host: NodeId" --include=*.rs "$(dirname "$0")/../crates"'
echo
echo "== results: $PASS passed, $FAIL failed =="
[ "$FAIL" -eq 0 ]