Skip to content

Soroban Transaction Footprint Optimizer #588

Description

@Kingsman-99

Description

Soroban transactions must declare their read and write ledger key footprints upfront; over-declaration wastes inclusion fees while under-declaration causes simulation failures. The SDK currently passes simulation footprints through without analysis, sometimes carrying stale or overly broad keys from earlier simulation runs that inflate resource fees. A footprint optimizer would diff a transaction's declared footprint against the minimal set returned by simulation and prune surplus entries before submission.

Technical Context

New module src/soroban/footprint.ts exposing optimizeFootprint(tx: Transaction, sim: SorobanRpc.Api.SimulateTransactionSuccessResponse): Transaction. Uses SorobanDataBuilder from @stellar/stellar-sdk to reconstruct the footprint in-place. A footprintDiff utility in src/utils/footprintDiff.ts returns { added: LedgerKey[]; removed: LedgerKey[]; unchanged: LedgerKey[] }. The optimizer is wired into the submission path in src/transaction/submit.ts as an opt-out step.

Acceptance Criteria

  • optimizeFootprint replaces the transaction's SorobanData with the minimal read/write key set reported by the simulation result
  • Ledger keys present in the original footprint but absent from simulation are removed, and each removed key is logged at debug level via the SDK logger
  • The optimizer is enabled by default and disabled by passing { optimizeFootprint: false } to submitTransaction
  • footprintDiff is exported as a public utility and covered by unit tests asserting correct classification of added, removed, and unchanged keys
  • Tests assert that a transaction with a bloated footprint is trimmed to match the simulation result exactly, and that an already-minimal footprint passes through unchanged
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions