feat: add wallet_id column for per-wallet state isolation#2
Merged
Conversation
Add wallet_id to all voting DB tables so round state is natively scoped per wallet when both hotkey and keystone are loaded. - Schema: wallet_id TEXT NOT NULL DEFAULT '' added to rounds (PK becomes (round_id, wallet_id)), bundles, cached_tree_state, proofs, witnesses, votes with cascading FKs - VotingDb: stores wallet_id on the struct, set once via set_wallet_id(). All operations pass it internally to queries. No public API signature changes. - Migration: v4 drop-and-recreate - Tests: wallet isolation test verifies two wallets in same round don't cross-contaminate
This was referenced Mar 15, 2026
greg0x
approved these changes
Mar 17, 2026
Comment on lines
+242
to
+267
| fn test_wallet_isolation() { | ||
| let db = test_db(); | ||
| let conn = db.conn(); | ||
| let params = test_params(); | ||
|
|
||
| queries::insert_round(&conn, "wallet-a", ¶ms, None).unwrap(); | ||
| queries::insert_round(&conn, "wallet-b", ¶ms, None).unwrap(); | ||
|
|
||
| queries::insert_bundle(&conn, "test-round-1", "wallet-a", 0, &[]).unwrap(); | ||
| queries::insert_bundle(&conn, "test-round-1", "wallet-b", 0, &[]).unwrap(); | ||
|
|
||
| let commitment = vec![0xCC; 128]; | ||
| queries::store_vote(&conn, "test-round-1", "wallet-a", 0, 0, 1, &commitment).unwrap(); | ||
| queries::store_vote(&conn, "test-round-1", "wallet-b", 0, 0, 2, &commitment).unwrap(); | ||
|
|
||
| let votes_a = queries::get_votes(&conn, "test-round-1", "wallet-a").unwrap(); | ||
| let votes_b = queries::get_votes(&conn, "test-round-1", "wallet-b").unwrap(); | ||
| assert_eq!(votes_a.len(), 1); | ||
| assert_eq!(votes_b.len(), 1); | ||
| assert_eq!(votes_a[0].choice, 1); | ||
| assert_eq!(votes_b[0].choice, 2); | ||
|
|
||
| queries::clear_round(&conn, "test-round-1", "wallet-a").unwrap(); | ||
| let rounds_b = queries::list_rounds(&conn, "wallet-b").unwrap(); | ||
| assert_eq!(rounds_b.len(), 1, "wallet-b round should survive wallet-a clear"); | ||
| } |
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.
Summary
Add
wallet_id TEXT NOT NULL DEFAULT ''to all voting DB tables so round state is natively scoped per wallet.VotingDbstores the wallet_id on the struct (set once viaset_wallet_id()), and all queries filter by it internally. No public API signature changes onVotingDbmethods.