-
Notifications
You must be signed in to change notification settings - Fork 473
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: Make AccountDelta fields visible for serialization. #4620
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4620 +/- ##
==========================================
+ Coverage 54.37% 54.40% +0.03%
==========================================
Files 407 407
Lines 52389 52389
==========================================
+ Hits 28486 28503 +17
+ Misses 21520 21507 -13
+ Partials 2383 2379 -4
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
I suggest not to expose this data type. Or at least not entirely (keep *Cache) portion private and reconstruct after deserialization as needed - they are just lookup helpers, and not sure if they needed by the Indexer at all. |
This PR was mostly for discussion. I have a branch on Indexer which is writing this to a file and loading Indexer with these files instead of a live algod. It seems to work fine and might be a simpler alternative to a new API. In either case the data needs to be serialized somehow. |
How's the StateDelta is used (which methods are needed) ? I guess only |
@@ -160,19 +157,19 @@ type AssetResourceRecord struct { | |||
// The map would point the address/address+creatable id onto the index of the | |||
// element within the slice. | |||
type AccountDeltas struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@algorandskiy converting to a thread
How's the StateDelta is used (which methods are needed) ? I guess only
GetByIdx
,Len
andGetResource
are needed. Only the last one requires maps for lookup.
When the object has been created by the ledger, we only need the public methods. This is all code that Tolic and Tsachi wrote. The entry point is here: https://github.com/algorand/indexer/blob/develop/idb/postgres/internal/writer/writer.go#L327
It's split out pretty nicely in writeAccountDeltas:
- writeAccount(... ledgercore.AccountData ...)
- writeAppResource(... ledgercore.AppResourceRecord ...)
- writeAssetResource(... ledgercore.AssetResourceRecord ...)
- A similar method for boxes has been written.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, so only accts
, appResources
, assetResources
should be exported for serialization. The downside is StateDelta would miss all maps after protocol.Decode
call.
func (ad *AccountDeltas) GetAllAppResources() []AppResourceRecord { | ||
return ad.appResources | ||
return ad.AppResources | ||
} | ||
|
||
// GetAllAssetResources returns all AssetResourceRecords | ||
func (ad *AccountDeltas) GetAllAssetResources() []AssetResourceRecord { | ||
return ad.assetResources | ||
return ad.AssetResources |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively we can just add
func (ad *AccountDeltas) GetAllAccounts() []NewBalanceRecord {
return ad.accts
}
so that we have accessors for all the private fields.
Summary
The StateDelta object is part of Indexer's interface and I'd like to serialize it to a file, but some of the fields are private.