fix(network): close multi-network gaps before #297 expansion#510
Merged
Conversation
- NETWORK env now required (Joi). Migration's fail-fast was bypassed by Joi default writing back to process.env. - DealService + dev-tools set deal.network from config on every insert. Drop DB DEFAULT clauses post-backfill so missed write paths fail loudly. - Thread network through ScheduleRow and pg-boss payloads (SpJobData, ProvidersRefreshJobData, DataRetentionJobData) so workers can route by network instead of relying on the running pod's NETWORK env.
silent-cipher
approved these changes
May 22, 2026
0968395
into
refactor/add-network-to-schema
9 checks passed
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.
Builds on top of #463. Tested live in a kind cluster against PR #463's HEAD; surfaced three gaps that bite the multi-network expansion path. None affect today's calibration-only deployment, but all three need to land before anyone flips on a second network. Filing as a friendly stack on top of #463 so it's easy to review the delta.
What changed
NETWORKenv is nowJoi.required(). The migration's "fail-fast if NETWORK missing" check was bypassed becauseJoi.default("calibration")writes back toprocess.envbefore TypeORM runs migrations. A mainnet operator who forgets to setNETWORKwould silently backfill every row ascalibration.DealServiceandDevToolsServicesetdeal.networkfrom blockchain config on every insert. The migration's per-columnDEFAULT '<backfill>'is dropped at the end ofup()so future writes that forget to setnetworkfail withNOT NULLviolation instead of inheriting a frozen default.networkis threaded throughScheduleRowand the pg-boss payload types (SpJobData,ProvidersRefreshJobData,DataRetentionJobData). Workers receive network in the job data instead of relying on whateverNETWORKenv the running pod was started with.How we found these
Spun up the existing kind cluster on
main, applied #463's image, then ran a small validation matrix:NETWORKfrom the configmap, restarted dealbot. Migration ran cleanly with'calibration'backfill anyway.kubectl exec ... node -e "console.log(process.env.NETWORK)"showedundefinedin a fresh node process. NestJSConfigModulemutatesprocess.envfrom Joi defaults during validation, so by the time TypeORM hits the migration,process.env.NETWORK = "calibration"is set even when the operator never provided it./api/dev/dealwith the column DEFAULT temporarily set to'mainnet'. GotFK_deals_storage_providersviolation since(spAddress, mainnet)doesn't exist instorage_providers. Dropped the DEFAULT entirely → every insert crashed withnull value in column "network" violates not-null constraint. ConfirmsDealServicenever setsdeal.network; it relied on the DB DEFAULT.pgboss.jobhad twosp.workjobs with identicalsingleton_keyand identicaldatapayload{"jobType":"deal","spAddress":"...","intervalSeconds":...}. Nonetworkfield. A worker pinned to one network has no way to know which schedule originated the job.Schema migration up + down both work cleanly when
NETWORKis set. Today's single-network deployments keep working unchanged because the DB DEFAULT happens to match config.How to verify
For a deeper check: spin up
make up, restart withNETWORKunset → app should now fail to boot at config validation instead of silently running. SetNETWORK=calibration, redeploy → migration runs and DROP DEFAULT clauses fire at the end ofup(). Verify\d dealsshows no DEFAULT onnetwork.Notes
network: "calibration"where the new types now require it.addressonly). Those are lower-impact for a single dealbot should be able to talk to both mainnet & calibration #297's first step. Filing separately makes sense.