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

REST API: add support for optional "round" parameter to lookup queries #4018

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cce
Copy link
Contributor

@cce cce commented May 20, 2022

Summary

This demonstrates how it would be possible to add support for providing a round number to ledger lookup methods accessed by the REST API.

Test Plan

Existing tests should pass, extra tests could be added for querying data using round numbers that are too old to be retrieved.

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 want this change because it enshrines the conclusion we've been getting to lately: algod ought to support at least some lookback, as an aid to retrieving a set of data consistent across calls, for speculative execution, and because indexer can't.

// getOptionalRound converts an optional round argument into a basics.Round(0) for "latest"
// or a non-negative integer.
// TODO: could change this to parse a string argument and allow param to use string value "latest"
func getOptionalRound(round *uint64) (basics.Round, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This interface seems like a funny middle ground. If we only care about supporting "latest" or a number, I think it's fine to only take numbers, and remove all of the ceremony around an error that never happens. If we wanted to support of kind of tokens besides "latest" we would need to change the input type and the output type (because using 0 as a special case would be insufficient). I lean toward guessing there are no other good named rounds, so I'd rather just skip the error stuff for now.

Comment on lines +749 to +750
// totalsImpl returns the online totals of all accounts at the end of round rnd.
func (au *accountUpdates) totalsImpl(rnd basics.Round) (ledgercore.AccountTotals, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we do this a lot, but "Impl" always bugs be as a name because it doesn't say anything about why it's pulled out. Here I guess the point is that it is totalsWithoutLocking or some such. (I'd love a more concise convention for such cases.)

Here, since it's only called from Totals, I guess I'd rather just inline it.

Comment on lines +468 to +473
data, rnd, withoutRewards, err := l.accts.lookupLatest(0, addr)
if err != nil {
return basics.AccountData{}, basics.Round(0), basics.MicroAlgos{}, err
}

return data, rnd, withoutRewards, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
data, rnd, withoutRewards, err := l.accts.lookupLatest(0, addr)
if err != nil {
return basics.AccountData{}, basics.Round(0), basics.MicroAlgos{}, err
}
return data, rnd, withoutRewards, nil
return l.accts.lookupLatest(0, addr)

defer l.trackerMu.RUnlock()

// Intentionally apply (pending) rewards up to rnd.
data, rnd, withoutRewards, err := l.accts.lookupLatest(round, addr)
Copy link
Contributor

Choose a reason for hiding this comment

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

same suggestion, but github won't let me do it inline because this isn't all new code

@jannotti
Copy link
Contributor

@tzaffi would we need to change the algod/indexer API parity checker to allow this?

@tzaffi
Copy link
Contributor

tzaffi commented May 23, 2022

@tzaffi would we need to change the algod/indexer API parity checker to allow this?

Looks like this is going to pass the indexer parity check as is (I tested this locally). This may be because the latest iteration is only looking at the definitions.Account sub-section of swagger (so is not looking at the endpoint definitions). I'm wondering whether that is sufficient, or if it misses a diff that it ought to alert on for this PR.

@winder

@@ -1084,7 +1129,7 @@ func (v2 *Handlers) GetPendingTransactions(ctx echo.Context, params generated.Ge

// GetApplicationByID returns application information by app idx.
// (GET /v2/applications/{application-id})
func (v2 *Handlers) GetApplicationByID(ctx echo.Context, applicationID uint64) error {
func (v2 *Handlers) GetApplicationByID(ctx echo.Context, applicationID uint64, params generated.GetApplicationByIDParams) error {
appIdx := basics.AppIndex(applicationID)
ledger := v2.Node.LedgerForAPI()
creator, ok, err := ledger.GetCreator(basics.CreatableIndex(appIdx), basics.AppCreatable)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just realized this does not use GetCreatorForRound

@codecov
Copy link

codecov bot commented Oct 26, 2023

Codecov Report

Attention: Patch coverage is 5.71429% with 66 lines in your changes missing coverage. Please review.

Project coverage is 54.36%. Comparing base (8e6cef1) to head (8020f6a).
Report is 1355 commits behind head on master.

Files with missing lines Patch % Lines
daemon/algod/api/server/v2/handlers.go 0.00% 45 Missing ⚠️
ledger/acctupdates.go 16.66% 9 Missing and 1 partial ⚠️
ledger/ledger.go 20.00% 7 Missing and 1 partial ⚠️
daemon/algod/api/server/v2/utils.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4018      +/-   ##
==========================================
+ Coverage   49.77%   54.36%   +4.59%     
==========================================
  Files         409      390      -19     
  Lines       69157    48559   -20598     
==========================================
- Hits        34420    26400    -8020     
+ Misses      31014    19930   -11084     
+ Partials     3723     2229    -1494     

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

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