Combine nonces and vaults table #50
Merged
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.
NOTE
Change base branch to
mainbefore merging, i built this branch off ofdk/assignDeposit, assuming it would be merged first.Summary
This PR merges the standalone nonces table into the vaults table by adding a NOT NULL DEFAULT 0 nonce column and enforcing that every vault always has at least one controller. All reads/writes of nonce now use vaults.nonce, and the legacy nonces table and its index are removed. API behavior is preserved, with stricter validation and clearer errors.
Changes
Schema and migrations
nonce INTEGER NOT NULL DEFAULT 0tovaults.vaults_controllers_nonemptyto ensure controllers are never empty.migrations/4_merge_nonces_into_vaults.sh:vaults.noncefrom legacynoncesif it exists.unique_lower_vault_noncesand thenoncestable.migrations/1_start.shto remove creation ofnoncesand related index/lowercasing.App logic
src/controllers.ts):/nonce/:vaultGET now reads fromvaults.nonce./nonce/:vaultPOST now updatesvaults.nonce; returns 404 if the vault doesn’t exist.SELECT COUNT(*) FROM vaults.src/proposer.ts):vaults.nonce.vaults.nonceonly; no row creation. Logs a warning if the vault is missing.src/utils/vaults.ts):updateVaultControllersrejects empty controller arrays.removeControllerFromVaultprevents removing the last controller; reverts the change and throws a descriptive error.src/config/dbSettings.ts): removednoncesfromREQUIRED_TABLES.Setup scripts and tests
scripts/shared/db-setup.js: removenoncestable and index; addvaults.noncewith default 0; update drop/verify/log messages; keep balances lowercasing.scripts/setup-db.jsandscripts/setup-test-db.js: update help text to reflectvaultsstoring nonce.test/helpers/testServer.ts: removenoncesfrom TRUNCATE list.test/integration/vaults.db.test.ts):Deployment notes
migrations/4_merge_nonces_into_vaults.sh:vaults.nonce, enforces non-empty controllers, backfills fromnonces, then drops the legacy table and index.