Skip to content

core: implement Stellar sequence-number management for concurrent submission #82

Description

@EmeditWeb

Problem

Server-submitted transactions (loan funding, default detection job, admin
operations) are all sent from the protocol source account via
blockchain.service. Each submission fetches the account sequence number
from Horizon independently. When two submissions run concurrently — e.g. the
hourly default-detection job overlapping an admin call — they read the same
sequence number and the second transaction fails with tx_bad_seq. There is
no serialization, channel-account pool, or sequence allocator, so throughput
is capped at one in-flight transaction and collisions fail silently.

Before Starting

Read ALL of these before writing any code:

  • context/architecture-context.md
  • context/code-standards.md
  • context/progress-tracker.md

What To Build

A sequence-number manager for the protocol signing account:

  1. Serialize submissions from the source account through a single allocator
    that hands out monotonic sequence numbers and re-syncs from Horizon on
    tx_bad_seq or restart.
  2. Optionally support a pool of channel accounts to allow concurrent
    in-flight transactions without collisions.
  3. Integrate with the existing submit/status-checker flow and expose metrics
    (in-flight count, bad-seq retries).

Files To Touch

  • src/blockchain/* (sequence manager / channel pool)
  • src/jobs/transaction-status-checker/*
  • src/modules/blockchain/*
  • corresponding *.spec.ts

Acceptance Criteria

  • Concurrent submissions no longer collide with tx_bad_seq
  • Sequence allocator re-syncs from Horizon on failure/restart
  • Optional channel-account pool enables concurrent in-flight txs
  • Metrics exported for in-flight count and bad-seq retries
  • Concurrency test proves ordered submission under parallel callers

Mandatory Checks Before Opening PR

  • All context/ files read and understood
  • context/progress-tracker.md updated
  • npm run build passes with zero TypeScript errors
  • npm test passes — test count not decreased
  • No new any types introduced
  • Swagger decorators on any new endpoint
  • Migration file created for any schema changes
  • PR references this issue number

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions