Skip to content

Conversation

joe-p
Copy link
Contributor

@joe-p joe-p commented Oct 1, 2025

This PR ensures that resource population is deterministic. It should be noted that there is no way to guarantee that the algorithm we have is the most efficient and what works best for one group may not be best for another. For now, having determinism is a good starting point to eliminate edge-case failures. In the future we could potentially add retry mechanism with different ordering.

}

const allResources = []
for (let i = 0; i < 100; i++) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

100 iterations takes ~800ms on my machine. I think it's good enough to feel confident that it is indeed deterministic

@joe-p joe-p requested review from Copilot and lempira October 1, 2025 15:24
Copy link
Contributor

@Copilot Copilot AI left a comment

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 ensures deterministic resource population for AlgoKit when populating app call resources. It addresses non-deterministic resource ordering that was causing edge-case failures by implementing a consistent sorting algorithm for all resource types.

  • Implements deterministic sorting for all resource arrays returned by groupResponse.unnamedResourcesAccessed
  • Adds comprehensive tests to verify deterministic behavior across 100 iterations
  • Updates corresponding artifact files to reflect the new smart contract functionality

Reviewed Changes

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

Show a summary per file
File Description
tests/example-contracts/resource-packer/resource-packer.algo.ts Adds new methods and properties to test deterministic resource population
tests/example-contracts/resource-packer/artifacts/ResourcePackerv9.arc32.json Updates compiled contract artifacts with new methods and updated bytecode
tests/example-contracts/resource-packer/artifacts/ResourcePackerv8.arc32.json Updates bytecode to reflect changes in the contract compilation
tests/example-contracts/resource-packer/artifacts/InnerBoxApp.arc32.json Updates compiled bytecode for inner box application
tests/example-contracts/resource-packer/artifacts/ExternalApp.arc32.json Updates compiled bytecode for external application
src/transaction/transaction.ts Implements deterministic sorting logic for all resource types
src/transaction/transaction.spec.ts Adds test to verify deterministic resource ordering across multiple iterations
docs/code/modules/index.md Updates line numbers in documentation due to code changes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

return compare(aStr, bStr)
})
sortedResources.assetHoldings?.sort((a, b) => {
const aStr = `${a.asset}-${b.account}`

Choose a reason for hiding this comment

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

Suggested change
const aStr = `${a.asset}-${b.account}`
const aStr = `${a.asset}-${a.account}`

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.

2 participants