Skip to content

Lock TTL 30s too short for Stellar transactions #237

Description

@DeFiVC

Problem

In src/utils/lock.ts line 9, the default lock TTL is 30 seconds. Stellar network transactions can take 5-30 seconds depending on network congestion. The lock heartbeat fires at ttlMs / 2 = 15 seconds.

If the Stellar transaction takes longer than 30 seconds and the heartbeat fails (e.g., a transient Redis blip), the lock expires, and another request could enter the critical section.

Impact

  • Duplicate Stellar transactions possible
  • Lock expires during long operations
  • Potential double-spending

Fix

Increase default TTL and make it configurable:

export async function withLock<T>(
  key: string,
  fn: () => Promise<T>,
  ttlMs: number = 60_000, // 60 seconds default
): Promise<T> {

Also update callers to pass appropriate TTLs:

await withLock(`reward:${submissionId}`, async () => {
  // Stellar transaction
}, 90_000); // 90 seconds for Stellar operations

Scope

  • src/utils/lock.ts -- update default TTL
  • Update callers to pass appropriate TTLs

Acceptance Criteria

  1. Default TTL is 60 seconds
  2. Stellar operations use 90+ second TTL
  3. Lock does not expire during normal operations
  4. Existing tests pass

Technical Context

  • src/utils/lock.ts:9 -- default TTL
  • src/modules/rewards/reward.service.ts:207 -- Stellar lock usage

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't workingmedium

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions