Skip to content

Feat/issue 37 cold storage#164

Merged
JerryIdoko merged 2 commits intoVesting-Vault:mainfrom
AlAfiz:feat/issue-37-cold-storage
Mar 23, 2026
Merged

Feat/issue 37 cold storage#164
JerryIdoko merged 2 commits intoVesting-Vault:mainfrom
AlAfiz:feat/issue-37-cold-storage

Conversation

@AlAfiz
Copy link
Copy Markdown
Contributor

@AlAfiz AlAfiz commented Mar 23, 2026

Summary

Resolves Issue #37: [Database] Cold Storage for Completed Vaults.

As the protocol grows, active database tables will accumulate 100% claimed and completed vaults, which can eventually degrade query performance for active vaults. This PR introduces a cold storage archival system. It safely moves fully completed vaults (where claimable balance is 0 and the vesting end time has passed) into a dedicated archived_vaults table via a weekly scheduled job.

Acceptance Criteria Met

  • Create an archived_vaults table.
  • Run a weekly cron job to move vaults where claimable_balance == 0 and end_time has passed to the archive table.

Changes Made

  • Created vaultArchivalJob.js:
    • Initializes the archived_vaults table on application boot.
    • Registers a node-cron job scheduled to run every Sunday at 02:00 AM (0 2 * * 0).
    • Identifies vaults with a claimable_balance of <= 0 and an expired end_time.
    • Securely copies the full vault payload (as JSON) into the archived_vaults table inside a database transaction.
    • Safely deletes the archived vault and its direct dependencies (SubSchedule, Notification) from the active tables to free up indexing space.
  • Updated index.js:
    • Hooked the initialization of the VaultArchivalJob into the main application startup sequence.

How to Test

  1. Pull down the branch and start the backend (npm run dev or docker-compose up).
  2. Verify in your database client (e.g., pgAdmin, psql) that the archived_vaults table has been automatically created.
  3. Optional for testing: Temporarily change the cron expression in vaultArchivalJob.js from '0 2 * * 0' to '* * * * *' (every minute) and set an active vault's end date to the past with a 0 balance to watch it get automatically archived in real-time.

Labels

  • database
  • optimization

Fixes #37

…ult#38)

Update rpc_url and network_passphrase to be strictly ENV driven. Prevent Mainnet DB from connecting to Testnet RPC by validating genesis hash on startup.
…Vault#37)

Create archived_vaults table and weekly cron job to move completed vaults to optimize database performance.
@JerryIdoko JerryIdoko merged commit 24f8996 into Vesting-Vault:main Mar 23, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants