feat(db-sync): support configurable layouts and schema policies - #2065
Open
Scitz0 wants to merge 2 commits into
Open
feat(db-sync): support configurable layouts and schema policies#2065Scitz0 wants to merge 2 commits into
Scitz0 wants to merge 2 commits into
Conversation
Add support for tx_in and consumed inputs, inline and normalized addresses, and apply, verify, or skip index management. Update node queries, operator documentation, and regression coverage for read-only db-sync deployments. Refs midnightntwrk#1160
I, Ola Ahlman <ola.ahlman@gmail.com>, hereby add my Signed-off-by to this commit: 6d499a0 Signed-off-by: Ola Ahlman <ola.ahlman@gmail.com>
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.
Overview
This PR lets Midnight use supported Cardano db-sync layouts without requiring Midnight to own or modify the database schema.
It adds consistent support for:
tx_inor represented bytx_out.consumed_by_tx_id.tx_out.addressor normalized through theaddresstable.This allows operators to reuse an existing db-sync deployment instead of maintaining another full copy or granting the node DDL privileges.
A read-only
consumed + address_tabledeployment can use:What changed
Configuration
db_sync_tx_input_modeauto,tx_in,consumedautodb_sync_address_modeinline,address_tableinlinedb_sync_schema_modeapply,verify,skipapplyEquivalent
DB_SYNC_*environment variables are supported. The selected layout is validated once and shared by all data sources. Explicit modes fail early when required structures are missing.autoselects a populated input representation and rejects an ambiguous empty dual-layout database rather than guessing.Schema policy
applyverifyskipIndexes are matched structurally rather than by name. Compatible operator-owned indexes are accepted when their access method and leading keys satisfy the query, including wider composite and descending B-tree indexes. This avoids unnecessary duplicate indexes.
Query and node integration
The resolved layout is now used consistently by Partner Chains candidate and bridge queries, Midnight candidate queries, cNight registration/deregistration/create/spend/bound queries, federated-authority observation, and ICS/reserve genesis lookups.
Only fixed internal SQL fragments are selected dynamically; values remain bound parameters. Datum and metadata queries also support retained text-backed JSON through
jsonbcasts, and multi-asset policy/name matching now uses raw bytes and ordinary B-tree indexes.Normal startup resolves the layout once, applies the selected schema policy, and passes the result to all data sources. The broader cNight genesis path manages its additional indexes and autovacuum settings. ICS, reserve, and federated-authority paths validate the layout without installing their own manifest.
Changed areas
partner-chains/toolkit/utils/db-sync-sqlx/*partner-chains/toolkit/data-sources/db-sync/src/*primitives/mainchain-follower/src/*node/src/*,res/cfg/default.tomldocs/*,scripts/genesis/README.md,changes/*,Cargo.lockdb-sync-sqlxaddsserdeandlog; the node directly consumes its shared types.testcontainers-modulesis a dev-only dependency for PostgreSQL layout tests and was already present in the workspace lock graph.Compatibility and limitations
auto/inline/apply, preserving behavior for initialized standard db-sync deployments.SQLx cache note
The pre-existing
.sqlx/query-*.jsonfiles are intentionally unchanged. The affected layout-dependent queries now use runtime-selected SQL and no longer consume those entries. Keeping them avoids unrelated generated-cache churn; they can be reconciled later through the normal SQLx cache workflow.☑ TODO before merging
bot:ai-assistedlabel.📌 Submission Checklist
git commit -s) for the DCO🧪 Testing Evidence
Passed locally:
PostgreSQL tests cover structural index verification and all four input/address combinations, including
consumed + address_tableafter physically removingtx_inandtx_out.address. They compiled locally but were not executed because Docker was unavailable; CI must confirm them.🔱 Fork Strategy
This can be deployed as a node-client update without a runtime fork or network reset. Existing deployments may retain the defaults; read-only deployments install the documented indexes before selecting
verify.Links
This intentionally does not use
Closes #1160because that issue has a broader scope.