Skip to content

V-L2-L2: UNIQUE INDEX(entity_id, previous_hash) makes forks structurally impossible #32

@hyperpolymath

Description

@hyperpolymath

Context

V-L2-L1 prevents forks at the application layer. Defence in depth:
make forks structurally impossible by adding a DB-level UNIQUE
constraint on (entity_id, previous_hash). A second writer that
somehow sneaks past the chain_head lock still cannot insert because
the unique constraint rejects the second row with the same predecessor.

What to do

In src/codegen/overlay.rs::generate_provenance_table, add:

CREATE UNIQUE INDEX IF NOT EXISTS ux_provenance_chain
  ON verisimdb_provenance_log(entity_id, previous_hash);

(Genesis records all have previous_hash = ''; one genesis per
entity is exactly what we want, so the unique index correctly
forbids duplicate geneses too.)

In tests, assert that the generated DDL contains the unique
index, and that an attempted duplicate insert fails with a
constraint violation.

Acceptance

  • Generated DDL contains the UNIQUE INDEX
  • DDL test asserts the index is present
  • Integration test: with V-L2-L1 in place, attempt two parallel
    appends; one succeeds, the other gets a constraint-violation
    error and retries against the new head (graceful)
  • Documented in README §"Provenance Tracking" + the threat
    model doc

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions