Skip to content

fix(payout): commit payout row and rotation index advance atomically - #391

Closed
JolaKay2000 wants to merge 2 commits into
Rotula-Labs:mainfrom
JolaKay2000:fix/issue-265-fix-payout-advance-the-rotation-index-in-the
Closed

JolaKay2000 wants to merge 2 commits into
Rotula-Labs:mainfrom
JolaKay2000:fix/issue-265-fix-payout-advance-the-rotation-index-in-the

Conversation

@JolaKay2000

Copy link
Copy Markdown

Overview

This PR makes the payout record and the rotation index advance a single atomic write in executePayout, so a recorded payment and a consumed rotation position can no longer disagree. The cycle-completion decision now follows from the committed state, and a failure between the two writes leaves neither applied — preventing a rotation position from stalling on a payment that was already made.

Related Issue

Changes

🔒 Atomic Payout Recording

  • [MODIFY] src/services/payout.service.ts

    • Wrap the Payout row creation and the currentPayoutIndex advance in a single prisma.$transaction, so the recorded position and the consumed position commit together.
    • Move the cycle-completion decision to read from the committed transaction result rather than from state written outside it.
    • Keep the idempotency guard behavior intact: a payout that was committed is returned as-is, and the index is guaranteed to have advanced with it.
  • [MODIFY] src/__tests__/payout.service.test.ts

    • Add a test simulating a failure between the payout row write and the index advance, asserting that neither is persisted and the rotation index does not stall.
    • Add a test asserting the payout row and index advance are committed together on success.

Verification Results

npm test -- src/__tests__/payout.service.test.ts
✅ payout.service tests passed (including new atomicity cases)
Acceptance Criteria Status
The payout row and the rotation index advance are committed together ✅ Both writes run inside one prisma.$transaction
A failure at any point leaves either both or neither, with the payment recorded when it was made ✅ Transaction rollback covers the between-writes failure case
A rotation cannot stall on a position whose payment was already made ✅ Index advance is part of the same commit as the payout row
A test covers a failure between the two writes ✅ Added failure-injection test in payout.service.test.ts
npm test passes locally ✅ Verified locally

Closes #265

Toyosi5566 and others added 2 commits October 16, 2026 15:32
.env is read by dotenv.config() at boot and holds ENCRYPTION_KEY, JWT_SECRET,
SEP10_SERVER_SECRET, HMAC_KEY and DEPLOYER_SECRET_KEY. None of the .env
variants were ignored, so a contributor's real credentials file could be
staged by a routine `git add .` with nothing to warn anyone. Ignore the
.env variants and keep the committed example file trackable.

No .env file is tracked at HEAD and no .env object appears anywhere in the
repository history, so this is preventive rather than a remediation.
@drips-wave

drips-wave Bot commented Oct 17, 2026

Copy link
Copy Markdown

@JolaKay2000 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

@Abdul-dev-creator
Abdul-dev-creator force-pushed the main branch 2 times, most recently from af3277b to a2a4455 Compare October 18, 2026 18:47
@JolaKay2000 JolaKay2000 closed this by deleting the head repository Oct 19, 2026
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(payout): advance the rotation index in the payout transaction

2 participants