Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 16
feat(weights): tip-track /v1/weights/latest via leaf supersede + reseal#121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| -- Tip leaf supersede: allow replacing a raw_weight_snapshot row when the | ||
| -- payload_digest changes for the same (challenge_id, epoch, miner_hotkey). | ||
| -- | ||
| -- `base_app` still has no direct UPDATE privilege on append-only tables | ||
| -- (schema tests keep that invariant). Tip supersede runs through this | ||
| -- SECURITY DEFINER helper owned by the migration role. | ||
| CREATE OR REPLACE FUNCTION upsert_raw_weight_tip( | ||
| p_id uuid, | ||
| p_challenge_id text, | ||
| p_epoch bigint, | ||
| p_miner_hotkey text, | ||
| p_kind text, | ||
| p_score bigint, | ||
| p_absence_reason text, | ||
| p_payload bytea, | ||
| p_payload_digest bytea, | ||
| p_signature bytea, | ||
| p_nonce bytea | ||
| ) RETURNS uuid | ||
| LANGUAGE plpgsql | ||
| SECURITY DEFINER | ||
| SET search_path = public | ||
| AS $$ | ||
| DECLARE | ||
| result_id uuid; | ||
| BEGIN | ||
| INSERT INTO raw_weight_snapshot ( | ||
| id, challenge_id, epoch, miner_hotkey, kind, score, absence_reason, | ||
| payload, payload_digest, signature, nonce | ||
| ) VALUES ( | ||
| p_id, p_challenge_id, p_epoch, p_miner_hotkey, p_kind, p_score, | ||
| p_absence_reason, p_payload, p_payload_digest, p_signature, p_nonce | ||
| ) | ||
| ON CONFLICT (challenge_id, epoch, miner_hotkey) DO UPDATE SET | ||
| id = EXCLUDED.id, | ||
| kind = EXCLUDED.kind, | ||
| score = EXCLUDED.score, | ||
| absence_reason = EXCLUDED.absence_reason, | ||
| payload = EXCLUDED.payload, | ||
| payload_digest = EXCLUDED.payload_digest, | ||
| signature = EXCLUDED.signature, | ||
| nonce = EXCLUDED.nonce | ||
| WHERE raw_weight_snapshot.payload_digest IS DISTINCT FROM EXCLUDED.payload_digest | ||
| RETURNING id INTO result_id; | ||
| RETURN result_id; | ||
| END; | ||
| $$; | ||
| REVOKE ALL ON FUNCTION upsert_raw_weight_tip( | ||
| uuid, text, bigint, text, text, bigint, text, bytea, bytea, bytea, bytea | ||
| ) FROM PUBLIC; | ||
| GRANT EXECUTE ON FUNCTION upsert_raw_weight_tip( | ||
| uuid, text, bigint, text, text, bigint, text, bytea, bytea, bytea, bytea | ||
| ) TO base_app; | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Bind the helper to the migration schema.
Line 23 forces object lookup to
public.test_pool_with_urlmigrates a generated schema after setting<schema>, publicincrates/db/src/lib.rsLines 282-304. The helper can then accesspublic.raw_weight_snapshotinstead of the isolated table, or fail when that table is absent.Capture the trusted migration search path, or schema-qualify the target table without weakening the SECURITY DEFINER boundary.
Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents