Repository navigation
Receipt proof D1 cost: cached verified checkpoint, indexed receipt_id, single scan, hardcoded /verify - #105
Merged
Merged
Conversation
… scan, hardcoded /verify
…ation for receipt_id index
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #104 (a7bc992), covering AZBot's D1-cost review. Revised after the review at 61485ce.
{seq, hash, count, at, hashes[]}is cached per isolate and in the Cache API (__ledger-checkpoint/v1, 1 day). No KV writes.hashes[]holds the verified entry_hash for every seq, about 4.5 KB today. TODO: when the ledger grows large, replace it with a Merkle root plus per-row inclusion paths. Each request runs a one-row head probe (ORDER BY sequence DESC LIMIT 1).json_extract(payload_json,'$.receipt_id').ledgerandproof. A read fails closed if its row count differs fromhead.seq - checkpoint.seqor it doesn't end at the probed head./verifylink is hardcoded and never rendered from the server.Fixes the fail-open AZBot found: a receipt row now counts as verified only if its entry_hash equals the checkpoint hash at its seq and its previous_hash equals the checkpoint hash at seq-1. It also has to recompute to its own hash. A row below the checkpoint that was rewritten with a recomputed hash, with head and count unchanged, now shows unverified with no seal. A test covers it.
Migration:
workers/godlock-uk/migrations/0001_ledger_receipt_id_index.sql, withmigrations_dir = "migrations"set in wrangler.toml. Apply it withwrangler d1 migrations apply godlock-uk --remote. The per-isolateCREATE INDEX IF NOT EXISTSstays only as a fallback.Behavior change (caused_by): the old substring scan also matched RESCORE entries whose
caused_bywas this receipt, i.e. entries written when this receipt triggered a rescore of an older one. The exactreceipt_idmatch no longer lists those on the causing receipt's page or proof. They still appear on the rescored receipt, whosereceipt_idthey carry, and in the full chain at /verify. That's a deliberate narrowing. If the causing receipt should still show them, add a second indexed lookup on$.caused_by.Hash-linked and sealed, not signed. Tests: 283/283. Not merged, not deployed.