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 Deltas: AccountDelta retrieval through ledger/catchup service #4658

Merged
merged 71 commits into from
Dec 6, 2022

Conversation

Eric-Warehime
Copy link
Contributor

@Eric-Warehime Eric-Warehime commented Oct 17, 2022

Summary

WIP PR that exposes AccountDeltas via the NodeInterface (APIs). The motivation for this is to be able to decouple the Indexer from having a go-algorand dependency via the local ledger--which requires us to be able to fetch Account changes per round.

This includes two new APIs:

  • /v2/ledger/sync/
  • /v2/deltas/

The sync round API will only be exposed via an admin API, and will specify the minimum round that the user wants to ensure the cache will hold the AccountDeltas object for. In order to implement this we simply prevent the ledger from progressing via the agreement service (by not running it), and no-op any round fetches by the catchup service until the sync round changes.

TODO

  • Unit Tests
  • Add algod APIs

@codecov
Copy link

codecov bot commented Oct 18, 2022

Codecov Report

Merging #4658 (59563ba) into master (3a5e584) will increase coverage by 0.04%.
The diff coverage is 56.77%.

@@            Coverage Diff             @@
##           master    #4658      +/-   ##
==========================================
+ Coverage   53.76%   53.80%   +0.04%     
==========================================
  Files         421      422       +1     
  Lines       53849    54002     +153     
==========================================
+ Hits        28950    29056     +106     
- Misses      22543    22589      +46     
- Partials     2356     2357       +1     
Impacted Files Coverage Δ
daemon/algod/api/server/v2/handlers.go 0.87% <0.00%> (-0.04%) ⬇️
ledger/ledger.go 69.87% <0.00%> (-0.66%) ⬇️
node/node.go 4.34% <0.00%> (-0.03%) ⬇️
daemon/algod/api/server/v2/test/helpers.go 74.65% <57.14%> (+0.71%) ⬆️
daemon/algod/api/server/v2/account.go 77.52% <64.28%> (-0.26%) ⬇️
ledger/acctupdates.go 68.99% <65.38%> (-0.59%) ⬇️
ledger/accountdb.go 68.34% <66.66%> (+0.27%) ⬆️
daemon/algod/api/server/v2/delta.go 71.13% <71.13%> (ø)
catchup/service.go 70.04% <75.00%> (+1.82%) ⬆️
ledger/blockqueue.go 85.63% <0.00%> (-2.88%) ⬇️
... and 13 more

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

@Eric-Warehime Eric-Warehime changed the title WIP: AccountDelta retrieval through ledger/catchup service Ledger Deltas: AccountDelta retrieval through ledger/catchup service Oct 24, 2022
@Eric-Warehime Eric-Warehime marked this pull request as ready for review October 24, 2022 01:38
catchup/service.go Outdated Show resolved Hide resolved
winder
winder previously approved these changes Dec 2, 2022
Copy link
Contributor

@winder winder left a comment

Choose a reason for hiding this comment

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

Thanks for the updates, looks good!

catchup/service.go Outdated Show resolved Hide resolved
catchup/service.go Outdated Show resolved Hide resolved
@@ -164,7 +164,7 @@ type accountUpdates struct {
cachedDBRound basics.Round

// deltas stores updates for every round after dbRound.
deltas []ledgercore.AccountDeltas
deltas []ledgercore.StateDelta
Copy link
Contributor

@cce cce Dec 2, 2022

Choose a reason for hiding this comment

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

StateDelta contains AccountTotals too like what's in []roundTotals right? That is another duplicate now..

Copy link
Contributor

Choose a reason for hiding this comment

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

StateDelta contains a block header pointer that contains the version data in []versions too ... IDK how far this goes but it would be duplicate memory too.. maybe having helper methods for each of the things being replaced?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it does, but combining it into the state deltas in the same way as the other deltas caused a bunch of test failures unrelated to these changes. So in favor of caution I decided it leave those separate.

Copy link
Contributor

Choose a reason for hiding this comment

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

test compilation failures you didn't want to have to change or test run failures? which one, totals or versions or both?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Combining the roundTotals caused test run failures--I'm struggling to remember exactly which test failed, but it caused incorrect totals to be reported. It's possible (probable?) this was just a mistake in my implementation.

The other problem with it is that the totals includes the currentDbRound which means it's longer than the size of deltas.

I'm happy to give it another shot if these are blocking issues.

Copy link
Contributor

@algorandskiy algorandskiy Dec 2, 2022

Choose a reason for hiding this comment

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

this one is easy to answer: totals and versions have the very first entry deducated for dbRound (latest committed), and deltas do not have it.

Copy link
Contributor

Choose a reason for hiding this comment

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

It sounds like this shouldn't be a blocker.

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've been working through this, removing the storage duplication, and I think it's best done in its own PR. @algorandskiy @cce Is it ok if we merge this for now and I'll follow up with a change to dedupe data stored in StateDelta/accountupdates?

winder
winder previously approved these changes Dec 3, 2022
algorandskiy
algorandskiy previously approved these changes Dec 5, 2022
Copy link
Contributor

@algorandskiy algorandskiy left a comment

Choose a reason for hiding this comment

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

LGTM, consider changing semantic of catchup.Service.syncRound

syncStartNS int64 // at top of struct to keep 64 bit aligned for atomic.* ops
syncStartNS int64 // at top of struct to keep 64 bit aligned for atomic.* ops
// SyncRound, provided externally, which the ledger must keep in cache
syncRound uint64
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe syncRound -> targetSyncRound or something ?
the comment opens too much details about ledger to the service. What if the caller sets syncRound to X-cfg.MaxAcctLookback? in this case this would be a target sync round

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've moved MaxAcctLookback access out of the catchup service which makes it more straightforward and avoids the catchup service knowing about the ledger trackers' cache size.

The new variable is disableSyncRound which is the first round we don't want to fetch from the network. Now the node passes in the correct round to the catchup service. This avoids requiring API users from having to think about cache settings when using the API.

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.

7 participants