ledger: Make AccountDelta fields visible for serialization.#4620
ledger: Make AccountDelta fields visible for serialization.#4620winder merged 4 commits intoalgorand:masterfrom
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.
@algorandskiy converting to a thread
How's the StateDelta is used (which methods are needed) ? I guess only
GetByIdx,LenandGetResourceare 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.
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.
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.