Skip to content

feat: throw helpful error on duplicate transactions in composer - #591

Open
mitre88 wants to merge 2 commits into
algorandfoundation:mainfrom
mitre88:mitre88/fix/composer-duplicate-txn-error
Open

feat: throw helpful error on duplicate transactions in composer#591
mitre88 wants to merge 2 commits into
algorandfoundation:mainfrom
mitre88:mitre88/fix/composer-duplicate-txn-error

Conversation

@mitre88

@mitre88 mitre88 commented Aug 1, 2026

Copy link
Copy Markdown

Summary

  • Detects identical transaction IDs within a composed group in build() and buildTransactions().
  • Throws a descriptive error that explains the common suggestedParams cache cause and how to make each txn unique (note, lease, validityWindow, rounds, or refresh params).
  • Adds unit tests covering the failure path and the successful differentiated-note path.

Context

Fixes #366. Duplicate transactions are easy to create accidentally when suggestedParams are cached (same first/last valid), e.g. multiple identical gas/app calls in one group. Today the network rejects the group with a less actionable error; this fails early with guidance.

Validation

npx vitest run src/types/composer.spec.ts -t "duplicate"
npx tsc --noEmit
npx eslint src/types/composer.ts src/types/composer.spec.ts

@mitre88

mitre88 commented Aug 9, 2026

Copy link
Copy Markdown
Author

Hi @joe-p @mrcointreau, this PR is ready for review. It fixes #366 by detecting duplicate transaction IDs in the composer group and throwing an actionable error that explains the suggestedParams cache cause and the fixes (note, lease, validityWindow, rounds). Unit tests cover the failure path and the differentiated-note success path. Validation: vitest, tsc, eslint all pass.

@mitre88
mitre88 force-pushed the mitre88/fix/composer-duplicate-txn-error branch from 9b0847f to 5f29ea2 Compare August 10, 2026 01:51
@joe-p
joe-p requested a lite review from Copilot August 14, 2026 19:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds early, descriptive detection of duplicate transactions within a composed transaction group, addressing cases where cached suggested params can lead to identical txIDs and an unhelpful network rejection.

Changes:

  • Add duplicate-transaction detection in build() and buildTransactions() and throw a guidance-rich error.
  • Add unit tests covering both the failure case (identical txns) and a success case (differentiated notes).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/types/composer.ts Adds duplicate txID detection and throws a descriptive error during build paths.
src/types/composer.spec.ts Adds unit tests to validate duplicate detection and a note-based differentiation scenario.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/types/composer.ts
Comment on lines +1895 to +1898
for (let index = 0; index < transactions.length; index++) {
const txId = transactions[index].txID()
const firstIndex = firstIndexById.get(txId)
if (firstIndex !== undefined) {
Comment thread src/types/composer.ts
Comment on lines +1899 to +1904
throw new Error(
`Transaction group contains duplicate transactions (same transaction ID) at indexes ${firstIndex} and ${index} (txID: ${txId}). ` +
`This often happens when suggestedParams are cached, so identical calls get the same firstValid/lastValid rounds. ` +
`Make each transaction unique (e.g. different note, lease, validityWindow, firstValidRound/lastValidRound, or other fields), ` +
`or refresh suggested params (setSuggestedParamsCacheTimeout(0) or wait for the cache to expire and call getSuggestedParams again).`,
)
@joe-p

joe-p commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

This PR should be targeting main and not release. It's also not clear why there are changes outside of src/

@mitre88
mitre88 force-pushed the mitre88/fix/composer-duplicate-txn-error branch from 5f29ea2 to 6f931b4 Compare August 20, 2026 04:58
@mitre88

mitre88 commented Aug 20, 2026

Copy link
Copy Markdown
Author

Update (author)

Rebased onto latest main and unblocked the previous build-and-test / node-ci failure.

  • Root cause was better-npm-audit / current advisory DB (not the composer feature).
  • Refreshed .nsprc + package.json overrides (incl. nanoid advisory 1139427; brace-expansion >=5.0.9).
  • Locally: npm run auditAll good.
  • Head: 6f931b42.

GitHub Actions on this fork PR is currently action_required (workflow run waiting on maintainer approval to execute), so checks may not show green until a maintainer approves the workflow run:
https://github.com/algorandfoundation/algokit-utils-ts/actions/runs/32333845516

Happy to adjust if review wants a different audit policy than the exclusions already used on sibling PRs.

Detect identical transaction IDs within a composed group and fail early
with guidance about cached suggestedParams and how to differentiate
transactions (note, lease, validity window). Closes algorandfoundation#366.
@mitre88
mitre88 force-pushed the mitre88/fix/composer-duplicate-txn-error branch from 6f931b4 to 7062441 Compare August 20, 2026 05:03
@mitre88

mitre88 commented Aug 20, 2026

Copy link
Copy Markdown
Author

Rebased onto main. The diff is now only src/types/composer.ts and the spec; the extra files were from the old release comparison.

Duplicate-detection tests pass locally (npx vitest run src/types/composer.spec.ts -t "duplicate detection"). The error text now points at AlgorandClient suggested-params cache APIs, not methods on TransactionComposer.

node-ci on the previous head failed in npm audit against main's lockfile, not this change. #600 refreshes .nsprc so this PR can stay feature-only.

Call out 0-based indexes and keep the suggested-params hint on
AlgorandClient APIs so TransactionComposer users are not pointed at
methods that do not exist on the composer.
@mitre88

mitre88 commented Aug 20, 2026

Copy link
Copy Markdown
Author

Thanks for the base-branch note.

This PR now targets main and only changes src/types/composer.ts plus tests. I dropped the CI/audit files so the review stays on the duplicate-transaction error.

The node-ci npm run audit failures on this repo are pre-existing on main (dev-only advisories). Fork workflows also still need a maintainer approval to run.

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.

The composer should throw a helpful error message on duplicate transactions

3 participants