Skip to content
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

ledger: fix lookupLatest usage of the resources cache #3939

Merged
merged 2 commits into from
May 1, 2022

Conversation

algorandskiy
Copy link
Contributor

Summary

  • In some situations the method might incorrectly count
    deleted items towards total items
  • This might result not returning all the resources to
    REST API clients

Test Plan

Test added

* In some situations the method might incorrectly count
  deleted items towards total items
* This might result not returning all the resources to
  REST API clients
@codecov-commenter
Copy link

codecov-commenter commented Apr 30, 2022

Codecov Report

Merging #3939 (fd5d14d) into master (1729a3e) will increase coverage by 0.01%.
The diff coverage is 28.57%.

@@            Coverage Diff             @@
##           master    #3939      +/-   ##
==========================================
+ Coverage   49.79%   49.80%   +0.01%     
==========================================
  Files         409      409              
  Lines       68892    68897       +5     
==========================================
+ Hits        34303    34313      +10     
+ Misses      30884    30881       -3     
+ Partials     3705     3703       -2     
Impacted Files Coverage Δ
ledger/ledgercore/accountresource.go 0.00% <0.00%> (ø)
ledger/acctupdates.go 68.77% <100.00%> (+0.26%) ⬆️
ledger/blockqueue.go 82.18% <0.00%> (-2.88%) ⬇️
data/abi/abi_type.go 87.67% <0.00%> (-0.95%) ⬇️
network/wsNetwork.go 62.99% <0.00%> (-0.20%) ⬇️
network/wsPeer.go 68.88% <0.00%> (+0.27%) ⬆️
cmd/tealdbg/debugger.go 73.49% <0.00%> (+0.80%) ⬆️
catchup/peerSelector.go 100.00% <0.00%> (+1.04%) ⬆️
crypto/merkletrie/node.go 93.48% <0.00%> (+1.86%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1729a3e...fd5d14d. Read the comment docs.

@@ -42,29 +42,34 @@ type AppResource struct {

// AssignAccountResourceToAccountData assignes the Asset/App params/holdings contained
// in the AccountResource to the given basics.AccountData, creating maps if necessary.
func AssignAccountResourceToAccountData(cindex basics.CreatableIndex, resource AccountResource, ad *basics.AccountData) {
func AssignAccountResourceToAccountData(cindex basics.CreatableIndex, resource AccountResource, ad *basics.AccountData) (assigned bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe a comment like

Suggested change
func AssignAccountResourceToAccountData(cindex basics.CreatableIndex, resource AccountResource, ad *basics.AccountData) (assigned bool) {
// Returns true if the AccountResource contained a new or updated resource, and false if the AccountResource contained no changes (indicating the resource was deleted).
func AssignAccountResourceToAccountData(cindex basics.CreatableIndex, resource AccountResource, ad *basics.AccountData) (assigned bool) {

Copy link
Contributor

@cce cce May 1, 2022

Choose a reason for hiding this comment

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

I guess another way to do it (rather than mix it into the Assign method) would be to have a method like

// IsEmpty is maybe not a great name, perhaps there is something clearer
func (r *AccountResource) IsEmpty() bool {
   return r.AssetParams == nil && r.AssetHolding == nil && r.AppLocalState == nil && r.AppParams == nil
}

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 thought about checking in addResource but I think AssignAccountResourceToAccountData is a right place because 1) it has "insertion" logic 2) it basically creates the output data structure 3) it is used only in addResource.
Updated the AssignAccountResourceToAccountData comment as suggested.

cce
cce previously approved these changes May 1, 2022
Copy link
Contributor

@cce cce left a comment

Choose a reason for hiding this comment

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

Glad you found this, I did not consider needing to skip counting empty AccountResources.. LGTM, just a minor point about comments or alternate IsEmpty() approach that might make it easier to read

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.

3 participants