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 11 commits 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:

ledger/catchpointfileheader.go Show resolved Hide resolved
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?

Copy link
Contributor Author

@cce cce Dec 4, 2024

Choose a reason for hiding this comment

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

This is a good point, when KVs were added to the catchpoint V6 format's chunk encoding in #4455 it did not require making a new catchpoint version V7, because the existence of the KV fields signaled they were there, and the merkle trie implementation was updated to include KVs as a possible node type for the trie. So the KVs got hashed along with accounts and resources, and overall the verification scheme was the same as existing V6, so it was not a bump to V7. Once the KV consensus flag flipped over, then KVs would be populated in catchpoint files.

Later state proof recovery was added to catchpoints, that was a whole new and separate hash added to the header and label-generating scheme, so it got bumped to V7 to support state proofs (plus a consensus flag so all nodes switched to the new hashing scheme at the same time). V7 did not touch the catchpointFileChunkV6 type at all so its name was left alone.

Similarly, I am adding two new hashes (onlineaccounts and onlineroundparams) so I am bumping the catchpoint file format to "V8" (like state proof recovery did with V7) but still extending the "catchpiontFileChunkV6" struct with two new fields (like KV for catchpoints did). I guess that is a weird thing to do.. and maybe I should make a new V8 type like you're suggesting

@@ -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