summaryrefslogtreecommitdiff
path: root/ledger/accountdb.go
diff options
context:
space:
mode:
Diffstat (limited to 'ledger/accountdb.go')
-rw-r--r--ledger/accountdb.go76
1 files changed, 19 insertions, 57 deletions
diff --git a/ledger/accountdb.go b/ledger/accountdb.go
index 1a8b6f973..2b12b42c2 100644
--- a/ledger/accountdb.go
+++ b/ledger/accountdb.go
@@ -682,8 +682,8 @@ func removeEmptyAccountData(tx *sql.Tx, queryAddresses bool) (num int64, address
// the full AccountData because we need to store a large number of these
// in memory (say, 1M), and storing that many AccountData could easily
// cause us to run out of memory.
-func accountDataToOnline(address basics.Address, ad *basics.AccountData, proto config.ConsensusParams) *onlineAccount {
- return &onlineAccount{
+func accountDataToOnline(address basics.Address, ad *basics.AccountData, proto config.ConsensusParams) *ledgercore.OnlineAccount {
+ return &ledgercore.OnlineAccount{
Address: address,
MicroAlgos: ad.MicroAlgos,
RewardsBase: ad.RewardsBase,
@@ -711,14 +711,18 @@ func accountsReset(tx *sql.Tx) error {
return err
}
-// accountsRound returns the tracker balances round number, and the round of the hash tree
-// if the hash of the tree doesn't exists, it returns zero.
-func accountsRound(tx *sql.Tx) (rnd basics.Round, hashrnd basics.Round, err error) {
+// accountsRound returns the tracker balances round number
+func accountsRound(tx *sql.Tx) (rnd basics.Round, err error) {
err = tx.QueryRow("SELECT rnd FROM acctrounds WHERE id='acctbase'").Scan(&rnd)
if err != nil {
return
}
+ return
+}
+// accountsHashRound returns the round of the hash tree
+// if the hash of the tree doesn't exists, it returns zero.
+func accountsHashRound(tx *sql.Tx) (hashrnd basics.Round, err error) {
err = tx.QueryRow("SELECT rnd FROM acctrounds WHERE id='hashbase'").Scan(&hashrnd)
if err == sql.ErrNoRows {
hashrnd = basics.Round(0)
@@ -727,7 +731,7 @@ func accountsRound(tx *sql.Tx) (rnd basics.Round, hashrnd basics.Round, err erro
return
}
-func accountsDbInit(r db.Queryable, w db.Queryable) (*accountsDbQueries, error) {
+func accountsInitDbQueries(r db.Queryable, w db.Queryable) (*accountsDbQueries, error) {
var err error
qs := &accountsDbQueries{}
@@ -1009,14 +1013,14 @@ func (qs *accountsDbQueries) close() {
//
// Note that this does not check if the accounts have a vote key valid for any
// particular round (past, present, or future).
-func accountsOnlineTop(tx *sql.Tx, offset, n uint64, proto config.ConsensusParams) (map[basics.Address]*onlineAccount, error) {
+func accountsOnlineTop(tx *sql.Tx, offset, n uint64, proto config.ConsensusParams) (map[basics.Address]*ledgercore.OnlineAccount, error) {
rows, err := tx.Query("SELECT address, data FROM accountbase WHERE normalizedonlinebalance>0 ORDER BY normalizedonlinebalance DESC, address DESC LIMIT ? OFFSET ?", n, offset)
if err != nil {
return nil, err
}
defer rows.Close()
- res := make(map[basics.Address]*onlineAccount, n)
+ res := make(map[basics.Address]*ledgercore.OnlineAccount, n)
for rows.Next() {
var addrbuf []byte
var buf []byte
@@ -1181,54 +1185,8 @@ func accountsNewRound(tx *sql.Tx, updates compactAccountDeltas, creatables map[b
return
}
-// totalsNewRounds updates the accountsTotals by applying series of round changes
-func totalsNewRounds(tx *sql.Tx, updates []ledgercore.AccountDeltas, compactUpdates compactAccountDeltas, accountTotals []ledgercore.AccountTotals, proto config.ConsensusParams) (err error) {
- var ot basics.OverflowTracker
- totals, err := accountsTotals(tx, false)
- if err != nil {
- return
- }
-
- // copy the updates base account map, since we don't want to modify the input map.
- accounts := make(map[basics.Address]basics.AccountData, compactUpdates.len())
- for i := 0; i < compactUpdates.len(); i++ {
- addr, acctData := compactUpdates.getByIdx(i)
- accounts[addr] = acctData.old.accountData
- }
-
- for i := 0; i < len(updates); i++ {
- totals.ApplyRewards(accountTotals[i].RewardsLevel, &ot)
-
- for j := 0; j < updates[i].Len(); j++ {
- addr, data := updates[i].GetByIdx(j)
-
- if oldAccountData, has := accounts[addr]; has {
- totals.DelAccount(proto, oldAccountData, &ot)
- } else {
- err = fmt.Errorf("missing old account data")
- return
- }
-
- totals.AddAccount(proto, data, &ot)
- accounts[addr] = data
- }
- }
-
- if ot.Overflowed {
- err = fmt.Errorf("overflow computing totals")
- return
- }
-
- err = accountsPutTotals(tx, totals, false)
- if err != nil {
- return
- }
-
- return
-}
-
// updates the round number associated with the current account data.
-func updateAccountsRound(tx *sql.Tx, rnd basics.Round, hashRound basics.Round) (err error) {
+func updateAccountsRound(tx *sql.Tx, rnd basics.Round) (err error) {
res, err := tx.Exec("UPDATE acctrounds SET rnd=? WHERE id='acctbase' AND rnd<?", rnd, rnd)
if err != nil {
return
@@ -1254,13 +1212,17 @@ func updateAccountsRound(tx *sql.Tx, rnd basics.Round, hashRound basics.Round) (
return
}
}
+ return
+}
- res, err = tx.Exec("INSERT OR REPLACE INTO acctrounds(id,rnd) VALUES('hashbase',?)", hashRound)
+// updates the round number associated with the hash of current account data.
+func updateAccountsHashRound(tx *sql.Tx, hashRound basics.Round) (err error) {
+ res, err := tx.Exec("INSERT OR REPLACE INTO acctrounds(id,rnd) VALUES('hashbase',?)", hashRound)
if err != nil {
return
}
- aff, err = res.RowsAffected()
+ aff, err := res.RowsAffected()
if err != nil {
return
}