Skip to content

Migrate withdrawal_audit to async flusher w/ Postgres sink (with multi-instance lock) #139

Description

@ibrahimmosouf-png

Migrate withdrawal_audit to async flusher w/ Postgres sink (with multi-instance lock)

Labels: cli, infrastructure, priority/medium
Difficulty: High · Effort: L
Backlog slot: 52

Problem Statement

WithdrawalAuditLog is in-memory + on-disk JSONL. No durable multi-host store; no scheduled flush. Critically, two concurrent CLI processes writing to the same JSONL file can interleave bytes, corrupt records, or duplicate appends — this is single-writer-only but the file system does not enforce it.

Why it Matters

  • A serious operational tool needs a back-end store that survives container eviction and supports analytics.
  • Audit logs must be tamper-evident; interleaved writes silently violate that.

Expected Outcome

  • Background tokio task flushes every 5s.
  • Plugin arch: AuditSink trait with JsonlSink and PostgresSink impls.
  • Process-policy lock: a flock(2) advisory lock on a sidecar file (audit.lock) gates every flush; flushers in degraded Postgres mode rotate through a leader-election pattern anchored on the lock. Two CLI processes running concurrently must produce append-only output without interleaving.

Acceptance Criteria

  • Two-process race test: cargo test --features integration flush_concurrent_processes_succeeds passes.
  • Documented operational guide + runbook including "what the advisory lock does under transient network partition".

Files Likely Affected

  • crates/tools/src/withdrawal_audit.rs

Dependencies

None.


Activity

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

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26cliImported from .github/ISSUES_TO_CREATE.mdinfrastructureImported from .github/ISSUES_TO_CREATE.mdpriority/mediumImported from .github/ISSUES_TO_CREATE.md

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions