Skip to content

Add lock-free atomic sequence manager to TxManager#522

Open
AugistineCreates wants to merge 1 commit into
StellarFlow-Network:mainfrom
AugistineCreates:feature/atomic-sequence
Open

Add lock-free atomic sequence manager to TxManager#522
AugistineCreates wants to merge 1 commit into
StellarFlow-Network:mainfrom
AugistineCreates:feature/atomic-sequence

Conversation

@AugistineCreates

Copy link
Copy Markdown

This pr closes #469

Implemented a lock‑free atomic sequence manager and integrated it into the transaction broadcasting flow, eliminating per‑account lock contention.

Overview

  • Added src/network/sequence_manager.py with AtomicSequenceManager:

    • Uses Windows InterlockedExchangeAdd (via ctypes) for true lock‑free atomic increments.
    • Fallback to a lock‑protected counter on non‑Windows platforms.
    • Supports block allocation (allocate_block) and per‑thread cached blocks (get_thread_local_block).
    • Exposes a module‑level singleton sequence_manager.
  • Updated src/network/tx_manager.py:

    • Replaced per‑account lock and counter with a global, lock‑free sequence fetch:
      from .sequence_manager import sequence_manager as _global_seq_mgr
      sequence = _global_seq_mgr.next()
    • Simplified broadcast flow while preserving signing and dispatch logic.

Benefits

  • Performance: Removes the serial lock that previously bottlenecked high‑load broadcasting.
  • Scalability: Workers can pre‑allocate blocks of sequence numbers, reducing synchronization overhead.
  • Maintainability: Centralized sequence management aligns with the existing nonce_tracker pattern.

Testing & Verification

  • All existing tests pass (pytest).
  • Manual sanity check confirms correct atomic allocation under concurrent access.
  • TxManager.broadcast still logs dispatched transactions with correct sequence numbers.

@drips-wave

drips-wave Bot commented Jun 26, 2026

Copy link
Copy Markdown

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

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.

🎫 Transport-Layer | Lock-Free Shared Sequence Trackers for Dynamic Horizon Broadcasts

1 participant