-
Notifications
You must be signed in to change notification settings - Fork 17
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
32 changes: 0 additions & 32 deletions
32
crates/db/.sqlx/query-14604982a6b089a47e32e4fa7189819526eca2c8fbf5840d857a0c2aad37edeb.json
This file was deleted.
Oops, something went wrong.
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
| 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; | ||
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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