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

catchpoints: Add onlineaccounts and onlineroundparamstail tables to snapshot files #6177

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

Conversation

cce
Copy link
Contributor

@cce cce commented Nov 25, 2024

Summary

The new opcodes in #5984 require access to historical lookups of online account details and total circulation amounts. During catchpoint restore, replaying and evaluating old blocks bootstraps the tracker DBs. However transactions that use these opcodes will fail, since they need access to historical ledger amounts earlier than the horizon of the catchpoint snapshot. This PR adds the onlineaccounts and onlineroundparamstail tables to the snapshot files, which provide online account lookup and total circulation amounts, respectively.

Test Plan

Existing tests should pass — working on extending an existing catchpoint test to use the voter_params_get and online_stake opcodes (similar to some catchpoint tests written for testing use of box opcodes).

Copy link

codecov bot commented Nov 25, 2024

Codecov Report

Attention: Patch coverage is 39.95157% with 248 lines in your changes missing coverage. Please review.

Project coverage is 51.79%. Comparing base (0bc3d7e) to head (d775659).

Files with missing lines Patch % Lines
ledger/store/trackerdb/sqlitedriver/kvsIter.go 0.00% 58 Missing ⚠️
ledger/store/trackerdb/sqlitedriver/catchpoint.go 0.00% 47 Missing ⚠️
ledger/catchupaccessor.go 62.88% 24 Missing and 12 partials ⚠️
ledger/catchpointfilewriter.go 74.68% 10 Missing and 10 partials ⚠️
.../store/trackerdb/dualdriver/accounts_reader_ext.go 0.00% 20 Missing ⚠️
ledger/store/trackerdb/sqlitedriver/accountsV2.go 0.00% 14 Missing ⚠️
ledger/ledgercore/catchpointlabel.go 27.77% 13 Missing ⚠️
ledger/catchpointtracker.go 81.25% 5 Missing and 4 partials ⚠️
...edger/store/trackerdb/sqlitedriver/sqlitedriver.go 0.00% 6 Missing ⚠️
ledger/store/trackerdb/dualdriver/dualdriver.go 0.00% 5 Missing ⚠️
... and 6 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6177      +/-   ##
==========================================
- Coverage   51.86%   51.79%   -0.08%     
==========================================
  Files         639      640       +1     
  Lines       85492    85818     +326     
==========================================
+ Hits        44344    44447     +103     
- Misses      38331    38525     +194     
- Partials     2817     2846      +29     

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


🚨 Try these New Features:

Comment on lines +37 to +38
TotalOnlineAccounts uint64 `codec:"onlineAccountsCount"`
TotalOnlineRoundParams uint64 `codec:"onlineRoundParamsCount"`
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't these added at the end of the struct? If I remember correctly msgp can encode structs into arrays or maps

Balances []encoded.BalanceRecordV6 `codec:"bl,allocbound=BalancesPerCatchpointFileChunk"`
numAccounts uint64
KVs []encoded.KVRecordV6 `codec:"kv,allocbound=BalancesPerCatchpointFileChunk"`
OnlineAccounts []encoded.OnlineAccountRecordV6 `codec:"oa,allocbound=BalancesPerCatchpointFileChunk"`
Copy link
Contributor

Choose a reason for hiding this comment

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

why adding into v6 struct and not defining v7 struct?

@@ -1165,7 +1201,7 @@ func (ct *catchpointTracker) isWritingCatchpointDataFile() bool {
// - Balance and KV chunk (named balances.x.msgpack).
// ...
// - Balance and KV chunk (named balances.x.msgpack).
func (ct *catchpointTracker) generateCatchpointData(ctx context.Context, accountsRound basics.Round, catchpointGenerationStats *telemetryspec.CatchpointGenerationEventDetails, encodedSPData []byte) (totalKVs, totalAccounts, totalChunks, biggestChunkLen uint64, err error) {
func (ct *catchpointTracker) generateCatchpointData(ctx context.Context, accountsRound basics.Round, catchpointGenerationStats *telemetryspec.CatchpointGenerationEventDetails, encodedSPData []byte) (totalAccounts, totalKVs, totalOnlineAccounts, totalOnlineRoundParams, totalChunks, biggestChunkLen uint64, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like it is time to switch from 7 return params to struct?

}
}

func (l *CatchpointLabelMakerCurrent) buffer() []byte {
Copy link
Contributor

Choose a reason for hiding this comment

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

I got lost, we added online account into v8 label, didn't we?

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.

Implementation looks correct. Our versioning is very confusing though

@@ -854,7 +854,7 @@ func TestExactAccountChunk(t *testing.T) {
catchpointFilePath := filepath.Join(tempDir, t.Name()+".catchpoint.tar.gz")

cph := testWriteCatchpoint(t, dl.validator.trackerDB(), catchpointDataFilePath, catchpointFilePath, 0)
require.EqualValues(t, cph.TotalChunks, 1)
require.EqualValues(t, cph.TotalChunks, 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

why is there one more chunk? Added online accounts overgrew the max chunk size?

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.

2 participants