Skip to content

simulate: resource population #6015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 74 commits into
base: master
Choose a base branch
from

Conversation

joe-p
Copy link
Contributor

@joe-p joe-p commented Jun 5, 2024

Summary

When a user calls simulate with UnnamedResources enabled, simulate should suggest to the user how they can populate the resource arrays in their transactions to properly send the transaction group to the network.

Test Plan

  • Test ResourcePopulator works with simple local (not group sharing) resources
  • Test ResourcePopulator with group sharing
  • Test ResourcePopulator resource limit detection with group sharing (ie. it is able to find the correct transaction to put a resource in)
  • Test Simulate with ResourcePopulator functionality
  • Test /simulate endpoint with ResourcePopulator functionality
  • Write smaller tests for better ledger/simulation/resources.go coverage

@joe-p joe-p changed the title Feat/populate_resources resource population Jun 5, 2024
@joe-p joe-p force-pushed the feat/populate_resources branch from 466fd50 to 5ba0a9a Compare June 5, 2024 23:06
@joe-p joe-p changed the title resource population simulate: resource population Jun 5, 2024
Copy link

codecov bot commented Jun 6, 2024

Codecov Report

Attention: Patch coverage is 89.97494% with 40 lines in your changes missing coverage. Please review.

Project coverage is 51.77%. Comparing base (c95bb50) to head (a253291).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
daemon/algod/api/server/v2/utils.go 0.00% 26 Missing ⚠️
ledger/simulation/resources.go 97.22% 6 Missing and 4 partials ⚠️
ledger/simulation/simulator.go 66.66% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6015      +/-   ##
==========================================
+ Coverage   51.60%   51.77%   +0.17%     
==========================================
  Files         649      649              
  Lines       87048    87447     +399     
==========================================
+ Hits        44917    45277     +360     
- Misses      39269    39302      +33     
- Partials     2862     2868       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joe-p
Copy link
Contributor Author

joe-p commented Mar 8, 2025

CI is failing due to an unrelated test: TestP2PEnableGossipService_BothDisable

Re-triggered test run passing

Copy link
Contributor

@jannotti jannotti left a comment

Choose a reason for hiding this comment

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

I still have a lot to look at, but don't want to sit on my current comments.

"description": "The account that needed to sign this transaction when no signature was provided and the provided signer was incorrect.",
"type": "string",
"x-algorand-format": "Address"
},
"populated-resource-arrays": {
Copy link
Contributor

@jannotti jannotti Mar 14, 2025

Choose a reason for hiding this comment

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

I'm basically agnostic on this question: Do you think this should be present if it's empty? I lean toward it not appearing, but don't care too much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think mirroring the behavior of unnamed-resources-accessed (not being a required field) makes the most sense

Copy link
Contributor

@jannotti jannotti left a comment

Choose a reason for hiding this comment

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

A couple small utility functions that I had forgotten we had ready to go.

@joe-p
Copy link
Contributor Author

joe-p commented May 5, 2025

All comments have been addressed. I also noticed CI failed. I need to step away for a minute but will take a closer look later today.

Also apologies for the long delays between addressing feedback, should be able to focus on this to get it across the finish line now.

Edit: Seemed to have introduced a regression
Edit2: Should be fixed in 0df1e0f. Tests passing locally, will wait for CI

@jannotti
Copy link
Contributor

jannotti commented May 5, 2025

You probably need to re-merge master and make api to fix the generated conflicts.

@jannotti jannotti requested review from jannotti and jasonpaulos May 5, 2025 23:31
Copy link
Contributor

@jannotti jannotti left a comment

Choose a reason for hiding this comment

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

Some simplistic code comments, and some question about when you add certain things. I think the existing order may be perfectly fine, despite my early comments reservations. But take my confusion as a request to find a good place to describe the whole strategy all at once in a comment.

I became worried that you are not accounting for old avm version apps, which can't use resource sharing. But I think maybe you're ok, because the response from simulate was taken that into account and places the necessary refs in the specific transactions if needed?

Boxes: &boxes,
}

return &populatedResourceArrays
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm concerned this will always return in the json even if it's empty. It will always be non-nil, and it will always contain non-nil fields. boxes is always non-nil, and the others probably are too, depending on exactly how convertSlice deals with empty slices.

return nil
}

// addBox adds a box to the box array. It does NOT add the app to the app array.
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it should fail if the app is not there then? I haven't looked to see how it's used yet...

Comment on lines 1090 to 1096
for box := range groupResourceTracker.Boxes {
groupResources.Boxes = append(groupResources.Boxes, box)
}
slices.SortFunc(groupResources.Boxes, func(a, b logic.BoxRef) int {
// NOTE: We intentionally sort in reverse order for apps so appID 0 is last since they can go anywhere
return cmp.Or(cmp.Compare(b.App, a.App), cmp.Compare(a.Name, b.Name))
})
Copy link
Contributor

Choose a reason for hiding this comment

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

same, though I now see you essentially do the deferral of the 0 app box refs I was thinking about.

maybe worth commenting to that effect in addBox? I don't know.

})
}

// Then assign accounts because they have a lower limit than other resources
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, interesting. You're doing the single resources last. In some of my reasoning above, I assumed you'd do them first. I think I agree with this though. Your cross-ref types will "find" the best place to land based on the existing references and fields, right? So after that, it is indeed probably better to do these last, because the cross-ref types may make have already put them somewhere.

@joe-p
Copy link
Contributor Author

joe-p commented May 6, 2025

Some simplistic code comments, and some question about when you add certain things. I think the existing order may be perfectly fine, despite my early comments reservations. But take my confusion as a request to find a good place to describe the whole strategy all at once in a comment.

I will add this in a comment but the general philosophy is to go in order of resources with the most restrictions to least. This is why the order is

  1. Txn-specific resources
  2. Cross-ref resources (because they need two slots and we don't want single slot resources to potentially use up one of the available two-slot transactions)
  3. Boxes, because they may require an app ref in addition to the box ref
  4. Accounts because they have a lower limit than other resources
  5. Standalone resources

I became worried that you are not accounting for old avm version apps, which can't use resource sharing. But I think maybe you're ok, because the response from simulate was taken that into account and places the necessary refs in the specific transactions if needed?

Yeah exactly. The logic for transaction-specific references exists upstream in simulate. By the time we reach the resource populator we know txn-specific resources and can handle those first

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

Successfully merging this pull request may close these issues.

Given list of necessary resources, automatically populate reference arrays
5 participants