Skip to content

Evict expired and submitted operations from MultiSigEscrowClient's in-memory Map #137

Description

@meshackyaro

Description

This issue aims to address the implementation of Automatic Eviction of Terminal MultiSig Operations.

The core objective is to: Add automatic eviction of completed ('submitted') and expired ('expired') multi-sig operations from MultiSigEscrowClient's internal operations Map, so long-lived SDK processes coordinating many escrow operations don't accumulate unbounded memory. MultiSigEscrowClient (src/escrow/multisig.ts) stores every operation ever created in private readonly operations = new Map<string, MultiSigOperation>() for the lifetime of the client instance. initMultiSigOperation only ever adds to this Map; nothing in the class ever calls this.operations.delete(...). getMultiSigStatus lazily flips an operation's status to 'expired' when checked past its expiresAt, and submitWhenReady flips it to 'submitted' on success, but a terminal-status operation is never removed — listOperations(escrowId) will keep returning every historical operation for that escrow forever. This is a distinct concern from the cross-process persistence gap already tracked by the #79 spike and #83 (which is about state not surviving a process boundary) — this issue is about state that never gets cleaned up even within one process's lifetime.

By completing this feature, we will ensure that the TrustFlow protocol maintains its high standards for security, usability, and decentralized logic. This issue requires careful attention to the SDK Wrapper architecture and adherence to the existing project conventions.

Component

SDK

Difficulty

🔴 Hard

Tasks

  • Review existing Typescript types (MultiSigOperation/MultiSigOperationStatus in src/types/multisig.ts)
  • Implement SDK method for: automatic eviction of completed and expired multi-sig operations from the operations Map
  • Decide on an eviction policy (e.g. delete N minutes after reaching a terminal status, or expose an explicit MultiSigEscrowClient.prune() method)
  • Document that listOperations reflects only retained (non-evicted) operations
  • Write Jest tests validating eviction behavior with fake timers

Acceptance Criteria

  • Feature accurately implements the objective above
  • MultiSigEscrowClient's operations Map does not grow without bound in a long-lived process
  • Any PR that introduces TypeScript errors is automatically blocked
  • Code is properly reviewed and approved by codeowners

Estimated Time

2-3 days

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions