Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkgs/id/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkgs/id/crates/id-currency-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ default = []

[dependencies]
blake3 = "1"
sha2 = "0.11"

[lints.rust]
unsafe_code = "warn"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Reverse of migration 0002 (grant table, issue #2294).

DROP INDEX IF EXISTS grant_record_pending_window;
DROP INDEX IF EXISTS grant_record_user;
DROP INDEX IF EXISTS grant_record_live_key_hash;
DROP TABLE IF EXISTS grant_record;
48 changes: 48 additions & 0 deletions pkgs/id/crates/id-currency-registry/migrations/0002_grants.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
-- Migration 0002: the grant table (design
-- 2026-10-29T12-10-00Z_design_refundable_grants_pending_transfers,
-- section 2.3; slice G1 of the grant service, issue #2294).
--
-- The control-plane record TigerBeetle cannot hold: which Steam
-- key (by hash — the key itself is never stored) a pending
-- transfer's value came from, and whether it is still revocable.
-- Ids and transfer ids are TigerBeetle u128s, stored as decimal
-- text like migration 0001's account_id; amounts are u128,
-- stored as numeric(39,0). Times are unix seconds (bigint),
-- matching the in-memory store's record exactly.

CREATE TABLE grant_record (
id text PRIMARY KEY,
steam_key_hash bytea NOT NULL CHECK (octet_length(steam_key_hash) = 32),
user_id text NOT NULL,
ledger bigint NOT NULL CHECK (ledger BETWEEN 1 AND 4294967295),
amount numeric(39, 0) NOT NULL CHECK (amount > 0),
state text NOT NULL DEFAULT 'pending'
CHECK (state IN ('pending', 'posted', 'voided', 'expired',
'clawback_pending', 'clawback_settled', 'debt')),
pending_transfer_id text NOT NULL UNIQUE,
resolution_transfer_id text UNIQUE,
window_started_at bigint NOT NULL,
window_ends_at bigint NOT NULL CHECK (window_ends_at >= window_started_at),
created_at bigint NOT NULL,
updated_at bigint NOT NULL,
attempt_count integer NOT NULL DEFAULT 0 CHECK (attempt_count >= 0),
last_error text,
correction_of text REFERENCES grant_record (id)
);

-- A key redeems once, ever: at most one live (non-voided) grant
-- per steam_key_hash. A voided grant's hash may recur only on its
-- own correction chain (enforced by the store seam; this index is
-- the schema half of the rule).
CREATE UNIQUE INDEX grant_record_live_key_hash
ON grant_record (steam_key_hash)
WHERE state <> 'voided';

-- The GET /users/{id}/grants read.
CREATE INDEX grant_record_user ON grant_record (user_id, id);

-- The reconciler's sweep (design section 6.3): pending grants
-- whose window has closed.
CREATE INDEX grant_record_pending_window
ON grant_record (window_ends_at)
WHERE state = 'pending';
Loading