-
Notifications
You must be signed in to change notification settings - Fork 494
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
base: master
Are you sure you want to change the base?
Conversation
466fd50
to
5ba0a9a
Compare
Codecov ReportAttention: Patch coverage is
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. 🚀 New features to boost your workflow:
|
Re-triggered test run passing |
There was a problem hiding this 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": { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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.
prefer Sort over SortFunc and use Cmp.or instead of Sprintf
Co-authored-by: John Jannotti <[email protected]>
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 |
This was erroneously removed in 6353f3b
You probably need to re-merge master and |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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...
ledger/simulation/resources.go
Outdated
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)) | ||
}) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
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
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 |
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
/simulate
endpoint with ResourcePopulator functionalityledger/simulation/resources.go
coverage