Skip to content

Accrue revenue only after on-chain confirmation - #1544

Merged
greatest0fallt1me merged 2 commits into
CalloraOrg:mainfrom
Joseph-tech10:fix/issue-1498
Oct 24, 2026
Merged

greatest0fallt1me merged 2 commits into
CalloraOrg:mainfrom
Joseph-tech10:fix/issue-1498

Conversation

@Joseph-tech10

Copy link
Copy Markdown
Contributor

Summary

  • Index confirmed usage events from the primary database with durable checkpointing and retry handling.
  • Handle voids by reversing unsettled entries or recording compensation for settled entries.
  • Add tests and documentation for confirmation, retries, reversals, and payout invariants.

Verification

  • git diff --check passed.
  • Tests and PostgreSQL EXPLAIN checks were not run because dependencies and a local database are unavailable in this environment.

Closes #1498

@drips-wave

drips-wave Bot commented Oct 20, 2026

Copy link
Copy Markdown

@Joseph-tech10 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	src/services/usageStore.ts
@greatest0fallt1me
greatest0fallt1me merged commit ba9f54f into CalloraOrg:main Oct 24, 2026
1 of 3 checks passed
greatest0fallt1me added a commit that referenced this pull request Oct 24, 2026
The indexer SQL from #1544 uses features pg-mem cannot emulate, so the
database-backed indexer tests now use a testcontainers PostgreSQL (one
database per harness). The pg-mem copy of the findUnindexed test is
skipped with a pointer to that coverage. Make the sweeper time-budget
test deterministic by driving performance.now().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
greatest0fallt1me added a commit that referenced this pull request Oct 24, 2026
* fix: repair corrupted code merged in #1525, #1538, #1539 and #1540

Restore identifiers and values mutated by corrupted merges and get the
migration layout policy passing again.

- config: restore TESTNET_NETWORK_PASSPHRASE ("Test SDF Network ;
  September 2015"), drop references to undefined env keys
- env: restore DB_POOL_MAX / DB_IDLE_TIMEOUT_MS / DB_CONN_TIMEOUT_MS /
  DB_USER, drop duplicate STELLAR_*_HORIZON_URL / *_VAULT_CONTRACT_ID keys,
  restore safeParse error reporting
- feeBumper: revert the unwired, broken rewrite from #1539
- revert #1540 (mutated metrics test identifiers, NUL byte in a test,
  deleted tests, conflict branch with no service support)
- migrations: drop the never-runnable 0026_add_developer_payout_address
  (syntax error, unused) and the unused fee/fingerprint migrations;
  renumber the remaining duplicate 0026/0027 files sequentially in merge
  order; add missing rollback/destructive-approved markers
- services/billing: import logger; routes/billing: narrow repo type
- docs: restore mutated contract ids in network-configuration.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: revert #1543 and repair tests broken by unverified merges

- Revert #1543 (global request ID registry). It was merged without CI
  running, broke ten suites that build pg-mem/mock schemas without
  apis/usage_event_request_ids, and its own integration test failed. Its
  migration was added today and is removed; revenue_ledger_indexer moves
  to 0032.
- idempotencySweeper test: drop duplicate __filename/import.meta use that
  cannot compile under CommonJS jest.
- revenueLedgerIndexer test: give mocked events a stellarTxHash now that
  only confirmed charges are indexed, wait for the first query before
  releasing it, and use TIMESTAMPTZ for the pg-mem lease column.
- reportExporter test: the CSV stream ends with a newline.
- settlementStoreSchema test: settlement amounts are bigint units.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: make revenue ledger SQL and test schemas work under pg-mem

- indexRevenueLedgerEvent: use uncorrelated EXISTS/NOT EXISTS guards
  (same semantics) instead of selecting from usage_events in the insert.
- Lease fallback (used only without advisory locks): take a free lease
  with a guarded UPDATE, else create the row with ON CONFLICT DO NOTHING,
  instead of ON CONFLICT DO UPDATE ... WHERE.
- pg-mem harnesses: TIMESTAMPTZ for lease/retry columns compared to NOW().
- billing.units test schema: add deduction_status columns.
- idempotencySweeper test: wait for the second postgres ready message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: run revenue ledger indexer DB tests on real PostgreSQL

The indexer SQL from #1544 uses features pg-mem cannot emulate, so the
database-backed indexer tests now use a testcontainers PostgreSQL (one
database per harness). The pg-mem copy of the findUnindexed test is
skipped with a pointer to that coverage. Make the sweeper time-budget
test deterministic by driving performance.now().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: greatest0fallt1me <greatest0fallt1me@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

Accrue revenue_ledger rows only for on-chain-confirmed usage events

2 participants