Skip to content

Fix/db unique loan events#520

Open
mijinummi wants to merge 8 commits intoLabsCrypt:mainfrom
mijinummi:fix/db-unique-loan-events
Open

Fix/db unique loan events#520
mijinummi wants to merge 8 commits intoLabsCrypt:mainfrom
mijinummi:fix/db-unique-loan-events

Conversation

@mijinummi
Copy link
Copy Markdown

📝 Description

Overview

This PR adds a unique constraint to the loan_events table and updates the event indexer to prevent duplicate entries.

Key Features

  • Unique constraint on (transaction_hash, event_index)
  • Updated indexer insert logic with ON CONFLICT DO NOTHING
  • Ensures idempotent re‑indexing
  • Prevents double‑counted repayments and inflated event history

Closes #439

@ogazboiz
Copy link
Copy Markdown
Contributor

The contracts CI is failing on the rustfmt format check. This isn't a logic issue, just formatting.

Run this in the contracts directory and push:

cd contracts
cargo fmt

Then commit and push the formatting changes. The CI should pass after that.

@ogazboiz
Copy link
Copy Markdown
Contributor

Backend CI is failing with a Jest environment error:

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.

This usually means a test file has async operations that outlive the test suite — either missing await on async teardown, or an import that fires a side effect (like a Redis/DB connection) after the test runner has already cleaned up.

To fix: check if any test files in your PR have async operations in top-level scope without proper beforeAll/afterAll cleanup. Also make sure any mocks for Redis or DB are set up before the app module is imported.

Contracts CI is also failing on cargo fmt. Run cargo fmt in the contracts/ directory and push the formatting changes.

Copy link
Copy Markdown
Contributor

@ogazboiz ogazboiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two failures to fix:

Contracts CI: Failing under 30s, which is a cargo fmt issue.

cd contracts
cargo fmt

Backend CI: eventIndexer.test.ts failure. Rebase on main to pick up the recent test fix:

git fetch upstream
git rebase upstream/main

Commit, format, and push when done.

@ogazboiz
Copy link
Copy Markdown
Contributor

The codebase issues on main have been resolved and all CI checks are passing now. Please rebase your branch to pull in the latest changes before continuing. Thanks for your patience.

Copy link
Copy Markdown
Contributor

@ogazboiz ogazboiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nearly identical to #519. Consolidate with #519 or close one. Same migration naming issue, same code quality issues. Fix ESM import paths and migration numbers.

@mijinummi mijinummi force-pushed the fix/db-unique-loan-events branch from f73becc to 6ec4504 Compare March 31, 2026 08:06
@ogazboiz
Copy link
Copy Markdown
Contributor

heads up, a few important changes just landed on main that affect your PR:

  1. axios pinned to 1.13.5 - there's an active supply chain attack on axios 1.14.1 (pulls in confirmed malware). we added overrides in all package.json files to block it.

  2. CI now runs a supply chain audit before backend/frontend jobs. if your lockfile has a compromised package, CI will fail with a clear error.

  3. backend test fixes - loanEndpoints tests now use valid Stellar addresses and base64 strings. if your PR was failing backend CI but you didn't touch backend code, this should fix it after rebase.

please rebase on latest main:

git fetch upstream
git rebase upstream/main
git push --force-with-lease

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.

fix(database): add unique constraint to prevent duplicate indexed events

2 participants