@@ -33,6 +33,7 @@ import (
3333 "github.com/algorand/go-algorand/data/basics"
3434 "github.com/algorand/go-algorand/data/bookkeeping"
3535 "github.com/algorand/go-algorand/ledger/ledgercore"
36+ "github.com/algorand/go-algorand/ledger/store"
3637 "github.com/algorand/go-algorand/logging"
3738 "github.com/algorand/go-algorand/util/db"
3839 "github.com/algorand/go-algorand/util/metrics"
@@ -51,9 +52,10 @@ type modifiedOnlineAccount struct {
5152}
5253
5354// cachedOnlineAccount is a light-weight version of persistedOnlineAccountData suitable for in-memory caching
55+ //
5456//msgp:ignore cachedOnlineAccount
5557type cachedOnlineAccount struct {
56- baseOnlineAccountData
58+ store. BaseOnlineAccountData
5759 updRound basics.Round
5860}
5961
@@ -63,7 +65,7 @@ type onlineAccounts struct {
6365 dbs db.Pair
6466
6567 // Prepared SQL statements for fast accounts DB lookups.
66- accountsq * onlineAccountsDbQueries
68+ accountsq store. OnlineAccountsReader
6769
6870 // cachedDBRoundOnline is always exactly tracker DB round (and therefore, onlineAccountsRound()),
6971 // cached to use in lookup functions
@@ -172,7 +174,7 @@ func (ao *onlineAccounts) initializeFromDisk(l ledgerForTracker, lastBalancesRou
172174 return
173175 }
174176
175- ao .accountsq , err = onlineAccountsInitDbQueries (ao .dbs .Rdb .Handle )
177+ ao .accountsq , err = store . OnlineAccountsInitDbQueries (ao .dbs .Rdb .Handle )
176178 if err != nil {
177179 return
178180 }
@@ -193,7 +195,7 @@ func (ao *onlineAccounts) latest() basics.Round {
193195// close closes the accountUpdates, waiting for all the child go-routine to complete
194196func (ao * onlineAccounts ) close () {
195197 if ao .accountsq != nil {
196- ao .accountsq .close ()
198+ ao .accountsq .Close ()
197199 ao .accountsq = nil
198200 }
199201
@@ -463,10 +465,10 @@ func (ao *onlineAccounts) postCommit(ctx context.Context, dcc *deferredCommitCon
463465 for _ , persistedAcct := range dcc .updatedPersistedOnlineAccounts {
464466 ao .baseOnlineAccounts .write (persistedAcct )
465467 ao .onlineAccountsCache .writeFrontIfExist (
466- persistedAcct .addr ,
468+ persistedAcct .Addr ,
467469 cachedOnlineAccount {
468- baseOnlineAccountData : persistedAcct .accountData ,
469- updRound : persistedAcct .updRound ,
470+ BaseOnlineAccountData : persistedAcct .AccountData ,
471+ updRound : persistedAcct .UpdRound ,
470472 })
471473 }
472474
@@ -526,7 +528,7 @@ func (ao *onlineAccounts) onlineTotalsEx(rnd basics.Round) (basics.MicroAlgos, e
526528 ao .log .Errorf ("onlineTotalsImpl error: %v" , err )
527529 }
528530
529- totalsOnline , err = ao .accountsq .lookupOnlineTotalsHistory (rnd )
531+ totalsOnline , err = ao .accountsq .LookupOnlineTotalsHistory (rnd )
530532 return totalsOnline , err
531533}
532534
@@ -615,7 +617,7 @@ func (ao *onlineAccounts) lookupOnlineAccountData(rnd basics.Round, addr basics.
615617 var paramsOffset uint64
616618 var rewardsProto config.ConsensusParams
617619 var rewardsLevel uint64
618- var persistedData persistedOnlineAccountData
620+ var persistedData store. PersistedOnlineAccountData
619621
620622 // the loop serves retrying logic if the database advanced while
621623 // the function was analyzing deltas or caches.
@@ -678,8 +680,8 @@ func (ao *onlineAccounts) lookupOnlineAccountData(rnd basics.Round, addr basics.
678680 // As an optimization, we avoid creating
679681 // a separate transaction here, and directly use a prepared SQL query
680682 // against the database.
681- persistedData , err = ao .accountsq .lookupOnline (addr , rnd )
682- if err != nil || persistedData .rowid == 0 {
683+ persistedData , err = ao .accountsq .LookupOnline (addr , rnd )
684+ if err != nil || persistedData .Rowid == 0 {
683685 // no such online account, return empty
684686 return ledgercore.OnlineAccountData {}, err
685687 }
@@ -694,7 +696,7 @@ func (ao *onlineAccounts) lookupOnlineAccountData(rnd basics.Round, addr basics.
694696 // * if commitRound deletes some history after, the cache has additional entries and updRound comparison gets a right value
695697 // 2. after commitRound but before postCommit => OK, read full history, ignore the update from postCommit in writeFront's updRound comparison
696698 // 3. after postCommit => OK, postCommit does not add new entry with writeFrontIfExist, but here all the full history is loaded
697- persistedDataHistory , validThrough , err := ao .accountsq .lookupOnlineHistory (addr )
699+ persistedDataHistory , validThrough , err := ao .accountsq .LookupOnlineHistory (addr )
698700 if err != nil || len (persistedDataHistory ) == 0 {
699701 return ledgercore.OnlineAccountData {}, err
700702 }
@@ -715,21 +717,21 @@ func (ao *onlineAccounts) lookupOnlineAccountData(rnd basics.Round, addr basics.
715717 } else {
716718 for _ , data := range persistedDataHistory {
717719 written := ao .onlineAccountsCache .writeFront (
718- data .addr ,
720+ data .Addr ,
719721 cachedOnlineAccount {
720- baseOnlineAccountData : data .accountData ,
721- updRound : data .updRound ,
722+ BaseOnlineAccountData : data .AccountData ,
723+ updRound : data .UpdRound ,
722724 })
723725 if ! written {
724726 ao .accountsMu .Unlock ()
725- err = fmt .Errorf ("failed to write history of acct %s for round %d into online accounts cache" , data .addr .String (), data .updRound )
727+ err = fmt .Errorf ("failed to write history of acct %s for round %d into online accounts cache" , data .Addr .String (), data .UpdRound )
726728 return ledgercore.OnlineAccountData {}, err
727729 }
728730 }
729731 ao .log .Info ("inserted new item to onlineAccountsCache" )
730732 }
731733 ao .accountsMu .Unlock ()
732- return persistedData .accountData .GetOnlineAccountData (rewardsProto , rewardsLevel ), nil
734+ return persistedData .AccountData .GetOnlineAccountData (rewardsProto , rewardsLevel ), nil
733735 }
734736 // case 3.3: retry (for loop iterates and queries again)
735737 ao .accountsMu .Unlock ()
0 commit comments