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

algod: Migrate internal uses of v1 algod API to v2 #4684

Merged
merged 37 commits into from
Nov 3, 2022

Conversation

algochoi
Copy link
Contributor

@algochoi algochoi commented Oct 21, 2022

Summary

As part of sunsetting v1 algod APIs, we want to only use v2 algod APIs in the internal REST client. Relates to #2976.

This PR changes the client code and internal tests/tooling to use v2 models and endpoints.

There are two v1 endpoints that do not have an equivalent endpoint in v2:

  • /v1/account/%s/transactions
    • There is a direct test in restClient_test.go that uses this endpoint - resolve/delete test when v1 API is sunsetted.
  • /v1/account/%s/transactions/%s
    • Replaced with v2 API: /v2/account/%s/transactions/pending

Major Changes:

  • restClient.go, libgoal: Add v2 endpoints and use v2 models/responses. Add helper function in libgoal to parse pending transaction responses into a struct by decoding from msgpack.
  • algoh: Use v2 Block instead of v1 Block. Since the v2 Block API does not return the Proposer information, we get the raw block and parse it for the block + certificate.
  • loadgenerator (along with tests) now uses the v2 endpoint to send transactions
  • pingpong now uses the v2 models and endpoints
  • The block and transaction endpoints return different models in v1 versus v2 - related changes in response schema.
  • Change asset information with v2 responses - they now have pointer fields to denote whether a field is empty or not

Testing:

  • Modified and ran existing tests on CI
  • Pingpong tests show that the delta in performance with respect to master branch is <5%
  • Thanks to @algolucky for testing the changes on loadgenerator !

Future work

For the sake of keeping diffs small in a single PR, we should do the following in a future ticket:

  • Delete v1 endpoint usage in REST client and libgoal client
  • Delete any legacy or deprecated goal commands that use v1 functionality (legacyListParticipationKeysCommand)
  • Remove redundant tests that test both V1 and V2 functionality

@codecov
Copy link

codecov bot commented Oct 27, 2022

Codecov Report

Merging #4684 (52f3b85) into master (ab87a8a) will decrease coverage by 0.06%.
The diff coverage is 7.88%.

@@            Coverage Diff             @@
##           master    #4684      +/-   ##
==========================================
- Coverage   54.49%   54.43%   -0.07%     
==========================================
  Files         407      407              
  Lines       52425    52499      +74     
==========================================
+ Hits        28569    28576       +7     
- Misses      21472    21540      +68     
+ Partials     2384     2383       -1     
Impacted Files Coverage Δ
cmd/algoh/deadman.go 0.00% <0.00%> (ø)
cmd/goal/account.go 12.62% <0.00%> (ø)
cmd/goal/application.go 12.64% <0.00%> (ø)
cmd/goal/asset.go 15.58% <0.00%> (-0.67%) ⬇️
cmd/goal/clerk.go 8.75% <0.00%> (ø)
cmd/goal/interact.go 3.62% <0.00%> (ø)
cmd/goal/ledger.go 16.21% <0.00%> (ø)
cmd/goal/node.go 12.71% <0.00%> (ø)
daemon/algod/api/server/v2/handlers.go 0.00% <0.00%> (ø)
daemon/algod/api/server/v2/utils.go 13.19% <0.00%> (ø)
... and 14 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

libgoal/libgoal.go Outdated Show resolved Hide resolved
libgoal/libgoal.go Outdated Show resolved Hide resolved
cmd/algoh/blockstats.go Outdated Show resolved Hide resolved
Co-authored-by: Will Winder <wwinder.unh@gmail.com>
@algochoi algochoi mentioned this pull request Nov 2, 2022
@brianolson
Copy link
Contributor

brianolson commented Nov 2, 2022

I looked at shared/pingpong/*.go and libgoal/*.go and things look good, but a couple deprecated functions in libgoal/*.go -- could we just delete them? Assume that nothing outside this repository uses them and other things use go-algorand-sdk ?

@algochoi
Copy link
Contributor Author

algochoi commented Nov 3, 2022

@brianolson Thanks a lot for confirming the pingpong files 👍

I looked at shared/pingpong/.go and libgoal/.go and things look good, but a couple deprecated functions in libgoal/*.go -- could we just delete them? Assume that nothing outside this repository uses them and other things use go-algorand-sdk ?

Yes, we can do that - I noted down things we can delete in a near future PR (deleting all deprecated libgoal/client code, tests, deprecated goal commands) to keep diffs smaller for reviewers and narrow the scope of work here.

Copy link
Contributor

@michaeldiamant michaeldiamant left a comment

Choose a reason for hiding this comment

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

@algochoi Thanks for covering a lot of ground here - Looks ready to go from my side.

algod, err := c.ensureAlgodClient()
if err == nil {
var resp []byte
resp, err = algod.RawBlock(round)
if err == nil {
var b rpcs.EncodedBlockCert
err = protocol.DecodeReflect(resp, &b)
err = protocol.DecodeReflect(resp, &blockCert)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I know you didn't write the original code, but rpcs.EncodedBlockCert has generated msgp methods, so it would benefit slightly from using protocol.Decode instead of protocol.DecodeReflect

}

reserve, err := client.AccountInformation(params.ReserveAddr)
reserve, err := client.AccountInformationV2(*asset.Params.Reserve, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think client.AccountAssetInformation(*asset.Params.Reserve, assetID) could be used instead of client.AccountInformationV2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Followed up offline: It looks like we'd want to change the behavior so that goal asset info fails if the reserve doesn’t hold the asset - this will likely involve changing a test (test/scripts/e2e_subs/asset-misc.sh) to address this in a follow-up PR.

} else {
// Fetch the current state, to fill in as a template
current, err := c.AccountInformation(creator)
current, err := c.AccountInformationV2(creator, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to suggest this could be improved with client.AccountAssetInformation, but I don't think this side of the if statement needs to exist at all.

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 I agree - I'll follow up on this in another PR

@michaeldiamant
Copy link
Contributor

Merging - Have agreed with @algochoi that the remaining open threads will be addressed in a prior PR before closing the story. Merging the PR to minimize merge conflicts.

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.

5 participants